def test_read_token_from_header(self, app, db, user_class, client): """ This test verifies that a token may be properly read from a flask request's header using the configuration settings for header name and type """ guard = Praetorian(app, user_class) the_dude = user_class( username="******", password=guard.hash_password("abides"), roles="admin,operator", ) db.session.add(the_dude) db.session.commit() with plummet.frozen_time('2017-05-21 18:39:55'): token = guard.encode_jwt_token(the_dude) client.get( "/unprotected", headers={ "Content-Type": "application/json", DEFAULT_JWT_HEADER_NAME: DEFAULT_JWT_HEADER_TYPE + " " + token, }, ) assert guard.read_token_from_header() == token assert guard.read_token() == token
def test_read_token_from_cookie(self, app, db, user_class, client, use_cookie): """ This test verifies that a token may be properly read from a flask request's cookies using the configuration settings for cookie """ guard = Praetorian(app, user_class) the_dude = user_class( username="******", password=guard.hash_password("abides"), roles="admin,operator", ) db.session.add(the_dude) db.session.commit() with plummet.frozen_time('2017-05-21 18:39:55'): token = guard.encode_jwt_token(the_dude) with use_cookie(token): client.get("/unprotected", ) assert guard.read_token_from_cookie() == token assert guard.read_token() == token