Add etag header to last modified check of motd (#1739)

* Add etag header to last modified check of motd

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2021-12-31 09:30:12 +01:00 committed by GitHub
parent ca49eb957d
commit 20d9a15cff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 6 deletions

View file

@ -9,16 +9,16 @@ const MOCK_LAST_MODIFIED = 'mockETag'
const motdMockContent = 'This is the mock Motd call' const motdMockContent = 'This is the mock Motd call'
describe('Motd', () => { describe('Motd', () => {
const mockExistingMotd = () => { const mockExistingMotd = (useEtag?: boolean) => {
cy.intercept('GET', '/mock-backend/public/motd.txt', { cy.intercept('GET', '/mock-backend/public/motd.txt', {
statusCode: 200, statusCode: 200,
headers: { 'Last-Modified': MOCK_LAST_MODIFIED }, headers: { [useEtag ? 'etag' : 'Last-Modified']: MOCK_LAST_MODIFIED },
body: motdMockContent body: motdMockContent
}) })
cy.intercept('HEAD', '/mock-backend/public/motd.txt', { cy.intercept('HEAD', '/mock-backend/public/motd.txt', {
statusCode: 200, statusCode: 200,
headers: { 'Last-Modified': MOCK_LAST_MODIFIED } headers: { [useEtag ? 'etag' : 'Last-Modified']: MOCK_LAST_MODIFIED }
}) })
} }
@ -32,6 +32,18 @@ describe('Motd', () => {
cy.getByCypressId('motd').contains(motdMockContent) cy.getByCypressId('motd').contains(motdMockContent)
}) })
it('can be dismissed using etag', () => {
mockExistingMotd(true)
cy.visit('/')
cy.getByCypressId('motd').contains(motdMockContent)
cy.getByCypressId('motd-dismiss')
.click()
.then(() => {
expect(localStorage.getItem(MOTD_LOCAL_STORAGE_KEY)).to.equal(MOCK_LAST_MODIFIED)
})
cy.getByCypressId('motd').should('not.exist')
})
it('can be dismissed', () => { it('can be dismissed', () => {
mockExistingMotd() mockExistingMotd()
cy.visit('/') cy.visit('/')

View file

@ -32,7 +32,8 @@ export const fetchMotd = async (customizeAssetsUrl: string): Promise<void> => {
if (response.status !== 200) { if (response.status !== 200) {
return return
} }
if (response.headers.get('Last-Modified') === cachedLastModified) { const lastModified = response.headers.get('Last-Modified') || response.headers.get('etag')
if (lastModified === cachedLastModified) {
return return
} }
} }
@ -47,9 +48,9 @@ export const fetchMotd = async (customizeAssetsUrl: string): Promise<void> => {
const motdText = await response.text() const motdText = await response.text()
const lastModified = response.headers.get('Last-Modified') const lastModified = response.headers.get('Last-Modified') || response.headers.get('etag')
if (!lastModified) { if (!lastModified) {
log.warn("'Last-Modified' not found for motd.txt!") log.warn("'Last-Modified' or 'Etag' not found for motd.txt!")
} }
setMotd(motdText, lastModified) setMotd(motdText, lastModified)