Public shares: any valid Immich link opens through the proxy and is recorded in /admin, with a per-share sign-in-only switch; comments stay recipient-only

This commit is contained in:
zyphlar
2026-11-07 22:34:44 -08:00
parent d4ce4444b8
commit 17bf59b218
9 changed files with 368 additions and 42 deletions
+71 -1
View File
@@ -18,6 +18,9 @@ const KEY_A = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
const KEY_B = 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'
const KEY_C = 'ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc'
const KEY_P = 'ppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp'
// In Immich but never added to the proxy: opened by their Immich links
const KEY_D = 'ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'
const KEY_E = 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'
const ASSET_1 = '11111111-1111-4111-8111-111111111111'
const ASSET_2 = '22222222-2222-4222-8222-222222222222'
const ASSET_B = '33333333-3333-4333-8333-333333333333'
@@ -53,7 +56,9 @@ const links: Record<string, ReturnType<typeof link>> = {
[KEY_A]: link(KEY_A, 'Holiday', 'holiday', [ASSET_1, ASSET_2]),
[KEY_B]: link(KEY_B, 'Wedding', null, [ASSET_B]),
[KEY_C]: link(KEY_C, 'Garden', null, [ASSET_1]),
[KEY_P]: link(KEY_P, 'Private party', null, [ASSET_P])
[KEY_P]: link(KEY_P, 'Private party', null, [ASSET_P]),
[KEY_D]: link(KEY_D, 'Picnic', null, [ASSET_2]),
[KEY_E]: link(KEY_E, 'Beach', 'beach', [ASSET_1])
}
const PASSWORD = 'party-pw'
const IMMICH_TOKEN = 'immich-token-for-p'
@@ -459,3 +464,68 @@ describe('admin console', () => {
expect((await request(linkPath, { page: true })).res.status).toBe(401)
})
})
describe('public shares', () => {
it('an Immich link not seen before opens for anyone, without comments, and is recorded as public', async () => {
const page = await request('/share/' + KEY_D, { page: true })
expect(page.res.status).toBe(200)
expect(page.text).toContain('Picnic')
expect(page.text).not.toContain('/share/comments/')
expect(page.res.headers.get('vary')).toContain('Cookie')
expect(store.getShare(KEY_D)).toMatchObject({ title: 'Picnic', public: true, password: null })
const photo = await request('/share/photo/' + KEY_D + '/' + ASSET_2 + '/thumbnail')
expect(photo.res.status).toBe(200)
expect(photo.text).toBe('JPEG:' + ASSET_2)
// Another share's photo can't be pulled through this one
expect((await request('/share/photo/' + KEY_D + '/' + ASSET_1 + '/thumbnail')).res.status).toBe(404)
// Comments stay recipient-only
expect((await request('/share/comments/' + KEY_D + '/' + ASSET_2)).res.status).toBe(404)
expect((await request('/share/comments/' + KEY_D + '/' + ASSET_2, { json: { body: 'hi' } })).res.status).toBe(404)
})
it('opens by slug too, recording the share under its key', async () => {
expect((await request('/s/beach', { page: true })).res.status).toBe(200)
expect(store.getShare(KEY_E)).toMatchObject({ slug: 'beach', public: true })
})
it('refuses a key Immich does not know, and asks Immich about it only once', async () => {
const unknown = 'z'.repeat(67)
const before = immichCalls
expect((await request('/share/' + unknown, { page: true })).res.status).toBe(401)
expect((await request('/share/' + unknown, { page: true })).res.status).toBe(401)
expect(immichCalls - before).toBe(1)
expect(store.getShare(unknown)).toBeUndefined()
})
it('a recipient not given the share can view it, but not comment', async () => {
const cookie = await signIn()
const page = await request('/share/' + KEY_D, { page: true, cookie })
expect(page.res.status).toBe(200)
expect(page.text).not.toContain('/share/comments/')
expect((await request('/share/comments/' + KEY_D + '/' + ASSET_2, { cookie, json: { body: 'hi' } })).res.status).toBe(404)
})
it('the admin can switch a share to sign-in only, and back', async () => {
const login = await request('/admin/login', { form: { password: 'admin-secret' } })
const admin = cookieFrom(login.res, 'imp_admin')!
const dashboard = await request('/admin', { page: true, cookie: admin })
expect(dashboard.text).toContain('Picnic')
expect(dashboard.text).toContain('Public link works')
await request('/admin/shares/' + KEY_D + '/access', { cookie: admin, form: { public: '0' } })
expect(store.getShare(KEY_D)?.public).toBe(false)
expect((await request('/share/' + KEY_D, { page: true })).res.status).toBe(401)
expect((await request('/share/photo/' + KEY_D + '/' + ASSET_2 + '/thumbnail')).res.status).toBe(404)
expect((await request('/share/' + KEY_D, { page: true, cookie: await signIn() })).res.status).toBe(404)
await request('/admin/shares/' + KEY_D + '/access', { cookie: admin, form: { public: ['0', '1'] } })
expect(store.getShare(KEY_D)?.public).toBe(true)
expect((await request('/share/' + KEY_D, { page: true })).res.status).toBe(200)
})
it('needs the admin session to change access', async () => {
await request('/admin/shares/' + KEY_D + '/access', { form: { public: '0' } })
expect(store.getShare(KEY_D)?.public).toBe(true)
})
})