Initial work on upload app server

This commit is contained in:
Alan Grainger
2026-10-06 10:07:20 +13:00
parent 9e6c00da35
commit 95ac498cf0
38 changed files with 1493 additions and 40 deletions
+38
View File
@@ -0,0 +1,38 @@
import { describe, it, expect, afterEach } from 'vitest'
import { KeyType } from '@ipp/core'
import { assertPermit, authoriseUpload, UploadPermit } from '../src/gate'
import { resetConfig, setConfig, share } from './helpers'
afterEach(resetConfig)
describe('authoriseUpload', () => {
it('issues a permit only when the share\'s Immich toggle is on', () => {
expect(authoriseUpload(share(), 'k', KeyType.key)).not.toBeNull()
expect(authoriseUpload(share({ allowUpload: false }), 'k', KeyType.key)).toBeNull()
expect(authoriseUpload(share({ allowUpload: undefined }), 'k', KeyType.key)).toBeNull()
})
it('refuses slug links when the operator has turned them off', () => {
setConfig({ ipp: { allowSlugLinks: false } })
expect(authoriseUpload(share(), 'my-slug', KeyType.slug)).toBeNull()
expect(authoriseUpload(share(), 'k', KeyType.key)).not.toBeNull()
})
})
describe('assertPermit', () => {
it('passes a permit from authoriseUpload', () => {
expect(() => assertPermit(authoriseUpload(share(), 'k', KeyType.key)!)).not.toThrow()
})
it('throws for a permit built by hand', () => {
const forged = { link: share(), key: 'k', keyType: KeyType.key } as unknown as UploadPermit
expect(() => assertPermit(forged)).toThrow('without a permit')
})
it('throws when the share stopped accepting uploads after the permit was issued', () => {
const link = share()
const permit = authoriseUpload(link, 'k', KeyType.key)!
link.allowUpload = false
expect(() => assertPermit(permit)).toThrow('does not allow uploads')
})
})