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

Raise warning in case a SSLStream method returns none because no handshake was established #743

Merged
merged 15 commits into from
Oct 29, 2018

Conversation

jxub
Copy link
Contributor

@jxub jxub commented Oct 20, 2018

References the issue #735
The problem could be extended to the following methods in SSLStream which return none in case the handshake is not established:

These methods raise now a NoHandshakeError if the handshake wasn't established. Note that they still return None in the cases when:

  • If the other party does not support ALPN/NPN.
  • If SSLContext.set_alpn_protocols() or SSLContext.set_npn_protocols() was not called.

and in the case of get_channel_binding in the case when there is no connection.

@codecov
Copy link

codecov bot commented Oct 20, 2018

Codecov Report

Merging #743 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #743      +/-   ##
==========================================
+ Coverage   99.34%   99.34%   +<.01%     
==========================================
  Files          96       96              
  Lines       11577    11625      +48     
  Branches      827      828       +1     
==========================================
+ Hits        11501    11549      +48     
  Misses         56       56              
  Partials       20       20
Impacted Files Coverage Δ
trio/_core/__init__.py 100% <ø> (ø) ⬆️
trio/__init__.py 100% <ø> (ø) ⬆️
trio/_ssl.py 100% <100%> (ø) ⬆️
trio/tests/test_ssl.py 100% <100%> (ø) ⬆️
trio/_core/_exceptions.py 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 106991f...32028b7. Read the comment docs.


with pytest.raises(NoHandshakeError):
client.selected_alpn_protocol()
server.selected_alpn_protocol()
Copy link
Contributor

@sorcio sorcio Oct 22, 2018

Choose a reason for hiding this comment

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

In order to make the test actually cover both lines, you need to have two separate pytest.raises() blocks. Otherwise what happens is that either the block exits at the first line because it raises (and it never executes the second one); or the first line doesn't raise, but you won't see that because the second one does raise.

Suggested change
server.selected_alpn_protocol()
with pytest.raises(NoHandshakeError):
server.selected_alpn_protocol()

The same applies to the other similar tests. This is the reason why codecov is complaining, and if you fix it (assuming the tests pass) you will get full coverage again :)

Copy link
Contributor Author

@jxub jxub Oct 23, 2018

Choose a reason for hiding this comment

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

I see, I'll fix it. Thanks for your help with that!

@jxub
Copy link
Contributor Author

jxub commented Oct 23, 2018

@sorcio Just fixed the tests, and they seem to pass locally. Let's see what'll say codecov now :)

@sorcio
Copy link
Contributor

sorcio commented Oct 23, 2018

@jxub fantastic, thank you! :) Since this change is affecting public API I need to bother you a bit more for a couple small tasks:

I'm not sure what the best strategy to document this is. It could go in the docstring for SSLStream but it's easy to miss. You might need to explicitly define those three methods and add a docstring describing the behavior. I'm invoking @njsmith for a suggestion here.

@jxub
Copy link
Contributor Author

jxub commented Oct 24, 2018

I added the things you suggested, both the documentation and the newsfragments entry, but I'll await any pending suggestions from both you @sorcio as well as @njsmith, as this documentation might not be enough in behaviour that varies from the stdlib one.

@jxub
Copy link
Contributor Author

jxub commented Oct 25, 2018

I'm gonna look at the failing checks asap.

@Fuyukai
Copy link
Member

Fuyukai commented Oct 25, 2018

Failed build seems to just be a Travis backend hiccough, I restarted the job.

Copy link
Member

@Fuyukai Fuyukai left a comment

Choose a reason for hiding this comment

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

This looks good to me.

@Fuyukai Fuyukai merged commit 63c9399 into python-trio:master Oct 29, 2018
@jxub
Copy link
Contributor Author

jxub commented Oct 29, 2018

Yay! 😍 Thanks.

@njsmith
Copy link
Member

njsmith commented Oct 30, 2018

Thanks, and welcome! 🎉 🎂 And, no pressure, but if you'd like to keep contributing then we'd love to have you, so I'm sending you a github invite now. You can read more about this in our contributing documentation.

njsmith added a commit to njsmith/trio that referenced this pull request Dec 22, 2018
- Move the exception from the main namespace into trio.ssl, since it's
  ssl-specific, and rename from NoHandshakeError → NeedHandshakeError
- Add the exception to the docs
- In the newsfragment, use the original issue number, and shorten
- Smooth out the docs a bit
- Add some more methods that require handshakes to the list
@njsmith njsmith mentioned this pull request Dec 22, 2018
njsmith added a commit that referenced this pull request Dec 29, 2018
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