feat: add public image read boundary
Quality / test (push) Canceled after 0s

This commit is contained in:
2026-09-08 21:58:30 -04:00
parent 5452bd5589
commit b00bd388a9
15 changed files with 223 additions and 9 deletions
@@ -0,0 +1,47 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { buildApp } from '../../src/app/build-app.js';
test('serves public image bytes with the stored safe MIME type', async (testContext) => {
const app = buildApp({
publicImageService: {
async getContent(id) {
assert.equal(id, 'image-1');
return { mimeType: 'image/webp', data: Buffer.from('webp-bytes') };
},
},
});
testContext.after(() => app.close());
const response = await app.inject({
method: 'GET',
url: '/api/v1/public/images/image-1',
});
assert.equal(response.statusCode, 200);
assert.equal(response.headers['content-type'], 'image/webp');
assert.equal(response.rawPayload.toString(), 'webp-bytes');
});
test('does not expose hidden image errors as internal failures', async (testContext) => {
const app = buildApp({
publicImageService: {
async getContent() {
const error = new Error('Image was not found.');
error.code = 'IMAGE_NOT_FOUND';
error.statusCode = 404;
throw error;
},
},
});
testContext.after(() => app.close());
const response = await app.inject({
method: 'GET',
url: '/api/v1/public/images/hidden-image',
});
assert.equal(response.statusCode, 404);
assert.equal(response.json().error.code, 'IMAGE_NOT_FOUND');
});