Setup
cp .env.example .env
- Fill
.env
with desired values make start
to start applicationmake seed
to seed database with 10 users:
user-0@example.com / password
user-1@example.com / password
user-2@example.com / password
[...]
- Swagger available under
localhost:3000/docs
NodeJS task
Write NodeJS app that has 3 endpoints
Some requirements:
- Use any HTTP library you want
- Don’t use real database - in-memory implementationis sufficient
- Add README with setup, starting instructions,andall users and passwords used in mock
Nice to have (not required though):
- TypeScript
- NestJS (and it’s features)
Tips:
-
Use proper HTTP statuses
-
Handle as many errors as you like - imagine, you area user of such API, and you want to know how you can fix something, in caseof a problem.
-
Treat this application as MVP, which will be expanded further later on.
-
For encryption you may need to ask Google for help,as you are expected to encounter some problems. Feel free to solve this problemas you like. Additional point if you manage to solve it withoutusage of external libraries.
-
Some application architecture is expected - the mostimportant is responsibility of different areas.
-
If you want to use a library for something, don’thesitate.
-
Authorization
Header: Authorization: Bearer <token>
- POST /api/sign-in
Not authorized.
It should support at least 2 users (2 distinct emailaddresses).
In POST body you should be able to send:
{
"email" : "example@mail.com" ,
"password" : "1234"
}
And in return you should get the JWT token valid for5 minutes:
{
"authToken" : "eyJhbGc..."
}
Which holds this payload: { "email" : "example@mail.com" }
- POST /api/generate-key-pair
Authorized.
It should associate appropriate key with authorizeduser.
It should return generated pair of public and privateRSA keys (any length)
{
"privKey": "-----BEGIN ENCRYPTED PRIVATE KEY-----
MIIJrT ....",
"pubKey": "-----BEGIN PUBLIC KEY-----MII..."
}
- POST /api/encrypt
Authorized
Endpoint should encrypt file (http://www.africau.edu/images/default/sample.pdf)and return it as Base64 string (content-type is up toYou). Payload should be encrypted with usage of generated public key, so user can (hypothetically)decrypt it using his private key.