This commit is contained in:
@@ -1,43 +1,51 @@
|
||||
import { describe, it, expect, afterEach } from 'vitest'
|
||||
import { getAuthConfig } from '../../server/utils/authConfig.js'
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { getAuthConfig } from '../../server/utils/oidc.js'
|
||||
import { withTemporaryEnv } from '../helpers/env.js'
|
||||
|
||||
describe('authConfig', () => {
|
||||
const origEnv = { ...process.env }
|
||||
|
||||
afterEach(() => {
|
||||
process.env = { ...origEnv }
|
||||
it('returns oidc disabled when OIDC env vars are unset', () => {
|
||||
withTemporaryEnv(
|
||||
{ OIDC_ISSUER: undefined, OIDC_CLIENT_ID: undefined, OIDC_CLIENT_SECRET: undefined },
|
||||
() => {
|
||||
expect(getAuthConfig()).toEqual({ oidc: { enabled: false, label: '' } })
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
it('returns oidc disabled when OIDC env vars are unset', () => {
|
||||
delete process.env.OIDC_ISSUER
|
||||
delete process.env.OIDC_CLIENT_ID
|
||||
delete process.env.OIDC_CLIENT_SECRET
|
||||
expect(getAuthConfig()).toEqual({
|
||||
oidc: { enabled: false, label: '' },
|
||||
it.each([
|
||||
[{ OIDC_ISSUER: 'https://auth.example.com' }, false],
|
||||
[{ OIDC_CLIENT_ID: 'client' }, false],
|
||||
[{ OIDC_ISSUER: 'https://auth.example.com', OIDC_CLIENT_ID: 'client' }, false],
|
||||
])('returns oidc disabled when only some vars are set: %j', (env, expected) => {
|
||||
withTemporaryEnv({ ...env, OIDC_CLIENT_SECRET: undefined }, () => {
|
||||
expect(getAuthConfig().oidc.enabled).toBe(expected)
|
||||
})
|
||||
})
|
||||
|
||||
it('returns oidc disabled when only some OIDC vars are set', () => {
|
||||
process.env.OIDC_ISSUER = 'https://auth.example.com'
|
||||
process.env.OIDC_CLIENT_ID = 'client'
|
||||
delete process.env.OIDC_CLIENT_SECRET
|
||||
expect(getAuthConfig().oidc.enabled).toBe(false)
|
||||
})
|
||||
|
||||
it('returns oidc enabled and default label when all OIDC vars are set', () => {
|
||||
process.env.OIDC_ISSUER = 'https://auth.example.com'
|
||||
process.env.OIDC_CLIENT_ID = 'client'
|
||||
process.env.OIDC_CLIENT_SECRET = 'secret'
|
||||
const config = getAuthConfig()
|
||||
expect(config.oidc.enabled).toBe(true)
|
||||
expect(config.oidc.label).toBe('Sign in with OIDC')
|
||||
it('returns oidc enabled with default label when all vars are set', () => {
|
||||
withTemporaryEnv(
|
||||
{
|
||||
OIDC_ISSUER: 'https://auth.example.com',
|
||||
OIDC_CLIENT_ID: 'client',
|
||||
OIDC_CLIENT_SECRET: 'secret',
|
||||
},
|
||||
() => {
|
||||
expect(getAuthConfig()).toEqual({ oidc: { enabled: true, label: 'Sign in with OIDC' } })
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
it('uses OIDC_LABEL when set', () => {
|
||||
process.env.OIDC_ISSUER = 'https://auth.example.com'
|
||||
process.env.OIDC_CLIENT_ID = 'client'
|
||||
process.env.OIDC_CLIENT_SECRET = 'secret'
|
||||
process.env.OIDC_LABEL = 'Sign in with Authentik'
|
||||
expect(getAuthConfig().oidc.label).toBe('Sign in with Authentik')
|
||||
withTemporaryEnv(
|
||||
{
|
||||
OIDC_ISSUER: 'https://auth.example.com',
|
||||
OIDC_CLIENT_ID: 'client',
|
||||
OIDC_CLIENT_SECRET: 'secret',
|
||||
OIDC_LABEL: 'Sign in with Authentik',
|
||||
},
|
||||
() => {
|
||||
expect(getAuthConfig().oidc.label).toBe('Sign in with Authentik')
|
||||
},
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user