Skip to content

Commit

Permalink
Merge branch 'AN-404-clearer-workflow-config-behavior-messaging' of g…
Browse files Browse the repository at this point in the history
…ithub.com:DataBiosphere/terra-ui into AN-404-clearer-workflow-config-behavior-messaging
  • Loading branch information
LizBaldo committed Feb 5, 2025
2 parents 6e24eb0 + 5696fd7 commit e09b99b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/auth/oidc-broker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const getOidcConfig = () => {
// Leo's setCookie interval is currently 5 min, set refresh auth then 5 min 30 seconds to guarantee that setCookie's token won't expire between 2 setCookie api calls
accessTokenExpiringNotificationTimeInSeconds: 330,
includeIdTokenInSilentRenew: true,
includeIdTokenInSilentSignout: true,
extraQueryParams: { access_type: 'offline' },
redirect_uri: '', // this field is not being used currently, but is expected from UserManager
};
Expand Down
21 changes: 20 additions & 1 deletion src/auth/signout/sign-out.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ jest.mock('src/libs/state', (): StateExports => {
get: jest.fn().mockReturnValue({
userManager: {
signoutRedirect: jest.fn(() => 'Default signOutRedirectFn'),
getUser: jest.fn().mockReturnValue('not null'),
},
}),
},
Expand Down Expand Up @@ -91,7 +92,7 @@ describe('sign-out', () => {
const link = '/signout';
const expectedState = btoa(JSON.stringify({ signOutRedirect: currentRoute, signOutCause: 'unspecified' }));
asMockedFn(oidcStore.get).mockReturnValue({
userManager: { signoutRedirect: signOutRedirectFn },
userManager: { signoutRedirect: signOutRedirectFn, getUser: jest.fn().mockReturnValue('not null') },
} as unknown as OidcState);
asMockedFn(leoCookieProvider.unsetCookies).mockImplementation(unsetCookiesFn);
asMockedFn(Nav.getPath).mockReturnValue(link);
Expand All @@ -116,6 +117,7 @@ describe('sign-out', () => {
asMockedFn(oidcStore.get).mockReturnValue({
userManager: {
signoutRedirect: signOutRedirectFn,
getUser: jest.fn().mockReturnValue('not null'),
},
} as unknown as OidcState);
asMockedFn(removeUserFromLocalState).mockImplementation(removeUserFromLocalStateFn);
Expand All @@ -131,4 +133,21 @@ describe('sign-out', () => {
expect(removeUserFromLocalStateFn).toHaveBeenCalled();
expect(goToRootFn).toHaveBeenCalledWith('root');
});
it('calls userSignedOut if getUser returns null', async () => {
// Arrange
const removeUserFromLocalStateFn = jest.fn();
const goToRootFn = jest.fn();
asMockedFn(oidcStore.get).mockReturnValue({
userManager: {
getUser: jest.fn().mockReturnValue(null),
},
} as unknown as OidcState);
asMockedFn(removeUserFromLocalState).mockImplementation(removeUserFromLocalStateFn);
asMockedFn(goToPath).mockImplementation(goToRootFn);
// Act
await doSignOut();
// Assert
expect(removeUserFromLocalStateFn).toHaveBeenCalled();
expect(goToRootFn).toHaveBeenCalledWith('root');
});
});
14 changes: 10 additions & 4 deletions src/auth/signout/sign-out.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,16 @@ export const doSignOut = async (signOutCause: SignOutCause = 'unspecified'): Pro
const { name, query, params }: SignOutRedirect = Nav.getCurrentRoute();
const signOutState: SignOutState = { signOutRedirect: { name, query, params }, signOutCause };
const encodedState = btoa(JSON.stringify(signOutState));
userManager!.signoutRedirect({
post_logout_redirect_uri: redirectUrl,
extraQueryParams: { state: encodedState },
});
const user = await userManager!.getUser();
if (user) {
userManager!.signoutRedirect({
post_logout_redirect_uri: redirectUrl,
extraQueryParams: { state: encodedState },
});
} else {
userSignedOut(signOutCause, true);
Nav.goToPath('root');
}
} catch (e: unknown) {
console.error('Signing out with B2C failed. Falling back on local signout', e);
userSignedOut(signOutCause, true);
Expand Down

0 comments on commit e09b99b

Please sign in to comment.