This commit is contained in:
@@ -1,19 +1,18 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { parseTakStreamFrame, parseTraditionalXmlFrame, parseCotPayload } from '../../../server/utils/cotParser.js'
|
||||
|
||||
const encodeVarint = (value, bytes = []) => {
|
||||
const byte = value & 0x7F
|
||||
const remaining = value >>> 7
|
||||
if (remaining === 0) {
|
||||
return [...bytes, byte]
|
||||
}
|
||||
return encodeVarint(remaining, [...bytes, byte | 0x80])
|
||||
}
|
||||
|
||||
function buildTakFrame(payload) {
|
||||
const buf = Buffer.from(payload, 'utf8')
|
||||
let n = buf.length
|
||||
const varint = []
|
||||
while (true) {
|
||||
const byte = n & 0x7F
|
||||
n >>>= 7
|
||||
if (n === 0) {
|
||||
varint.push(byte)
|
||||
break
|
||||
}
|
||||
varint.push(byte | 0x80)
|
||||
}
|
||||
const varint = encodeVarint(buf.length)
|
||||
return Buffer.concat([Buffer.from([0xBF]), Buffer.from(varint), buf])
|
||||
}
|
||||
|
||||
@@ -42,14 +41,7 @@ describe('cotParser', () => {
|
||||
|
||||
it('returns null for payload length exceeding max', () => {
|
||||
const hugeLen = 64 * 1024 + 1
|
||||
const varint = []
|
||||
let n = hugeLen
|
||||
while (true) {
|
||||
varint.push(n & 0x7F)
|
||||
n >>>= 7
|
||||
if (n === 0) break
|
||||
varint[varint.length - 1] |= 0x80
|
||||
}
|
||||
const varint = encodeVarint(hugeLen)
|
||||
const buf = Buffer.concat([Buffer.from([0xBF]), Buffer.from(varint)])
|
||||
expect(parseTakStreamFrame(buf)).toBeNull()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user