-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
Empty or corrupt files detection and error + code cleanup #96
Conversation
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 looks mostly sensible to me. I do wish git had more useful diffs for when a big chunk of code has just been moved without modifications.
re: the split_pems test, you could just add it to its own test case class, without any of the mixins. What was your other idea?
simp_le.py
Outdated
try: | ||
key = OpenSSL.crypto.load_privatekey(self.typ, data) | ||
except OpenSSL.crypto.Error: | ||
raise Error("simp_le couldn't load a key from {0}, the " |
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.
Grammar issue: you want either a period or a semicolon here, not a comma.
simp_le.py
Outdated
return self.Data(account_key=False, key=False, cert=False, chain=True) | ||
|
||
def load_from_content(self, content): | ||
pems = [pem for pem in self.split_pems(content)] |
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.
Could just do list(self.split_pems(content))
simp_le.py
Outdated
def load_from_content(self, content): | ||
pems = [pem for pem in self.split_pems(content)] | ||
if len(pems) < 2: | ||
raise Error("Not enough PEM encoded messages were found on {0}, " |
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.
Grammar:
- s/on/in/
- Use a semicolon, not a comma.
Same thing the other places this message shows up.
Yes, this is the other code I tested:
That's longer but it makes more sense to me than performing this exact test five more times. Do you prefer that too ? |
If you make split pems a stand alone function, you can inherit just from unittest.TestCase, so you don't need the stub methods. I think this makes a bit more sense anyway, since it doesn't need self for anything. |
I do agree with the fact that making |
Might be cleaner to get the structure by splitting things into files, but that doesn't need to happen now. You could also make it a static method and call it as OpenSSLIOPlugin.spit_pems(), rather than self. |
001d80a
to
e4ed2cb
Compare
e4ed2cb
to
653be58
Compare
I did the requested changes and made |
653be58
to
383d4b2
Compare
note: there is nothing similar yet for the |
Fix for raising-format-tuple(W0715) introduced in Pylint 1.8.0
383d4b2
to
92d9424
Compare
Okay, looks good to me, merging. |
This a first take at what's been discussed on #23
730831b just reorder plugins and unit test classes to something a bit more readable and logical to me. There is zero code change on this commit.
3f11801 change the
AccountKey()
KeyFile()
CertFile()
ChainFile()
FullChainFile()
andFullFile()
IOPlugins classes to be more similar.FullChainFile()
is no longer a subclass ofChainFile()
. The 3 "chain" plugins use a list built from the iterator created bysplit_pems()
to allow testing its length (required to catch issues with those files later).e078cee
split_pems()
is only used by subclasses ofOpenSSLIOPlugin()
so it make more sense to me to make it a method of this class rather than a function. The test performed by the function doctest has been moved to the unit test for the IOPlugins. I'm not 100% happy with this has it means it will be tested again for each plugin but that's the solution with the least amount of additional code (I can detail the other possibility I thought of).27b822d same as above with
load_pem_jwk()
anddump_pem_jwk()
functions being moved to methods of theJWKIOPlugin()
class, for the same reasons.158fef0 catch openssl errors on the
OpenSSLIOPlugin()
methods. This is enough for the "single files" plugins as empty or invalid content will result in openssl throwing an error.3c5b4aa catch empty file for the "chain" plugins or files that didn't contain enough discrete pem encoded data + tests for this and the openssl error
001d80a fix for a new check added in Pylint 1.8.0 that
simp_le
was failing.