mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Allow custom label for auth provider (#15673)
* Allow to pass custom label for auth provider * Add tests * Update api/src/cli/utils/create-env/env-stub.liquid * Fix tests Co-authored-by: Azri Kahar <42867097+azrikahar@users.noreply.github.com>
This commit is contained in:
83
api/src/utils/get-auth-providers.test.ts
Normal file
83
api/src/utils/get-auth-providers.test.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
let factoryEnv: { [k: string]: any } = {};
|
||||
|
||||
jest.mock(
|
||||
'../../src/env',
|
||||
() =>
|
||||
new Proxy(
|
||||
{},
|
||||
{
|
||||
get(target, prop) {
|
||||
return factoryEnv[prop as string];
|
||||
},
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
import { getAuthProviders } from '../../src/utils/get-auth-providers';
|
||||
|
||||
const scenarios = [
|
||||
{
|
||||
name: 'when no providers configured',
|
||||
input: {},
|
||||
output: [],
|
||||
},
|
||||
{
|
||||
name: 'when no driver configured',
|
||||
input: {
|
||||
AUTH_PROVIDERS: 'directus',
|
||||
},
|
||||
output: [],
|
||||
},
|
||||
|
||||
{
|
||||
name: 'when single provider and driver are properly configured',
|
||||
input: {
|
||||
AUTH_PROVIDERS: 'directus',
|
||||
AUTH_DIRECTUS_DRIVER: 'openid',
|
||||
AUTH_DIRECTUS_LABEL: 'Directus',
|
||||
AUTH_DIRECTUS_ICON: 'hare',
|
||||
},
|
||||
output: [
|
||||
{
|
||||
name: 'directus',
|
||||
driver: 'openid',
|
||||
label: 'Directus',
|
||||
icon: 'hare',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
{
|
||||
name: 'when multiple provider and driver are properly configured',
|
||||
input: {
|
||||
AUTH_PROVIDERS: 'directus,custom',
|
||||
AUTH_DIRECTUS_DRIVER: 'openid',
|
||||
AUTH_DIRECTUS_LABEL: 'Directus',
|
||||
AUTH_DIRECTUS_ICON: 'hare',
|
||||
AUTH_CUSTOM_DRIVER: 'openid',
|
||||
AUTH_CUSTOM_ICON: 'lock',
|
||||
},
|
||||
output: [
|
||||
{
|
||||
name: 'directus',
|
||||
driver: 'openid',
|
||||
label: 'Directus',
|
||||
icon: 'hare',
|
||||
},
|
||||
{
|
||||
name: 'custom',
|
||||
driver: 'openid',
|
||||
icon: 'lock',
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
describe('get auth providers', () => {
|
||||
for (const scenario of scenarios) {
|
||||
test(scenario.name, () => {
|
||||
factoryEnv = scenario.input;
|
||||
expect(getAuthProviders()).toEqual(scenario.output);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -2,6 +2,7 @@ import { toArray } from '@directus/shared/utils';
|
||||
import env from '../env';
|
||||
|
||||
interface AuthProvider {
|
||||
label: string;
|
||||
name: string;
|
||||
driver: string;
|
||||
icon?: string;
|
||||
@@ -12,6 +13,7 @@ export function getAuthProviders(): AuthProvider[] {
|
||||
.filter((provider) => provider && env[`AUTH_${provider.toUpperCase()}_DRIVER`])
|
||||
.map((provider) => ({
|
||||
name: provider,
|
||||
label: env[`AUTH_${provider.toUpperCase()}_LABEL`],
|
||||
driver: env[`AUTH_${provider.toUpperCase()}_DRIVER`],
|
||||
icon: env[`AUTH_${provider.toUpperCase()}_ICON`],
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user