def test_valid_jwt_no_exp(self): payload = { 'user_id': 0, } token = auth.create_jwt(payload) user = auth.authenticate_user(token) self.assertEqual(user['user_id'], 0)
def test_no_role(self, import_data): payload = {} auth_token = auth.create_jwt(payload) headers = {'Authorization': 'Bearer ' + auth_token} resp = self.test_client.post(self.API_URL + '/data-imports/', headers=headers) self.assertEqual(resp.status_code, 403) self.assertFalse(import_data.called)
def test_valid_jwt(self): payload = { 'user_id': 0, 'exp': datetime.utcnow() + timedelta(days=1) } token = auth.create_jwt(payload) user = auth.authenticate_user(token) self.assertEqual(user['user_id'], 0)
def test_no_aud(self): payload = { 'user_id': 0 } token = auth.create_jwt(payload, set_audience=False) with self.assertRaises(Unauthorized) as cm: auth.authenticate_user(token) self.assertEqual(cm.exception.description, 'Token invalid')
def test_expired(self): payload = { 'user_id': 0, 'exp': datetime(2000, 1, 1) } token = auth.create_jwt(payload) with self.assertRaises(Unauthorized) as cm: auth.authenticate_user(token) self.assertEqual(cm.exception.description, 'Token is expired')
def test_valid_jwt_no_exp(self): payload = {"user_id": 0} token = auth.create_jwt(payload) user = auth.authenticate_user(token) self.assertEqual(user["user_id"], 0)
def test_valid_jwt(self): payload = {"user_id": 0, "exp": datetime.utcnow() + timedelta(days=1)} token = auth.create_jwt(payload) user = auth.authenticate_user(token) self.assertEqual(user["user_id"], 0)
def test_expired(self): payload = {"user_id": 0, "exp": datetime(2000, 1, 1)} token = auth.create_jwt(payload) with self.assertRaises(Unauthorized) as cm: auth.authenticate_user(token) self.assertEqual(cm.exception.description, "Token is expired")
def test_invalid_aud(self): payload = {"user_id": 0, "aud": "bla"} token = auth.create_jwt(payload, set_audience=False) with self.assertRaises(Unauthorized) as cm: auth.authenticate_user(token) self.assertEqual(cm.exception.description, "Incorrect audience")
def setUpClass(cls): core.celery.conf['CELERY_ALWAYS_EAGER'] = True payload = { 'roles': ['importer'] } cls.auth_token = auth.create_jwt(payload)
def setUpClass(cls): core.celery.conf['CELERY_ALWAYS_EAGER'] = True cls.headers = {'Authorization': 'Bearer ' + auth.create_jwt({})}