Skip to content

Commit

Permalink
test: add test_provider
Browse files Browse the repository at this point in the history
  • Loading branch information
spacemeowx2 committed May 8, 2022
1 parent 79522e5 commit e15297f
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ yaml-merge-keys = { version = "0.5.1", features = ["serde_yaml"] }
serde_json = "1.0"
serde = { version = "1.0.119", features = ["derive"] }
rd-interface = { path = "./rabbit-digger/rd-interface/", version = "0.4" }
rd-std = { path = "./rabbit-digger/rd-std/", version = "0.1" }
cfg-if = "1.0"
reqwest = { version = "0.11.4", features = ["native-tls-vendored", "socks"] }
parking_lot = "0.12.0"
Expand Down
2 changes: 1 addition & 1 deletion protocol/obfs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"

[dependencies]
rd-interface = { path = "../../rabbit-digger/rd-interface/", version = "0.4" }
# rd-interface = "0.3"
rd-std = { path = "../../rabbit-digger/rd-std/", version = "0.1" }
serde = "1.0"
tokio = "1.0"
pin-project-lite = "0.2.6"
Expand Down
28 changes: 28 additions & 0 deletions protocol/obfs/src/obfs_net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,31 @@ impl ITcpListener for ObfsTcpListener {
self.0.local_addr().await
}
}

#[cfg(test)]
mod tests {
use rd_std::tests::{assert_net_provider, ProviderCapability, TestNet};

use super::*;

#[test]
fn test_provider() {
let net = TestNet::new().into_dyn();

let obfs = ObfsNet::new(ObfsNetConfig {
net: NetRef::new_with_value("test".into(), net.clone()),
obfs_type: ObfsType::Plain(Default::default()),
})
.unwrap()
.into_dyn();

assert_net_provider(
&obfs,
ProviderCapability {
tcp_connect: true,
tcp_bind: true,
..Default::default()
},
);
}
}
2 changes: 1 addition & 1 deletion protocol/obfs/src/plain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::Obfs;
use rd_interface::{prelude::*, Address, Result, TcpStream};

#[rd_config]
#[derive(Debug)]
#[derive(Debug, Default)]
pub struct Plain;

impl Obfs for Plain {
Expand Down
31 changes: 31 additions & 0 deletions protocol/rpc/src/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,34 @@ impl INet for RpcNet {
Some(self)
}
}

#[cfg(test)]
mod tests {
use rd_interface::IntoAddress;
use rd_std::tests::{assert_net_provider, ProviderCapability, TestNet};

use super::*;

#[test]
fn test_provider() {
let net = TestNet::new().into_dyn();

let rpc = RpcNet::new(
net,
"127.0.0.1:1234".into_address().unwrap(),
true,
Codec::Cbor,
)
.into_dyn();

assert_net_provider(
&rpc,
ProviderCapability {
tcp_connect: true,
tcp_bind: true,
udp_bind: true,
lookup_host: true,
},
);
}
}
31 changes: 31 additions & 0 deletions protocol/ss/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,34 @@ impl INet for SSNet {
Some(self)
}
}

#[cfg(test)]
mod tests {
use rd_interface::IntoAddress;
use rd_std::tests::{assert_net_provider, ProviderCapability, TestNet};

use super::*;

#[test]
fn test_provider() {
let net = TestNet::new().into_dyn();

let ss = SSNet::new(SSNetConfig {
server: "127.0.0.1:1234".into_address().unwrap(),
password: "password".to_string(),
udp: false,
cipher: Cipher::AES_128_CCM,
net: NetRef::new_with_value("test".into(), net),
})
.into_dyn();

assert_net_provider(
&ss,
ProviderCapability {
tcp_connect: true,
udp_bind: true,
..Default::default()
},
);
}
}
34 changes: 34 additions & 0 deletions protocol/trojan/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,37 @@ impl INet for TrojanNet {
Some(self)
}
}

#[cfg(test)]
mod tests {
use rd_interface::IntoAddress;
use rd_std::tests::{assert_net_provider, ProviderCapability, TestNet};

use super::*;

#[test]
fn test_provider() {
let net = TestNet::new().into_dyn();

let trojan = TrojanNet::new(TrojanNetConfig {
net: NetRef::new_with_value("test".into(), net),
server: "127.0.0.1:1234".into_address().unwrap(),
password: "password".to_string(),
sni: None,
skip_cert_verify: false,
websocket: None,
handshake_timeout: None,
})
.unwrap()
.into_dyn();

assert_net_provider(
&trojan,
ProviderCapability {
tcp_connect: true,
udp_bind: true,
..Default::default()
},
);
}
}
30 changes: 30 additions & 0 deletions src/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,33 @@ pub fn init(registry: &mut Registry) -> Result<()> {
registry.add_net::<SelectNet>();
Ok(())
}

#[cfg(test)]
mod tests {
use rd_interface::IntoDyn;
use rd_std::tests::{assert_net_provider, ProviderCapability, TestNet};

use super::*;

#[test]
fn test_provider() {
let net = NetRef::new_with_value("test".into(), TestNet::new().into_dyn());

let select = SelectNet::new(SelectNetConfig {
selected: net.clone(),
list: vec![net],
})
.unwrap()
.into_dyn();

assert_net_provider(
&select,
ProviderCapability {
tcp_connect: true,
tcp_bind: true,
udp_bind: true,
lookup_host: true,
},
);
}
}

0 comments on commit e15297f

Please sign in to comment.