MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / test_validate

Function test_validate

gateway/src/config.rs:340–392  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

338
339 #[test]
340 fn test_validate() {
341 // Valid configuration
342 let ip = Ipv4Net::from_str("10.1.2.3/24").unwrap();
343 let reserved_net = Ipv4Net::from_str("10.1.2.0/30").unwrap();
344 let result = validate(
345 ip,
346 &[reserved_net],
347 Ipv4Net::from_str("10.1.2.128/25").unwrap(),
348 );
349 assert!(result.is_ok());
350
351 // Reserved net does not contain network
352 let ip = Ipv4Net::from_str("10.2.0.1/24").unwrap();
353 let reserved_net = Ipv4Net::from_str("10.1.0.0/16").unwrap();
354 let result = validate(
355 ip,
356 &[reserved_net],
357 Ipv4Net::from_str("10.2.0.128/25").unwrap(),
358 );
359 assert!(result.is_err());
360 assert_eq!(
361 result.unwrap_err().to_string(),
362 "Reserved net is not in the network"
363 );
364
365 // IP not in reserved net
366 let ip = Ipv4Net::from_str("10.1.2.16/24").unwrap();
367 let reserved_net = Ipv4Net::from_str("10.1.2.0/30").unwrap();
368 let result = validate(
369 ip,
370 &[reserved_net],
371 Ipv4Net::from_str("10.1.2.128/25").unwrap(),
372 );
373 assert!(result.is_err());
374 assert_eq!(
375 result.unwrap_err().to_string(),
376 "Wg peer IP is not in the reserved net"
377 );
378
379 // Client IP range not in network
380 let ip = Ipv4Net::from_str("10.1.2.3/24").unwrap();
381 let reserved_net = Ipv4Net::from_str("10.1.2.0/30").unwrap();
382 let result = validate(
383 ip,
384 &[reserved_net],
385 Ipv4Net::from_str("10.1.3.128/25").unwrap(),
386 );
387 assert!(result.is_err());
388 assert_eq!(
389 result.unwrap_err().to_string(),
390 "Client IP range is not in the network"
391 );
392 }
393}

Callers

nothing calls this directly

Calls 1

validateFunction · 0.85

Tested by

no test coverage detected