Skip to content

Commit

Permalink
tests(iroh): add download via relay test and expose insecure_skip_rel…
Browse files Browse the repository at this point in the history
…ay_cert_verify
  • Loading branch information
Frando committed Apr 4, 2024
1 parent 9832643 commit 9ec342a
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
2 changes: 2 additions & 0 deletions iroh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ metrics = ["iroh-metrics", "iroh-bytes/metrics"]
fs-store = ["iroh-bytes/fs-store"]
test = []
examples = ["dep:clap", "dep:indicatif"]
test-utils = ["iroh-net/test-utils"]

[dev-dependencies]
anyhow = { version = "1" }
bytes = "1"
console-subscriber = "0.2"
genawaiter = { version = "0.99", features = ["futures03"] }
iroh-test = { path = "../iroh-test" }
iroh-net = { path = "../iroh-net", features = ["test-utils"] }
proptest = "1.2.0"
rand_chacha = "0.3.1"
regex = { version = "1.7.1", features = ["std"] }
Expand Down
48 changes: 47 additions & 1 deletion iroh/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,14 @@ mod tests {
use bytes::Bytes;
use futures::StreamExt;
use iroh_bytes::provider::AddProgress;
use iroh_net::relay::RelayMode;

use crate::rpc_protocol::{BlobAddPathRequest, BlobAddPathResponse, SetTagOption, WrapOption};
use crate::{
client::BlobAddOutcome,
rpc_protocol::{
BlobAddPathRequest, BlobAddPathResponse, BlobDownloadRequest, SetTagOption, WrapOption,
},
};

use super::*;

Expand Down Expand Up @@ -407,4 +413,44 @@ mod tests {

Ok(())
}

#[tokio::test]
async fn test_download_via_relay() -> Result<()> {
let _guard = iroh_test::logging::setup();
let (relay_map, relay_url, _guard) = iroh_net::test_utils::run_relay_server().await?;

let node1 = Node::memory()
.bind_port(0)
.relay_mode(RelayMode::Custom(relay_map.clone()))
.insecure_skip_relay_cert_verify(true)
.spawn()
.await?;
let node2 = Node::memory()
.bind_port(0)
.relay_mode(RelayMode::Custom(relay_map.clone()))
.insecure_skip_relay_cert_verify(true)
.spawn()
.await?;
let BlobAddOutcome { hash, .. } = node1.blobs.add_bytes(b"foo".to_vec()).await?;

// create a node addr with only a relay URL, no direct addresses
let addr = NodeAddr::new(node1.node_id()).with_relay_url(relay_url);
let req = BlobDownloadRequest {
hash,
tag: SetTagOption::Auto,
format: BlobFormat::Raw,
peer: addr,
};
node2.blobs.download(req).await?.await?;
assert_eq!(
node2
.blobs
.read_to_bytes(hash)
.await
.context("get")?
.as_ref(),
b"foo"
);
Ok(())
}
}
26 changes: 26 additions & 0 deletions iroh/src/node/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ where
relay_mode: RelayMode,
gc_policy: GcPolicy,
docs_store: iroh_sync::store::fs::Store,
#[cfg(any(test, feature = "test-utils"))]
insecure_skip_relay_cert_verify: bool,
}

/// Configuration for storage.
Expand All @@ -104,6 +106,8 @@ impl Default for Builder<iroh_bytes::store::mem::Store> {
rpc_endpoint: Default::default(),
gc_policy: GcPolicy::Disabled,
docs_store: iroh_sync::store::Store::memory(),
#[cfg(any(test, feature = "test-utils"))]
insecure_skip_relay_cert_verify: false,
}
}
}
Expand All @@ -125,6 +129,8 @@ impl<D: Map> Builder<D> {
rpc_endpoint: Default::default(),
gc_policy: GcPolicy::Disabled,
docs_store,
#[cfg(any(test, feature = "test-utils"))]
insecure_skip_relay_cert_verify: false,
}
}
}
Expand Down Expand Up @@ -183,6 +189,8 @@ where
relay_mode: self.relay_mode,
gc_policy: self.gc_policy,
docs_store,
#[cfg(any(test, feature = "test-utils"))]
insecure_skip_relay_cert_verify: false,
})
}

Expand All @@ -199,6 +207,8 @@ where
relay_mode: self.relay_mode,
gc_policy: self.gc_policy,
docs_store: self.docs_store,
#[cfg(any(test, feature = "test-utils"))]
insecure_skip_relay_cert_verify: self.insecure_skip_relay_cert_verify,
}
}

Expand All @@ -222,6 +232,8 @@ where
relay_mode: self.relay_mode,
gc_policy: self.gc_policy,
docs_store: self.docs_store,
#[cfg(any(test, feature = "test-utils"))]
insecure_skip_relay_cert_verify: self.insecure_skip_relay_cert_verify,
})
}

Expand Down Expand Up @@ -261,6 +273,15 @@ where
self
}

/// Skip verification of SSL certificates from relay servers
///
/// May only be used in tests.
#[cfg(any(test, feature = "test-utils"))]
pub fn insecure_skip_relay_cert_verify(mut self, skip_verify: bool) -> Self {
self.insecure_skip_relay_cert_verify = skip_verify;
self
}

/// Whether to log the SSL pre-master key.
///
/// If `true` and the `SSLKEYLOGFILE` environment variable is the path to a file this
Expand Down Expand Up @@ -301,6 +322,11 @@ where
.transport_config(transport_config)
.concurrent_connections(MAX_CONNECTIONS)
.relay_mode(self.relay_mode);

#[cfg(any(test, feature = "test-utils"))]
let endpoint =
endpoint.insecure_skip_relay_cert_verify(self.insecure_skip_relay_cert_verify);

let endpoint = match self.storage {
StorageConfig::Persistent(ref root) => {
let peers_data_path = IrohPaths::PeerData.with_root(root);
Expand Down

0 comments on commit 9ec342a

Please sign in to comment.