交付 Windows 与 Web 端到端加密附件预览
This commit is contained in:
1 parent
d1efdedc57
commit
c24960d22a
19 files changed
+421
-58
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { randomBytes } from 'node:crypto'
|
||||
import { mkdtemp, rm } from 'node:fs/promises'
|
||||
import { mkdtemp, readFile, rm } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import test from 'node:test'
|
||||
@@ -46,7 +46,7 @@ test('Web 与 Windows 安全码校验、加密互发、离线接收和状态恢
|
||||
const profile = await mkdtemp(join(tmpdir(), 'xhchat-mls-test-'))
|
||||
let desktop
|
||||
try {
|
||||
const web = await browser.newPage()
|
||||
const web = await browser.newPage({ acceptDownloads: true })
|
||||
await web.goto(base)
|
||||
desktop = await _electron.launch({
|
||||
executablePath: electron,
|
||||
@@ -106,6 +106,33 @@ test('Web 与 Windows 安全码校验、加密互发、离线接收和状态恢
|
||||
await send(windows, reply)
|
||||
await web.getByText(reply, { exact: true }).waitFor()
|
||||
|
||||
const contents = Buffer.from('端到端文件 ' + randomBytes(32).toString('hex'))
|
||||
const fileName = '跨端验收.txt'
|
||||
const upload = windows.waitForRequest((req) => req.method() === 'POST' && req.url().includes('/api/v1/attachments/'))
|
||||
await windows.locator('input[type=file]').setInputFiles({ name: fileName, mimeType: 'text/plain', buffer: contents })
|
||||
const fileRequest = await upload
|
||||
const uploaded = fileRequest.postDataBuffer()
|
||||
assert.ok(uploaded)
|
||||
assert.equal(uploaded.length, contents.length + 16)
|
||||
assert.ok(!uploaded.includes(contents))
|
||||
assert.ok(!fileRequest.url().includes(encodeURIComponent(fileName)))
|
||||
const fileButton = web.getByRole('button', { name: '下载 ' + fileName, exact: true })
|
||||
await fileButton.waitFor()
|
||||
const fileURL = new URL(fileRequest.url())
|
||||
await web.route(fileURL.origin + fileURL.pathname, async (route) => {
|
||||
const response = await route.fetch()
|
||||
const corrupted = await response.body()
|
||||
corrupted[0] ^= 1
|
||||
await route.fulfill({ response, body: corrupted })
|
||||
}, { times: 1 })
|
||||
await fileButton.click()
|
||||
await web.getByText('附件完整性校验失败').waitFor()
|
||||
const downloaded = web.waitForEvent('download')
|
||||
await fileButton.click()
|
||||
const file = await downloaded
|
||||
assert.equal(file.suggestedFilename(), fileName)
|
||||
assert.deepEqual(await readFile(await file.path()), contents)
|
||||
|
||||
await windows.getByRole('button', { name: '退出登录' }).click()
|
||||
await windows.getByRole('heading', { name: '登录 XHChat' }).waitFor()
|
||||
const offline = '离线补拉 ' + randomBytes(8).toString('hex')
|
||||
|
||||
Reference in new issue
Block a user