mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-09 13:21:42 +00:00
Closes #40069. Salvaged from #40242; re-verified on main, tightened, tested. Co-authored-by: maxpetrusenkoagent <maxpetrusenkoagent@users.noreply.github.com>
30 lines
1.1 KiB
JavaScript
30 lines
1.1 KiB
JavaScript
/**
|
|
* Regression coverage for the OAuth-session Electron net.request path.
|
|
*
|
|
* Electron net rejects manual Content-Length/Host headers with
|
|
* net::ERR_INVALID_ARGUMENT. Node HTTP helpers may still set Content-Length;
|
|
* this guard is scoped to fetchJsonViaOauthSession only.
|
|
*/
|
|
|
|
const test = require('node:test')
|
|
const assert = require('node:assert/strict')
|
|
const fs = require('node:fs')
|
|
const path = require('node:path')
|
|
|
|
const source = fs.readFileSync(path.join(__dirname, 'main.cjs'), 'utf8')
|
|
|
|
function extractFetchJsonViaOauthSession() {
|
|
const start = source.indexOf('function fetchJsonViaOauthSession')
|
|
const end = source.indexOf('// Mint a single-use WS ticket', start)
|
|
assert.notEqual(start, -1, 'fetchJsonViaOauthSession should exist')
|
|
assert.notEqual(end, -1, 'fetchJsonViaOauthSession boundary should exist')
|
|
return source.slice(start, end)
|
|
}
|
|
|
|
test('OAuth Electron net request does not set forbidden Content-Length header', () => {
|
|
const fn = extractFetchJsonViaOauthSession()
|
|
|
|
assert.match(fn, /electronNet\.request/)
|
|
assert.doesNotMatch(fn, /setHeader\(['"]Content-Length['"]/)
|
|
assert.match(fn, /request\.write\(body\)/)
|
|
})
|