test: comprehensive test suites and quality gates pass across backend, storefront and admin
- Backend (NestJS): 82 suites, 641 tests passing; 0 ESLint errors; 0 tsc errors. Hardened SSL cert/key matching, SSRF IP pinning, and eBank validation. - Admin Panel (Vite/React): 48 suites, 300 tests passing; 0 ESLint errors; 0 tsc errors. Full coverage across all pages and settings. - Storefront (Next.js): 62 suites, 368 tests passing; 0 ESLint errors; 0 tsc errors. - Fixed unmount lifecycle guards, promise error handling, and component edge cases.
This commit is contained in:
1 parent
1e73715169
commit
ddbf1ca026
439 files changed
+32911
-6107
No files matched your search
@@ -7,15 +7,15 @@ import {
|
||||
UseGuards,
|
||||
Req,
|
||||
Res,
|
||||
} from '@nestjs/common';
|
||||
import type { Response } from 'express';
|
||||
import { Throttle } from '@nestjs/throttler';
|
||||
import { AuthService } from './auth.service';
|
||||
import { SendOtpDto } from './dto/send-otp.dto';
|
||||
import { VerifyOtpDto } from './dto/verify-otp.dto';
|
||||
import { RegisterDto } from './dto/register.dto';
|
||||
import { LoginDto } from './dto/login.dto';
|
||||
import { JwtAuthGuard } from './jwt-auth.guard';
|
||||
} from "@nestjs/common";
|
||||
import type { Response } from "express";
|
||||
import { Throttle } from "@nestjs/throttler";
|
||||
import { AuthService } from "./auth.service";
|
||||
import { SendOtpDto } from "./dto/send-otp.dto";
|
||||
import { VerifyOtpDto } from "./dto/verify-otp.dto";
|
||||
import { RegisterDto } from "./dto/register.dto";
|
||||
import { LoginDto } from "./dto/login.dto";
|
||||
import { JwtAuthGuard } from "./jwt-auth.guard";
|
||||
import {
|
||||
ApiTags,
|
||||
ApiOperation,
|
||||
@@ -23,21 +23,21 @@ import {
|
||||
ApiOkResponse,
|
||||
ApiBadRequestResponse,
|
||||
ApiBearerAuth,
|
||||
} from '@nestjs/swagger';
|
||||
} from "@nestjs/swagger";
|
||||
|
||||
import { AdminLoginDto } from './dto/admin-login.dto';
|
||||
import { RefreshTokenDto } from './dto/refresh-token.dto';
|
||||
import { AdminLoginDto } from "./dto/admin-login.dto";
|
||||
import { RefreshTokenDto } from "./dto/refresh-token.dto";
|
||||
|
||||
@ApiTags('Auth - احراز هویت')
|
||||
@Controller('auth')
|
||||
@ApiTags("Auth - احراز هویت")
|
||||
@Controller("auth")
|
||||
@ApiResponse({
|
||||
status: HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
description: 'خطای داخلی سرور',
|
||||
description: "خطای داخلی سرور",
|
||||
schema: {
|
||||
example: {
|
||||
success: false,
|
||||
message: 'خطای ناشناخته در سرور رخ داده است',
|
||||
code: 'SERVER_ERROR',
|
||||
message: "خطای ناشناخته در سرور رخ داده است",
|
||||
code: "SERVER_ERROR",
|
||||
details: {},
|
||||
},
|
||||
},
|
||||
@@ -46,19 +46,19 @@ export class AuthController {
|
||||
constructor(private readonly authService: AuthService) {}
|
||||
|
||||
@Throttle({ default: { limit: 5, ttl: 60000 } })
|
||||
@Post('send-otp')
|
||||
@Post("send-otp")
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@ApiOperation({ summary: 'ارسال کد تایید پیامکی (OTP)' })
|
||||
@ApiOperation({ summary: "ارسال کد تایید پیامکی (OTP)" })
|
||||
@ApiOkResponse({
|
||||
description: 'کد با موفقیت به شماره تلفن همراه پیامک شد',
|
||||
description: "کد با موفقیت به شماره تلفن همراه پیامک شد",
|
||||
schema: {
|
||||
example: {
|
||||
success: true,
|
||||
message: 'کد تایید با موفقیت به شماره شما پیامک شد.',
|
||||
message: "کد تایید با موفقیت به شماره شما پیامک شد.",
|
||||
},
|
||||
},
|
||||
})
|
||||
@ApiBadRequestResponse({ description: 'شماره تلفن همراه نامعتبر است' })
|
||||
@ApiBadRequestResponse({ description: "شماره تلفن همراه نامعتبر است" })
|
||||
sendOtp(@Body() sendOtpDto: SendOtpDto) {
|
||||
return this.authService.sendOtp(sendOtpDto);
|
||||
}
|
||||
@@ -68,52 +68,52 @@ export class AuthController {
|
||||
accessToken?: string,
|
||||
refreshToken?: string,
|
||||
) {
|
||||
if (!res || typeof res.cookie !== 'function') return;
|
||||
const isProd = process.env.NODE_ENV === 'production';
|
||||
if (!res || typeof res.cookie !== "function") return;
|
||||
const isProd = process.env.NODE_ENV === "production";
|
||||
if (accessToken) {
|
||||
res.cookie('accessToken', accessToken, {
|
||||
res.cookie("accessToken", accessToken, {
|
||||
httpOnly: true,
|
||||
secure: isProd,
|
||||
sameSite: 'lax',
|
||||
sameSite: "lax",
|
||||
maxAge: 15 * 60 * 1000, // 15 mins
|
||||
path: '/',
|
||||
path: "/",
|
||||
});
|
||||
}
|
||||
if (refreshToken) {
|
||||
res.cookie('refreshToken', refreshToken, {
|
||||
res.cookie("refreshToken", refreshToken, {
|
||||
httpOnly: true,
|
||||
secure: isProd,
|
||||
sameSite: 'lax',
|
||||
sameSite: "lax",
|
||||
maxAge: 30 * 24 * 60 * 60 * 1000, // 30 days
|
||||
path: '/',
|
||||
path: "/",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private clearAuthCookies(res?: Response) {
|
||||
if (!res || typeof res.clearCookie !== 'function') return;
|
||||
const isProd = process.env.NODE_ENV === 'production';
|
||||
res.clearCookie('accessToken', {
|
||||
if (!res || typeof res.clearCookie !== "function") return;
|
||||
const isProd = process.env.NODE_ENV === "production";
|
||||
res.clearCookie("accessToken", {
|
||||
httpOnly: true,
|
||||
secure: isProd,
|
||||
sameSite: 'lax',
|
||||
path: '/',
|
||||
sameSite: "lax",
|
||||
path: "/",
|
||||
});
|
||||
res.clearCookie('refreshToken', {
|
||||
res.clearCookie("refreshToken", {
|
||||
httpOnly: true,
|
||||
secure: isProd,
|
||||
sameSite: 'lax',
|
||||
path: '/',
|
||||
sameSite: "lax",
|
||||
path: "/",
|
||||
});
|
||||
}
|
||||
|
||||
@Throttle({ default: { limit: 10, ttl: 60000 } })
|
||||
@Post('verify-otp')
|
||||
@Post("verify-otp")
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@ApiOperation({ summary: 'تایید کد پیامکی و ورود به سیستم' })
|
||||
@ApiOkResponse({ description: 'کد تایید شد و ورود با موفقیت انجام گردید' })
|
||||
@ApiOperation({ summary: "تایید کد پیامکی و ورود به سیستم" })
|
||||
@ApiOkResponse({ description: "کد تایید شد و ورود با موفقیت انجام گردید" })
|
||||
@ApiBadRequestResponse({
|
||||
description: 'کد تایید اشتباه است یا منقضی شده است',
|
||||
description: "کد تایید اشتباه است یا منقضی شده است",
|
||||
})
|
||||
async verifyOtp(
|
||||
@Body() verifyOtpDto: VerifyOtpDto,
|
||||
@@ -131,12 +131,12 @@ export class AuthController {
|
||||
}
|
||||
|
||||
@Throttle({ default: { limit: 5, ttl: 60000 } })
|
||||
@Post('register')
|
||||
@Post("register")
|
||||
@HttpCode(HttpStatus.CREATED)
|
||||
@ApiOperation({ summary: 'ثبتنام با ایمیل/موبایل و رمز عبور' })
|
||||
@ApiOkResponse({ description: 'کاربر با موفقیت ثبتنام شد' })
|
||||
@ApiOperation({ summary: "ثبتنام با ایمیل/موبایل و رمز عبور" })
|
||||
@ApiOkResponse({ description: "کاربر با موفقیت ثبتنام شد" })
|
||||
@ApiBadRequestResponse({
|
||||
description: 'اطلاعات ثبتنام نامعتبر است یا کاربر از قبل وجود دارد',
|
||||
description: "اطلاعات ثبتنام نامعتبر است یا کاربر از قبل وجود دارد",
|
||||
})
|
||||
async register(
|
||||
@Body() registerDto: RegisterDto,
|
||||
@@ -154,11 +154,11 @@ export class AuthController {
|
||||
}
|
||||
|
||||
@Throttle({ default: { limit: 5, ttl: 60000 } })
|
||||
@Post('login')
|
||||
@Post("login")
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@ApiOperation({ summary: 'ورود با موبایل و رمز عبور' })
|
||||
@ApiOkResponse({ description: 'ورود موفق به همراه توکن دسترسی' })
|
||||
@ApiBadRequestResponse({ description: 'نام کاربری یا رمز عبور اشتباه است' })
|
||||
@ApiOperation({ summary: "ورود با موبایل و رمز عبور" })
|
||||
@ApiOkResponse({ description: "ورود موفق به همراه توکن دسترسی" })
|
||||
@ApiBadRequestResponse({ description: "نام کاربری یا رمز عبور اشتباه است" })
|
||||
async login(
|
||||
@Body() loginDto: LoginDto,
|
||||
@Res({ passthrough: true }) res?: Response,
|
||||
@@ -175,11 +175,11 @@ export class AuthController {
|
||||
}
|
||||
|
||||
@Throttle({ default: { limit: 5, ttl: 300000 } }) // 5 attempts per 5 minutes
|
||||
@Post('admin-login')
|
||||
@Post("admin-login")
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@ApiOperation({ summary: 'ورود ادمین به پنل مدیریت' })
|
||||
@ApiOkResponse({ description: 'ورود موفق ادمین به همراه توکن' })
|
||||
@ApiBadRequestResponse({ description: 'اطلاعات ورود ادمین اشتباه است' })
|
||||
@ApiOperation({ summary: "ورود ادمین به پنل مدیریت" })
|
||||
@ApiOkResponse({ description: "ورود موفق ادمین به همراه توکن" })
|
||||
@ApiBadRequestResponse({ description: "اطلاعات ورود ادمین اشتباه است" })
|
||||
async adminLogin(
|
||||
@Body() body: AdminLoginDto,
|
||||
@Res({ passthrough: true }) res?: Response,
|
||||
@@ -196,13 +196,13 @@ export class AuthController {
|
||||
}
|
||||
|
||||
@Throttle({ default: { limit: 10, ttl: 60000 } })
|
||||
@Post('refresh-token')
|
||||
@Post("refresh-token")
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@ApiOperation({
|
||||
summary: 'دریافت جفت توکن جدید با استفاده از توکن تازهسازی',
|
||||
summary: "دریافت جفت توکن جدید با استفاده از توکن تازهسازی",
|
||||
})
|
||||
@ApiOkResponse({ description: 'توکنهای جدید با موفقیت صادر شدند' })
|
||||
@ApiBadRequestResponse({ description: 'توکن نامعتبر یا منقضی است' })
|
||||
@ApiOkResponse({ description: "توکنهای جدید با موفقیت صادر شدند" })
|
||||
@ApiBadRequestResponse({ description: "توکن نامعتبر یا منقضی است" })
|
||||
async refreshToken(
|
||||
@Body() body: RefreshTokenDto,
|
||||
@Req() req: any,
|
||||
@@ -226,10 +226,10 @@ export class AuthController {
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('refresh')
|
||||
@Post("refresh")
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@ApiOperation({ summary: 'تازهسازی توکن دسترسی (Refresh Token)' })
|
||||
@ApiOkResponse({ description: 'توکن جدید با موفقیت صادر شد' })
|
||||
@ApiOperation({ summary: "تازهسازی توکن دسترسی (Refresh Token)" })
|
||||
@ApiOkResponse({ description: "توکن جدید با موفقیت صادر شد" })
|
||||
async refresh(
|
||||
@Req()
|
||||
req: {
|
||||
@@ -250,15 +250,15 @@ export class AuthController {
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('logout')
|
||||
@Post("logout")
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@ApiOperation({ summary: 'خروج از حساب کاربری و ابطال توکن' })
|
||||
@ApiOkResponse({ description: 'با موفقیت خارج شدید' })
|
||||
@ApiOperation({ summary: "خروج از حساب کاربری و ابطال توکن" })
|
||||
@ApiOkResponse({ description: "با موفقیت خارج شدید" })
|
||||
async logout(@Req() req: any, @Res({ passthrough: true }) res?: Response) {
|
||||
let token: string | undefined;
|
||||
const authHeader = req.headers?.authorization;
|
||||
if (authHeader && authHeader.startsWith('Bearer ')) {
|
||||
token = authHeader.replace('Bearer ', '').trim();
|
||||
if (authHeader && authHeader.startsWith("Bearer ")) {
|
||||
token = authHeader.replace("Bearer ", "").trim();
|
||||
} else if (req.headers?.cookie) {
|
||||
const match = req.headers.cookie.match(/(?:^|;\s*)accessToken=([^;]+)/);
|
||||
if (match) token = decodeURIComponent(match[1]);
|
||||
@@ -267,6 +267,6 @@ export class AuthController {
|
||||
await this.authService.blacklistToken(token);
|
||||
}
|
||||
this.clearAuthCookies(res);
|
||||
return { success: true, message: 'با موفقیت خارج شدید' };
|
||||
return { success: true, message: "با موفقیت خارج شدید" };
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user