Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f7cd514997
|
||
|
|
3a4f6624fc
|
||
|
|
8a146a2e1d
|
||
|
|
1ab6e1a969
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@memegoat/backend",
|
"name": "@memegoat/backend",
|
||||||
"version": "1.10.0",
|
"version": "1.10.2",
|
||||||
"description": "",
|
"description": "",
|
||||||
"author": "",
|
"author": "",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ export class AuthService {
|
|||||||
async login(dto: LoginDto, userAgent?: string, ip?: string) {
|
async login(dto: LoginDto, userAgent?: string, ip?: string) {
|
||||||
const emailHash = await this.hashingService.hashEmail(dto.email);
|
const emailHash = await this.hashingService.hashEmail(dto.email);
|
||||||
this.logger.log(`Login attempt for email hash: ${emailHash}`);
|
this.logger.log(`Login attempt for email hash: ${emailHash}`);
|
||||||
const { email, password } = dto;
|
const { password } = dto;
|
||||||
const user = await this.usersService.findByEmailHash(emailHash);
|
const user = await this.usersService.findByEmailHash(emailHash);
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
|
|||||||
@@ -49,7 +49,9 @@ describe("AllExceptionsFilter", () => {
|
|||||||
|
|
||||||
filter.catch(exception, mockArgumentsHost);
|
filter.catch(exception, mockArgumentsHost);
|
||||||
|
|
||||||
expect(mockResponse.status).toHaveBeenCalledWith(HttpStatus.INTERNAL_SERVER_ERROR);
|
expect(mockResponse.status).toHaveBeenCalledWith(
|
||||||
|
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
|
);
|
||||||
expect(Sentry.withScope).toHaveBeenCalled();
|
expect(Sentry.withScope).toHaveBeenCalled();
|
||||||
|
|
||||||
// Vérifier que captureException a été appelé (via withScope)
|
// Vérifier que captureException a été appelé (via withScope)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { createHash } from "node:crypto";
|
||||||
import {
|
import {
|
||||||
ArgumentsHost,
|
ArgumentsHost,
|
||||||
Catch,
|
Catch,
|
||||||
@@ -6,7 +7,6 @@ import {
|
|||||||
HttpStatus,
|
HttpStatus,
|
||||||
Logger,
|
Logger,
|
||||||
} from "@nestjs/common";
|
} from "@nestjs/common";
|
||||||
import { createHash } from "node:crypto";
|
|
||||||
import * as Sentry from "@sentry/nestjs";
|
import * as Sentry from "@sentry/nestjs";
|
||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
import { createHash } from "node:crypto";
|
||||||
import { CACHE_MANAGER } from "@nestjs/cache-manager";
|
import { CACHE_MANAGER } from "@nestjs/cache-manager";
|
||||||
import { Inject, Injectable, Logger, NestMiddleware } from "@nestjs/common";
|
import { Inject, Injectable, Logger, NestMiddleware } from "@nestjs/common";
|
||||||
import type { Cache } from "cache-manager";
|
import type { Cache } from "cache-manager";
|
||||||
import { createHash } from "node:crypto";
|
|
||||||
import type { NextFunction, Request, Response } from "express";
|
import type { NextFunction, Request, Response } from "express";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
import { CACHE_MANAGER } from "@nestjs/cache-manager";
|
import { CACHE_MANAGER } from "@nestjs/cache-manager";
|
||||||
import { Test, TestingModule } from "@nestjs/testing";
|
import { Test, TestingModule } from "@nestjs/testing";
|
||||||
|
import * as Sentry from "@sentry/nestjs";
|
||||||
import { DatabaseService } from "./database/database.service";
|
import { DatabaseService } from "./database/database.service";
|
||||||
import { HealthController } from "./health.controller";
|
import { HealthController } from "./health.controller";
|
||||||
|
|
||||||
|
jest.mock("@sentry/nestjs", () => ({
|
||||||
|
getClient: jest.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
describe("HealthController", () => {
|
describe("HealthController", () => {
|
||||||
let controller: HealthController;
|
let controller: HealthController;
|
||||||
|
|
||||||
@@ -37,10 +42,15 @@ describe("HealthController", () => {
|
|||||||
it("should return ok if database and redis are connected", async () => {
|
it("should return ok if database and redis are connected", async () => {
|
||||||
mockDb.execute.mockResolvedValue([]);
|
mockDb.execute.mockResolvedValue([]);
|
||||||
mockCacheManager.set.mockResolvedValue(undefined);
|
mockCacheManager.set.mockResolvedValue(undefined);
|
||||||
|
(Sentry.getClient as jest.Mock).mockReturnValue({
|
||||||
|
getOptions: () => ({ dsn: "http://dsn" }),
|
||||||
|
});
|
||||||
|
|
||||||
const result = await controller.check();
|
const result = await controller.check();
|
||||||
expect(result.status).toBe("ok");
|
expect(result.status).toBe("ok");
|
||||||
expect(result.database).toBe("connected");
|
expect(result.database).toBe("connected");
|
||||||
expect(result.redis).toBe("connected");
|
expect(result.redis).toBe("connected");
|
||||||
|
expect(result.sentry).toBe("active");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return error if database is disconnected", async () => {
|
it("should return error if database is disconnected", async () => {
|
||||||
@@ -62,4 +72,19 @@ describe("HealthController", () => {
|
|||||||
expect(result.redis).toBe("disconnected");
|
expect(result.redis).toBe("disconnected");
|
||||||
expect(result.redisError).toBe("Redis Error");
|
expect(result.redisError).toBe("Redis Error");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should return sentry disabled if client or dsn is missing", async () => {
|
||||||
|
mockDb.execute.mockResolvedValue([]);
|
||||||
|
mockCacheManager.set.mockResolvedValue(undefined);
|
||||||
|
(Sentry.getClient as jest.Mock).mockReturnValue(undefined);
|
||||||
|
|
||||||
|
const result = await controller.check();
|
||||||
|
expect(result.sentry).toBe("disabled");
|
||||||
|
|
||||||
|
(Sentry.getClient as jest.Mock).mockReturnValue({
|
||||||
|
getOptions: () => ({ dsn: undefined }),
|
||||||
|
});
|
||||||
|
const result2 = await controller.check();
|
||||||
|
expect(result2.sentry).toBe("disabled");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { CACHE_MANAGER } from "@nestjs/cache-manager";
|
import { CACHE_MANAGER } from "@nestjs/cache-manager";
|
||||||
import { Controller, Get, Inject } from "@nestjs/common";
|
import { Controller, Get, Inject } from "@nestjs/common";
|
||||||
|
import * as Sentry from "@sentry/nestjs";
|
||||||
import type { Cache } from "cache-manager";
|
import type { Cache } from "cache-manager";
|
||||||
import { sql } from "drizzle-orm";
|
import { sql } from "drizzle-orm";
|
||||||
import { DatabaseService } from "./database/database.service";
|
import { DatabaseService } from "./database/database.service";
|
||||||
@@ -39,6 +40,14 @@ export class HealthController {
|
|||||||
health.redisError = error.message;
|
health.redisError = error.message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check Sentry status
|
||||||
|
const sentryClient = Sentry.getClient();
|
||||||
|
if (sentryClient?.getOptions().dsn) {
|
||||||
|
health.sentry = "active";
|
||||||
|
} else {
|
||||||
|
health.sentry = "disabled";
|
||||||
|
}
|
||||||
|
|
||||||
return health;
|
return health;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,9 +19,10 @@ async function bootstrap() {
|
|||||||
|
|
||||||
const sentryDsn = configService.get<string>("SENTRY_DSN");
|
const sentryDsn = configService.get<string>("SENTRY_DSN");
|
||||||
if (sentryDsn) {
|
if (sentryDsn) {
|
||||||
|
try {
|
||||||
Sentry.init({
|
Sentry.init({
|
||||||
dsn: sentryDsn,
|
dsn: sentryDsn,
|
||||||
integrations: [nodeProfilingIntegration()],
|
integrations: [Sentry.nestIntegration(), nodeProfilingIntegration()],
|
||||||
tracesSampleRate: 1.0,
|
tracesSampleRate: 1.0,
|
||||||
profilesSampleRate: 1.0,
|
profilesSampleRate: 1.0,
|
||||||
sendDefaultPii: false, // RGPD
|
sendDefaultPii: false, // RGPD
|
||||||
@@ -35,6 +36,18 @@ async function bootstrap() {
|
|||||||
return event;
|
return event;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const client = Sentry.getClient();
|
||||||
|
if (client?.getOptions().dsn) {
|
||||||
|
logger.log("Sentry is initialized and connection is active");
|
||||||
|
} else {
|
||||||
|
logger.warn("Sentry initialized but DSN is missing");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(`Failed to initialize Sentry: ${error.message}`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logger.warn("Sentry is disabled (SENTRY_DSN not configured)");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sécurité
|
// Sécurité
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@memegoat/frontend",
|
"name": "@memegoat/frontend",
|
||||||
"version": "1.10.0",
|
"version": "1.10.2",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@memegoat/source",
|
"name": "@memegoat/source",
|
||||||
"version": "1.10.0",
|
"version": "1.10.2",
|
||||||
"description": "",
|
"description": "",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"version:get": "cmake -P version.cmake GET",
|
"version:get": "cmake -P version.cmake GET",
|
||||||
|
|||||||
Reference in New Issue
Block a user