Bug #21925
openImporting invalid job templates shows undefined method `valid?' for nil:NilClass
Description
Cloned from https://bugzilla.redhat.com/show_bug.cgi?id=1524131
Description of problem: Attempting to import invalid job templates shows undefined method `valid?' for nil:NilClass and request completed 500 Internal Server Error.
Version-Release number of selected component (if applicable): Satellite 6.3 snap 27
How reproducible: always
Steps to Reproduce:
1. Navigate to host -> job templates
2. Try to import invalid job template file
Actual results:
UI showed Oops, we're sorry but something went wrong undefined method `valid?' for nil:NilClass and production.log showed
2017-12-10 04:52:04 afac570b [app] [I] Started POST "/job_templates/import" for IP at 2017-12-10 04:52:04 -0500
2017-12-10 04:52:04 afac570b [app] [I] Processing by JobTemplatesController#import as HTML
2017-12-10 04:52:04 afac570b [app] [I] Parameters: {"utf8"=>"✓", "authenticity_token"=>"9jAVhNK3OGCUTWZ4Alru+kjX0FN5uFX/mA3PbwSsjm+6evu99DCEFJxd6
On3qHdBt/+ahUzoHT17ljC9AJnjBQ==", "imported_template"=>{"template"=>#<ActionDispatch::Http::UploadedFile:0x00000008328360 @tempfile=#<Tempfile:/tmp
/RackMultipart20171210-31078-4rxj7p.txt>, @original_filename="invalid_file.txt", @content_type="text/plain", @headers="Content-Disposition:
form-data; name=\"imported_template[template]\"; filename=\"invalid_file.txt\"\r\nContent-Type: text/plain\r\n">, "overwrite"=>"0"}, "comm
it"=>"Submit"}
2017-12-10 04:52:05 afac570b [app] [I] Current user: admin (administrator)
2017-12-10 04:52:05 afac570b [app] [W] Action failed
| NoMethodError: undefined method `valid?' for nil:NilClass
| /opt/theforeman/tfm/root/usr/share/gems/gems/foreman_remote_execution-1.3.7/app/controllers/job_templates_controller.rb:38:in `import'
| /opt/rh/rh-ror42/root/usr/share/gems/gems/actionpack-4.2.6/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
| /opt/rh/rh-ror42/root/usr/share/gems/gems/actionpack-4.2.6/lib/abstract_controller/base.rb:198:in `process_action'
| /opt/rh/rh-ror42/root/usr/share/gems/gems/actionpack-4.2.6/lib/action_controller/metal/rendering.rb:10:in `process_action'
| /opt/rh/rh-ror42/root/usr/share/gems/gems/actionpack-4.2.6/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
| /opt/rh/rh-ror42/root/usr/share/gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:117:in `call'
| /opt/rh/rh-ror42/root/usr/share/gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
| /opt/rh/rh-ror42/root/usr/share/gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:505:in `call'
| /opt/rh/rh-ror42/root/usr/share/gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:498:in `block (2 levels) in around'
| /opt/rh/rh-ror42/root/usr/share/gems/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:313:in `block (2 levels) in halting'
| /usr/share/foreman/app/controllers/concerns/application_shared.rb:15:in `set_timezone'
Expected results: Error should get handled.
Additional info:
Updated by Adam Ruzicka over 7 years ago
- Category set to Foreman
Invalid job template can be test.erb without any data or having only data
<%#
name: example
%>
<% advisories = input(:errata).split(',').map { |e| "--advisory=#{e}" }.join(' ') %>
<%= render_template('Package Action - SSH Default', :action => 'update-minimal', :package => advisories) %>