Skip to content

Commit 2c822c2

Browse files
committed
Added a unit test and changed reqwest to rustls-tls
1 parent 8c84dc7 commit 2c822c2

File tree

4 files changed

+89
-81
lines changed

4 files changed

+89
-81
lines changed

Cargo.lock

Lines changed: 38 additions & 79 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ prometheus = "0.14.0"
5757
prost = "0.13.4"
5858
rand = { version = "0.9", features = ["os_rng"] }
5959
rayon = "1.10.0"
60-
reqwest = { version = "0.12.4", features = ["json", "stream"] }
60+
rcgen = "0.14.5"
61+
reqwest = { version = "0.12.4", default-features = false, features = ["json", "stream", "rustls-tls"] }
6162
serde = { version = "1.0.202", features = ["derive"] }
6263
serde_json = "1.0.117"
6364
serde_yaml = "0.9.33"

tests/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ tree_hash.workspace = true
2323
url.workspace = true
2424

2525
[dev-dependencies]
26-
cb-common = { path = "../crates/common", features = ["testing-flags"] }
26+
cb-common = { path = "../crates/common", features = ["testing-flags"] }
27+
rcgen.workspace = true
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
use std::io::Write;
2+
3+
use cb_common::{
4+
commit::client::SignerClient,
5+
config::ClientAuthConfig,
6+
types::{Jwt, ModuleId},
7+
};
8+
use cb_tests::utils::setup_test_env;
9+
use eyre::Result;
10+
use rcgen::{CertificateParams, KeyPair};
11+
12+
const JWT_MODULE: &str = "test-module";
13+
const JWT_SECRET: &str = "test-jwt-secret";
14+
15+
/// Test that the SignerClient can be created with client authentication
16+
#[tokio::test]
17+
async fn test_web3_signer_client_auth() -> Result<()> {
18+
setup_test_env();
19+
20+
// Create a keypair first (default: ECDSA P-256)
21+
let key_pair = KeyPair::generate().unwrap();
22+
23+
// Create the certificate
24+
let params = CertificateParams::new(vec!["web3signer-client-test".to_string()])?;
25+
let cert = params.self_signed(&key_pair)?;
26+
27+
// PEM-encode the key and certificate to temp files
28+
let mut cert_file = tempfile::NamedTempFile::new()?;
29+
let mut key_file = tempfile::NamedTempFile::new()?;
30+
write!(cert_file, "{}", cert.pem())?;
31+
write!(key_file, "{}", key_pair.serialize_pem())?;
32+
33+
// Create the signer config with client auth - this will create a new client
34+
// that has client auth enabled, so if it fails anywhere then it'll fail
35+
// here
36+
let _client = SignerClient::new(
37+
"http://localhost:0".parse()?,
38+
Jwt(JWT_SECRET.to_string()),
39+
ModuleId(JWT_MODULE.to_string()),
40+
Some(ClientAuthConfig {
41+
cert_path: cert_file.path().to_path_buf(),
42+
key_path: key_file.path().to_path_buf(),
43+
}),
44+
)?;
45+
46+
Ok(())
47+
}

0 commit comments

Comments
 (0)