From 64a6a6d950bb1bf857efb040f523580d88b68cea Mon Sep 17 00:00:00 2001 From: Jesse MacFadyen Date: Thu, 4 Dec 2025 19:30:36 -0800 Subject: [PATCH 1/2] Remove auditUserId and handle undefined cache config --- lib/remote-storage.js | 34 ++++++++++++++++++++------------- test/lib/remote-storage.test.js | 33 ++++++++++++++++++++++++++++---- 2 files changed, 50 insertions(+), 17 deletions(-) diff --git a/lib/remote-storage.js b/lib/remote-storage.js index f5741ce..7c202fa 100644 --- a/lib/remote-storage.js +++ b/lib/remote-storage.js @@ -170,9 +170,6 @@ module.exports = class RemoteStorage { delete responseHeaders['adp-cache-control'] } - if (appConfig.auditUserId) { - responseHeaders['adp-AuditUserId'] = appConfig.auditUserId - } // we only set metadata if we have added anything to responseHeaders object // it is not null, but could be empty if (Object.keys(responseHeaders).length > 0) { @@ -318,16 +315,27 @@ module.exports = class RemoteStorage { const cacheControlStr = 's-maxage=60' if (!mimeType) { return null - } else if (mimeType === mime.lookup('html')) { - return `${cacheControlStr}, max-age=${appConfig.htmlCacheDuration}` - } else if (mimeType === mime.lookup('js')) { - return `${cacheControlStr}, max-age=${appConfig.jsCacheDuration}` - } else if (mimeType === mime.lookup('css')) { - return `${cacheControlStr}, max-age=${appConfig.cssCacheDuration}` - } else if (mimeType.startsWith('image')) { - return `${cacheControlStr}, max-age=${appConfig.imageCacheDuration}` - } else { - return null } + if (mimeType === mime.lookup('html')) { + if (appConfig.htmlCacheDuration) { + return `${cacheControlStr}, max-age=${appConfig.htmlCacheDuration}` + } + } + if (mimeType === mime.lookup('js')) { + if (appConfig.jsCacheDuration) { + return `${cacheControlStr}, max-age=${appConfig.jsCacheDuration}` + } + } + if (mimeType === mime.lookup('css')) { + if (appConfig.cssCacheDuration) { + return `${cacheControlStr}, max-age=${appConfig.cssCacheDuration}` + } + } + if (mimeType.startsWith('image')) { + if (appConfig.imageCacheDuration) { + return `${cacheControlStr}, max-age=${appConfig.imageCacheDuration}` + } + } + return null } } diff --git a/test/lib/remote-storage.test.js b/test/lib/remote-storage.test.js index 2a72b72..8154655 100644 --- a/test/lib/remote-storage.test.js +++ b/test/lib/remote-storage.test.js @@ -327,6 +327,34 @@ describe('RemoteStorage', () => { expect(response).toBe(null) }) + test('cachecontrol string for html when htmlCacheDuration is not defined', async () => { + const rs = new RemoteStorage(global.fakeTVMResponse) + const appConfigWithoutHtmlCache = global.configWithMissing(global.fakeConfig.app, 'htmlCacheDuration') + const response = rs._getCacheControlConfig('text/html', appConfigWithoutHtmlCache) + expect(response).toBe(null) + }) + + test('cachecontrol string for JS when jsCacheDuration is not defined', async () => { + const rs = new RemoteStorage(global.fakeTVMResponse) + const appConfigWithoutJsCache = global.configWithMissing(global.fakeConfig.app, 'jsCacheDuration') + const response = rs._getCacheControlConfig('application/javascript', appConfigWithoutJsCache) + expect(response).toBe(null) + }) + + test('cachecontrol string for CSS when cssCacheDuration is not defined', async () => { + const rs = new RemoteStorage(global.fakeTVMResponse) + const appConfigWithoutCssCache = global.configWithMissing(global.fakeConfig.app, 'cssCacheDuration') + const response = rs._getCacheControlConfig('text/css', appConfigWithoutCssCache) + expect(response).toBe(null) + }) + + test('cachecontrol string for Image when imageCacheDuration is not defined', async () => { + const rs = new RemoteStorage(global.fakeTVMResponse) + const appConfigWithoutImageCache = global.configWithMissing(global.fakeConfig.app, 'imageCacheDuration') + const response = rs._getCacheControlConfig('image/jpeg', appConfigWithoutImageCache) + expect(response).toBe(null) + }) + // response header tests test('get response header from config with multiple rules', async () => { const rs = new RemoteStorage(global.fakeTVMResponse) @@ -616,10 +644,7 @@ describe('RemoteStorage', () => { Bucket: 'fake-bucket', Key: 'fakeprefix/index.js', Body: body, - ContentType: 'application/javascript', - Metadata: expect.objectContaining({ - 'adp-AuditUserId': 'test-user-123' - }) + ContentType: 'application/javascript' } expect(mockS3.putObject).toHaveBeenCalledWith(expect.objectContaining(expected)) }) From dc3d6e022593541414ca99a4073b03558bcb24e8 Mon Sep 17 00:00:00 2001 From: Jesse MacFadyen Date: Fri, 5 Dec 2025 10:13:29 -0800 Subject: [PATCH 2/2] nit: remove all references to auditUserId --- test/lib/remote-storage.test.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/lib/remote-storage.test.js b/test/lib/remote-storage.test.js index 8154655..8086c3f 100644 --- a/test/lib/remote-storage.test.js +++ b/test/lib/remote-storage.test.js @@ -348,7 +348,7 @@ describe('RemoteStorage', () => { expect(response).toBe(null) }) - test('cachecontrol string for Image when imageCacheDuration is not defined', async () => { + test('cachecontrol string for image when imageCacheDuration is not defined', async () => { const rs = new RemoteStorage(global.fakeTVMResponse) const appConfigWithoutImageCache = global.configWithMissing(global.fakeConfig.app, 'imageCacheDuration') const response = rs._getCacheControlConfig('image/jpeg', appConfigWithoutImageCache) @@ -649,12 +649,12 @@ describe('RemoteStorage', () => { expect(mockS3.putObject).toHaveBeenCalledWith(expect.objectContaining(expected)) }) - test('uploadFile does not set Metadata when responseHeaders is empty and auditUserId is not set', async () => { + test('uploadFile does not set Metadata when responseHeaders is empty', async () => { global.addFakeFiles(vol, 'fakeDir', { 'index.js': 'fake content' }) const rs = new RemoteStorage(global.fakeTVMResponse) const fakeConfig = { app: global.fakeConfig.app - // No web.response-headers and no auditUserId + // No web.response-headers } await rs.uploadFile('fakeDir/index.js', 'fakeprefix', fakeConfig, 'fakeDir') const body = Buffer.from('fake content', 'utf8') @@ -668,12 +668,12 @@ describe('RemoteStorage', () => { }) }) - test('uploadFile sets CacheControl even when responseHeaders is empty and auditUserId is not set', async () => { + test('uploadFile sets CacheControl even when responseHeaders is empty', async () => { global.addFakeFiles(vol, 'fakeDir', { 'index.html': 'fake content' }) const rs = new RemoteStorage(global.fakeTVMResponse) const fakeConfig = { app: global.fakeConfig.app - // No web.response-headers and no auditUserId + // No web.response-headers } await rs.uploadFile('fakeDir/index.html', 'fakeprefix', fakeConfig, 'fakeDir') const body = Buffer.from('fake content', 'utf8')