Skip to content

Commit

Permalink
fix(idx): allow proceed when saved idxResponse is available - OKTA-51…
Browse files Browse the repository at this point in the history
  • Loading branch information
shuowu committed Jul 11, 2022
1 parent dd3078f commit 0f54b76
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/idx/proceed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import { AuthSdkError } from '../errors';

export function canProceed(authClient: OktaAuthIdxInterface, options: ProceedOptions = {}): boolean {
const meta = getSavedTransactionMeta(authClient, options);
return !!(meta || options.stateHandle);
const savedIdxResponse = authClient.transactionManager.loadIdxResponse(options);
const stateHandle = savedIdxResponse?.stateHandle || options.stateHandle;
return !!(meta || stateHandle);
}

export async function proceed(
Expand Down
1 change: 1 addition & 0 deletions test/spec/idx/authenticate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ describe('idx/authenticate', () => {
clear: () => {},
save: () => {},
saveIdxResponse: () => {},
loadIdxResponse: () => {},
},
token: {
exchangeCodeForTokens: () => Promise.resolve(tokenResponse)
Expand Down
10 changes: 9 additions & 1 deletion test/spec/idx/proceed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('idx/proceed', () => {
urls: { authorizeUrl: 'meta-authorizeUrl' },
ignoreSignature: true,
};
const savedIdxResponse = { stateHandle: 'fake-stateHandle' };
const authClient = {
options: {
issuer,
Expand All @@ -48,6 +49,7 @@ describe('idx/proceed', () => {
transactionManager: {
exists: () => true,
load: () => transactionMeta,
loadIdxResponse: () => {},
clear: () => {},
save: () => {},
},
Expand All @@ -62,16 +64,22 @@ describe('idx/proceed', () => {
redirectUri,
stateHandle,
transactionMeta,
savedIdxResponse,
authClient
};
});

describe('canProceed', () => {
it('returns true if there is a saved transaction', () => {
it('returns true if there is a saved transaction meta', () => {
const { authClient, transactionMeta } = testContext;
jest.spyOn(mocked.transactionMeta, 'getSavedTransactionMeta').mockReturnValue(transactionMeta);
expect(canProceed(authClient)).toBe(true);
});
it('returns true if there is a saved idxTransaction', () => {
const { authClient, savedIdxResponse } = testContext;
jest.spyOn(authClient.transactionManager, 'loadIdxResponse').mockReturnValue(savedIdxResponse);
expect(canProceed(authClient)).toBe(true);
});
it('returns false if there is no saved transaction', () => {
const { authClient } = testContext;
jest.spyOn(mocked.transactionMeta, 'getSavedTransactionMeta').mockReturnValue(undefined);
Expand Down

0 comments on commit 0f54b76

Please sign in to comment.