auth) fixing tests
All checks were successful
PR Checks / lint-test-and-docker-build (pull_request) Successful in 2m20s

This commit is contained in:
2026-02-22 00:10:56 -05:00
parent a67b1db90a
commit 99a90ed551
2 changed files with 19 additions and 8 deletions

View File

@@ -22,6 +22,10 @@ const attemptsByIdentifier = new Map<string, AttemptState>();
const attemptsByIp = new Map<string, AttemptState>(); const attemptsByIp = new Map<string, AttemptState>();
let dummyHashPromise: Promise<string> | null = null; let dummyHashPromise: Promise<string> | null = null;
const getEnvValue = (key: keyof typeof env): string | undefined => {
return process.env[key] ?? env[key];
};
const getNumberEnv = (value: string | undefined, fallback: number): number => { const getNumberEnv = (value: string | undefined, fallback: number): number => {
const parsed = Number.parseInt(value ?? '', 10); const parsed = Number.parseInt(value ?? '', 10);
return Number.isFinite(parsed) ? parsed : fallback; return Number.isFinite(parsed) ? parsed : fallback;
@@ -29,10 +33,10 @@ const getNumberEnv = (value: string | undefined, fallback: number): number => {
const getLocalAuthConfig = () => { const getLocalAuthConfig = () => {
return { return {
enabled: env.LOCAL_AUTH_ENABLED === 'true', enabled: getEnvValue('LOCAL_AUTH_ENABLED') === 'true',
maxAttempts: getNumberEnv(env.LOCAL_AUTH_MAX_ATTEMPTS, 5), maxAttempts: getNumberEnv(getEnvValue('LOCAL_AUTH_MAX_ATTEMPTS'), 5),
windowMs: getNumberEnv(env.LOCAL_AUTH_WINDOW_SECONDS, 900) * 1000, windowMs: getNumberEnv(getEnvValue('LOCAL_AUTH_WINDOW_SECONDS'), 900) * 1000,
lockoutMs: getNumberEnv(env.LOCAL_AUTH_LOCKOUT_SECONDS, 900) * 1000 lockoutMs: getNumberEnv(getEnvValue('LOCAL_AUTH_LOCKOUT_SECONDS'), 900) * 1000
}; };
}; };
@@ -111,7 +115,11 @@ export async function verifyLocalCredentials(
const ipKey = normalizeIp(ipAddress); const ipKey = normalizeIp(ipAddress);
const now = Date.now(); const now = Date.now();
const identifierState = getEffectiveState(attemptsByIdentifier.get(identifierKey), now, config.windowMs); const identifierState = getEffectiveState(
attemptsByIdentifier.get(identifierKey),
now,
config.windowMs
);
const ipState = getEffectiveState(attemptsByIp.get(ipKey), now, config.windowMs); const ipState = getEffectiveState(attemptsByIp.get(ipKey), now, config.windowMs);
const locked = isLocked(identifierState, now) || isLocked(ipState, now); const locked = isLocked(identifierState, now) || isLocked(ipState, now);

View File

@@ -8,10 +8,13 @@ const resolveErrorMessage = (value: string | null): string | null => {
}; };
export const load: PageServerLoad = async ({ url }) => { export const load: PageServerLoad = async ({ url }) => {
const authUrl = process.env.AUTH_URL ?? env.AUTH_URL ?? '';
const localAuthEnabled = (process.env.LOCAL_AUTH_ENABLED ?? env.LOCAL_AUTH_ENABLED) === 'true';
return { return {
signinUrl: `${env.AUTH_URL}/signin/synology`, signinUrl: `${authUrl}/signin/synology`,
localSigninUrl: `${env.AUTH_URL}/signin/local`, localSigninUrl: `${authUrl}/signin/local`,
localAuthEnabled: env.LOCAL_AUTH_ENABLED === 'true', localAuthEnabled,
error: resolveErrorMessage(url.searchParams.get('error')) error: resolveErrorMessage(url.searchParams.get('error'))
}; };
}; };