Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,34 @@ afterEach(() => {
})

describe('chunked transfer handlers', () => {
it('rejects fractional chunk counts', async () => {
const { start } = createHarness()

setTransferableHandler('test:echo', async (_ctx, _placeholder, body) => body)

await expect(start(ctx('client-1'), {
totalBytes: 10,
chunkCount: 1.5,
channel: 'test:echo',
args: [null, null],
largeArgIndex: 1,
})).rejects.toThrow('Invalid chunkCount')
})

it('rejects fractional total byte counts', async () => {
const { start } = createHarness()

setTransferableHandler('test:echo', async (_ctx, _placeholder, body) => body)

await expect(start(ctx('client-1'), {
totalBytes: 10.5,
chunkCount: 1,
channel: 'test:echo',
args: [null, null],
largeArgIndex: 1,
})).rejects.toThrow('Invalid totalBytes')
})

it('rejects chunk uploads from a different client', async () => {
const { start, chunk } = createHarness()
const payload = encodeParts({ hello: 'world' })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ export function registerTransferHandlers(server: RpcServer): void {
largeArgIndex: number
checksum?: string
}) => {
if (!opts || typeof opts.chunkCount !== 'number' || opts.chunkCount < 1) {
if (!opts || !Number.isInteger(opts.chunkCount) || opts.chunkCount < 1) {
throw new Error('Invalid chunkCount')
}
if (typeof opts.totalBytes !== 'number' || opts.totalBytes < 0) {
if (!Number.isInteger(opts.totalBytes) || opts.totalBytes < 0) {
throw new Error('Invalid totalBytes')
}
if (!opts.channel || typeof opts.channel !== 'string') {
Expand Down
Loading