Skip to content

Commit 33372ed

Browse files
Merge pull request #1943 from Yberion/feature/enhance-manual-renew-session
fix(refresh-session): `forceRefreshSession` does not reset `storageSilentRenewRunning`
2 parents 602b667 + 8d737ca commit 33372ed

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

projects/angular-auth-oidc-client/src/lib/callback/refresh-session.service.spec.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { FlowsDataService } from '../flows/flows-data.service';
99
import { RefreshSessionIframeService } from '../iframe/refresh-session-iframe.service';
1010
import { SilentRenewService } from '../iframe/silent-renew.service';
1111
import { LoggerService } from '../logging/logger.service';
12+
import { LoginResponse } from '../login/login-response';
13+
import { PublicEventsService } from '../public-events/public-events.service';
1214
import { StoragePersistenceService } from '../storage/storage-persistence.service';
1315
import { UserService } from '../user-data/user.service';
1416
import { FlowHelper } from '../utils/flowHelper/flow-helper.service';
@@ -44,6 +46,7 @@ describe('RefreshSessionService ', () => {
4446
mockProvider(StoragePersistenceService),
4547
mockProvider(RefreshSessionRefreshTokenService),
4648
mockProvider(UserService),
49+
mockProvider(PublicEventsService),
4750
],
4851
});
4952
});
@@ -162,6 +165,63 @@ describe('RefreshSessionService ', () => {
162165
expect(writeSpy).not.toHaveBeenCalled();
163166
});
164167
}));
168+
169+
it('should call resetSilentRenewRunning in case of an error', waitForAsync(() => {
170+
spyOn(refreshSessionService, 'forceRefreshSession').and.returnValue(
171+
throwError(() => new Error('error'))
172+
);
173+
spyOn(flowsDataService, 'resetSilentRenewRunning');
174+
const allConfigs = [
175+
{
176+
configId: 'configId1',
177+
useRefreshToken: false,
178+
silentRenewTimeoutInSeconds: 10,
179+
},
180+
];
181+
182+
refreshSessionService
183+
.userForceRefreshSession(allConfigs[0], allConfigs)
184+
.subscribe({
185+
next: () => {
186+
fail('It should not return any result.');
187+
},
188+
error: (error) => {
189+
expect(error).toBeInstanceOf(Error);
190+
},
191+
complete: () => {
192+
expect(
193+
flowsDataService.resetSilentRenewRunning
194+
).toHaveBeenCalledOnceWith(allConfigs[0]);
195+
},
196+
});
197+
}));
198+
199+
it('should call resetSilentRenewRunning in case of no error', waitForAsync(() => {
200+
spyOn(refreshSessionService, 'forceRefreshSession').and.returnValue(
201+
of({} as LoginResponse)
202+
);
203+
spyOn(flowsDataService, 'resetSilentRenewRunning');
204+
const allConfigs = [
205+
{
206+
configId: 'configId1',
207+
useRefreshToken: false,
208+
silentRenewTimeoutInSeconds: 10,
209+
},
210+
];
211+
212+
refreshSessionService
213+
.userForceRefreshSession(allConfigs[0], allConfigs)
214+
.subscribe({
215+
error: () => {
216+
fail('It should not return any error.');
217+
},
218+
complete: () => {
219+
expect(
220+
flowsDataService.resetSilentRenewRunning
221+
).toHaveBeenCalledOnceWith(allConfigs[0]);
222+
},
223+
});
224+
}));
165225
});
166226

167227
describe('forceRefreshSession', () => {

projects/angular-auth-oidc-client/src/lib/callback/refresh-session.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
retryWhen,
1414
switchMap,
1515
take,
16+
tap,
1617
timeout,
1718
} from 'rxjs/operators';
1819
import { AuthStateService } from '../auth-state/auth-state.service';
@@ -75,7 +76,9 @@ export class RefreshSessionService {
7576

7677
this.persistCustomParams(extraCustomParams, config);
7778

78-
return this.forceRefreshSession(config, allConfigs, extraCustomParams);
79+
return this.forceRefreshSession(config, allConfigs, extraCustomParams).pipe(
80+
tap(() => this.flowsDataService.resetSilentRenewRunning(config))
81+
);
7982
}
8083

8184
forceRefreshSession(

0 commit comments

Comments
 (0)