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]] [[package]]
name = "simple-auth" name = "simple-auth"
version = "0.2.0" version = "0.3.0"
dependencies = [ dependencies = [
"async-std", "async-std",
"async-trait", "async-trait",

View File

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