1 parent
16e3bb7d7a
commit
23c9028b57
4 files changed
+85
-2
No files matched your search
Generated
+15
@@ -2415,6 +2415,20 @@ version = "0.2.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f8eb564c5c7423d25c886fb561d1e4ee69f72354d16918afa32c08811f6b6a55"
|
checksum = "f8eb564c5c7423d25c886fb561d1e4ee69f72354d16918afa32c08811f6b6a55"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fast-socks5"
|
||||||
|
version = "0.10.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d09fe4a491909a716088083eeb5bcc25427330fdbcd4ecd3dfa5469b3da795df"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"async-trait",
|
||||||
|
"log",
|
||||||
|
"thiserror 1.0.69",
|
||||||
|
"tokio",
|
||||||
|
"tokio-stream",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fastrand"
|
name = "fastrand"
|
||||||
version = "2.5.0"
|
version = "2.5.0"
|
||||||
@@ -4465,6 +4479,7 @@ dependencies = [
|
|||||||
"bson",
|
"bson",
|
||||||
"derive-where",
|
"derive-where",
|
||||||
"derive_more",
|
"derive_more",
|
||||||
|
"fast-socks5",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-io",
|
"futures-io",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ tiberius = { version = "0.12.3", default-features = false, features = ["tds73",
|
|||||||
reqwest = { version = "0.12", default-features = false, features = ["json", "stream", "rustls-tls", "socks"] }
|
reqwest = { version = "0.12", default-features = false, features = ["json", "stream", "rustls-tls", "socks"] }
|
||||||
prometheus-parse = "=0.2.5"
|
prometheus-parse = "=0.2.5"
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
mongodb = "3.2.5"
|
mongodb = { version = "3.2.5", features = ["socks5-proxy"] }
|
||||||
rumqttc = { version = "0.24", features = ["websocket"], optional = true }
|
rumqttc = { version = "0.24", features = ["websocket"], optional = true }
|
||||||
russh = "0.60"
|
russh = "0.60"
|
||||||
pageant = "0.2"
|
pageant = "0.2"
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
use mongodb::options::ClientOptions;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use dbx_core::db::mongo_driver;
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn parses_socks5_proxy_host_and_port() {
|
||||||
|
let options = ClientOptions::parse("mongodb://localhost/?proxyHost=127.0.0.1&proxyPort=1080")
|
||||||
|
.await
|
||||||
|
.expect("MongoDB connection strings should accept SOCKS5 proxy options");
|
||||||
|
|
||||||
|
let proxy = options.socks5_proxy.expect("SOCKS5 proxy options");
|
||||||
|
assert_eq!(proxy.host, "127.0.0.1");
|
||||||
|
assert_eq!(proxy.port, Some(1080));
|
||||||
|
assert_eq!(proxy.authentication, None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn parses_socks5_proxy_credentials() {
|
||||||
|
let options =
|
||||||
|
ClientOptions::parse("mongodb://localhost/?proxyHost=proxy.example.com&proxyUsername=dbx&proxyPassword=secret")
|
||||||
|
.await
|
||||||
|
.expect("MongoDB connection strings should accept SOCKS5 proxy credentials");
|
||||||
|
|
||||||
|
let proxy = options.socks5_proxy.expect("SOCKS5 proxy options");
|
||||||
|
assert_eq!(proxy.host, "proxy.example.com");
|
||||||
|
assert_eq!(proxy.port, None);
|
||||||
|
assert_eq!(proxy.authentication, Some(("dbx".to_string(), "secret".to_string())));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn rejects_socks5_proxy_port_without_host() {
|
||||||
|
let error = ClientOptions::parse("mongodb://localhost/?proxyPort=1080")
|
||||||
|
.await
|
||||||
|
.expect_err("proxyPort without proxyHost should remain invalid");
|
||||||
|
|
||||||
|
let message = error.to_string();
|
||||||
|
assert!(
|
||||||
|
message.to_ascii_lowercase().contains("proxyport cannot be set if proxyhost is unspecified"),
|
||||||
|
"unexpected error: {message}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn leaves_direct_connections_without_a_proxy() {
|
||||||
|
let options = ClientOptions::parse("mongodb://localhost:27017/dbx")
|
||||||
|
.await
|
||||||
|
.expect("ordinary MongoDB connection strings should remain valid");
|
||||||
|
|
||||||
|
assert!(options.socks5_proxy.is_none());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
#[ignore = "requires DBX_LIVE_MONGODB_SOCKS5_URL routed through a SOCKS5 proxy"]
|
||||||
|
async fn connects_to_mongodb_through_socks5_proxy() {
|
||||||
|
let url = std::env::var("DBX_LIVE_MONGODB_SOCKS5_URL").expect("DBX_LIVE_MONGODB_SOCKS5_URL");
|
||||||
|
let client = mongo_driver::connect(&url, Duration::from_secs(5), Duration::from_secs(60))
|
||||||
|
.await
|
||||||
|
.expect("connect to MongoDB through SOCKS5");
|
||||||
|
|
||||||
|
mongo_driver::test_connection(&client, Duration::from_secs(5), Some("admin"))
|
||||||
|
.await
|
||||||
|
.expect("ping MongoDB through SOCKS5");
|
||||||
|
let version = mongo_driver::server_version(&client, "admin").await.expect("MongoDB buildInfo through SOCKS5");
|
||||||
|
if let Ok(expected) = std::env::var("DBX_LIVE_MONGODB_EXPECTED_VERSION") {
|
||||||
|
assert_eq!(version, expected);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -52,7 +52,7 @@ tiberius = { version = "0.12.3", default-features = false, features = ["tds73",
|
|||||||
tokio-util = { version = "0.7", features = ["compat"] }
|
tokio-util = { version = "0.7", features = ["compat"] }
|
||||||
reqwest = { version = "0.12", features = ["json", "stream"] }
|
reqwest = { version = "0.12", features = ["json", "stream"] }
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
mongodb = "3.2.5"
|
mongodb = { version = "3.2.5", features = ["socks5-proxy"] }
|
||||||
percent-encoding = "2"
|
percent-encoding = "2"
|
||||||
minisign-verify = "0.2.5"
|
minisign-verify = "0.2.5"
|
||||||
semver = "1"
|
semver = "1"
|
||||||
|
|||||||
Reference in new issue
Block a user