Skip to content

Commit 6ccd194

Browse files
committed
chore: linting
1 parent 6706945 commit 6ccd194

2 files changed

Lines changed: 49 additions & 37 deletions

File tree

packages/nestjs-authentication/src/authentication.module-definition.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,11 @@ function definitionTransform(
7171
}
7272

7373
export function createAuthenticationImports(options: {
74-
imports: DynamicModule['imports'];
75-
}): DynamicModule['imports']
76-
{
74+
imports: DynamicModule['imports'];
75+
}): DynamicModule['imports'] {
7776
return [
7877
...(options.imports || []),
79-
ConfigModule.forFeature(authenticationDefaultConfig)
78+
ConfigModule.forFeature(authenticationDefaultConfig),
8079
];
8180
}
8281

packages/nestjs-authentication/src/authentication.module.spec.ts

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { DynamicModule, Inject, Injectable, Module, ModuleMetadata } from '@nestjs/common';
1+
import {
2+
DynamicModule,
3+
Inject,
4+
Injectable,
5+
Module,
6+
ModuleMetadata,
7+
} from '@nestjs/common';
28
import { Test, TestingModule } from '@nestjs/testing';
39

410
import { JwtModule } from '@concepta/nestjs-jwt';
@@ -95,7 +101,8 @@ describe(AuthenticationModule, () => {
95101
class TestController {
96102
constructor(
97103
@Inject(IssueTokenService)
98-
private readonly issueTokenService: IssueTokenService) {
104+
private readonly issueTokenService: IssueTokenService,
105+
) {
99106
// TestController with injected IssueTokenService
100107
}
101108
}
@@ -109,11 +116,11 @@ describe(AuthenticationModule, () => {
109116
) {}
110117

111118
// Method to issue tokens using TEMP secrets
112-
async issueAccessToken(payload: any) {
119+
async issueAccessToken(payload: string) {
113120
return this.issueTokenService.accessToken(payload);
114121
}
115122

116-
async issueRefreshToken(payload: any) {
123+
async issueRefreshToken(payload: string) {
117124
return this.issueTokenService.refreshToken(payload);
118125
}
119126

@@ -136,27 +143,27 @@ describe(AuthenticationModule, () => {
136143
access: {
137144
secret: 'TEMP',
138145
signOptions: {
139-
expiresIn: '1h'
140-
}
146+
expiresIn: '1h',
147+
},
141148
},
142149
refresh: {
143150
secret: 'TEMP',
144151
signOptions: {
145-
expiresIn: '99y'
146-
}
147-
}
148-
}
149-
})
152+
expiresIn: '99y',
153+
},
154+
},
155+
},
156+
}),
150157
],
151158
inject: [],
152-
useFactory: () => ({})
159+
useFactory: () => ({}),
153160
}),
154161
],
155162
controllers: [TestController],
156-
providers: [TestService]
163+
providers: [TestService],
157164
})
158165
class TestModule {}
159-
166+
160167
beforeEach(async () => {
161168
testModule = await Test.createTestingModule(
162169
testModuleFactory([
@@ -171,7 +178,7 @@ describe(AuthenticationModule, () => {
171178

172179
it('should isolate TEMP secrets from global secrets - cross-verification should fail', async () => {
173180
commonVars();
174-
181+
175182
// Get services from the main testModule (global JWT)
176183
// These are the services from the testModuleFactory with 'global' secrets
177184
const globalIssueService = issueTokenService;
@@ -181,33 +188,39 @@ describe(AuthenticationModule, () => {
181188
const testService = testModule.get(TestService);
182189

183190
const payload = { sub: 'test-user-id', username: 'testuser' };
184-
191+
185192
// Create token with TEMP secret (via TestService)
186193
const tempAccessToken = await testService.issueAccessToken(payload);
187194
const tempRefreshToken = await testService.issueRefreshToken(payload);
188-
195+
189196
// Create token with global secret (from main testModule)
190197
const globalAccessToken = await globalIssueService.accessToken(payload);
191198
const globalRefreshToken = await globalIssueService.refreshToken(payload);
192-
199+
193200
// Test 1: TEMP token should NOT be verifiable by global service
194-
await expect(globalVerifyService.accessToken(tempAccessToken))
195-
.rejects.toThrow(); // Should fail due to wrong secret
196-
197-
await expect(globalVerifyService.refreshToken(tempRefreshToken))
198-
.rejects.toThrow(); // Should fail due to wrong secret
199-
201+
await expect(
202+
globalVerifyService.accessToken(tempAccessToken),
203+
).rejects.toThrow(); // Should fail due to wrong secret
204+
205+
await expect(
206+
globalVerifyService.refreshToken(tempRefreshToken),
207+
).rejects.toThrow(); // Should fail due to wrong secret
208+
200209
// Test 2: Global token should NOT be verifiable by TEMP service (via TestService)
201-
await expect(testService.verifyAccessToken(globalAccessToken))
202-
.rejects.toThrow(); // Should fail due to wrong secret
203-
204-
await expect(testService.verifyRefreshToken(globalRefreshToken))
205-
.rejects.toThrow(); // Should fail due to wrong secret
206-
210+
await expect(
211+
testService.verifyAccessToken(globalAccessToken),
212+
).rejects.toThrow(); // Should fail due to wrong secret
213+
214+
await expect(
215+
testService.verifyRefreshToken(globalRefreshToken),
216+
).rejects.toThrow(); // Should fail due to wrong secret
217+
207218
// Test 3: But tokens should be verifiable by their own services (sanity check)
208-
const tempVerified = await testService.verifyAccessToken(tempAccessToken);
209-
const globalVerified = await globalVerifyService.accessToken(globalAccessToken);
210-
219+
const tempVerified = await testService.verifyAccessToken(tempAccessToken);
220+
const globalVerified = await globalVerifyService.accessToken(
221+
globalAccessToken,
222+
);
223+
211224
expect(tempVerified).toBeDefined();
212225
expect(globalVerified).toBeDefined();
213226
});

0 commit comments

Comments
 (0)