forked from jrconlin/vapid
-
Notifications
You must be signed in to change notification settings - Fork 27
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
bug: use better host validation for sub
#92
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
from cryptography.hazmat.primitives import serialization | ||
from mock import patch, Mock | ||
|
||
from py_vapid import Vapid01, Vapid02, VapidException | ||
from py_vapid import Vapid01, Vapid02, VapidException, _check_sub | ||
from py_vapid.jwt import decode | ||
|
||
TEST_KEY_PRIVATE_DER = """ | ||
|
@@ -228,7 +228,12 @@ def test_bad_sign(self): | |
self.assertRaises(VapidException, | ||
v.sign, | ||
{'sub': 'mailto:[email protected]', | ||
'aud': "https://p.example.com:8080/"}) | ||
'aud': "https://p.example.com:8080/"}) | ||
|
||
def test_ignore_sub(self): | ||
v = Vapid02.from_file("/tmp/private") | ||
v.conf['no-strict'] = True | ||
assert v.sign({"sub": "foo", "aud": "http://localhost:8000"}) | ||
|
||
@patch('cryptography.hazmat.primitives.asymmetric' | ||
'.ec.EllipticCurvePublicNumbers') | ||
|
@@ -247,3 +252,29 @@ def test_invalid_sig(self, mm): | |
decode, | ||
'foo.bar.a', | ||
'aaaa') | ||
|
||
def test_sub(self): | ||
valid = [ | ||
'mailto:me@localhost', | ||
'mailto:[email protected]', | ||
'mailto:me@1234::', | ||
'mailto:me@1234::5678', | ||
'mailto:[email protected]', | ||
'https://localhost', | ||
'https://8001::', | ||
'https://8001:1000:0001', | ||
'https://1.2.3.4' | ||
] | ||
invalid = [ | ||
'mailto:@foobar.com', | ||
'mailto:example.org', | ||
'mailto:0123:', | ||
'mailto:::1234', | ||
'https://somehost', | ||
'https://xyz:123', | ||
] | ||
|
||
for val in valid: | ||
assert _check_sub(val) is True | ||
for val in invalid: | ||
assert _check_sub(val) is False |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Rarely do I use py.test's parameterized tests (it's a bit of magic) but I may have actually considered it here
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.
Maybe? I dunno. For something like this, I think it's clearer for future me to be less clever and just specify what goes into which gauntlet as a delineated list like this, rather than as a CSV.
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.
Yea that's part of why I don't use it, it's a bit too clever. I think the main benefit is debugging and test output is a bit improved over a loop