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
3 changed files with 16 additions and 3 deletions

View File

@@ -91,7 +91,7 @@ describe('<LDAPDetail />', () => {
assertVariableDetail( assertVariableDetail(
wrapper, wrapper,
'LDAP Group Type Parameters', '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 User Flags By Group', '{}');
assertVariableDetail(wrapper, 'LDAP Organization Map', '{}'); assertVariableDetail(wrapper, 'LDAP Organization Map', '{}');

View File

@@ -68,7 +68,7 @@ describe('<MiscAuthenticationDetail />', () => {
assertVariableDetail( assertVariableDetail(
wrapper, wrapper,
'OAuth 2 Timeout Settings', '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'); assertDetail(wrapper, 'Login redirect override URL', 'https://foohost');
assertVariableDetail( assertVariableDetail(

View File

@@ -4,6 +4,19 @@ import { t } from '@lingui/macro';
import { Detail } from 'components/DetailList'; import { Detail } from 'components/DetailList';
import CodeDetail from 'components/DetailList/CodeDetail'; 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 }) => { export default ({ helpText, id, label, type, unit = '', value }) => {
const dataType = value === '$encrypted$' ? 'encrypted' : type; const dataType = value === '$encrypted$' ? 'encrypted' : type;
let detail = null; let detail = null;
@@ -17,7 +30,7 @@ export default ({ helpText, id, label, type, unit = '', value }) => {
label={label} label={label}
mode="javascript" mode="javascript"
rows={4} rows={4}
value={JSON.stringify(value || {}, undefined, 2)} value={JSON.stringify(sortObj(value || {}), undefined, 2)}
/> />
); );
break; break;