Пример #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)