summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/headers.rs32
-rw-r--r--tests/v2ray_geosite.rs16
2 files changed, 31 insertions, 17 deletions
diff --git a/tests/headers.rs b/tests/headers.rs
index 3c1b74a..ff51111 100644
--- a/tests/headers.rs
+++ b/tests/headers.rs
@@ -1,8 +1,8 @@
use nsc::sniffing::*;
use crate::headers::Protocol;
-use nsc::sniffing::headers::sniff_raw_packets;
use nsc::sniffing::headers::PacketInfo;
+use nsc::sniffing::headers::sniff_raw_packets;
#[test]
fn generic_typeck() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
@@ -115,7 +115,8 @@ fn generic_typeck() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// [0] IPv4 TCP 192.168.1.100:4832 → 93.184.216.34:443
assert_eq!(
sniff_raw_packets(test_suite[0])?,
- PacketInfo::V6 { dns: false,
+ PacketInfo::V6 {
+ dns: false,
src_ip: [192, 168, 1, 100],
src_port: 4832,
dst_ip: [93, 184, 216, 34],
@@ -127,7 +128,8 @@ fn generic_typeck() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// [1] IPv4 UDP 10.0.0.9:5353 → 224.0.0.251:5353 (mDNS)
assert_eq!(
sniff_raw_packets(test_suite[1])?,
- PacketInfo::V6 { dns: false,
+ PacketInfo::V6 {
+ dns: false,
src_ip: [10, 0, 0, 9],
src_port: 5353,
dst_ip: [224, 0, 0, 251],
@@ -139,7 +141,8 @@ fn generic_typeck() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// [2] IPv4 UDP 10.0.0.9:1024 → 8.8.8.8:53 (DNS)
assert_eq!(
sniff_raw_packets(test_suite[2])?,
- PacketInfo::V6 { dns: false,
+ PacketInfo::V6 {
+ dns: false,
src_ip: [10, 0, 0, 9],
src_port: 1024,
dst_ip: [8, 8, 8, 8],
@@ -151,7 +154,8 @@ fn generic_typeck() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// [3] IPv4 TCP 10.0.0.5:54321 → 10.0.0.1:80 (HTTP)
assert_eq!(
sniff_raw_packets(test_suite[3])?,
- PacketInfo::V6 { dns: false,
+ PacketInfo::V6 {
+ dns: false,
src_ip: [10, 0, 0, 5],
src_port: 54321,
dst_ip: [10, 0, 0, 1],
@@ -163,7 +167,8 @@ fn generic_typeck() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// [4] IPv4 TCP 172.16.0.1:65535 → 172.16.0.2:8080
assert_eq!(
sniff_raw_packets(test_suite[4])?,
- PacketInfo::V6 { dns: false,
+ PacketInfo::V6 {
+ dns: false,
src_ip: [172, 16, 0, 1],
src_port: 65535,
dst_ip: [172, 16, 0, 2],
@@ -175,7 +180,8 @@ fn generic_typeck() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// [5] IPv4 TCP IHL=6 10.0.0.1:9090 → 10.0.0.2:22 (requires IHL-based offset)
assert_eq!(
sniff_raw_packets(test_suite[5])?,
- PacketInfo::V6 { dns: false,
+ PacketInfo::V6 {
+ dns: false,
src_ip: [10, 0, 0, 1],
src_port: 9090,
dst_ip: [10, 0, 0, 2],
@@ -187,7 +193,8 @@ fn generic_typeck() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// [6] IPv4 ICMP (unsupported, "ports" are just ICMP body bytes)
assert_eq!(
sniff_raw_packets(test_suite[6])?,
- PacketInfo::V6 { dns: false,
+ PacketInfo::V6 {
+ dns: false,
src_ip: [10, 0, 0, 9],
src_port: 2048,
dst_ip: [10, 0, 0, 1],
@@ -199,7 +206,8 @@ fn generic_typeck() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// [7] IPv6 TCP [::1]:4000 → [2606:4700::1]:443
assert_eq!(
sniff_raw_packets(test_suite[7])?,
- PacketInfo::V6 { dns: false,
+ PacketInfo::V6 {
+ dns: false,
src_ip: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
src_port: 4000,
dst_ip: [0x26, 0x06, 0x47, 0x00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
@@ -211,7 +219,8 @@ fn generic_typeck() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// [8] IPv6 UDP [fd00::9]:1234 → [fd00::1]:53 (requires fixing 17 => UDP)
assert_eq!(
sniff_raw_packets(test_suite[8])?,
- PacketInfo::V6 { dns: false,
+ PacketInfo::V6 {
+ dns: false,
src_ip: [0xFD, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9],
src_port: 1234,
dst_ip: [0xFD, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
@@ -223,7 +232,8 @@ fn generic_typeck() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// [9] IPv6 ICMPv6 (unsupported, "ports" are ICMPv6 body bytes)
assert_eq!(
sniff_raw_packets(test_suite[9])?,
- PacketInfo::V6 { dns: false,
+ PacketInfo::V6 {
+ dns: false,
src_ip: [0xFE, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
src_port: 32768,
dst_ip: [0xFF, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
diff --git a/tests/v2ray_geosite.rs b/tests/v2ray_geosite.rs
index f4ea664..d400839 100644
--- a/tests/v2ray_geosite.rs
+++ b/tests/v2ray_geosite.rs
@@ -30,7 +30,11 @@ fn get_geosite_service() -> Result<GeoSiteService, Box<dyn std::error::Error>> {
#[test]
fn geosite_service_creation() {
let service = get_geosite_service();
- assert!(service.is_ok(), "Failed to create GeoSiteService: {:?}", service.err());
+ assert!(
+ service.is_ok(),
+ "Failed to create GeoSiteService: {:?}",
+ service.err()
+ );
}
#[test]
@@ -51,7 +55,10 @@ fn lookup_nonexistent_domain() {
};
let result = service.lookup(domain.value.as_str());
- assert!(result.is_none(), "Should return none for not existing domain");
+ assert!(
+ result.is_none(),
+ "Should return none for not existing domain"
+ );
println!("{:?}", result);
}
@@ -59,10 +66,7 @@ fn lookup_nonexistent_domain() {
fn geosite_list_not_empty() {
let service = get_geosite_service().expect("Failed to create service");
- assert!(
- !service.is_empty(),
- "GeoSiteList should not be empty"
- );
+ assert!(!service.is_empty(), "GeoSiteList should not be empty");
println!("Loaded {} GeoSite entries", service.len());
}