mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-01-27 06:21:44 +00:00
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:
parent
ca49eb957d
commit
20d9a15cff
2 changed files with 19 additions and 6 deletions
|
@ -9,16 +9,16 @@ const MOCK_LAST_MODIFIED = 'mockETag'
|
|||
const motdMockContent = 'This is the mock Motd call'
|
||||
|
||||
describe('Motd', () => {
|
||||
const mockExistingMotd = () => {
|
||||
const mockExistingMotd = (useEtag?: boolean) => {
|
||||
cy.intercept('GET', '/mock-backend/public/motd.txt', {
|
||||
statusCode: 200,
|
||||
headers: { 'Last-Modified': MOCK_LAST_MODIFIED },
|
||||
headers: { [useEtag ? 'etag' : 'Last-Modified']: MOCK_LAST_MODIFIED },
|
||||
body: motdMockContent
|
||||
})
|
||||
|
||||
cy.intercept('HEAD', '/mock-backend/public/motd.txt', {
|
||||
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)
|
||||
})
|
||||
|
||||
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', () => {
|
||||
mockExistingMotd()
|
||||
cy.visit('/')
|
||||
|
|
|
@ -32,7 +32,8 @@ export const fetchMotd = async (customizeAssetsUrl: string): Promise<void> => {
|
|||
if (response.status !== 200) {
|
||||
return
|
||||
}
|
||||
if (response.headers.get('Last-Modified') === cachedLastModified) {
|
||||
const lastModified = response.headers.get('Last-Modified') || response.headers.get('etag')
|
||||
if (lastModified === cachedLastModified) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -47,9 +48,9 @@ export const fetchMotd = async (customizeAssetsUrl: string): Promise<void> => {
|
|||
|
||||
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) {
|
||||
log.warn("'Last-Modified' not found for motd.txt!")
|
||||
log.warn("'Last-Modified' or 'Etag' not found for motd.txt!")
|
||||
}
|
||||
|
||||
setMotd(motdText, lastModified)
|
||||
|
|
Loading…
Reference in a new issue