-
Notifications
You must be signed in to change notification settings - Fork 96
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
allow to specify --response-code for 3xx codes without specifying -r or --response-code option #139
base: master
Are you sure you want to change the base?
Conversation
Thanks for your contribution to Sensu plugins! Without people like you submitting PRs we couldn't run the project. I will review it shortly. |
It's been a while since I looked through this code and I seem to recall that explicitly requiring |
When I have some more time (tonight or tomorrow evening) I will take a closer look at the code to see if this is something we want to support. |
My take on this was that if I set the expected response code explicitly then I already know what I'm doing like when setting it to e.g. 503 or 404 and why should 3xx any different? (I have all 3 cases in my environment) But I definitely get your point to avoid counting a redirect as success by accident. |
To avoid any confusion or misunderstanding here an example of the current behaviour and thus why I created this PR: Server returns 201: Server returns 503: Server returns 404: Server returns 301: |
The very nature of 2xx, 3xx, 4xx, and 5xx status responses are very different and pretending that these should all be handled the same does not make sense to me. A 3xx indicates that it is a redirect of some kind, what is the value of asserting that there is a redirect if you don't check what its link location is? Even still the
Due to the specific and intentional logic around redirects it still triggers a warning without the
I get the expected response with
That being said that's absolutely true for non redirects:
I do think that is a bug but realistically the thing about exposing regex to the cli is that these kind of hacks will probably always be possible to write a regex to "trick" the program into doing something "incorrect" that feature was implemented with the best of intentions. We can probably fix this up fairly easy for this edge case but in general it will be hard to save the user from themselves.
I think I could be talked into allowing the logic to allow a special case when response code is specified and matches a 3xx to make it BTW response code offers full regex support so you can do more complicated conditions and highlights the difficulty of protecting people from themselves:
I won't pretend this check is perfect (the code could definitely use some cleanup) but the behavior I see [1] matches my expectations as a user just reading the descriptions on the arguments. I can see why this might not match your initial expectations but we want to be very careful about trying to divine what people will use this for, hence the explicit argument around redirects. This offers max flexibility and takes the secure by default approach and allows users to opt out of security in multiple ways depending on what they are trying to accomplish. Perhaps adding some more documentation to the readme around this would help?
[1]: other than specifying the response code an empty string, which makes perfect sense I just did not consider that edge case when I reviewed #99 which added regex support for response code. Given that this defaults to a reasonable regex and you can always write a nonsensical regex I am not even sure I consider this a bug and more of a potential to improve the ux around useless matches. |
I spent some more time looking at the code and I think it honestly needs an overhaul. I think we can give what you want but it requires changes to other sections of the code to accomplish this without some side effects. I think we inspect the desired response code and if there is a |
I started a refactor of this logic and I am not sure we have a good/safe path forward without dropping support for regex, or I should say without full regex support that is. We could potentially still support automatically matching the last 2 values so you could say specify 3 which would match |
@ydkn any chance you have had a chance to look at what I have and see if this solves your issue? |
@majormoses sorry for the late response. It took me a while to test your changes. First of all, thank you very much for the work you put into this! I found a few problems:
I also changed the Now the response_code config option is always checked and to be backward compatible I changed the default regexp to include 3xx codes. Another thought would be to check pattern, negpattern and sha256checksum regardless of the response code - currently this is only checked against 2xx codes... why not do it for all responses? But this a completely different topic. You can take a look at my proposed changes here: |
@ydkn sorry I must have missed the notification and it fell off my radar. If this is still something you want to work on, I will put aside some time to help. If thats the case I will rebase my branch and take a closer look at the changes to see why the two issues you raised are happening. I do like your changes on top of the work I started, there were definitely some ugly bits there.
Ya that makes sense, if you can raise an issue we can discuss it further. Please ping me on the issue. |
allow to specify
--response-code
for 3xx codes without specifying-r
or--redirect-to
Pull Request Checklist
General
[ x] Update Changelog following the conventions laid out here
[ x] RuboCop passes
[x ] Existing tests pass
Purpose
Currently if you run
check-http.rb
with--response-code
for a 3xx response code e.g.301
and do not specify-r
or--redirect-to
the check raises a warning instead of the expected behaviour of passing the check. This PR will fix this by not returning a warning if a 3xx response code was returned by the server and--response-code
is set.