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

View File

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