Skip to content

Commit

Permalink
fix: prevents incorrectly removing idx message duplicates (#1446)
Browse files Browse the repository at this point in the history
OKTA-630044 fix: prevents incorrectly removing dup keys with different messages
  • Loading branch information
jaredperreault-okta authored Aug 17, 2023
1 parent 31b0f70 commit 92826f6
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 7.4.1

### Bug Fix

- [#1446](https://github.com/okta/okta-auth-js/pull/1446) Fix: prevents incorrectly removing idx message duplicates

## 7.4.0

### Features
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ require('@okta/okta-auth-js/polyfill');
The built polyfill bundle is also available on our global CDN. Include the following script in your HTML file to load before any other scripts:

```html
<script src="https://global.oktacdn.com/okta-auth-js/7.0.0/okta-auth-js.polyfill.js" type="text/javascript"></script>
<script src="https://global.oktacdn.com/okta-auth-js/7.4.1/okta-auth-js.polyfill.js" type="text/javascript"></script>
```

> :warning: The version shown in this sample may be older than the current version. We recommend using the highest version available
Expand Down Expand Up @@ -171,7 +171,7 @@ If you are using the JS on a web page from the browser, you can copy the `node_m
The built library bundle is also available on our global CDN. Include the following script in your HTML file to load before your application script:

```html
<script src="https://global.oktacdn.com/okta-auth-js/7.0.0/okta-auth-js.min.js" type="text/javascript"></script>
<script src="https://global.oktacdn.com/okta-auth-js/7.4.1/okta-auth-js.min.js" type="text/javascript"></script>
```

> :warning: The version shown in this sample may be older than the current version. We recommend using the highest version available
Expand Down Expand Up @@ -812,7 +812,7 @@ const config = {
};

const authClient = new OktaAuth(config);
const tokens = await authClient.token.getWithoutPrompt();
const { tokens } = await authClient.token.getWithoutPrompt();
authClient.tokenManager.setTokens(tokens); // storageProvider.setItem

```
Expand Down
3 changes: 2 additions & 1 deletion lib/idx/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,14 @@ export function getMessagesFromResponse(idxResponse: IdxResponse, options: RunOp
const seen = {};
messages = messages.reduce((filtered, message) => {
const key = message.i18n?.key;
if (key && seen[key]) {
if (key && seen[key] && message.message === seen[key].message) {
return filtered;
}
seen[key] = message;
filtered = [...filtered, message] as never;
return filtered;
}, []);

return messages;
}

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": "7.4.0",
"version": "7.4.1",
"homepage": "https://github.com/okta/okta-auth-js",
"license": "Apache-2.0",
"main": "build/cjs/exports/default.js",
Expand Down
40 changes: 40 additions & 0 deletions test/spec/idx/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,46 @@ describe('idx/util', () => {
}]);
});

it('removes duplicate messages', () => {
const expected = [
{
class: 'ERROR',
i18n: {
key: 'security.access_denied'
},
message: 'You do not have permission to perform the requested action.'
},
{
class: 'ERROR',
i18n: {
key: 'security.access_denied'
},
message: 'some random text'
}
];

const rawIdxState = RawIdxResponseFactory.build({
messages: IdxMessagesFactory.build({
value: [
IdxErrorAccessDeniedFactory.build(),
IdxErrorAccessDeniedFactory.build(),
IdxErrorAccessDeniedFactory.build(),
IdxErrorAccessDeniedFactory.build({
message: 'some random text'
})
]
})
});
const idxResponse = IdxResponseFactory.build({
rawIdxState
});
const res = getMessagesFromResponse(idxResponse, {});
expect(res).toEqual(expected);

const genericRemRes = getMessagesFromResponse(idxResponse, { useGenericRemediator: true });
expect(genericRemRes).toEqual(expected);
});

describe('form level messages', () => {
let idxResponse;
beforeEach(() => {
Expand Down

0 comments on commit 92826f6

Please sign in to comment.