fix(tests): check if the fetch pubkey validates the JWT

This commit is contained in:
landrigun 2022-11-21 10:13:20 +00:00
parent 0cc5169664
commit 900dcebcad
2 changed files with 7 additions and 4 deletions

2
Cargo.lock generated
View File

@ -1231,7 +1231,7 @@ dependencies = [
[[package]]
name = "simple-auth"
version = "0.2.0"
version = "0.3.0"
dependencies = [
"async-std",
"async-trait",

View File

@ -15,7 +15,7 @@ class TestResponse(TestCase):
with open(PUB_KEY_PATH, "r") as f:
self.pub_key = f.read()
def test_get_target(self):
def test_get_target(self, pubkey=None):
resp = requests.post(
URL + "/get/", json={"username": "toto", "password": "tata"}
)
@ -25,7 +25,7 @@ class TestResponse(TestCase):
token = resp.json()["token"]
jwt_decoded = jwt.decode(
token,
self.pub_key,
pubkey or self.pub_key,
algorithms=["RS384"],
options={
"verify_signature": True,
@ -123,7 +123,10 @@ class TestResponse(TestCase):
b64_pubkey = base64.b64decode(resp.json()["pubkey"])
self.assertIsNotNone(b64_pubkey, "public key b64 decoded can't be empty")
self.assertIn("-BEGIN PUBLIC KEY-", b64_pubkey.decode())
b64_pubkey_decoded = b64_pubkey.decode()
self.assertIn("-BEGIN PUBLIC KEY-", b64_pubkey_decoded)
self.test_get_target(b64_pubkey_decoded)
def test_get_pubkey_bad_method(self):
resp = requests.post(URL + "/pubkey/", json={"tutu": "toto"})