Skip to content

Commit

Permalink
fix: polling issue with using generic remediator
Browse files Browse the repository at this point in the history
chore: bump version to 6.5.2

OKTA-502192
<<<Jenkins Check-In of Tested SHA: 02d3a1d for [email protected]>>>
Artifact: okta-auth-js
Files changed count: 4
PR Link: #1215
  • Loading branch information
shuowu authored and eng-prod-CI-bot-okta committed May 30, 2022
1 parent 003673d commit c0859b2
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 26 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 6.5.2

### Fixes

- [#1215](https://github.com/okta/okta-auth-js/pull/1215) Fixes polling issue in GenericRemediator (beta)

## 6.5.1

### Fixes
Expand Down
14 changes: 14 additions & 0 deletions lib/idx/remediate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,20 @@ export async function remediate(
// Let the remediator decide what the values should be (default to current values)
values = remediator.getValuesAfterProceed();
options = { ...options, step: undefined }; // do not re-use the step

// generic remediator should not auto proceed in pending status
// return nextStep directly
if (options.useGenericRemediator && !idxResponse.interactionCode) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const gr = getRemediator(idxResponse.neededToProceed, values, options)!;
const nextStep = getNextStep(authClient, gr, idxResponse);
return {
idxResponse,
nextStep,
messages: messages.length ? messages: undefined
};
}

return remediate(authClient, idxResponse, values, options); // recursive call
} catch (e) {
return handleIdxError(authClient, e, remediator);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": true,
"name": "@okta/okta-auth-js",
"description": "The Okta Auth SDK",
"version": "6.5.1",
"version": "6.5.2",
"homepage": "https://github.com/okta/okta-auth-js",
"license": "Apache-2.0",
"main": "build/cjs/index.js",
Expand Down
70 changes: 45 additions & 25 deletions test/spec/idx/remediate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe('idx/remediate', () => {
});
expect(util.getRemediator).toHaveBeenCalledTimes(2);
expect(util.getRemediator).toHaveBeenNthCalledWith(1, idxResponse.neededToProceed, { resend: true }, {});
expect(util.getRemediator).toHaveBeenNthCalledWith(2, responseFromAction.neededToProceed, {}, { actions: []});
expect(util.getRemediator).toHaveBeenNthCalledWith(2, responseFromAction.neededToProceed, {}, { actions: [] });
});

