예제 #1
0
def test_str_to_claims_valid_v1(app):
    with app.app_context():
        input_claims = {'id': 25, 'v': 1}
        token_str = app.tokenauth_serializer.dumps(input_claims)
        got_claims = tokenstr.str_to_claims(token_str)
        # v1 token is rewritten to ra2 format
        exp_claims = {'iss': 'ra2', 'typ': 'prm', 'jti': 't25'}
        eq_(got_claims, exp_claims)
예제 #2
0
def test_str_to_claims_bad_exception(app):
    # some errors can cause itsdangerous to raise errors other than
    # BadData, and these should be handled correctly
    with app.app_context():
        with mock.patch('itsdangerous.JSONWebSignatureSerializer.loads') as loads:
            loads.side_effect = RuntimeError("uhoh")
            got_claims = tokenstr.str_to_claims('eyJhbGciOiJIUzI1NiJ9.e')
            eq_(got_claims, None)
예제 #3
0
def test_str_to_claims_valid_v1(app):
    with app.app_context():
        input_claims = {'id': 25, 'v': 1}
        token_str = app.tokenauth_serializer.dumps(input_claims)
        got_claims = tokenstr.str_to_claims(token_str)
        # v1 token is rewritten to ra2 format
        exp_claims = {'iss': 'ra2', 'typ': 'prm', 'jti': 't25'}
        eq_(got_claims, exp_claims)
예제 #4
0
 def from_str(self, token_str):
     claims = tokenstr.str_to_claims(token_str)
     if not claims:
         return
     try:
         typ_fn = self.type_functions[claims['typ']]
     except KeyError:
         return
     return typ_fn(claims)
 def from_str(self, token_str):
     claims = tokenstr.str_to_claims(token_str)
     if not claims:
         return
     try:
         typ_fn = self.type_functions[claims['typ']]
     except KeyError:
         return
     return typ_fn(claims)
def test_str_to_claims_bad_exception(app):
    # some errors can cause itsdangerous to raise errors other than
    # BadData, and these should be handled correctly
    with app.app_context():
        with mock.patch(
                'itsdangerous.JSONWebSignatureSerializer.loads') as loads:
            loads.side_effect = RuntimeError("uhoh")
            got_claims = tokenstr.str_to_claims('eyJhbGciOiJIUzI1NiJ9.e')
            eq_(got_claims, None)
예제 #7
0
 def from_str(self, token_str):
     claims = tokenstr.str_to_claims(token_str)
     if not claims:
         return
     try:
         typ_fn = self.type_functions[claims['typ']]
     except KeyError:
         return
     user = typ_fn(claims)
     if user:
         logger.debug("Token access by %s", user)
     return user
예제 #8
0
 def from_str(self, token_str):
     claims = tokenstr.str_to_claims(token_str)
     if not claims:
         return
     try:
         typ_fn = self.type_functions[claims['typ']]
     except KeyError:
         return
     user = typ_fn(claims)
     if user:
         logger.debug("Token access by %s", user)
     return user
예제 #9
0
def test_str_to_claims_invalid_claims(app):
    with app.app_context():
        input_claims = {'in': 'valid'}
        token_str = app.tokenauth_serializer.dumps(input_claims)
        got_claims = tokenstr.str_to_claims(token_str)
        eq_(got_claims, None)
예제 #10
0
def test_str_to_claims_valid_v2(app):
    with app.app_context():
        input_claims = {'iss': 'ra2', 'typ': 'prm', 'jti': 't20'}
        token_str = app.tokenauth_serializer.dumps(input_claims)
        got_claims = tokenstr.str_to_claims(token_str)
        eq_(got_claims, input_claims)
예제 #11
0
def test_str_to_claims_invalid_str(app):
    with app.app_context():
        got_claims = tokenstr.str_to_claims('abcd')
        eq_(got_claims, None)
예제 #12
0
def test_str_to_claims_invalid_claims(app):
    with app.app_context():
        input_claims = {'in': 'valid'}
        token_str = app.tokenauth_serializer.dumps(input_claims)
        got_claims = tokenstr.str_to_claims(token_str)
        eq_(got_claims, None)
예제 #13
0
def test_str_to_claims_valid_v2(app):
    with app.app_context():
        input_claims = {'iss': 'ra2', 'typ': 'prm', 'jti': 't20'}
        token_str = app.tokenauth_serializer.dumps(input_claims)
        got_claims = tokenstr.str_to_claims(token_str)
        eq_(got_claims, input_claims)
def test_str_to_claims_invalid_padding(app):
    with app.app_context():
        got_claims = tokenstr.str_to_claims('eyJhbGciOiJIUzI1NiJ9.e')
        eq_(got_claims, None)
예제 #15
0
def test_str_to_claims_invalid_str(app):
    with app.app_context():
        got_claims = tokenstr.str_to_claims('abcd')
        eq_(got_claims, None)
예제 #16
0
def test_claims_to_str_to_claims(app):
    with app.app_context():
        input_claims = {'iss': 'ra2', 'typ': 'prm', 'jti': 't10'}
        token_str = tokenstr.claims_to_str(input_claims)
        got_claims = tokenstr.str_to_claims(token_str)
        eq_(got_claims, input_claims)
예제 #17
0
def test_claims_to_str_to_claims(app):
    with app.app_context():
        input_claims = {'iss': 'ra2', 'typ': 'prm', 'jti': 't10'}
        token_str = tokenstr.claims_to_str(input_claims)
        got_claims = tokenstr.str_to_claims(token_str)
        eq_(got_claims, input_claims)
예제 #18
0
def test_str_to_claims_invalid_padding(app):
    with app.app_context():
        got_claims = tokenstr.str_to_claims('eyJhbGciOiJIUzI1NiJ9.e')
        eq_(got_claims, None)