Merge pull request #10982 from keithjgrant/json-deterministic-order

Ensure deterministic order of JSON serializing for misc auth settings
This commit is contained in:
Sarah Akus 2021-08-31 14:14:19 -04:00 committed by GitHub
commit 30cf483357
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 3 deletions

View File

@ -91,7 +91,7 @@ describe('<LDAPDetail />', () => {
assertVariableDetail(
wrapper,
'LDAP Group Type Parameters',
'{\n "name_attr": "cn",\n "member_attr": "member"\n}'
'{\n "member_attr": "member",\n "name_attr": "cn"\n}'
);
assertVariableDetail(wrapper, 'LDAP User Flags By Group', '{}');
assertVariableDetail(wrapper, 'LDAP Organization Map', '{}');

View File

@ -68,7 +68,7 @@ describe('<MiscAuthenticationDetail />', () => {
assertVariableDetail(
wrapper,
'OAuth 2 Timeout Settings',
'{\n "ACCESS_TOKEN_EXPIRE_SECONDS": 31536000000,\n "REFRESH_TOKEN_EXPIRE_SECONDS": 2628000,\n "AUTHORIZATION_CODE_EXPIRE_SECONDS": 600\n}'
'{\n "ACCESS_TOKEN_EXPIRE_SECONDS": 31536000000,\n "AUTHORIZATION_CODE_EXPIRE_SECONDS": 600,\n "REFRESH_TOKEN_EXPIRE_SECONDS": 2628000\n}'
);
assertDetail(wrapper, 'Login redirect override URL', 'https://foohost');
assertVariableDetail(

View File

@ -4,6 +4,19 @@ import { t } from '@lingui/macro';
import { Detail } from 'components/DetailList';
import CodeDetail from 'components/DetailList/CodeDetail';
function sortObj(obj) {
if (typeof obj !== 'object' || Array.isArray(obj)) {
return obj;
}
const sorted = {};
Object.keys(obj)
.sort()
.forEach((key) => {
sorted[key] = sortObj(obj[key]);
});
return sorted;
}
export default ({ helpText, id, label, type, unit = '', value }) => {
const dataType = value === '$encrypted$' ? 'encrypted' : type;
let detail = null;
@ -17,7 +30,7 @@ export default ({ helpText, id, label, type, unit = '', value }) => {
label={label}
mode="javascript"
rows={4}
value={JSON.stringify(value || {}, undefined, 2)}
value={JSON.stringify(sortObj(value || {}), undefined, 2)}
/>
);
break;