This commit is contained in:
@@ -1,27 +1,25 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { isCotFirstByte, COT_FIRST_BYTE_TAK, COT_FIRST_BYTE_XML } from '../../server/utils/cotRouter.js'
|
||||
import { isCotFirstByte, COT_FIRST_BYTE_TAK, COT_FIRST_BYTE_XML } from '../../server/utils/cotParser.js'
|
||||
|
||||
describe('cotRouter', () => {
|
||||
describe('isCotFirstByte', () => {
|
||||
it('returns true for TAK Protocol (0xBF)', () => {
|
||||
expect(isCotFirstByte(0xBF)).toBe(true)
|
||||
expect(isCotFirstByte(COT_FIRST_BYTE_TAK)).toBe(true)
|
||||
it.each([
|
||||
[0xBF, true],
|
||||
[COT_FIRST_BYTE_TAK, true],
|
||||
[0x3C, true],
|
||||
[COT_FIRST_BYTE_XML, true],
|
||||
])('returns true for valid COT bytes: 0x%02X', (byte, expected) => {
|
||||
expect(isCotFirstByte(byte)).toBe(expected)
|
||||
})
|
||||
|
||||
it('returns true for traditional XML (<)', () => {
|
||||
expect(isCotFirstByte(0x3C)).toBe(true)
|
||||
expect(isCotFirstByte(COT_FIRST_BYTE_XML)).toBe(true)
|
||||
})
|
||||
|
||||
it('returns false for HTTP-like first bytes', () => {
|
||||
expect(isCotFirstByte(0x47)).toBe(false) // 'G' GET
|
||||
expect(isCotFirstByte(0x50)).toBe(false) // 'P' POST
|
||||
expect(isCotFirstByte(0x48)).toBe(false) // 'H' HEAD
|
||||
})
|
||||
|
||||
it('returns false for other bytes', () => {
|
||||
expect(isCotFirstByte(0x00)).toBe(false)
|
||||
expect(isCotFirstByte(0x16)).toBe(false) // TLS client hello
|
||||
it.each([
|
||||
[0x47, false], // 'G' GET
|
||||
[0x50, false], // 'P' POST
|
||||
[0x48, false], // 'H' HEAD
|
||||
[0x00, false],
|
||||
[0x16, false], // TLS client hello
|
||||
])('returns false for non-COT bytes: 0x%02X', (byte, expected) => {
|
||||
expect(isCotFirstByte(byte)).toBe(expected)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user