MCPcopy Create free account
hub / github.com/ermak-dev/cloudpub / test_proxy_v2_header_ipv4

Function test_proxy_v2_header_ipv4

common/src/proxy_protocol.rs:138–170  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

136
137 #[test]
138 fn test_proxy_v2_header_ipv4() {
139 let client = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(192, 168, 1, 100), 54321));
140 let server = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(10, 0, 0, 1), 25565));
141
142 let header = build_proxy_v2_header(&client, &server);
143
144 // Check signature
145 assert_eq!(&header[0..12], &PROXY_V2_SIGNATURE);
146
147 // Check version + command
148 assert_eq!(header[12], 0x21); // v2 + PROXY
149
150 // Check address family + protocol
151 assert_eq!(header[13], 0x11); // AF_INET + STREAM
152
153 // Check address length
154 assert_eq!(&header[14..16], &12u16.to_be_bytes());
155
156 // Total header size for IPv4: 16 + 12 = 28 bytes
157 assert_eq!(header.len(), 28);
158
159 // Verify source IP
160 assert_eq!(&header[16..20], &[192, 168, 1, 100]);
161
162 // Verify destination IP
163 assert_eq!(&header[20..24], &[10, 0, 0, 1]);
164
165 // Verify source port (54321 = 0xD431)
166 assert_eq!(&header[24..26], &54321u16.to_be_bytes());
167
168 // Verify destination port (25565 = 0x63DD)
169 assert_eq!(&header[26..28], &25565u16.to_be_bytes());
170 }
171
172 #[test]
173 fn test_proxy_v2_header_ipv6() {

Callers

nothing calls this directly

Calls 1

build_proxy_v2_headerFunction · 0.85

Tested by

no test coverage detected