mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-17 13:05:32 +09:00
refactor(api): purge cache by canonical media prefix (#2802)
This commit is contained in:
1 parent
570c8776c4
commit
7412ec3395
13 files changed
+293
-329
No files matched your search
@@ -484,7 +484,8 @@ function validateCachePurgeConfig(config: MasterConfig): void {
|
||||
) {
|
||||
throw new Error('FLUXER_CACHE_PURGE_HTTP_ENDPOINT must be an absolute http or https URL without credentials');
|
||||
}
|
||||
if (!/^[\x21-\x7e]*$/u.test(cachePurge.http.token)) {
|
||||
requireString(cachePurge.http.token, 'FLUXER_CACHE_PURGE_HTTP_TOKEN');
|
||||
if (!/^[\x21-\x7e]+$/u.test(cachePurge.http.token)) {
|
||||
throw new Error('FLUXER_CACHE_PURGE_HTTP_TOKEN must contain only visible ASCII characters');
|
||||
}
|
||||
assertIntegerInRange(cachePurge.http.timeout_ms, 'FLUXER_CACHE_PURGE_HTTP_TIMEOUT_MS', 1_000, 10_000);
|
||||
|
||||
@@ -572,6 +572,14 @@ describe('ConfigLoader', () => {
|
||||
await expect(loadConfig()).rejects.toThrow('FLUXER_CACHE_PURGE_HTTP_ENDPOINT is required');
|
||||
});
|
||||
|
||||
test('rejects the http cache purge adapter without a token', async () => {
|
||||
stubMinimalEnv({
|
||||
FLUXER_CACHE_PURGE_ADAPTER: 'http',
|
||||
FLUXER_CACHE_PURGE_HTTP_ENDPOINT: 'https://purge.internal/purge',
|
||||
});
|
||||
await expect(loadConfig()).rejects.toThrow('FLUXER_CACHE_PURGE_HTTP_TOKEN is required');
|
||||
});
|
||||
|
||||
test('rejects a cache purge endpoint that is not an absolute http URL', async () => {
|
||||
for (const endpoint of ['/purge', 'purge.internal/purge', 'ftp://purge.internal/purge']) {
|
||||
stubMinimalEnv({FLUXER_CACHE_PURGE_ADAPTER: 'http', FLUXER_CACHE_PURGE_HTTP_ENDPOINT: endpoint});
|
||||
@@ -596,6 +604,7 @@ describe('ConfigLoader', () => {
|
||||
stubMinimalEnv({
|
||||
FLUXER_CACHE_PURGE_ADAPTER: 'http',
|
||||
FLUXER_CACHE_PURGE_HTTP_ENDPOINT: 'https://purge.internal/purge',
|
||||
FLUXER_CACHE_PURGE_HTTP_TOKEN: 'purge-token',
|
||||
FLUXER_CACHE_PURGE_HTTP_TIMEOUT_MS: timeout,
|
||||
});
|
||||
await expect(loadConfig()).rejects.toThrow(
|
||||
|
||||
Reference in new issue
Block a user