Skip to content
Snippets Groups Projects
Commit ba11d966 authored by julian.baeume's avatar julian.baeume :pick:
Browse files

OXUIB-1528: Read-through cache not working

Root cause: cache keys handled differently when reading/writing
Solution: make sure keys are handled equally

Fixes OXUIB-1528
parent 0ea2de7e
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,7 @@ describe('File caching service', function () {
let app
before(async function () {
let count = 0
mockConfig({ urls: ['http://ui-server/'] })
mockFetch({
'http://ui-server': {
......@@ -33,6 +34,13 @@ describe('File caching service', function () {
'/index.html': () => new Response('<html><head></head><body>it\'s me</body></html>', { headers: { 'content-type': 'text/html' } }),
'/main.css': () => new Response('.foo { color: #000; }', { headers: { 'content-type': 'text/css' } }),
'/favicon.ico': 'not really a favicon, though',
'/test.svg': () => {
if (count > 0) {
return new Response(null, { status: 404 })
}
count++
return new Response('<svg></svg>', { headers: { 'content-type': 'image/svg' } })
},
'/image.png': () => {
return new Response(image, {
headers: {
......@@ -89,6 +97,15 @@ describe('File caching service', function () {
expect(response.text).to.equal('not really a favicon, though')
})
it('caches files not referenced in manifest.json fetched from upstream servers', async function () {
let response = await request(app).get('/test.svg')
expect(response.statusCode).to.equal(200)
expect(String(response.body)).to.equal('<svg></svg>')
response = await request(app).get('/test.svg')
expect(response.statusCode).to.equal(200)
expect(String(response.body)).to.equal('<svg></svg>')
})
it('returns 404 if file can not be resolved', async function () {
const response = await request(app).get('/unknown-file.txt')
expect(response.statusCode).to.equal(404)
......
......@@ -94,7 +94,7 @@ class FileCache {
const [[key, value]] =
(await Promise.allSettled(config.urls.map(baseUrl => fetchData(path, baseUrl))))
.filter(r => r.status === 'fulfilled').map(r => r.value)
this._cache[key] = value
this._cache[key.slice(1)] = value
return value
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment