package awgserver import ( "encoding/binary" "testing" ) func testConfig() *Config { return &Config{ S1: 10, H1: HeaderRange{Min: 1000, Max: 2000}, S2: 10, H2: HeaderRange{Min: 3000, Max: 4000}, S3: 10, H3: HeaderRange{Min: 5000, Max: 6000}, S4: 10, H4: HeaderRange{Min: 7000, Max: 8000}, } } func TestIsAWGPacket_Initiation(t *testing.T) { cfg := testConfig() // Build a packet: S1(10) padding + 148 bytes = 158 total. pkt := make([]byte, 10+messageInitiationSize) binary.LittleEndian.PutUint32(pkt[10:], 1500) // H1 value in range if !isAWGPacket(pkt, cfg) { t.Error("expected initiation packet to match") } // Wrong size — should not match initiation (and other checks also won't match). wrongSize := make([]byte, 10+messageInitiationSize+1) binary.LittleEndian.PutUint32(wrongSize[10:], 1500) if isAWGPacket(wrongSize, cfg) { t.Error("wrong size should not match") } // H1 out of range. pktOutOfRange := make([]byte, 10+messageInitiationSize) binary.LittleEndian.PutUint32(pktOutOfRange[10:], 999) if isAWGPacket(pktOutOfRange, cfg) { t.Error("out-of-range H1 should not match") } } func TestIsAWGPacket_Transport(t *testing.T) { cfg := testConfig() cfg.S4 = 5 cfg.H4 = HeaderRange{Min: 500, Max: 600} // Transport: size >= S4+16. pkt := make([]byte, 5+messageTransportHeaderSize+100) binary.LittleEndian.PutUint32(pkt[5:], 550) if !isAWGPacket(pkt, cfg) { t.Error("expected transport packet to match") } // Too small. small := make([]byte, 5+messageTransportHeaderSize-1) if isAWGPacket(small, cfg) { t.Error("too-small packet should not match transport") } } func TestIsAWGPacket_NonAWG(t *testing.T) { cfg := testConfig() // Random packet that doesn't match any message type. pkt := make([]byte, 200) if isAWGPacket(pkt, cfg) { t.Error("random packet should not match") } }