-
Notifications
You must be signed in to change notification settings - Fork 110
/
users.e2e-spec.ts
87 lines (74 loc) · 2.33 KB
/
users.e2e-spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { UsersModule } from '../../src/users';
import config from '../../src/mikro-orm.config';
import { SecRunner } from '@sectester/runner';
import { AttackParamLocation, Severity, TestType } from '@sectester/scan';
import { INestApplication } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { ConfigModule } from '@nestjs/config';
import { MikroOrmModule } from '@mikro-orm/nestjs';
import { Server } from 'https';
describe('/users', () => {
const timeout = 600000;
jest.setTimeout(timeout);
let runner!: SecRunner;
let app!: INestApplication;
let baseUrl!: string;
beforeAll(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [
UsersModule,
ConfigModule.forRoot(),
MikroOrmModule.forRoot(config)
]
}).compile();
app = moduleFixture.createNestApplication({
logger: false
});
await app.init();
const server = app.getHttpServer();
server.listen(0);
const port = server.address().port;
const protocol = server instanceof Server ? 'https' : 'http';
baseUrl = `${protocol}://localhost:${port}`;
});
afterAll(() => app.close());
beforeEach(async () => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
runner = new SecRunner({ hostname: process.env.BRIGHT_HOSTNAME! });
await runner.init();
});
afterEach(() => runner.clear());
describe('POST /', () => {
it('should not have XSS', async () => {
await runner
.createScan({
name: expect.getState().currentTestName,
tests: [TestType.XSS],
attackParamLocations: [AttackParamLocation.BODY]
})
.threshold(Severity.MEDIUM)
.timeout(timeout)
.run({
method: 'POST',
url: `${baseUrl}/users`,
body: { firstName: 'Test', lastName: 'Test' }
});
});
});
describe('GET /:id', () => {
it('should not have SQLi', async () => {
await runner
.createScan({
name: expect.getState().currentTestName,
tests: [TestType.SQLI],
attackParamLocations: [AttackParamLocation.PATH]
})
.threshold(Severity.MEDIUM)
.timeout(timeout)
.run({
method: 'GET',
url: `${baseUrl}/users/1`
});
});
});
});