Secure Sakani portal and show full album titles
This commit is contained in:
1 parent
c40ccf77cf
commit
69264ce165
49 files changed
+1362
-601
No files matched your search
@@ -20,6 +20,7 @@ import {
|
||||
createDownloadService,
|
||||
createRepeatDownloadRepository,
|
||||
} from "@/modules/downloads/service";
|
||||
import { assertOriginalAccess } from "@/modules/albums/photo-access";
|
||||
import { requestFingerprint } from "@/modules/usages/types";
|
||||
import { startPostgres } from "./postgres";
|
||||
|
||||
@@ -59,7 +60,8 @@ function createServices() {
|
||||
immich,
|
||||
}),
|
||||
downloadService: createDownloadService({
|
||||
repository: createRepeatDownloadRepository(database),
|
||||
repository: createRepeatDownloadRepository(database, (editorialId, assetId, albumId, tx) =>
|
||||
assertOriginalAccess(editorialId, assetId, albumId, tx, immich)),
|
||||
}),
|
||||
immich,
|
||||
};
|
||||
@@ -240,7 +242,7 @@ test("rechecks exact album membership after database locks before inserting", as
|
||||
expect(usageCount.value).toBe(0);
|
||||
});
|
||||
|
||||
test("returns a winner committed while waiting before later mutable state is checked", async () => {
|
||||
test("rejects an otherwise equivalent winner when the editorial is suspended while waiting", async () => {
|
||||
const editorialId = await seedEditorial();
|
||||
const input = newInput(editorialId);
|
||||
const immich = createServices().immich;
|
||||
@@ -267,7 +269,7 @@ test("returns a winner committed while waiting before later mutable state is che
|
||||
try {
|
||||
const pending = usageService.createNewUsage(input);
|
||||
await fastMiss;
|
||||
const winner = await insertWinner(
|
||||
await insertWinner(
|
||||
locker,
|
||||
input,
|
||||
requestFingerprint({
|
||||
@@ -284,12 +286,7 @@ test("returns a winner committed while waiting before later mutable state is che
|
||||
]);
|
||||
await locker.query("commit");
|
||||
|
||||
await expect(pending).resolves.toMatchObject({
|
||||
id: winner.eventId,
|
||||
usageId: winner.usageId,
|
||||
authorizedAt: winner.authorizedAt,
|
||||
billable: true,
|
||||
});
|
||||
await expect(pending).rejects.toMatchObject({ code: "EDITORIAL_NOT_ACTIVE" });
|
||||
expect(immich.getAlbum).toHaveBeenCalledTimes(1);
|
||||
expect(immich.getAsset).toHaveBeenCalledTimes(1);
|
||||
} finally {
|
||||
@@ -494,7 +491,7 @@ test("rechecks suspension after an idempotent repeat winner commits", async () =
|
||||
idempotencyKey: randomUUID(),
|
||||
};
|
||||
const downloadService = createDownloadService({
|
||||
repository: createRepeatDownloadRepository(database),
|
||||
repository: createRepeatDownloadRepository(database, async () => undefined),
|
||||
});
|
||||
const eventId = randomUUID();
|
||||
const authorizedAt = new Date("2026-08-09T11:00:00.000Z");
|
||||
@@ -584,3 +581,39 @@ async function markDelivered(downloadId: string): Promise<void> {
|
||||
})
|
||||
.where(eq(downloadEvents.id, downloadId));
|
||||
}
|
||||
|
||||
test("revocation blocks an idempotent new intent and an eligible repeat while retaining the usage", async () => {
|
||||
const editorialId = await seedEditorial();
|
||||
const { usageService, downloadService } = createServices();
|
||||
const input = newInput(editorialId);
|
||||
const intent = await usageService.createNewUsage(input);
|
||||
await database.update(downloadEvents).set({ status: "completed", transferredBytes: 8 })
|
||||
.where(eq(downloadEvents.id, intent.id));
|
||||
const repeatInput = { editorialId, usageId: intent.usageId, idempotencyKey: randomUUID() };
|
||||
await expect(downloadService.createRepeatDownload(repeatInput)).resolves.toMatchObject({ priceCents: 0 });
|
||||
|
||||
await database.update(albumGrants).set({ revokedAt: new Date() })
|
||||
.where(eq(albumGrants.editorialAccountId, editorialId));
|
||||
await expect(usageService.createNewUsage(input)).rejects.toMatchObject({ code: "ALBUM_NOT_GRANTED" });
|
||||
await expect(downloadService.createRepeatDownload(repeatInput)).rejects.toMatchObject({ code: "ALBUM_NOT_GRANTED" });
|
||||
await expect(usageService.listPriorUsages(editorialId, assetId)).resolves.toEqual([
|
||||
expect.objectContaining({ id: intent.usageId, purpose: input.purpose }),
|
||||
]);
|
||||
});
|
||||
|
||||
test("calculates ZIP pricing server-side and refuses a price above the confirmed cap", async () => {
|
||||
const editorialId = await seedEditorial({ priceCents: 1500 });
|
||||
const { usageService } = createServices();
|
||||
const input = newInput(editorialId);
|
||||
await expect(usageService.createNewUsage({ ...input, maxPriceCents: 1499 }))
|
||||
.rejects.toMatchObject({ code: "INVALID_PRICE" });
|
||||
|
||||
await database.update(editorialAccounts).set({
|
||||
flatrateActive: true, flatratePriceCents: 10000, flatrateAssetLimit: 1,
|
||||
}).where(eq(editorialAccounts.id, editorialId));
|
||||
|
||||
await expect(usageService.createNewUsage({ ...input, maxPriceCents: 1499 }))
|
||||
.resolves.toMatchObject({ priceCents: 0 });
|
||||
await expect(usageService.createNewUsage({ ...newInput(editorialId), maxPriceCents: 1500 }))
|
||||
.resolves.toMatchObject({ priceCents: 1500 });
|
||||
});
|
||||
Reference in new issue
Block a user