-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JWT Gen + Validation & Service integration
- Loading branch information
1 parent
25cdb55
commit 5695a16
Showing
25 changed files
with
314 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,12 @@ import * as request from 'supertest'; | |
import { ResetProtoFile } from 'juno-proto'; | ||
import * as GRPC from '@grpc/grpc-js'; | ||
import * as ProtoLoader from '@grpc/proto-loader'; | ||
import * as jwt from 'jsonwebtoken'; | ||
|
||
let app: INestApplication; | ||
const ADMIN_EMAIL = '[email protected]'; | ||
const ADMIN_PASSWORD = 'test-password'; | ||
|
||
let token: string; | ||
|
||
beforeAll(async () => { | ||
const proto = ProtoLoader.loadSync([ResetProtoFile]) as any; | ||
|
@@ -47,18 +51,38 @@ beforeEach(async () => { | |
app.useGlobalInterceptors(new ClassSerializerInterceptor(app.get(Reflector))); | ||
|
||
await app.init(); | ||
|
||
if (!token) { | ||
const key = await request(app.getHttpServer()) | ||
.post('/auth/key') | ||
.send({ | ||
email: ADMIN_EMAIL, | ||
password: ADMIN_PASSWORD, | ||
environment: 'prod', | ||
project: { | ||
name: 'test-seed-project', | ||
}, | ||
}); | ||
|
||
const apiKey = key.body['apiKey']; | ||
|
||
const jwt = await request(app.getHttpServer()) | ||
.post('/auth/jwt') | ||
.set('Authorization', `Bearer ${apiKey}`) | ||
.send(); | ||
|
||
token = jwt.body['token']; | ||
} | ||
}); | ||
|
||
describe('Email Registration Routes', () => { | ||
it('Registers an email without a body', () => { | ||
const token = jwt.sign({}, 'secret'); | ||
return request(app.getHttpServer()) | ||
.post('/email/register-sender') | ||
.set('Authorization', 'Bearer ' + token) | ||
.expect(400); | ||
}); | ||
it('Has been called with a malformed emaiil', () => { | ||
const token = jwt.sign({}, 'secret'); | ||
return request(app.getHttpServer()) | ||
.post('/email/register-sender') | ||
.set('Authorization', 'Bearer ' + token) | ||
|
@@ -86,7 +110,6 @@ describe('Email Registration Routes', () => { | |
}); | ||
it('Registration endpoint called with a correct payload (header + body)', () => { | ||
// Assuming 'valid.jwt.token' is a placeholder for a valid JWT obtained in a way relevant to your test setup | ||
const token = jwt.sign({}, 'secret'); | ||
return request(app.getHttpServer()) | ||
.post('/email/register-sender') | ||
.set('Authorization', 'Bearer ' + token) | ||
|
@@ -122,7 +145,6 @@ describe('Email Sending Route', () => { | |
}); | ||
|
||
it('Send email with valid parameters and JWT is valid', async () => { | ||
const token = jwt.sign({}, 'secret'); | ||
return request(app.getHttpServer()) | ||
.post('/email/send') | ||
.set('Authorization', 'Bearer ' + token) | ||
|
@@ -135,7 +157,6 @@ describe('Email Sending Route', () => { | |
}); | ||
|
||
it('Send email with valid parameters (with names) and JWT is valid', async () => { | ||
const token = jwt.sign({}, 'secret'); | ||
return request(app.getHttpServer()) | ||
.post('/email/send') | ||
.set('Authorization', 'Bearer ' + token) | ||
|
@@ -150,7 +171,6 @@ describe('Email Sending Route', () => { | |
}); | ||
|
||
it('Send email with valid parameters (with names, multiple recipients) and JWT is valid', async () => { | ||
const token = jwt.sign({}, 'secret'); | ||
return request(app.getHttpServer()) | ||
.post('/email/send') | ||
.set('Authorization', 'Bearer ' + token) | ||
|
@@ -166,7 +186,6 @@ describe('Email Sending Route', () => { | |
}); | ||
|
||
it('Send email with valid parameters (with names, multiple recipients and contents) and JWT is valid', async () => { | ||
const token = jwt.sign({}, 'secret'); | ||
return request(app.getHttpServer()) | ||
.post('/email/send') | ||
.set('Authorization', 'Bearer ' + token) | ||
|
@@ -185,7 +204,6 @@ describe('Email Sending Route', () => { | |
}); | ||
|
||
it('Send email with empty request and JWT is valid', async () => { | ||
const token = jwt.sign({}, 'secret'); | ||
return request(app.getHttpServer()) | ||
.post('/email/send') | ||
.set('Authorization', 'Bearer ' + token) | ||
|
@@ -194,7 +212,6 @@ describe('Email Sending Route', () => { | |
}); | ||
|
||
it('Send email with empty sender email and JWT is valid', async () => { | ||
const token = jwt.sign({}, 'secret'); | ||
return request(app.getHttpServer()) | ||
.post('/email/send') | ||
.set('Authorization', 'Bearer ' + token) | ||
|
@@ -213,7 +230,6 @@ describe('Email Sending Route', () => { | |
}); | ||
|
||
it('Send email with invalid sender email and JWT is valid', async () => { | ||
const token = jwt.sign({}, 'secret'); | ||
return request(app.getHttpServer()) | ||
.post('/email/send') | ||
.set('Authorization', 'Bearer ' + token) | ||
|
@@ -232,7 +248,6 @@ describe('Email Sending Route', () => { | |
}); | ||
|
||
it('Send email with null sender email and JWT is valid', async () => { | ||
const token = jwt.sign({}, 'secret'); | ||
return request(app.getHttpServer()) | ||
.post('/email/send') | ||
.set('Authorization', 'Bearer ' + token) | ||
|
@@ -251,7 +266,6 @@ describe('Email Sending Route', () => { | |
}); | ||
|
||
it('Send email with empty recipients email and JWT is valid', async () => { | ||
const token = jwt.sign({}, 'secret'); | ||
return request(app.getHttpServer()) | ||
.post('/email/send') | ||
.set('Authorization', 'Bearer ' + token) | ||
|
@@ -270,7 +284,6 @@ describe('Email Sending Route', () => { | |
}); | ||
|
||
it('Send email with invalid recipients email and JWT is valid', async () => { | ||
const token = jwt.sign({}, 'secret'); | ||
return request(app.getHttpServer()) | ||
.post('/email/send') | ||
.set('Authorization', 'Bearer ' + token) | ||
|
@@ -289,7 +302,6 @@ describe('Email Sending Route', () => { | |
}); | ||
|
||
it('Send email with null recipients email and JWT is valid', async () => { | ||
const token = jwt.sign({}, 'secret'); | ||
return request(app.getHttpServer()) | ||
.post('/email/send') | ||
.set('Authorization', 'Bearer ' + token) | ||
|
@@ -308,7 +320,6 @@ describe('Email Sending Route', () => { | |
}); | ||
|
||
it('Send email with empty content type email and JWT is valid', async () => { | ||
const token = jwt.sign({}, 'secret'); | ||
return request(app.getHttpServer()) | ||
.post('/email/send') | ||
.set('Authorization', 'Bearer ' + token) | ||
|
@@ -327,7 +338,6 @@ describe('Email Sending Route', () => { | |
}); | ||
|
||
it('Send email with null content type email and JWT is valid', async () => { | ||
const token = jwt.sign({}, 'secret'); | ||
return request(app.getHttpServer()) | ||
.post('/email/send') | ||
.set('Authorization', 'Bearer ' + token) | ||
|
@@ -346,7 +356,6 @@ describe('Email Sending Route', () => { | |
}); | ||
|
||
it('Send email with empty content value email and JWT is valid', async () => { | ||
const token = jwt.sign({}, 'secret'); | ||
return request(app.getHttpServer()) | ||
.post('/email/send') | ||
.set('Authorization', 'Bearer ' + token) | ||
|
@@ -365,7 +374,6 @@ describe('Email Sending Route', () => { | |
}); | ||
|
||
it('Send email with null content value email and JWT is valid', async () => { | ||
const token = jwt.sign({}, 'secret'); | ||
return request(app.getHttpServer()) | ||
.post('/email/send') | ||
.set('Authorization', 'Bearer ' + token) | ||
|
@@ -386,15 +394,13 @@ describe('Email Sending Route', () => { | |
|
||
describe('Domain Registration Routes', () => { | ||
it('Registers a domain without a domain parameter', () => { | ||
const token = jwt.sign({}, 'secret'); | ||
return request(app.getHttpServer()) | ||
.post('/email/register-domain') | ||
.set('Authorization', 'Bearer ' + token) | ||
.expect(400); | ||
}); | ||
|
||
it('Registers a domain with valid parameters', () => { | ||
const token = jwt.sign({}, 'secret'); | ||
return request(app.getHttpServer()) | ||
.post('/email/register-domain') | ||
.set('Authorization', 'Bearer ' + token) | ||
|
Oops, something went wrong.