-
-
Notifications
You must be signed in to change notification settings - Fork 90
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
Add some framework for SSL tests and refactor makefile a bit #109
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
||
def __init__(self, sock, mode='r', bufsize=io.DEFAULT_BUFFER_SIZE): | ||
"""Initialize socket stream reader.""" | ||
super().__init__(socket.SocketIO(sock, mode), bufsize) |
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.
(This is always evaluated under Python 3, so no need to use Python 2 compatible super()
syntax)
Codecov Report
@@ Coverage Diff @@
## master #109 +/- ##
==========================================
+ Coverage 70.39% 74.13% +3.74%
==========================================
Files 20 21 +1
Lines 3219 3271 +52
==========================================
+ Hits 2266 2425 +159
+ Misses 953 846 -107 |
93241cf
to
3faa039
Compare
Makefile related stuff: https://github.com/urllib3/urllib3/blob/master/src/urllib3/contrib/securetransport.py#L293 |
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 looked some. It looks reasonable from a high level. However, I am not sufficiently versed in the SSL or stream details of cheroot.
Also, I don't completely understand the implications of using socket.SocketIO versus socket._fileobject
@jeffvanvoorst take into account that there's a lot of very old code, which we sometimes have trouble understanding completely. Among that, there's lots of backwards compatibility hacks. AFAIR |
Alright, it looks like @jaraco I think it'd be a good idea to adopt it. What do you think? I'd simplify our compatibility layers a lot! |
I've evaluated python-future in the past, and it seems like a pretty robust solution. The fact that it monkey patches the standard library has caused me problems in the past when I would be testing for Python 2/3 compatibility in an environment that had python-future, my results were influenced by the presence of that library, which left me with a slight distaste for it. But in general, I've seen good things come from it. My main reluctance stems from our existing use of six. I imagine the two can interoperate, though it's not mentioned in the narrative on the topic. However, given the potential benefits (more single-code base aligned to Python 3), I'm very much in favor, especially if this breathes some extra bit of life into the last Python 2 releases. |
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.
Overall, this all seems fine. If python-future can make the changes even more unified, I'd recommend going that route. The only change I disagree with is the copy/paste of SSL_fileobject._safe_call
. The rest is fine.
if self._refcount < 0: | ||
self.close() | ||
else: | ||
self._refcount -= 1 |
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.
This refcounting seems wrong to me. I would expect a refcount to be set to 1 when there's one object referencing it, and 0 when there are no objects referencing it. (not 0 when there's one, and -1 when there's none).
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 stole that from https://github.com/urllib3/urllib3/blob/e38125dbdb9db46ad3c3f3a9b507994fbfe34499/src/urllib3/contrib/securetransport.py#L670-L677
and it still doesn't seem to help. I'd postpone solving this for now.
@@ -200,4 +199,5 @@ def env_dn_dict(self, env_prefix, cert_value): | |||
|
|||
def makefile(self, sock, mode='r', bufsize=DEFAULT_BUFFER_SIZE): | |||
"""Return socket file object.""" | |||
return MakeFile(sock, mode, bufsize) | |||
cls = StreamReader if 'r' in mode else StreamWriter |
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.
It feels like this logic duplicates logic in makefile.MakeFile (Python 3 version). Ideally, this decision would be made in one place. Though, if one of these methods is deprecated, that's fine.
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 decided to delay this refactoring. I also don't like the inability to remove MakeFile
from cheroot.server
module completely...
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.
Oh, and I'm also trying hard to decouple those things.
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.
Which might mean removing makefile in lots of places.
cheroot/ssl/pyopenssl.py
Outdated
ssl_timeout = 3 | ||
ssl_retry = .01 | ||
|
||
def _safe_call(self, is_reader, call, *args, **kwargs): |
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.
This function seems to add a lot of repetition. I suggest extracting the common aspects of _safe_call into a mix-in for each of these SSLFileobject classes.
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.
Yeah, I just did this quick and dirty, I'm also in favor of having a mixin. Just didn't get to actually doing it.
@jaraco does it run monkey-patching by default? I thought it should be an explicit call for that. |
Perhaps not. I guess what I observed was that
So in that case, one does have to explicitly So my fears are assuaged (and not justified), so let's try it. |
I should also say - until this example, I've found no instances where use of |
Yeah, the most interesting thing to me is its collection of backports, unfortunately, this is not fully documented. I've found |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
So while testing
Which probably means that we need to standardize to writing bytes only there. Which is why I'm going to postpone trying to make use of this backport till a separate PR. |
@@ -87,7 +87,7 @@ | |||
from . import errors, __version__ | |||
from ._compat import bton, ntou | |||
from .workers import threadpool | |||
from .makefile import MakeFile | |||
from .makefile import MakeFile, StreamWriter |
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.
(It annoys me that I've failed to remove MakeFile
at all, but that's all I can do for now)
'sock_shutdown', 'get_peer_certificate', 'want_read', | ||
'want_write', 'set_connect_state', 'set_accept_state', | ||
'connect_ex', 'sendall', 'settimeout', 'gettimeout'): | ||
exec("""def %s(self, *args): |
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 didn't like that it was exec
ing things
69dfb97
to
2eb2abe
Compare
This comment has been minimized.
This comment has been minimized.
2eb2abe
to
7b1de00
Compare
This comment has been minimized.
This comment has been minimized.
Ref #95 In order for it to work now: * Mark pyopenssl adapter as xfail under Python 3 * Patch builtin SSL adapter to not load cert chain
Done this where possible for now
7b1de00
to
8aca957
Compare
This comment has been minimized.
This comment has been minimized.
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.
Looks good to me. Let's give it a try.
What kind of change does this PR introduce?
What is the related issue number (starting with
#
)Cannot import cheroot.ssl.pyopenssl #6 (
cheroot.ssl.pyopenssl
is now importable from under Python 3, but still doesn't work)Drop in integration testing for SSL/TLS stuff #95 (origins of testing SSL, added
trustme
for generation of CA and certs in runtime)What is the current behavior? (You can also link to an open issue here)
Mess in
cheroot.makefile
,cheroot.ssl.pyopenssl
import fails under Python 3 (trying to inherit class from function 🙈), no SSL tests, no way to generate test certificates.What is the new behavior (if this is a feature change)?
New test for adapters in the wild, makefile has separately importable
StreamWriter
andStreamReader
,Other information:
https://gitter.im/cherrypy/cherrypy?at=5b871411c2bd5d117aefa6db
Checklist:
and description in grammatically correct, complete sentences
This change is