feat: #11 impl JWT + add associated tests

This commit is contained in:
2022-10-10 17:22:36 +00:00
parent e22d289e0d
commit 72d1fba8f4
5 changed files with 693 additions and 10 deletions
+12 -3
View File
@@ -1,5 +1,8 @@
import jwt
import requests
from datetime import datetime
from unittest import TestCase
URL = "https://dev.thegux.fr"
@@ -12,9 +15,15 @@ class TestResponse(TestCase):
)
self.assertEqual(resp.status_code, 200, "bad status code returned")
self.assertIsNotNone(resp.json(), "response data can't be empty")
self.assertEqual(
resp.json()["token"], "header.payload.signature", "bad status returned"
)
token = resp.json()["token"]
jwt_decoded = jwt.decode(token, options={"verify_signature": False})
self.assertEqual("thegux.fr", jwt_decoded["iss"])
jwt_exp = datetime.fromtimestamp(jwt_decoded["exp"])
jwt_iat = datetime.fromtimestamp(jwt_decoded["iat"])
date_exp = datetime.strptime(str(jwt_exp - jwt_iat), "%H:%M:%S")
self.assertEqual(2, date_exp.hour)
def test_validate_target(self):
resp = requests.post(