Requirements
- Go 1.21.4
- MySQL 8 running on port 13316.
Run make run
and then navigate to http://localhost:8080
Run make docker
and then navigate to http://localhost:8080
- Create a JWT (e.g. https://www.javainuse.com/jwtgenerator) with the payload containing
userID
. Use the value ofJWT_SECRET
from.env
file as the secret.
{
"userID": "123"
}
- Use this JWT as
Authorization: BEARER eyJhbGciOiJIUzUxMiJ9.eyJ1c2VySUQiOjEyM30.LeNw5iobDHBW1rrdsW5-P38qfK0b6N2BOF-rfZKCXXMEVqqhGrAw7_rwVpFXVs6p2_0Y-sjMsHfG6FyErKqnsQ
- Make request.
{
"answers": [
{
"questionID": 1,
"answer": "answer 1"
},
{
"questionID": 2,
"answer": "answer 2"
}
]
}
Response
{
"userID": 123,
"signature": "4e1fce5c292feabce21c053f18a3ea41b4b684127069bce0c84a33beaa2ec206"
}
- Error scenarios
{
"status": "bad request",
"status_code": 400,
"error": "userID cannot be casted into int"
}
{
"status": "bad request",
"status_code": 400,
"error": "userID is not found in JWT payload"
}
{
"status": "bad request",
"status_code": 400,
"error": "retrieving JWT from context failed"
}
- Use the signature from previous step.
- Make request.
{
"userID": 123,
"signature": "4e1fce5c292feabce21c053f18a3ea41b4b684127069bce0c84a33beaa2ec206"
}
- Check response
{
"answers": [
{
"questionID": 1,
"answer": "answer 1"
},
{
"questionID": 2,
"answer": "answer 2"
}
],
"signedAt": "2023-12-12T15:45:41Z"
}
- Error scenarios
{
"status": "not found",
"status_code": 404,
"error": "record not found"
}
Due to the time constraints,
- The design of questions and answers tables is omitted. The signing is done by saving QAndA as a text column.
uesr
table is not defined and there's foreign key withtest
table.
Didn't have time to setup integration tests. The test cases to be covered:
-
POST /api/v1/users/sign-answers
- 400 - JWT generated with the wrong secret
- 400 - JWT has invalid payload
- 400 - JWT
userID
is not a number - 400 - Request is invalid
- 500 - unknown internal errors
- 200 - Success
-
POST /api/v1/admin/verify-signature
- 400 - Request is invalid
- 404 - cannot find the test with the userID and signature
- 200 - OK