Skip to content
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

Adding nginx_ssl_verify as a config option for nginx #1782

Merged
merged 1 commit into from
Jul 27, 2015

Conversation

JohnLZeller
Copy link
Contributor

Adding an 'nginx_ssl_verify' option to the nginx yaml config. This allows for setting the verify option in requests.get() when calling the url set by 'nginx_status_url'. The nginx_ssl_verify option defaults to True, staying consistent with requests.get(), which also defaults verify to True.

Working on a simple integration test now.

@JohnLZeller
Copy link
Contributor Author

I cleaned up the nginx tests with some comments, and separated 2 different tests for clarity. Added 'nginx_ssl_verify' to the self.config for the test. This doesn't actually test functionality with the verify option for requests.get(). To do that will require an https endpoint on localhost to run a request against, however this is testing the requests submodule, and not our code; therefore, I think an ssl_verify check here is unnecessary. The important part is that our config gets picked up, and defaults correctly, which this test, and the yaml config checks already do.

@remh
Copy link

remh commented Jul 22, 2015

@elafarge can you review please ?

},
{
'nginx_status_url': 'http://localhost:44441/nginx_status/',
'tags': ['second'],
'nginx_ssl_verify': True,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of these tests actually are made against an https:// url, nor do they flip the flag from True to False.
Is that expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, actually I referenced that in my comment above in this issue.

I basically confirm that this doesn't actually test functionality with the verify option for requests.get(), and that to do that would require an https endpoint on localhost to run a request against. However this is testing the requests submodule, and not our code, so I think an ssl_verify check here is unnecessary. The important part is that our config gets picked up.

But, I'm all for total coverage, so if you think adding this explicitly to the test is wise, then that's no problem. Is there an existing https endpoint on localhost that the test suite can access?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that I know of.

The nginx config we use in our CI test suite is located here : https://github.com/DataDog/dd-agent/blob/master/ci/resources/nginx/nginx.conf .

If you do want to test that (it doesn't seem very useful indeed... but almost no test does until it breaks :) ) you'll have to create an HTTPS VirtualHost in Nginx in the conf file above and enable status on it.

Oh and I don't think there's a need to enable nginx_ssl_verify for all the tests on http endpoints.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree, and it's doubly useless in this test, since True is the default :)
My thought was that if it was at least added in there, it wouldn't be forgotten :P

@miketheman
Copy link
Contributor

Cool stuff.
Should the toggle name nginx_ssl_verify be changed? It's already implicit that it's nginx due to being in nginx.yaml file, and I think the terminology should use validation vs verify.
Something like ssl_validation: True/False makes more sense to me.

@JohnLZeller
Copy link
Contributor Author

Yeah, those changes are fine. I was going for consistency of naming conventions, and noticed that the status url was called nginx_status_url. But, I agree, nginx is a bit redundant :)

I'll go with chaning to ssl_validation

@JohnLZeller
Copy link
Contributor Author

Okay, what do we think about the updated tests now?
@miketheman @elafarge

nginx.check(self.config['instances'][4])
except Exception as e:
pass
self.assertEquals(type(e), requests.exceptions.SSLError)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be possible to use assertRaises to make it a little cleaner (to avoid having a pass and using e that isn't really supposed to be defined in this block ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bah! Yeah, you're totally right, that'd be a lot cleaner.

@elafarge
Copy link
Contributor

Awesome job ! Congrats! Apart from the small notice I wrote concerning assertRaises everything looks great.

@remh
Copy link

remh commented Jul 27, 2015

@JohnLZeller tests are failing on

======================================================================
ERROR: test_nginx_ssl_validation_enabled (tests.checks.integration.test_nginx.TestNginx)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/DataDog/dd-agent/tests/checks/integration/test_nginx.py", line 82, in test_nginx_ssl_validation_enabled
    with self.assertRaises(requests.exceptions.SSLError):
TypeError: failUnlessRaises() takes at least 3 arguments (2 given)

@JohnLZeller
Copy link
Contributor Author

Ah, yeah. Turns out that the unittest submodule added the ability to use assertRaises() as a context manager only in 2.7, not 2.6. So I reverted the use back to a state that should work for both.

@elafarge
Copy link
Contributor

My bad, I didn't realize that when I suggested to use assertRaises :(

@JohnLZeller
Copy link
Contributor Author

It's okay :) Still using it, just not as a context manager.

@JohnLZeller
Copy link
Contributor Author

@remh should be g2g now

@remh
Copy link

remh commented Jul 27, 2015

Nice, can you squash your commits into one please ?

@JohnLZeller JohnLZeller force-pushed the zeller/nginx-ssl-verify branch from 6390117 to df50462 Compare July 27, 2015 17:55
@JohnLZeller
Copy link
Contributor Author

Squashed 👍

@remh
Copy link

remh commented Jul 27, 2015

👍

remh pushed a commit that referenced this pull request Jul 27, 2015
Adding nginx_ssl_verify as a config option for nginx
@remh remh merged commit aef931c into master Jul 27, 2015
@miketheman
Copy link
Contributor

💃 👯 💃 🍰 🎉 👯

@LeoCavaille LeoCavaille deleted the zeller/nginx-ssl-verify branch August 11, 2015 18:59
jslatts pushed a commit to jslatts/dd-agent that referenced this pull request Nov 18, 2015
- Same as flag added for nginx in issue DataDog#1782
jslatts pushed a commit to jslatts/dd-agent that referenced this pull request Nov 18, 2015
- Same as flag added for nginx in issue DataDog#1782
jslatts pushed a commit to jslatts/dd-agent that referenced this pull request Nov 18, 2015
- Same as flag added for nginx in issue DataDog#1782
jslatts pushed a commit to jslatts/dd-agent that referenced this pull request Dec 17, 2015
- Same as flag added for nginx in issue DataDog#1782
jslatts pushed a commit to jslatts/dd-agent that referenced this pull request Jan 4, 2016
- Same as flag added for nginx in issue DataDog#1782
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants