more tests

Massimo Melina committed May 14, 2026 at 19:25 UTC 4fe46df90ee52b80c3afab6ce33f34ba18b556f6
1 file changed +22 -2
tests/test.ts
+22 -2
@@ -1195,6 +1195,25 @@ describe('admin', () => {
1195 }
1196 finally { await rmAny(resolve(__dirname, rawName)) }
1197 })
1198 + test('monitor.connections upload path decodes colon folder', async () => {
1199 + const body = makeReadableThatTakes(700)
1200 + const size = body.length
1201 + const folderName = `colon:${randomId(4)}`
1202 + const fileName = 'slow-upload.txt'
1203 + const uploadPromise = reqUpload(`${UPLOAD_ROOT}${pathEncode(folderName)}/${fileName}`, () => true, body, size, 0, { auth })()
1204 + try {
1205 + await wait(200)
1206 + const res = await readEventStreamOnce(`${API}get_connections`, { auth })
1207 + await uploadPromise
1208 + const expectedPath = `${UPLOAD_ROOT}${folderName}/${fileName}`
1209 + const encodedPath = `${UPLOAD_ROOT}${pathEncode(folderName)}/${fileName}`
1210 + if (!res.data.includes(expectedPath))
1211 + throw Error('missing decoded upload path: ' + res.data)
1212 + if (res.data.includes(encodedPath))
1213 + throw Error('upload path still encoded: ' + res.data)
1214 + }
1215 + finally { await rmAny(resolve(__dirname, folderName)) }
1216 + })
1217 test('plugins.start_stop', async () => {
1218 const id = 'download-counter'
1219 await reqApi('stop_plugin', { id }, 200, { auth })()
@@ -1369,7 +1388,7 @@ function login(usr: string, pwd=password) {
1388 reqApi(cmd, params, (x,res)=> res.statusCode < 400)())
1389 }
1390
1372 -function reqUpload(dest: string, tester: Tester, body?: string | Readable, size?: number, resume=0) {
1391 +function reqUpload(dest: string, tester: Tester, body?: string | Readable, size?: number, resume=0, options?: ReqOptions) {
1392 if (resume)
1393 dest += (dest.includes('?') ? '&' : '?') + 'resume=' + resume
1394 size ??= (body as any)?.length ?? statSync(SAMPLE_FILE_PATH).size // it's ok that Readable.length is undefined
@@ -1390,7 +1409,8 @@ function reqUpload(dest: string, tester: Tester, body?: string | Readable, size?
1409 return req(dest, tester, {
1410 method: 'PUT',
1411 headers: { connection: 'close', 'content-length': size === undefined ? size : size - resume },
1393 - body: body ?? createReadStream(SAMPLE_FILE_PATH)
1412 + body: body ?? createReadStream(SAMPLE_FILE_PATH),
1413 + ...options,
1414 })
1415 }
1416