Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
Merge 310065b into f8c1d11
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Apr 25, 2015
2 parents f8c1d11 + 310065b commit 9707b29
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
10 changes: 8 additions & 2 deletions relengapi/blueprints/tokenauth/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ def __init__(self, claims, authenticated_email=None,
self.authenticated_email = authenticated_email

def get_id(self):
jti = (':' + self.claims['jti']) if 'jti' in self.claims else ''
return 'token:%s%s' % (self.claims['typ'], jti)
parts = ['token', self.claims['typ']]
if 'jti' in self.claims:
parts.append('id={}'.format(self.claims['jti']))
try:
parts.append('user={}'.format(self.authenticated_email))
except AttributeError:
pass
return ':'.join(parts)

def get_permissions(self):
return self._permissions
Expand Down
16 changes: 16 additions & 0 deletions relengapi/blueprints/tokenauth/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@
from relengapi.blueprints.tokenauth.util import insert_usr


def test_TokenUser_str_tmp():
tu = loader.TokenUser({'typ': 'tmp', 'mta': '{}'})
eq_(str(tu), 'token:tmp')


def test_TokenUser_str_usr():
tu = loader.TokenUser({'typ': 'usr', 'jti': '13'},
authenticated_email='foo@bar.com')
eq_(str(tu), 'token:usr:id=13:user=foo@bar.com')


def test_TokenUser_str_prm():
tu = loader.TokenUser({'typ': 'prm', 'jti': '13'})
eq_(str(tu), 'token:prm:id=13')


@test_context
def test_loader_no_header(app, client):
"""With no Authorization header, no permissions are allowed"""
Expand Down

0 comments on commit 9707b29

Please sign in to comment.