Files
test-project-161/test/keyescape-http.test.ts
2026-08-13 01:34:54 +09:00

50 lines
2.0 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import {
EDGE_USER_AGENT,
edgeBrowserHeaders,
encodeMultipart,
getKeyescapeTransportMode,
setKeyescapeTransportMode,
} from '../electron/main/keyescape-http'
describe('Edge-compatible Keyescape request metadata', () => {
it('matches the captured Edge client hints and XHR metadata', () => {
const headers = edgeBrowserHeaders({
accept: 'application/json, text/javascript, */*; q=0.01',
referer: 'https://www.keyescape.com/reservation2.php',
xhr: true,
})
expect(headers['User-Agent']).toBe(EDGE_USER_AGENT)
expect(headers['Sec-CH-UA']).toContain('Microsoft Edge')
expect(headers['Sec-CH-UA']).toContain('v="151"')
expect(headers['Sec-CH-UA-Mobile']).toBe('?0')
expect(headers['Sec-CH-UA-Platform']).toBe('"Windows"')
expect(headers['Sec-Fetch-Mode']).toBe('cors')
expect(headers['Sec-Fetch-Dest']).toBe('empty')
expect(headers['X-Requested-With']).toBe('XMLHttpRequest')
expect(headers.Origin).toBe('https://www.keyescape.com')
expect(headers.Priority).toBe('u=1, i')
expect(headers.Referer).toBe('https://www.keyescape.com/reservation2.php')
})
it('uses a fresh WebKit-style multipart boundary', () => {
const first = encodeMultipart({ device: 'pc', t: 'ins_rev' })
const second = encodeMultipart({ device: 'pc' })
expect(first.boundary).toMatch(/^----WebKitFormBoundary[A-Za-z0-9_-]{16}$/)
expect(second.boundary).not.toBe(first.boundary)
expect(first.body.toString('utf8')).toContain(`--${first.boundary}\r\n`)
expect(first.body.toString('utf8')).toContain('Content-Disposition: form-data; name="device"')
expect(first.body.toString('utf8')).toMatch(/--\r\n$/)
})
it('switches explicitly between the legacy and HTTP/2 transports', () => {
setKeyescapeTransportMode('http2')
expect(getKeyescapeTransportMode()).toBe('http2')
expect(setKeyescapeTransportMode('http2')).toBe(false)
expect(setKeyescapeTransportMode('http1')).toBe(true)
expect(getKeyescapeTransportMode()).toBe('http1')
})
})