it('will handle exceptions', async () => {
Expand Down Expand Up @@ -161,7 +161,7 @@ describe('idx/remediate', () => {
},
rawIdxState: {}
} as unknown as IdxResponse;
const res = await remediate(authClient, idxResponse, { resend: true }, { actions: ['some-action']});
const res = await remediate(authClient, idxResponse, { resend: true }, { actions: ['some-action'] });
expect(res).toEqual(errorResponse);
expect(util.handleIdxError).toHaveBeenCalledWith(authClient, error, remediator);
});
Expand Down Expand Up @@ -192,7 +192,7 @@ describe('idx/remediate', () => {
nextStep: {}
});
expect(util.getRemediator).toHaveBeenCalledTimes(2);
expect(util.getRemediator).toHaveBeenNthCalledWith(1, idxResponse.neededToProceed, { }, { actions: ['some-remediation'] });
expect(util.getRemediator).toHaveBeenNthCalledWith(1, idxResponse.neededToProceed, {}, { actions: ['some-remediation'] });
expect(util.getRemediator).toHaveBeenNthCalledWith(2, responseFromRemediation.neededToProceed, {}, { actions: [] });
});
it('will handle exceptions', async () => {
Expand All @@ -206,7 +206,7 @@ describe('idx/remediate', () => {
name: 'some-remediation'
}],
} as unknown as IdxResponse;
const res = await remediate(authClient, idxResponse, {}, { actions: ['some-remediation']});
const res = await remediate(authClient, idxResponse, {}, { actions: ['some-remediation'] });
expect(res).toBe(errorResponse);
expect(util.handleIdxError).toHaveBeenCalledWith(authClient, error, remediator);
});
Expand Down Expand Up @@ -295,7 +295,7 @@ describe('idx/remediate', () => {
name: 'some-action',
params: { foo: 'bar' }
};
const res = await remediate(authClient, idxResponse, {}, { actions: [action]});
const res = await remediate(authClient, idxResponse, {}, { actions: [action] });
expect(res).toBe(errorResponse);
expect(util.handleIdxError).toHaveBeenCalledWith(authClient, error, remediator);
expect(actionFn).toHaveBeenCalledWith({ foo: 'bar' });
Expand Down Expand Up @@ -330,7 +330,7 @@ describe('idx/remediate', () => {
nextStep: {}
});
expect(util.getRemediator).toHaveBeenCalledTimes(2);
expect(util.getRemediator).toHaveBeenNthCalledWith(1, idxResponse.neededToProceed, { }, { actions: [action] });
expect(util.getRemediator).toHaveBeenNthCalledWith(1, idxResponse.neededToProceed, {}, { actions: [action] });
expect(util.getRemediator).toHaveBeenNthCalledWith(2, responseFromRemediation.neededToProceed, {}, { actions: [] });
});
it('will handle exceptions', async () => {
Expand All @@ -347,7 +347,7 @@ describe('idx/remediate', () => {
const action = {
name: 'some-remediation'
};
const res = await remediate(authClient, idxResponse, {}, { actions: [action]});
const res = await remediate(authClient, idxResponse, {}, { actions: [action] });
expect(res).toBe(errorResponse);
expect(util.handleIdxError).toHaveBeenCalledWith(authClient, error, remediator);
});
Expand Down Expand Up @@ -420,27 +420,27 @@ describe('idx/remediate', () => {
},
});
expect(util.getRemediator).toHaveBeenCalledTimes(1);
expect(util.getRemediator).toHaveBeenNthCalledWith(1, idxResponse.neededToProceed, { }, { step: 'some-remediation' });
expect(util.getRemediator).toHaveBeenNthCalledWith(1, idxResponse.neededToProceed, {}, { step: 'some-remediation' });
expect(idxResponse.proceed).toHaveBeenCalledWith('some-remediation', {});
});
it('will handle exceptions', async () => {
let { authClient, idxResponse } = testContext;
const { errorResponse } = testContext;
const error = new Error('my test error');
idxResponse = {
...idxResponse,
proceed: jest.fn().mockRejectedValue(error),
neededToProceed: [{
name: 'some-remediation',
value: [{
name: 'foo'
}]
}],
} as unknown as IdxResponse;
const res = await remediate(authClient, idxResponse, {}, { step: 'some-remediation' });
expect(res).toBe(errorResponse);
expect(util.handleIdxError).toHaveBeenCalledWith(authClient, error);
expect(idxResponse.proceed).toHaveBeenCalledWith('some-remediation', {});
const { errorResponse } = testContext;
const error = new Error('my test error');
idxResponse = {
...idxResponse,
proceed: jest.fn().mockRejectedValue(error),
neededToProceed: [{
name: 'some-remediation',
value: [{
name: 'foo'
}]
}],
} as unknown as IdxResponse;
const res = await remediate(authClient, idxResponse, {}, { step: 'some-remediation' });
expect(res).toBe(errorResponse);
expect(util.handleIdxError).toHaveBeenCalledWith(authClient, error);
expect(idxResponse.proceed).toHaveBeenCalledWith('some-remediation', {});
});
});
describe('flow is "default"', () => {
Expand Down Expand Up @@ -556,6 +556,26 @@ describe('idx/remediate', () => {
});

describe('use generic remediator', () => {

it('does not auto proceed', async () => {
let { authClient, idxResponse, remediator } = testContext;
idxResponse = {
...idxResponse,
neededToProceed: [{
name: 'some-remediation'
}]
};
const responseFromProceed = {
...idxResponse,
rawIdxState: {
messages: {
value: ['hello']
}
}
};
idxResponse.proceed.mockResolvedValue(responseFromProceed);
remediator.canRemediate.mockReturnValue(true);
await remediate(authClient, idxResponse, {}, { useGenericRemediator: true });
expect(idxResponse.proceed).toHaveBeenCalledTimes(1);
});
});
});

0 comments on commit c0859b2

Please sign in to comment.