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)
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)
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)
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)
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
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
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)
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_str(app): with app.app_context(): got_claims = tokenstr.str_to_claims('abcd') eq_(got_claims, None)
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)
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)
def test_str_to_claims_invalid_str(app): with app.app_context(): got_claims = tokenstr.str_to_claims('abcd') eq_(got_claims, None)
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)
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)
def test_str_to_claims_invalid_padding(app): with app.app_context(): got_claims = tokenstr.str_to_claims('eyJhbGciOiJIUzI1NiJ9.e') eq_(got_claims, None)