fix(lint): enable require-await rule and remove unnecessary async
Enable @typescript-eslint/require-await to flag async functions without await. Convert synchronous functions from async to sync: - AuthService.login() - JWT generation is synchronous - AuthController.login() - now calls sync service method - AlertService.sendAlert() - only uses sync logger - MetricsPersistenceService.persistMetrics() - fire-and-forget pattern 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
872bdd546e
commit
3dba081b0a
8 changed files with 11 additions and 11 deletions
|
|
@ -107,7 +107,7 @@ describe('HostsController (Integration)', () => {
|
|||
await app.init();
|
||||
|
||||
// Generate valid JWT token for authenticated tests
|
||||
validJwtToken = await authService.login('test-password');
|
||||
validJwtToken = authService.login('test-password');
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
|
|
@ -156,7 +156,7 @@ describe('HostsController (Integration)', () => {
|
|||
|
||||
it('should reject request with expired JWT token', async () => {
|
||||
// Create token with immediate expiration
|
||||
const _expiredToken = await authService.login('test-password');
|
||||
const _expiredToken = authService.login('test-password');
|
||||
// Override token expiration by creating a new token manually
|
||||
// (in real scenario, wait for expiration or mock time)
|
||||
|
||||
|
|
|
|||
|
|
@ -177,7 +177,7 @@ describe('MetricsController (Integration)', () => {
|
|||
});
|
||||
|
||||
it('should reject JWT authentication (only mTLS/API Key allowed)', async () => {
|
||||
const jwtToken = await authService.login('test-password');
|
||||
const jwtToken = authService.login('test-password');
|
||||
|
||||
await request(app.getHttpServer())
|
||||
.post('/api/metrics/report')
|
||||
|
|
@ -466,7 +466,7 @@ describe('MetricsController (Integration)', () => {
|
|||
});
|
||||
|
||||
it('should NOT accept JWT authentication (only mTLS/API Key)', async () => {
|
||||
const jwtToken = await authService.login('test-password');
|
||||
const jwtToken = authService.login('test-password');
|
||||
|
||||
await request(app.getHttpServer())
|
||||
.post('/api/metrics/report')
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ describe('StatusController (Integration)', () => {
|
|||
|
||||
await app.init();
|
||||
|
||||
validJwtToken = await authService.login('test-password');
|
||||
validJwtToken = authService.login('test-password');
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
|
|
|
|||
|
|
@ -39,11 +39,11 @@ export class AuthController {
|
|||
@HttpCode(HttpStatus.OK)
|
||||
@UseGuards(RateLimitGuard)
|
||||
@RateLimit({ ttl: 60, limit: 5 }) // 5 attempts per minute
|
||||
async login(@Body() dto: LoginDto): Promise<LoginResponse> {
|
||||
login(@Body() dto: LoginDto): LoginResponse {
|
||||
let token: string | null;
|
||||
|
||||
try {
|
||||
token = await this.authService.login(dto.password, dto.totp);
|
||||
token = this.authService.login(dto.password, dto.totp);
|
||||
} catch (error) {
|
||||
// If TOTP is required but not provided, throw specific error
|
||||
if (error instanceof UnauthorizedException) {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ export class AuthService {
|
|||
* @returns JWT token or null if authentication fails
|
||||
* @throws UnauthorizedException if TOTP is required but not provided
|
||||
*/
|
||||
async login(password: string, totp?: string): Promise<string | null> {
|
||||
login(password: string, totp?: string): string | null {
|
||||
const { adminPassword, totpSecret } = this.configService.auth;
|
||||
|
||||
// Check password
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ export class AlertService {
|
|||
/**
|
||||
* Send alert notification
|
||||
*/
|
||||
async sendAlert(message: string, severity: AlertSeverity = 'info'): Promise<void> {
|
||||
sendAlert(message: string, severity: AlertSeverity = 'info'): void {
|
||||
const timestamp = new Date().toISOString();
|
||||
const severityUpper = severity.toUpperCase();
|
||||
const formattedMessage = `[${timestamp}] [${severityUpper}] ${message}`;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ describe('AuditLoggingInterceptor', () => {
|
|||
let interceptor: AuditLoggingInterceptor;
|
||||
let mockLogger: any;
|
||||
|
||||
beforeEach(async () => {
|
||||
beforeEach(() => {
|
||||
interceptor = new AuditLoggingInterceptor();
|
||||
mockLogger = {
|
||||
log: vi.fn(),
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ export class MetricsPersistenceService {
|
|||
*
|
||||
* @param metrics - Host metrics to persist
|
||||
*/
|
||||
async persistMetrics(metrics: HostMetrics): Promise<void> {
|
||||
persistMetrics(metrics: HostMetrics): void {
|
||||
// Convert HostMetrics to VPSResources format
|
||||
const vpsResources = this.convertToVPSResources(metrics);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue