|
|
|
@@ -50,7 +50,6 @@ const captureBackfillStub = {
|
|
|
|
|
scheduleUpload,
|
|
|
|
|
} as unknown as JourneyPhotoCaptureService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Build the controller.
|
|
|
|
|
*
|
|
|
|
@@ -1129,8 +1128,13 @@ describe('JourneyPublicController', () => {
|
|
|
|
|
});
|
|
|
|
|
const getPublicJourney = vi.fn().mockReturnValue({ id: 1 });
|
|
|
|
|
expect(await pub(open({ getPublicJourney })).get('tok', anon)).toEqual({ id: 1 });
|
|
|
|
|
// The reader is named for the view count by address and browser, nothing more.
|
|
|
|
|
expect(getPublicJourney).toHaveBeenCalledWith('tok', '203.0.113.9|Firefox');
|
|
|
|
|
expect(getPublicJourney).toHaveBeenCalledWith('tok');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('records a view against the link that passed the shared access check', async () => {
|
|
|
|
|
const recordPublicView = vi.fn().mockResolvedValue(undefined);
|
|
|
|
|
expect(await pub(open({ recordPublicView })).view('tok', anon)).toEqual({ success: true });
|
|
|
|
|
expect(recordPublicView).toHaveBeenCalledWith(1, '203.0.113.9|Firefox');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('GET /:token/map-layers 404 on an unknown link, else the layers as the service cut them (JRN-04)', async () => {
|
|
|
|
@@ -1239,28 +1243,46 @@ describe('JourneyPublicController', () => {
|
|
|
|
|
|
|
|
|
|
it('photo proxy 404 on invalid token, else streams', async () => {
|
|
|
|
|
const invalid = open({ validateShareTokenForPhoto: vi.fn().mockReturnValue(null) });
|
|
|
|
|
expect(await thrownAsync(() => pub(invalid).photo('tok', 7, 'thumbnail', {} as Response, anon))).toEqual({
|
|
|
|
|
expect(
|
|
|
|
|
await thrownAsync(() =>
|
|
|
|
|
pub(invalid).photo('tok', 7, 'thumbnail', { setHeader: vi.fn() } as unknown as Response, anon),
|
|
|
|
|
),
|
|
|
|
|
).toEqual({
|
|
|
|
|
status: 404,
|
|
|
|
|
body: { error: 'Not found' },
|
|
|
|
|
});
|
|
|
|
|
const streamPhoto = vi.fn().mockResolvedValue(undefined);
|
|
|
|
|
const s = open({ validateShareTokenForPhoto: vi.fn().mockReturnValue({ ownerId: 2 }), streamPhoto });
|
|
|
|
|
await pub(s).photo('tok', 7, 'original', {} as Response, anon);
|
|
|
|
|
expect(streamPhoto).toHaveBeenCalledWith({}, 2, 7, 'original');
|
|
|
|
|
await pub(s).photo('tok', 7, 'original', { setHeader: vi.fn() } as unknown as Response, anon);
|
|
|
|
|
expect(streamPhoto).toHaveBeenCalledWith(
|
|
|
|
|
expect.objectContaining({ setHeader: expect.any(Function) }),
|
|
|
|
|
2,
|
|
|
|
|
7,
|
|
|
|
|
'original',
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('legacy photo proxy: 404 invalid token, immich path streams', async () => {
|
|
|
|
|
const invalid = open({ validateShareTokenForAsset: vi.fn().mockReturnValue(null) });
|
|
|
|
|
expect(
|
|
|
|
|
await thrownAsync(() => pub(invalid).legacyPhoto('tok', 'immich', 'a1', 'thumbnail', {} as Response, anon)),
|
|
|
|
|
await thrownAsync(() =>
|
|
|
|
|
pub(invalid).legacyPhoto(
|
|
|
|
|
'tok',
|
|
|
|
|
'immich',
|
|
|
|
|
'a1',
|
|
|
|
|
'thumbnail',
|
|
|
|
|
{ setHeader: vi.fn() } as unknown as Response,
|
|
|
|
|
anon,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
).toEqual({ status: 404, body: { error: 'Not found' } });
|
|
|
|
|
// One call for every provider now, with the ids in a ref instead of in a
|
|
|
|
|
// per-provider argument order.
|
|
|
|
|
const streamProviderAsset = vi.fn().mockResolvedValue(undefined);
|
|
|
|
|
const s = open({ validateShareTokenForAsset: vi.fn().mockReturnValue({ ownerId: 5 }), streamProviderAsset });
|
|
|
|
|
await pub(s).legacyPhoto('tok', 'immich', 'a1', 'original', {} as Response, anon);
|
|
|
|
|
await pub(s).legacyPhoto('tok', 'immich', 'a1', 'original', { setHeader: vi.fn() } as unknown as Response, anon);
|
|
|
|
|
expect(streamProviderAsset).toHaveBeenCalledWith(
|
|
|
|
|
{},
|
|
|
|
|
expect.objectContaining({ setHeader: expect.any(Function) }),
|
|
|
|
|
'immich',
|
|
|
|
|
{ userId: 5, ownerId: 5, assetId: 'a1' },
|
|
|
|
|
'original',
|
|
|
|
@@ -1270,33 +1292,50 @@ describe('JourneyPublicController', () => {
|
|
|
|
|
it('photo proxy streams thumbnails too', async () => {
|
|
|
|
|
const streamPhoto = vi.fn().mockResolvedValue(undefined);
|
|
|
|
|
const s = open({ validateShareTokenForPhoto: vi.fn().mockReturnValue({ ownerId: 3 }), streamPhoto });
|
|
|
|
|
await pub(s).photo('tok', 7, 'thumbnail', {} as Response, anon);
|
|
|
|
|
expect(streamPhoto).toHaveBeenCalledWith({}, 3, 7, 'thumbnail');
|
|
|
|
|
await pub(s).photo('tok', 7, 'thumbnail', { setHeader: vi.fn() } as unknown as Response, anon);
|
|
|
|
|
expect(streamPhoto).toHaveBeenCalledWith(
|
|
|
|
|
expect.objectContaining({ setHeader: expect.any(Function) }),
|
|
|
|
|
3,
|
|
|
|
|
7,
|
|
|
|
|
'thumbnail',
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('both photo proxies hand a preview on as one (#2874), and any other size as the original', async () => {
|
|
|
|
|
const streamPhoto = vi.fn().mockResolvedValue(undefined);
|
|
|
|
|
const streamProviderAsset = vi.fn().mockResolvedValue(undefined);
|
|
|
|
|
const s = svc({
|
|
|
|
|
const s = open({
|
|
|
|
|
validateShareTokenForPhoto: vi.fn().mockReturnValue({ ownerId: 3 }),
|
|
|
|
|
validateShareTokenForAsset: vi.fn().mockReturnValue({ ownerId: 3 }),
|
|
|
|
|
streamPhoto,
|
|
|
|
|
streamProviderAsset,
|
|
|
|
|
} as Partial<JourneyService>);
|
|
|
|
|
const proxy = new JourneyPublicController(s, storageStub, publicMediaStub);
|
|
|
|
|
await proxy.photo('tok', 7, 'preview', {} as Response);
|
|
|
|
|
await proxy.photo('tok', 7, 'huge', {} as Response);
|
|
|
|
|
await proxy.legacyPhoto('tok', 'immich', 'a1', 'preview', {} as Response);
|
|
|
|
|
});
|
|
|
|
|
const proxy = pub(s);
|
|
|
|
|
await proxy.photo('tok', 7, 'preview', { setHeader: vi.fn() } as unknown as Response, anon);
|
|
|
|
|
await proxy.photo('tok', 7, 'huge', { setHeader: vi.fn() } as unknown as Response, anon);
|
|
|
|
|
await proxy.legacyPhoto('tok', 'immich', 'a1', 'preview', { setHeader: vi.fn() } as unknown as Response, anon);
|
|
|
|
|
expect(streamPhoto.mock.calls.map((call) => call[3])).toEqual(['preview', 'original']);
|
|
|
|
|
expect(streamProviderAsset).toHaveBeenCalledWith({}, 'immich', { userId: 3, ownerId: 3, assetId: 'a1' }, 'preview');
|
|
|
|
|
expect(streamProviderAsset).toHaveBeenCalledWith(
|
|
|
|
|
expect.objectContaining({ setHeader: expect.any(Function) }),
|
|
|
|
|
'immich',
|
|
|
|
|
{ userId: 3, ownerId: 3, assetId: 'a1' },
|
|
|
|
|
'preview',
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('legacy photo proxy: synology streams, and a failure becomes a 404 json', async () => {
|
|
|
|
|
const streamProviderAsset = vi.fn().mockResolvedValue(undefined);
|
|
|
|
|
const s = open({ validateShareTokenForAsset: vi.fn().mockReturnValue({ ownerId: 5 }), streamProviderAsset });
|
|
|
|
|
await pub(s).legacyPhoto('tok', 'synologyphotos', 'a1', 'thumbnail', {} as Response, anon);
|
|
|
|
|
await pub(s).legacyPhoto(
|
|
|
|
|
'tok',
|
|
|
|
|
'synologyphotos',
|
|
|
|
|
'a1',
|
|
|
|
|
'thumbnail',
|
|
|
|
|
{ setHeader: vi.fn() } as unknown as Response,
|
|
|
|
|
anon,
|
|
|
|
|
);
|
|
|
|
|
expect(streamProviderAsset).toHaveBeenCalledWith(
|
|
|
|
|
{},
|
|
|
|
|
expect.objectContaining({ setHeader: expect.any(Function) }),
|
|
|
|
|
'synologyphotos',
|
|
|
|
|
{ userId: 5, ownerId: 5, assetId: 'a1' },
|
|
|
|
|
'thumbnail',
|
|
|
|
@@ -1304,7 +1343,7 @@ describe('JourneyPublicController', () => {
|
|
|
|
|
|
|
|
|
|
const status = vi.fn().mockReturnThis();
|
|
|
|
|
const json = vi.fn();
|
|
|
|
|
const res = { status, json } as unknown as Response;
|
|
|
|
|
const res = { status, json, setHeader: vi.fn() } as unknown as Response;
|
|
|
|
|
const failing = open({
|
|
|
|
|
validateShareTokenForAsset: vi.fn().mockReturnValue({ ownerId: 0 }),
|
|
|
|
|
streamProviderAsset: vi.fn().mockRejectedValue(new Error('no synology')),
|
|
|
|
@@ -1321,7 +1360,7 @@ describe('JourneyPublicController', () => {
|
|
|
|
|
const streamProviderAsset = vi.fn().mockReturnValue(null);
|
|
|
|
|
const status = vi.fn().mockReturnThis();
|
|
|
|
|
const json = vi.fn();
|
|
|
|
|
const res = { status, json } as unknown as Response;
|
|
|
|
|
const res = { status, json, setHeader: vi.fn() } as unknown as Response;
|
|
|
|
|
const s = open({ validateShareTokenForAsset: vi.fn().mockReturnValue({ ownerId: 5 }), streamProviderAsset });
|
|
|
|
|
await pub(s).legacyPhoto('tok', 'photoprism', 'a1', 'original', res, anon);
|
|
|
|
|
expect(status).toHaveBeenCalledWith(404);
|
|
|
|
@@ -1334,9 +1373,9 @@ describe('JourneyPublicController', () => {
|
|
|
|
|
// the journey owner when the photo row carries no owner_id.
|
|
|
|
|
const streamProviderAsset = vi.fn().mockResolvedValue(undefined);
|
|
|
|
|
const s = open({ validateShareTokenForAsset: vi.fn().mockReturnValue({ ownerId: 3 }), streamProviderAsset });
|
|
|
|
|
await pub(s).legacyPhoto('tok', 'immich', 'a1', 'original', {} as Response, anon);
|
|
|
|
|
await pub(s).legacyPhoto('tok', 'immich', 'a1', 'original', { setHeader: vi.fn() } as unknown as Response, anon);
|
|
|
|
|
expect(streamProviderAsset).toHaveBeenCalledWith(
|
|
|
|
|
{},
|
|
|
|
|
expect.objectContaining({ setHeader: expect.any(Function) }),
|
|
|
|
|
'immich',
|
|
|
|
|
{ userId: 3, ownerId: 3, assetId: 'a1' },
|
|
|
|
|
'original',
|
|
|
|
@@ -1347,20 +1386,29 @@ describe('JourneyPublicController', () => {
|
|
|
|
|
storageExists.mockResolvedValue(false);
|
|
|
|
|
const s = open({ validateShareTokenForAsset: vi.fn().mockReturnValue({ ownerId: 5 }) });
|
|
|
|
|
expect(
|
|
|
|
|
await thrownAsync(() => pub(s).legacyPhoto('tok', 'local', 'gone.jpg', 'thumbnail', {} as Response, anon)),
|
|
|
|
|
await thrownAsync(() =>
|
|
|
|
|
pub(s).legacyPhoto(
|
|
|
|
|
'tok',
|
|
|
|
|
'local',
|
|
|
|
|
'gone.jpg',
|
|
|
|
|
'thumbnail',
|
|
|
|
|
{ setHeader: vi.fn() } as unknown as Response,
|
|
|
|
|
anon,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
).toEqual({ status: 404, body: { error: 'Not found' } });
|
|
|
|
|
expect(storageSendToResponse).not.toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('legacy photo proxy: local provider serves through storage with the day cache header', async () => {
|
|
|
|
|
it('legacy photo proxy: local provider serves through storage without allowing cached access', async () => {
|
|
|
|
|
storageExists.mockResolvedValue(true);
|
|
|
|
|
storageSendToResponse.mockResolvedValue(undefined);
|
|
|
|
|
const set = vi.fn();
|
|
|
|
|
const res = { set } as unknown as Response;
|
|
|
|
|
const setHeader = vi.fn();
|
|
|
|
|
const res = { setHeader } as unknown as Response;
|
|
|
|
|
const s = open({ validateShareTokenForAsset: vi.fn().mockReturnValue({ ownerId: 5 }) });
|
|
|
|
|
await pub(s).legacyPhoto('tok', 'local', 'photo.jpg', 'original', res, anon);
|
|
|
|
|
expect(storageExists).toHaveBeenCalledWith('journey', 'photo.jpg');
|
|
|
|
|
expect(set).toHaveBeenCalledWith('Cache-Control', 'public, max-age=86400');
|
|
|
|
|
expect(setHeader).toHaveBeenCalledWith('Cache-Control', 'private, no-store');
|
|
|
|
|
// The location-free copy goes out, never the stored original.
|
|
|
|
|
expect(renditionFor).toHaveBeenCalledWith('journey', 'photo.jpg');
|
|
|
|
|
expect(storageSendToResponse).toHaveBeenCalledWith('journey', 'public/photo.jpg', res);
|
|
|
|
@@ -1370,7 +1418,7 @@ describe('JourneyPublicController', () => {
|
|
|
|
|
storageExists.mockResolvedValue(true);
|
|
|
|
|
renditionFor.mockRejectedValueOnce(new RenditionPendingError());
|
|
|
|
|
const json = vi.fn();
|
|
|
|
|
const res = { set: vi.fn(), status: vi.fn(() => ({ json })) } as unknown as Response;
|
|
|
|
|
const res = { set: vi.fn(), setHeader: vi.fn(), status: vi.fn(() => ({ json })) } as unknown as Response;
|
|
|
|
|
const s = open({ validateShareTokenForAsset: vi.fn().mockReturnValue({ ownerId: 5 }) });
|
|
|
|
|
await pub(s).legacyPhoto('tok', 'local', 'clip.mp4', 'original', res, anon);
|
|
|
|
|
expect(res.status).toHaveBeenCalledWith(503);
|
|
|
|
@@ -1381,7 +1429,7 @@ describe('JourneyPublicController', () => {
|
|
|
|
|
it('legacy photo proxy: a local file that cannot be cleaned is a 404, not the original', async () => {
|
|
|
|
|
storageExists.mockResolvedValue(true);
|
|
|
|
|
renditionFor.mockResolvedValueOnce(null);
|
|
|
|
|
const res = { set: vi.fn() } as unknown as Response;
|
|
|
|
|
const res = { set: vi.fn(), setHeader: vi.fn() } as unknown as Response;
|
|
|
|
|
const s = open({ validateShareTokenForAsset: vi.fn().mockReturnValue({ ownerId: 5 }) });
|
|
|
|
|
expect(await thrownAsync(() => pub(s).legacyPhoto('tok', 'local', 'a.bmp', 'original', res, anon))).toEqual({
|
|
|
|
|
status: 404,
|
|
|
|
@@ -1393,7 +1441,7 @@ describe('JourneyPublicController', () => {
|
|
|
|
|
it('legacy photo proxy: local provider cannot escape uploads/journey via a traversal asset id', async () => {
|
|
|
|
|
storageExists.mockResolvedValue(true);
|
|
|
|
|
storageSendToResponse.mockResolvedValue(undefined);
|
|
|
|
|
const res = { set: vi.fn() } as unknown as Response;
|
|
|
|
|
const res = { set: vi.fn(), setHeader: vi.fn() } as unknown as Response;
|
|
|
|
|
const s = open({ validateShareTokenForAsset: vi.fn().mockReturnValue({ ownerId: 5 }) });
|
|
|
|
|
|
|
|
|
|
// Express decodes %2F in a single path param to '/', so the handler sees this.
|
|
|
|
@@ -1411,7 +1459,8 @@ describe('JourneyPublicController', () => {
|
|
|
|
|
// which the handler reads as a miss.
|
|
|
|
|
storageExists.mockRejectedValue(new Error('invalid storage key: journey/..'));
|
|
|
|
|
const s = open({ validateShareTokenForAsset: vi.fn().mockReturnValue({ ownerId: 5 }) });
|
|
|
|
|
const read = () => pub(s).legacyPhoto('tok', 'local', '..', 'original', {} as Response, anon);
|
|
|
|
|
const read = () =>
|
|
|
|
|
pub(s).legacyPhoto('tok', 'local', '..', 'original', { setHeader: vi.fn() } as unknown as Response, anon);
|
|
|
|
|
expect(await thrownAsync(read)).toEqual({
|
|
|
|
|
status: 404,
|
|
|
|
|
body: { error: 'Not found' },
|
|
|
|
|