add http method validation on each route + add pubkey tests
This commit is contained in:
+13
-2
@@ -9,8 +9,8 @@
|
||||
URL=${SIMPLE_AUTH_URL}
|
||||
if [ -z ${URL} ]
|
||||
then
|
||||
echo "[WARN]: SIMPLE_AUTH_URL is empty, set to http://localhost:9001"
|
||||
URL="http://localhost:9001"
|
||||
echo "[WARN]: SIMPLE_AUTH_URL is empty, set to http://localhost:5555"
|
||||
URL="http://localhost:5555"
|
||||
fi
|
||||
|
||||
for i in {0..10}
|
||||
@@ -39,3 +39,14 @@ do
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
for i in {0..10}
|
||||
do
|
||||
http_response=$(curl -s -o response.txt -w "%{http_code}" ${URL}/pubkey/)
|
||||
if [ $http_response != "200" ]
|
||||
then
|
||||
echo "bad http status code : ${http_response}, expect 400"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import base64
|
||||
import jwt
|
||||
import os
|
||||
import requests
|
||||
@@ -113,3 +114,23 @@ class TestResponse(TestCase):
|
||||
"the url requested does not exist",
|
||||
"invalid error message returned",
|
||||
)
|
||||
|
||||
def test_get_pubkey(self):
|
||||
resp = requests.get(URL + "/pubkey/")
|
||||
self.assertEqual(resp.status_code, 200, "bad status code returned")
|
||||
self.assertIsNotNone(resp.json(), "response data must not be empty")
|
||||
self.assertIsNotNone(resp.json()["pubkey"], "invalid error message returned")
|
||||
|
||||
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())
|
||||
|
||||
def test_get_pubkey_bad_method(self):
|
||||
resp = requests.post(URL + "/pubkey/", json={"tutu": "toto"})
|
||||
self.assertEqual(resp.status_code, 400, "bad status code returned")
|
||||
self.assertIsNotNone(resp.json(), "response data must not be empty")
|
||||
self.assertEqual(
|
||||
resp.json()["error"],
|
||||
"the incoming request is not valid",
|
||||
"invalid error message returned",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user