Skip to content

Commit

Permalink
chore: review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Samaritan1011001 committed Aug 21, 2024
1 parent a4d8850 commit 1b2e1f9
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { tokenOrchestrator } from '../../../../../src/providers/cognito/tokenProvider';
import { completeOAuthSignOut } from '../../../../../src/providers/cognito/utils/oauth/completeOAuthSignOut';
import { handleOAuthSignOut } from '../../../../../src/providers/cognito/utils/oauth/handleOAuthSignOut.native';
import { oAuthSignOutRedirect } from '../../../../../src/providers/cognito/utils/oauth/oAuthSignOutRedirect';
Expand All @@ -23,6 +24,9 @@ describe('handleOAuthSignOut (native)', () => {
// assert mocks
const mockCompleteOAuthSignOut = completeOAuthSignOut as jest.Mock;
const mockOAuthSignOutRedirect = oAuthSignOutRedirect as jest.Mock;
const mockTokenOrchestrator = tokenOrchestrator as jest.Mocked<
typeof tokenOrchestrator
>;
// create mocks
const mockStore = {
loadOAuthSignIn: jest.fn(),
Expand All @@ -43,7 +47,12 @@ describe('handleOAuthSignOut (native)', () => {
});
it('should complete OAuth sign out and redirect', async () => {
mockOAuthSignOutRedirect.mockResolvedValue({ type: 'success' });
await handleOAuthSignOut(cognitoConfig, mockStore);
await handleOAuthSignOut(
cognitoConfig,
mockStore,
mockTokenOrchestrator,
undefined,
);

expect(mockOAuthSignOutRedirect).toHaveBeenCalledWith(
cognitoConfig,
Expand All @@ -55,7 +64,12 @@ describe('handleOAuthSignOut (native)', () => {

it('should not complete OAuth sign out if redirect is canceled', async () => {
mockOAuthSignOutRedirect.mockResolvedValue({ type: 'canceled' });
await handleOAuthSignOut(cognitoConfig, mockStore);
await handleOAuthSignOut(
cognitoConfig,
mockStore,
mockTokenOrchestrator,
undefined,
);

expect(mockOAuthSignOutRedirect).toHaveBeenCalledWith(
cognitoConfig,
Expand All @@ -67,7 +81,12 @@ describe('handleOAuthSignOut (native)', () => {

it('should not complete OAuth sign out if redirect failed', async () => {
mockOAuthSignOutRedirect.mockResolvedValue({ type: 'error' });
await handleOAuthSignOut(cognitoConfig, mockStore);
await handleOAuthSignOut(
cognitoConfig,
mockStore,
mockTokenOrchestrator,
undefined,
);

expect(mockOAuthSignOutRedirect).toHaveBeenCalledWith(
cognitoConfig,
Expand All @@ -84,7 +103,12 @@ describe('handleOAuthSignOut (native)', () => {
preferPrivateSession: true,
});
mockOAuthSignOutRedirect.mockResolvedValue({ type: 'error' });
await handleOAuthSignOut(cognitoConfig, mockStore, undefined);
await handleOAuthSignOut(
cognitoConfig,
mockStore,
mockTokenOrchestrator,
undefined,
);

expect(mockOAuthSignOutRedirect).toHaveBeenCalledWith(
cognitoConfig,
Expand All @@ -99,7 +123,12 @@ describe('handleOAuthSignOut (native)', () => {
isOAuthSignIn: false,
preferPrivateSession: false,
});
await handleOAuthSignOut(cognitoConfig, mockStore);
await handleOAuthSignOut(
cognitoConfig,
mockStore,
mockTokenOrchestrator,
undefined,
);

expect(mockOAuthSignOutRedirect).not.toHaveBeenCalled();
expect(mockCompleteOAuthSignOut).toHaveBeenCalledWith(mockStore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ describe('handleOAuthSignOut', () => {
isOAuthSignIn: false,
preferPrivateSession: false,
});
await handleOAuthSignOut(cognitoConfig, mockStore, mockTokenOrchestrator);
await handleOAuthSignOut(
cognitoConfig,
mockStore,
mockTokenOrchestrator,
undefined,
);

expect(mockCompleteOAuthSignOut).toHaveBeenCalledWith(mockStore);
expect(mockOAuthSignOutRedirect).toHaveBeenCalledWith(
Expand All @@ -83,7 +88,12 @@ describe('handleOAuthSignOut', () => {
isOAuthSignIn: false,
preferPrivateSession: false,
});
await handleOAuthSignOut(cognitoConfig, mockStore, mockTokenOrchestrator);
await handleOAuthSignOut(
cognitoConfig,
mockStore,
mockTokenOrchestrator,
undefined,
);

expect(mockCompleteOAuthSignOut).toHaveBeenCalledWith(mockStore);
expect(mockOAuthSignOutRedirect).not.toHaveBeenCalled();
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/providers/cognito/apis/signOut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export async function signOut(input?: SignOutInput): Promise<void> {
cognitoConfig,
oAuthStore,
tokenOrchestrator,
input?.oauth?.preferredSignOutUrl,
input?.oauth?.preferredRedirectUrl,
)) ?? {};
if (type === 'error') {
throw new AuthError({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const handleOAuthSignOut = async (
store: DefaultOAuthStore,
// No-op in here as it's only used in the non-native implementation
tokenOrchestrator: TokenOrchestrator,
preferredSignOutUrl?: string,
preferredSignOutUrl: string | undefined,
): Promise<void | OpenAuthSessionResult> => {
const { isOAuthSignIn, preferPrivateSession } = await store.loadOAuthSignIn();
if (isOAuthSignIn) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const handleOAuthSignOut = async (
cognitoConfig: CognitoUserPoolConfig,
store: DefaultOAuthStore,
tokenOrchestrator: TokenOrchestrator,
preferredSignOutUrl?: string,
preferredSignOutUrl: string | undefined,
): Promise<void | OpenAuthSessionResult> => {
const { isOAuthSignIn } = await store.loadOAuthSignIn();
const oauthMetadata = await tokenOrchestrator.getOAuthMetadata();
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/src/types/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export interface AuthSignInInput<
export interface AuthSignOutInput {
global?: boolean;
oauth?: {
preferredSignOutUrl?: string;
preferredRedirectUrl?: string;
};
}

Expand Down

0 comments on commit 1b2e1f9

Please sign in to comment.