Auth: Store array settings from the config UI in JSON array format (#99454)

* Store array settings in JSON array format

* Align tests
This commit is contained in:
Misi 2025-01-26 10:08:07 -05:00 committed by GitHub
parent 154a57cd30
commit 25bb210ca3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 19 deletions

View File

@ -52,12 +52,12 @@ const testConfig: SSOProvider = {
clientId: '12345', clientId: '12345',
clientSecret: 'abcde', clientSecret: 'abcde',
enabled: true, enabled: true,
teamIds: '', teamIds: '[]',
allowedOrganizations: '', allowedOrganizations: '[]',
allowedDomains: '', allowedDomains: '[]',
allowedGroups: '', allowedGroups: '[]',
scopes: '', scopes: '[]',
orgMapping: '', orgMapping: '[]',
}, },
}; };
@ -147,8 +147,8 @@ describe('ProviderConfigForm', () => {
settings: { settings: {
allowAssignGrafanaAdmin: false, allowAssignGrafanaAdmin: false,
allowSignUp: false, allowSignUp: false,
allowedDomains: 'grafana.com', allowedDomains: '["grafana.com"]',
allowedOrganizations: '', allowedOrganizations: '[]',
autoLogin: true, autoLogin: true,
clientId: 'test-client-id', clientId: 'test-client-id',
clientSecret: 'test-client-secret', clientSecret: 'test-client-secret',
@ -157,10 +157,10 @@ describe('ProviderConfigForm', () => {
orgMapping: '["Group A:1:Editor","Group B:2:Admin"]', orgMapping: '["Group A:1:Editor","Group B:2:Admin"]',
roleAttributePath: 'new-attribute-path', roleAttributePath: 'new-attribute-path',
roleAttributeStrict: true, roleAttributeStrict: true,
scopes: 'user:email', scopes: '["user:email"]',
signoutRedirectUrl: '', signoutRedirectUrl: '',
skipOrgRoleSync: false, skipOrgRoleSync: false,
teamIds: '', teamIds: '[]',
tlsClientCa: '', tlsClientCa: '',
tlsClientCert: '', tlsClientCert: '',
tlsClientKey: '', tlsClientKey: '',
@ -197,8 +197,8 @@ describe('ProviderConfigForm', () => {
settings: { settings: {
allowAssignGrafanaAdmin: false, allowAssignGrafanaAdmin: false,
allowSignUp: false, allowSignUp: false,
allowedDomains: '', allowedDomains: '[]',
allowedOrganizations: '', allowedOrganizations: '[]',
autoLogin: true, autoLogin: true,
clientId: 'test-client-id', clientId: 'test-client-id',
clientSecret: 'test-client-secret', clientSecret: 'test-client-secret',
@ -206,16 +206,16 @@ describe('ProviderConfigForm', () => {
name: 'GitHub', name: 'GitHub',
roleAttributePath: '', roleAttributePath: '',
roleAttributeStrict: false, roleAttributeStrict: false,
scopes: 'user:email', scopes: '["user:email"]',
signoutRedirectUrl: '', signoutRedirectUrl: '',
skipOrgRoleSync: false, skipOrgRoleSync: false,
teamIds: '', teamIds: '[]',
tlsClientCa: '', tlsClientCa: '',
tlsClientCert: '', tlsClientCert: '',
tlsClientKey: '', tlsClientKey: '',
usePkce: false, usePkce: false,
useRefreshToken: false, useRefreshToken: false,
orgMapping: '', orgMapping: '[]',
}, },
}, },
{ showErrorAlert: false } { showErrorAlert: false }

View File

@ -78,10 +78,7 @@ export function dataToDTO(data?: SSOProvider): SSOProviderDTO {
} }
const valuesToString = (values: Array<SelectableValue<string>>) => { const valuesToString = (values: Array<SelectableValue<string>>) => {
if (values.length <= 1) { // Store arrays as JSON array
return values.map(({ value }) => value).join(',');
}
// Store as JSON array if there are multiple values
return JSON.stringify(values.map(({ value }) => value)); return JSON.stringify(values.map(({ value }) => value));
}; };