Skip to content

Commit

Permalink
✅ Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Xen0Xys committed Jan 3, 2024
1 parent 99d10b1 commit b935e0c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 29 deletions.
11 changes: 6 additions & 5 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {NestFactory} from "@nestjs/core";
import {AppModule} from "./app.module";
import * as process from "process";
import * as dotenv from "dotenv";
import fastifyHelmet from "@fastify/helmet";
import helmet from "@fastify/helmet";
import * as fs from "fs";
import * as os from "os";
import {SwaggerTheme} from "swagger-themes";
Expand Down Expand Up @@ -79,27 +79,28 @@ async function loadServer(server: NestFastifyApplication<RawServerDefault>){

// Middlewares
server.use(new LoggerMiddleware().use);
await server.register(fastifyHelmet, {
await server.register(helmet, {
contentSecurityPolicy: false,
});
await server.register(compression, {encodings: ["gzip", "deflate"]});

// Swagger
const config = new DocumentBuilder()
.setTitle("Template")
.setDescription("The Template API description")
.setTitle("Phoenix API")
.setDescription("Documentation for the Phoenix API")
.setVersion(process.env.npm_package_version)
.addBearerAuth()
.build();
const document = SwaggerModule.createDocument(server, config);
const theme = new SwaggerTheme("v3");
const customCss = theme.getBuffer("dark");
SwaggerModule.setup("api", server, document, {
swaggerOptions: {
filter: true,
displayRequestDuration: true,
persistAuthorization: true,
},
customCss: theme.getBuffer("dark"),
customCss,
});

server.useGlobalPipes(new CustomValidationPipe());
Expand Down
12 changes: 6 additions & 6 deletions src/services/jwt.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,30 @@ describe("ServicesService", () => {
const content = "test";
describe("JWT tests", () => {
it("Symmetric JWT", () => {
const token = service.generateJWT({content}, process.env.TOKEN_DURATION, process.env.JWT_KEY);
const token = service.generateJWT({content}, process.env.AT_DURATION, process.env.AT_KEY);
expect(typeof token).toBe("string");
const decoded = service.verifyJWT(token, process.env.JWT_KEY);
const decoded = service.verifyJWT(token, process.env.AT_KEY);
expect(typeof decoded).toBe("object");
expect(decoded).toHaveProperty("content");
});
it("Verify JWT with wrong key", async() => {
const token = service.generateJWT({content}, process.env.TOKEN_DURATION, process.env.JWT_KEY);
const token = service.generateJWT({content}, process.env.AT_DURATION, process.env.AT_KEY);
expect(() => service.verifyJWT(token, "wrong_key")).toThrow(Error);
});
it("Verify no JWT content", async() => {
expect(() => service.verifyJWT("invalid_content", process.env.JWT_KEY)).toThrow(Error);
expect(() => service.verifyJWT("invalid_content", process.env.AT_KEY)).toThrow(Error);
});
it("Asymmetric JWT", () => {
const localKeyPair = encryptionService.generateKeyPair(2048);
const token = service.generateJWT({content}, process.env.TOKEN_DURATION, localKeyPair.privateKey, false);
const token = service.generateJWT({content}, process.env.AT_DURATION, localKeyPair.privateKey, false);
expect(typeof token).toBe("string");
const decoded = service.verifyJWT(token, localKeyPair.publicKey);
expect(typeof decoded).toBe("object");
expect(decoded).toHaveProperty("content");
});
it("Asymmetric JWT with private encryption key", () => {
const localKeyPair = encryptionService.generateKeyPair(2048, process.env.ASYMMETRIC_ENCRYPTION_KEY);
const token = service.generateJWT({content}, process.env.TOKEN_DURATION, localKeyPair.privateKey, false, process.env.ASYMMETRIC_ENCRYPTION_KEY);
const token = service.generateJWT({content}, process.env.AT_DURATION, localKeyPair.privateKey, false, process.env.ASYMMETRIC_ENCRYPTION_KEY);
expect(typeof token).toBe("string");
const decoded = service.verifyJWT(token, localKeyPair.publicKey);
expect(typeof decoded).toBe("object");
Expand Down
18 changes: 0 additions & 18 deletions src/version/version.controller.spec.ts

This file was deleted.

0 comments on commit b935e0c

Please sign in to comment.