chore: tidy request handling across services (#3168)

This commit is contained in:
Hampus authored and GitHub committed 2026-10-03 15:36:33 +02:00
1 parent c6941d5905
commit da9e9ff0be
11 files changed
+428 -44

No files matched your search

@@ -0,0 +1,55 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import {isTestSsoProvider, normalizeAndValidateSsoConfig} from '@app/api/instance/SsoConfigValidation';
import {InputValidationError} from '@fluxer/errors/src/domains/core/InputValidationError';
import {describe, expect, it} from 'vitest';
function ssoConfig(overrides: {authorizationUrl?: string | null; tokenUrl?: string | null} = {}) {
return {
enabled: true,
enforced: false,
issuer: null,
authorizationUrl: 'test',
tokenUrl: 'test',
userInfoUrl: null,
jwksUrl: null,
clientId: 'client',
allowedEmailDomains: [],
...overrides,
};
}
describe('isTestSsoProvider', () => {
it('recognises the placeholder provider only when test mode is enabled', () => {
expect(isTestSsoProvider({authorizationUrl: 'test', tokenUrl: null}, true)).toBe(true);
expect(isTestSsoProvider({authorizationUrl: null, tokenUrl: 'test'}, true)).toBe(true);
expect(isTestSsoProvider({authorizationUrl: 'test-provider', tokenUrl: null}, true)).toBe(true);
});
it('never recognises the placeholder provider outside test mode', () => {
expect(isTestSsoProvider({authorizationUrl: 'test', tokenUrl: null}, false)).toBe(false);
expect(isTestSsoProvider({authorizationUrl: null, tokenUrl: 'test'}, false)).toBe(false);
expect(isTestSsoProvider({authorizationUrl: 'test', tokenUrl: 'test'}, false)).toBe(false);
expect(isTestSsoProvider({authorizationUrl: 'test-provider', tokenUrl: null}, false)).toBe(false);
});
});
describe('normalizeAndValidateSsoConfig placeholder endpoints', () => {
it('accepts placeholder endpoints in test mode', async () => {
const result = await normalizeAndValidateSsoConfig(ssoConfig(), {testModeEnabled: true});
expect(result.ready).toBe(true);
expect(result.authorizationUrl).toBe('test');
});
it('rejects a placeholder authorization endpoint outside test mode', async () => {
await expect(
normalizeAndValidateSsoConfig(ssoConfig({tokenUrl: null}), {testModeEnabled: false}),
).rejects.toBeInstanceOf(InputValidationError);
});
it('rejects a placeholder token endpoint outside test mode', async () => {
await expect(
normalizeAndValidateSsoConfig(ssoConfig({authorizationUrl: null}), {testModeEnabled: false}),
).rejects.toBeInstanceOf(InputValidationError);
});
});
@@ -64,10 +64,13 @@ export function isTestSsoProvider(
},
testModeEnabled: boolean,
): boolean {
if (!testModeEnabled) {
return false;
}
return (
config.authorizationUrl === 'test' ||
config.tokenUrl === 'test' ||
(testModeEnabled && (config.authorizationUrl?.startsWith('test-') ?? false))
(config.authorizationUrl?.startsWith('test-') ?? false)
);
}