feat: #11 impl JWT + add associated tests
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user