mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-22 23:01:48 +00:00
adding test
This commit is contained in:
@@ -51,14 +51,16 @@ vi.mock('../../src/utils/ssrfGuard', async () => {
|
|||||||
// Determine which API was called from the URL query param (e.g. ?api=SYNO.API.Auth)
|
// Determine which API was called from the URL query param (e.g. ?api=SYNO.API.Auth)
|
||||||
// or from the body for POST requests.
|
// or from the body for POST requests.
|
||||||
let apiName = '';
|
let apiName = '';
|
||||||
|
let params = new URLSearchParams();
|
||||||
try {
|
try {
|
||||||
apiName = new URL(u).searchParams.get('api') || '';
|
params = new URL(u).searchParams;
|
||||||
|
apiName = params.get('api') || '';
|
||||||
} catch {}
|
} catch {}
|
||||||
if (!apiName && init?.body) {
|
if (!apiName && init?.body) {
|
||||||
const body = init.body instanceof URLSearchParams
|
apiName = params.get('api') || '';
|
||||||
|
params = init.body instanceof URLSearchParams
|
||||||
? init.body
|
? init.body
|
||||||
: new URLSearchParams(String(init.body));
|
: new URLSearchParams(String(init.body));
|
||||||
apiName = body.get('api') || '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Auth login — used by settings save, status, test-connection
|
// Auth login — used by settings save, status, test-connection
|
||||||
@@ -154,6 +156,8 @@ vi.mock('../../src/utils/ssrfGuard', async () => {
|
|||||||
|
|
||||||
// Thumbnail stream
|
// Thumbnail stream
|
||||||
if (apiName === 'SYNO.Foto.Thumbnail') {
|
if (apiName === 'SYNO.Foto.Thumbnail') {
|
||||||
|
if (!(['sm', 'm', 'xl', 'preview'].includes(params.get('size') || '')))
|
||||||
|
return Promise.reject(new Error(`Unexpected thumbnail size: ${params.get('size')}`));
|
||||||
const imageBytes = Buffer.from('fake-synology-thumbnail');
|
const imageBytes = Buffer.from('fake-synology-thumbnail');
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
ok: true, status: 200,
|
ok: true, status: 200,
|
||||||
@@ -437,6 +441,24 @@ describe('Synology asset access', () => {
|
|||||||
expect(res.headers['content-type']).toContain('image/jpeg');
|
expect(res.headers['content-type']).toContain('image/jpeg');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('SYNO-032b — GET /api/photos/:id/thumbnail uses an allowed Synology thumbnail size', async () => {
|
||||||
|
const { user } = createUser(testDb);
|
||||||
|
setSynologyCredentials(testDb, user.id, 'https://synology.example.com', 'admin', 'pass');
|
||||||
|
|
||||||
|
const insert = testDb.prepare(
|
||||||
|
'INSERT INTO trek_photos (provider, asset_id, owner_id) VALUES (?, ?, ?)'
|
||||||
|
).run('synologyphotos', '101_cachekey', user.id);
|
||||||
|
const trekPhotoId = Number(insert.lastInsertRowid);
|
||||||
|
|
||||||
|
vi.mocked(safeFetch).mockClear();
|
||||||
|
|
||||||
|
const res = await request(app)
|
||||||
|
.get(`/api/photos/${trekPhotoId}/thumbnail`)
|
||||||
|
.set('Cookie', authCookie(user.id));
|
||||||
|
|
||||||
|
expect(res.status).toBe(200);
|
||||||
|
});
|
||||||
|
|
||||||
it('SYNO-033 — GET /assets/original streams image data for shared photo', async () => {
|
it('SYNO-033 — GET /assets/original streams image data for shared photo', async () => {
|
||||||
const { user: owner } = createUser(testDb);
|
const { user: owner } = createUser(testDb);
|
||||||
const { user: member } = createUser(testDb);
|
const { user: member } = createUser(testDb);
|
||||||
|
|||||||
Reference in New Issue
Block a user