Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run tests with test keys symlinks from crate directories #1218

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 18 additions & 20 deletions ntp-proto/src/nts_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2103,17 +2103,16 @@ mod test {

#[test]
fn test_keyexchange_client() {
let cert_chain: Vec<rustls::Certificate> =
rustls_pemfile::certs(&mut std::io::BufReader::new(include_bytes!(
"../../test-keys/end.fullchain.pem"
) as &[u8]))
.unwrap()
.into_iter()
.map(rustls::Certificate)
.collect();
let cert_chain: Vec<rustls::Certificate> = rustls_pemfile::certs(
&mut std::io::BufReader::new(include_bytes!("../test-keys/end.fullchain.pem") as &[u8]),
)
.unwrap()
.into_iter()
.map(rustls::Certificate)
.collect();
let key_der = rustls::PrivateKey(
rustls_pemfile::pkcs8_private_keys(&mut std::io::BufReader::new(include_bytes!(
"../../test-keys/end.key"
"../test-keys/end.key"
)
as &[u8]))
.unwrap()
Expand All @@ -2129,7 +2128,7 @@ mod test {
let mut root_store = rustls::RootCertStore::empty();
root_store.add_parsable_certificates(
&rustls_pemfile::certs(&mut std::io::BufReader::new(include_bytes!(
"../../test-keys/testca.pem"
"../test-keys/testca.pem"
) as &[u8]))
.unwrap(),
);
Expand Down Expand Up @@ -2176,17 +2175,16 @@ mod test {
}

fn client_server_pair() -> (KeyExchangeClient, KeyExchangeServer) {
let cert_chain: Vec<rustls::Certificate> =
rustls_pemfile::certs(&mut std::io::BufReader::new(include_bytes!(
"../../test-keys/end.fullchain.pem"
) as &[u8]))
.unwrap()
.into_iter()
.map(rustls::Certificate)
.collect();
let cert_chain: Vec<rustls::Certificate> = rustls_pemfile::certs(
&mut std::io::BufReader::new(include_bytes!("../test-keys/end.fullchain.pem") as &[u8]),
)
.unwrap()
.into_iter()
.map(rustls::Certificate)
.collect();
let key_der = rustls::PrivateKey(
rustls_pemfile::pkcs8_private_keys(&mut std::io::BufReader::new(include_bytes!(
"../../test-keys/end.key"
"../test-keys/end.key"
)
as &[u8]))
.unwrap()
Expand All @@ -2206,7 +2204,7 @@ mod test {
let mut root_store = rustls::RootCertStore::empty();
root_store.add_parsable_certificates(
&rustls_pemfile::certs(&mut std::io::BufReader::new(include_bytes!(
"../../test-keys/testca.pem"
"../test-keys/testca.pem"
) as &[u8]))
.unwrap(),
);
Expand Down
1 change: 1 addition & 0 deletions ntp-proto/test-keys
16 changes: 8 additions & 8 deletions ntpd/src/daemon/keyexchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,23 +524,23 @@ mod tests {

#[test]
fn parse_private_keys() {
let input = include_bytes!("../../../test-keys/end.key");
let input = include_bytes!("../../test-keys/end.key");
let _ = private_key_from_bufread(input.as_slice()).unwrap().unwrap();

let input = include_bytes!("../../../test-keys/testca.key");
let input = include_bytes!("../../test-keys/testca.key");
let _ = private_key_from_bufread(input.as_slice()).unwrap().unwrap();

// openssl does no longer seem to want to generate this format
// so we use https://github.com/rustls/pemfile/blob/main/tests/data/rsa1024.pkcs1.pem
let input = include_bytes!("../../../test-keys/rsa_key.pem");
let input = include_bytes!("../../test-keys/rsa_key.pem");
let _ = private_key_from_bufread(input.as_slice()).unwrap().unwrap();

// openssl ecparam -name prime256v1 -genkey -noout -out ec_key.pem
let input = include_bytes!("../../../test-keys/ec_key.pem");
let input = include_bytes!("../../test-keys/ec_key.pem");
let _ = private_key_from_bufread(input.as_slice()).unwrap().unwrap();

// openssl genpkey -algorithm EC -out pkcs8_key.pem -pkeyopt ec_paramgen_curve:prime256v1
let input = include_bytes!("../../../test-keys/pkcs8_key.pem");
let input = include_bytes!("../../test-keys/pkcs8_key.pem");
let _ = private_key_from_bufread(input.as_slice()).unwrap().unwrap();
}

Expand All @@ -551,8 +551,8 @@ mod tests {

let (_sender, keyset) = tokio::sync::watch::channel(keyset);
let nts_ke_config = NtsKeConfig {
certificate_chain_path: PathBuf::from("../test-keys/end.fullchain.pem"),
private_key_path: PathBuf::from("../test-keys/end.key"),
certificate_chain_path: PathBuf::from("test-keys/end.fullchain.pem"),
private_key_path: PathBuf::from("test-keys/end.key"),
key_exchange_timeout_ms: 1000,
listen: "0.0.0.0:5431".parse().unwrap(),
};
Expand All @@ -562,7 +562,7 @@ mod tests {
// give the server some time to make the port available
tokio::time::sleep(std::time::Duration::from_millis(100)).await;

let ca = include_bytes!("../../../test-keys/testca.pem");
let ca = include_bytes!("../../test-keys/testca.pem");
let result = key_exchange_client(
"localhost".to_string(),
5431,
Expand Down
1 change: 1 addition & 0 deletions ntpd/test-keys