nestjs-security-module
Version:
A plug-and-play NestJS security module with CORS, Helmet, rate limiting, audit logging, CSP, XSS sanitization, and more.
34 lines (27 loc) • 1.06 kB
text/typescript
import * as request from 'supertest';
import { Test } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import { TestAppModule } from './test-app.module';
describe('SecurityModule (e2e)', () => {
let app: INestApplication;
beforeAll(async () => {
const moduleFixture = await Test.createTestingModule({
imports: [TestAppModule],
}).compile();
app = moduleFixture.createNestApplication();
await app.init();
});
it('should respond with security headers', async () => {
const res = await request(app.getHttpServer()).get('/');
expect(res.status).toBe(200);
expect(res.headers['x-dns-prefetch-control']).toBe('off');
expect(res.headers['x-frame-options']).toBeDefined();
expect(res.headers['x-content-type-options']).toBe('nosniff');
expect(res.headers['content-security-policy']).toBeDefined();
expect(res.headers['permissions-policy']).toBeDefined();
expect(res.headers['expect-ct']).toContain('max-age');
});
afterAll(async () => {
await app.close();
});
});