Skip to content

Commit

Permalink
Quote issuer QS parameter in provisioning_uri. Fixes pyauth#47.
Browse files Browse the repository at this point in the history
  • Loading branch information
kislyuk committed Jun 3, 2017
1 parent bd59a56 commit dbc5194
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/pyotp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def build_uri(secret, name, initial_count=None, issuer_name=None,
label = quote(name)
if issuer_name is not None:
label = quote(issuer_name) + ':' + label
url_args['issuer'] = issuer_name
url_args['issuer'] = quote(issuer_name)

if is_initial_count_present:
url_args['counter'] = initial_count
Expand Down
10 changes: 5 additions & 5 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_provisioning_uri(self):
self.assertEqual(url.path, '/FooCorp%21:mark%40percival')
self.assertEqual(dict(parse_qsl(url.query)),
{'secret': 'wrn3pqx5uqxqvnqr', 'counter': '0',
'issuer': 'FooCorp!'})
'issuer': 'FooCorp%21'})

key = 'c7uxuqhgflpw7oruedmglbrk7u6242vb'
hotp = pyotp.HOTP(key, digits=8, digest=hashlib.sha256)
Expand All @@ -83,14 +83,14 @@ def test_provisioning_uri(self):

hotp = pyotp.HOTP(key, digits=8)
url = urlparse(
hotp.provisioning_uri('baco@peperina', issuer_name='FooCorp',
hotp.provisioning_uri('baco@peperina', issuer_name='Foo Corp',
initial_count=10))
self.assertEqual(url.scheme, 'otpauth')
self.assertEqual(url.netloc, 'hotp')
self.assertEqual(url.path, '/FooCorp:baco%40peperina')
self.assertEqual(url.path, '/Foo%20Corp:baco%40peperina')
self.assertEqual(dict(parse_qsl(url.query)),
{'secret': 'c7uxuqhgflpw7oruedmglbrk7u6242vb',
'counter': '10', 'issuer': 'FooCorp',
'counter': '10', 'issuer': 'Foo%20Corp',
'digits': '8'})

def test_other_secret(self):
Expand Down Expand Up @@ -199,7 +199,7 @@ def test_provisioning_uri(self):
self.assertEqual(url.path, '/FooCorp%21:mark%40percival')
self.assertEqual(dict(parse_qsl(url.query)),
{'secret': 'wrn3pqx5uqxqvnqr',
'issuer': 'FooCorp!'})
'issuer': 'FooCorp%21'})

key = 'c7uxuqhgflpw7oruedmglbrk7u6242vb'
totp = pyotp.TOTP(key, digits=8, interval=60, digest=hashlib.sha256)
Expand Down

0 comments on commit dbc5194

Please sign in to comment.