|
1 | 1 | import { EnvService } from '../env/index.js'; |
2 | | -import { AUTH_CALLBACK_INJECTION_TOKEN } from '../injection-tokens.js'; |
| 2 | +import { |
| 3 | + AUTH_CALLBACK_INJECTION_TOKEN, |
| 4 | + AUTH_CONFIG_INJECTION_TOKEN, |
| 5 | +} from '../injection-tokens.js'; |
3 | 6 | import { PortalModule } from '../portal.module.js'; |
4 | 7 | import { |
5 | 8 | AuthConfigService, |
| 9 | + EmptyAuthConfigService, |
6 | 10 | EnvAuthConfigService, |
7 | 11 | } from './auth-config.service.js'; |
8 | 12 | import { AuthTokenData, AuthTokenService } from './auth-token.service.js'; |
@@ -30,15 +34,21 @@ describe('AuthTokenService', () => { |
30 | 34 |
|
31 | 35 | authCallbackMock = mock<AuthCallback>(); |
32 | 36 | const module: TestingModule = await Test.createTestingModule({ |
33 | | - imports: [PortalModule.create({})], |
| 37 | + imports: [ |
| 38 | + PortalModule.create({ |
| 39 | + authConfigProvider: EnvAuthConfigService, |
| 40 | + }), |
| 41 | + ], |
34 | 42 | }) |
35 | 43 | .overrideProvider(AUTH_CALLBACK_INJECTION_TOKEN) |
36 | 44 | .useValue(authCallbackMock) |
37 | 45 | .compile(); |
38 | 46 |
|
39 | 47 | service = module.get<AuthTokenService>(AuthTokenService); |
40 | 48 | envService = module.get<EnvService>(EnvService); |
41 | | - authConfigService = module.get<AuthConfigService>(EnvAuthConfigService); |
| 49 | + authConfigService = module.get<AuthConfigService>( |
| 50 | + AUTH_CONFIG_INJECTION_TOKEN, |
| 51 | + ); |
42 | 52 | responseMock = mock<Response>(); |
43 | 53 | requestMock = mock<Request>(); |
44 | 54 | }); |
@@ -128,6 +138,29 @@ describe('AuthTokenService', () => { |
128 | 138 | 'Unexpected response code from auth token server: 206, Partial Content', |
129 | 139 | ); |
130 | 140 | }); |
| 141 | + |
| 142 | + it('should throw error when clientId is not configured', async () => { |
| 143 | + const module: TestingModule = await Test.createTestingModule({ |
| 144 | + imports: [ |
| 145 | + PortalModule.create({ |
| 146 | + authConfigProvider: EmptyAuthConfigService, |
| 147 | + }), |
| 148 | + ], |
| 149 | + }) |
| 150 | + .overrideProvider(AUTH_CALLBACK_INJECTION_TOKEN) |
| 151 | + .useValue(authCallbackMock) |
| 152 | + .compile(); |
| 153 | + |
| 154 | + const emptyService = module.get<AuthTokenService>(AuthTokenService); |
| 155 | + |
| 156 | + await expect( |
| 157 | + emptyService.exchangeTokenForRefreshToken( |
| 158 | + requestMock, |
| 159 | + responseMock, |
| 160 | + refreshToken, |
| 161 | + ), |
| 162 | + ).rejects.toThrow('Client ID is not configured'); |
| 163 | + }); |
131 | 164 | }); |
132 | 165 |
|
133 | 166 | describe('token for code - authorization_code flow', () => { |
@@ -182,6 +215,29 @@ describe('AuthTokenService', () => { |
182 | 215 | // Assert |
183 | 216 | assertResponseAndCookies(authTokenResponse); |
184 | 217 | }); |
| 218 | + |
| 219 | + it('should throw error when clientId is not configured', async () => { |
| 220 | + const module: TestingModule = await Test.createTestingModule({ |
| 221 | + imports: [ |
| 222 | + PortalModule.create({ |
| 223 | + authConfigProvider: EmptyAuthConfigService, |
| 224 | + }), |
| 225 | + ], |
| 226 | + }) |
| 227 | + .overrideProvider(AUTH_CALLBACK_INJECTION_TOKEN) |
| 228 | + .useValue(authCallbackMock) |
| 229 | + .compile(); |
| 230 | + |
| 231 | + const emptyService = module.get<AuthTokenService>(AuthTokenService); |
| 232 | + |
| 233 | + await expect( |
| 234 | + emptyService.exchangeTokenForCode( |
| 235 | + requestMock, |
| 236 | + responseMock, |
| 237 | + 'test-code', |
| 238 | + ), |
| 239 | + ).rejects.toThrow('Client ID is not configured'); |
| 240 | + }); |
185 | 241 | }); |
186 | 242 |
|
187 | 243 | it('handles an auth server error', async () => { |
|
0 commit comments