fix: harden editorial thumbnail authorization
This commit is contained in:
1 parent
66f0599653
commit
846904f3db
11 files changed
+182
-36
No files matched your search
@@ -38,6 +38,29 @@ test("lists albums through the documented API with server-side authentication",
|
||||
await expect(client.listAlbums()).resolves.toEqual([immichAlbum]);
|
||||
});
|
||||
|
||||
test("lists only the albums containing an asset through the documented assetId query", async () => {
|
||||
server.use(
|
||||
http.get(`${baseUrl}/api/albums`, ({ request }) => {
|
||||
const url = new URL(request.url);
|
||||
expect(url.searchParams.get("assetId")).toBe("asset-1");
|
||||
expect(request.headers.get("x-api-key")).toBe(apiKey);
|
||||
return HttpResponse.json([immichAlbum]);
|
||||
}),
|
||||
);
|
||||
|
||||
await expect(client.listAlbumsForAsset("asset-1")).resolves.toEqual([immichAlbum]);
|
||||
});
|
||||
|
||||
test("validates the narrow asset-album response before authorizing a thumbnail", async () => {
|
||||
server.use(
|
||||
http.get(`${baseUrl}/api/albums`, () => HttpResponse.json([{ id: "missing-album-fields" }])),
|
||||
);
|
||||
|
||||
await expect(client.listAlbumsForAsset("asset-1")).rejects.toMatchObject({
|
||||
code: "IMMICH_INVALID_RESPONSE",
|
||||
});
|
||||
});
|
||||
|
||||
test("gets album details from the documented album endpoint", async () => {
|
||||
server.use(
|
||||
http.get(`${baseUrl}/api/albums/album-1`, ({ request }) => {
|
||||
|
||||
@@ -308,6 +308,15 @@ export function createImmichClient({
|
||||
listAlbums(signal) {
|
||||
return requestJson<ImmichAlbumSummary[]>("/albums", { method: "GET" }, z.array(albumSummarySchema), signal);
|
||||
},
|
||||
listAlbumsForAsset(assetId, signal) {
|
||||
const query = new URLSearchParams({ assetId });
|
||||
return requestJson<ImmichAlbumSummary[]>(
|
||||
`/albums?${query.toString()}`,
|
||||
{ method: "GET" },
|
||||
z.array(albumSummarySchema),
|
||||
signal,
|
||||
);
|
||||
},
|
||||
getAlbum(albumId, signal) {
|
||||
return requestJson<ImmichAlbum>(
|
||||
`/albums/${encodeURIComponent(albumId)}`,
|
||||
|
||||
@@ -36,6 +36,7 @@ export type ImmichBinary = {
|
||||
|
||||
export interface ImmichClient {
|
||||
listAlbums(signal?: AbortSignal): Promise<ImmichAlbumSummary[]>;
|
||||
listAlbumsForAsset(assetId: string, signal?: AbortSignal): Promise<ImmichAlbumSummary[]>;
|
||||
getAlbum(albumId: string, signal?: AbortSignal): Promise<ImmichAlbum>;
|
||||
searchPhotos(
|
||||
input: { albumIds: string[]; description?: string; page: number; size: number; type?: "IMAGE" },
|
||||
|
||||
Reference in new issue
Block a user