This commit is contained in:
2026-10-18 13:01:44 +07:00
parent b05d55b3fa
commit 0cd736f682
6 changed files with 110 additions and 15 deletions
+28 -4
View File
@@ -2,7 +2,7 @@ const assert = require('node:assert/strict')
const { createServer } = require('node:http')
const { readFileSync, writeFileSync, mkdtempSync, rmSync } = require('node:fs')
const { tmpdir } = require('node:os')
const { dialog } = require('electron')
const { dialog, session } = require('electron')
const { join } = require('node:path')
module.exports = async function onlineSmoke({
@@ -49,7 +49,11 @@ module.exports = async function onlineSmoke({
const chunks = []
for await (const chunk of req) chunks.push(chunk)
const body = chunks.length ? JSON.parse(Buffer.concat(chunks).toString()) : {}
const path = req.url
assert.ok(
req.url.startsWith('http://screen-proxy.invalid/'),
'API and media use Chromium proxy',
)
const path = new URL(req.url).pathname
if (offline && path !== '/api/screens/state') {
res.destroy()
return
@@ -168,8 +172,17 @@ module.exports = async function onlineSmoke({
)
}
if (
['/api/files/intro.wav', '/api/files/music-a.wav', '/api/files/music-b.wav'].includes(path)
[
'/api/files/intro.wav',
'/api/files/cached-intro.wav',
'/api/files/music-a.wav',
'/api/files/music-b.wav',
].includes(path)
) {
if (path === '/api/files/intro.wav') {
res.writeHead(302, { Location: '/api/files/cached-intro.wav' })
return res.end()
}
if (path.endsWith('music-b.wav') && holdTrack) {
trackRequested = true
await new Promise((resolve) => {
@@ -224,7 +237,13 @@ module.exports = async function onlineSmoke({
send({}, 404)
})
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve))
const url = `http://127.0.0.1:${server.address().port}`
const url = 'http://screen-proxy.invalid'
await session.defaultSession.setProxy({
mode: 'fixed_servers',
proxyRules: `http=127.0.0.1:${server.address().port}`,
proxyBypassRules: '<-loopback>',
})
await session.defaultSession.closeAllConnections()
const act = (intent) => evaluate(`window.screenBridge.onlineAction(${JSON.stringify(intent)})`)
try {
await evaluate('window.screenBridge.closeOutput()')
@@ -832,8 +851,13 @@ module.exports = async function onlineSmoke({
),
'current local game stays visible after logout',
)
assert.ok(requests.includes('/api/auth/login'), 'login through proxy')
assert.ok(requests.includes('/api/files/cached-intro.wav'), 'redirected media through proxy')
console.log('SCREEN_PROXY_SMOKE_PASS')
console.log('SCREEN_ONLINE_SMOKE_PASS', JSON.stringify({ polls, requests: requests.length }))
} finally {
await session.defaultSession.setProxy({ mode: 'system' })
await session.defaultSession.closeAllConnections()
server.closeAllConnections()
await new Promise((resolve) => server.close(resolve))
}