-
Notifications
You must be signed in to change notification settings - Fork 981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #37341 - catch exception if host parameter can not be rendered #10122
base: develop
Are you sure you want to change the base?
Conversation
[test katello] |
[test unit] |
Looks like, the bug was introduced with c8236d2 @nadjaheitmann - maybe you want tor review this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sbernhard Is it possible to adapt/add tests to catch this error
722ab7d
to
937967a
Compare
4e12efe
to
7633793
Compare
if host.params.has_key? "#{last_report.origin.downcase}_interval" | ||
interval = host.params["#{last_report.origin.downcase}_interval"] | ||
end | ||
rescue NameError, Safemode::SecurityError, Safemode::NoMethodError => exception |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I like catching these exceptions here in the model layer. A user doesn't have access to the logs so they don't know their parameter is silently ignored.
Implementation wise I'd really want it to be:
def reported_origin_interval
return unless last_report&.origin
name = "#{last_report.origin.downcase}_interval"
host.params.fetch(name) { Setting[name.to_sym] }
end
Looking at the code I think host.params
will render all the parameters, so just calling that should be enough to trigger it an exception.
Thinking about solving it at a deeper level: should parameters be rendered before saving? Can that reliably work? It may still not be enough.
Perhaps HostParams
needs a safe_params
that ignores any invalid ERB. The reason I suggest this is that we use params in more places so I suspect there are more ways this bug could surface.
See https://projects.theforeman.org/issues/37341#note-1 for the reproducer
rescue blocks catches exception if safemode is 'on' and if 'off'