#8 return a 403 if credentials are invalid + adjust corresponding test
This commit is contained in:
@@ -11,15 +11,15 @@ URL="https://dev.thegux.fr"
|
||||
for i in {0..10}
|
||||
do
|
||||
http_response=$(curl -s -o response.txt -w "%{http_code}" ${URL}/get/ -d '{"username":"toto", "password":"tutu"}')
|
||||
if [ $http_response != "200" ]
|
||||
if [ $http_response != "403" ]
|
||||
then
|
||||
echo "bad http status code : ${http_response}, expect 200"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$(cat response.txt | jq -r '.token')" != "header.payload.signature" ]
|
||||
if [ "$(cat response.txt | jq -r '.error')" != "invalid credentials" ]
|
||||
then
|
||||
echo "bad data returned, expect : ok"
|
||||
echo "bad data returned, expect : invalid credentials"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -36,6 +36,28 @@ class TestResponse(TestCase):
|
||||
resp.json()["token"], "header.payload.signature", "bad status returned"
|
||||
)
|
||||
|
||||
def test_no_credentials(self):
|
||||
resp = requests.post(URL + "/get/")
|
||||
self.assertEqual(resp.status_code, 403, "bad status code returned")
|
||||
self.assertIsNotNone(resp.json(), "response data must not be empty")
|
||||
self.assertEqual(
|
||||
resp.json()["error"],
|
||||
"invalid credentials",
|
||||
"invalid error message returned",
|
||||
)
|
||||
|
||||
def test_bad_credentials(self):
|
||||
resp = requests.post(
|
||||
URL + "/get/", json={"username": "tutu", "password": "titi"}
|
||||
)
|
||||
self.assertEqual(resp.status_code, 403, "bas status code returned")
|
||||
self.assertIsNotNone(resp.json(), "response data must not be empty")
|
||||
self.assertEqual(
|
||||
resp.json()["error"],
|
||||
"invalid credentials",
|
||||
"invalid error message returned",
|
||||
)
|
||||
|
||||
def test_bad_target(self):
|
||||
resp = requests.post(
|
||||
URL + "/token/", json={"username": "toto", "password": "tata"}
|
||||
|
||||
Reference in New Issue
Block a user