Skip to content

Commit ff3c6e5

Browse files
committed
tests: add nginx 1.24 specific tests
We want to test the `ssl_conf_command` directive, but this is only available in nginx 1.24+. This commit adds a 1.24 specific config file and updates the test runner so we can spin up and test a nginx 1.24 server with this config when available. For now we test the `MinProtocol` and `MaxProtocol` OpenSSL CONF_CTX commands that the compat shim supports.
1 parent 38e4c44 commit ff3c6e5

File tree

2 files changed

+155
-0
lines changed

2 files changed

+155
-0
lines changed

rustls-libssl/tests/nginx_1_24.conf

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
daemon off;
2+
master_process off;
3+
pid nginx.pid;
4+
5+
events {
6+
}
7+
8+
http {
9+
# Default to both supported protocols enabled.
10+
ssl_protocols TLSv1.2 TLSv1.3;
11+
access_log access.log;
12+
13+
server {
14+
# Custom configuration w/ ssl_conf_command:
15+
# * TLS 1.3 or greater only
16+
listen 8447 ssl;
17+
ssl_certificate ../../../test-ca/rsa/server.cert;
18+
ssl_certificate_key ../../../test-ca/rsa/server.key;
19+
server_name localhost;
20+
21+
ssl_conf_command MinProtocol TLSv1.3;
22+
23+
location = / {
24+
return 200 "hello world\n";
25+
}
26+
27+
location /ssl-agreed {
28+
return 200 "protocol:$ssl_protocol,cipher:$ssl_cipher\n";
29+
}
30+
}
31+
32+
server {
33+
# Custom configuration w/ ssl_conf_command:
34+
# * TLS 1.2 or less only
35+
listen 8448 ssl;
36+
ssl_certificate ../../../test-ca/rsa/server.cert;
37+
ssl_certificate_key ../../../test-ca/rsa/server.key;
38+
server_name localhost;
39+
40+
ssl_conf_command MaxProtocol TLSv1.2;
41+
42+
location = / {
43+
return 200 "hello world\n";
44+
}
45+
46+
location /ssl-agreed {
47+
return 200 "protocol:$ssl_protocol,cipher:$ssl_cipher\n";
48+
}
49+
}
50+
}

rustls-libssl/tests/runner.rs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,111 @@ fn nginx() {
561561
drop(nginx_server);
562562
}
563563

564+
#[test]
565+
#[ignore]
566+
fn nginx_1_24() {
567+
let (major, minor) = nginx_version();
568+
if major != 1 || minor < 24 {
569+
println!("skipping Nginx 1.24 tests, installed version is {major}.{minor}.x");
570+
return;
571+
}
572+
573+
fs::create_dir_all("target/nginx-tmp/1_24/html").unwrap();
574+
fs::write(
575+
"target/nginx-tmp/1_24/server.conf",
576+
include_str!("nginx_1_24.conf"),
577+
)
578+
.unwrap();
579+
580+
let nginx_server = KillOnDrop(Some(
581+
Command::new("tests/maybe-valgrind.sh")
582+
.args([
583+
"nginx",
584+
"-g",
585+
&format!("error_log stderr {NGINX_LOG_LEVEL};"),
586+
"-p",
587+
"./target/nginx-tmp/1_24",
588+
"-c",
589+
"server.conf",
590+
])
591+
.spawn()
592+
.unwrap(),
593+
));
594+
wait_for_port(8447);
595+
wait_for_port(8448);
596+
597+
// TLS 1.2 to the TLS 1.3 only port should fail w/ exit code 35
598+
assert_eq!(
599+
Command::new("curl")
600+
.env("LD_LIBRARY_PATH", "")
601+
.args([
602+
"--cacert",
603+
"test-ca/rsa/ca.cert",
604+
"--tls-max",
605+
"1.2",
606+
"https://localhost:8447/ssl-agreed"
607+
])
608+
.stdout(Stdio::piped())
609+
.status()
610+
.unwrap()
611+
.code()
612+
.unwrap(),
613+
35
614+
);
615+
// TLS 1.3 to the TLS 1.3 only port should succeed.
616+
assert_eq!(
617+
Command::new("curl")
618+
.env("LD_LIBRARY_PATH", "")
619+
.args([
620+
"--cacert",
621+
"test-ca/rsa/ca.cert",
622+
"--tlsv1.3",
623+
"https://localhost:8447/ssl-agreed"
624+
])
625+
.stdout(Stdio::piped())
626+
.output()
627+
.unwrap()
628+
.stdout,
629+
"protocol:TLSv1.3,cipher:TLS_AES_256_GCM_SHA384\n".as_bytes()
630+
);
631+
632+
// TLS 1.3 to the TLS 1.2 only port should fail w/ exit code 35
633+
assert_eq!(
634+
Command::new("curl")
635+
.env("LD_LIBRARY_PATH", "")
636+
.args([
637+
"--cacert",
638+
"test-ca/rsa/ca.cert",
639+
"--tlsv1.3",
640+
"https://localhost:8448/ssl-agreed"
641+
])
642+
.stdout(Stdio::piped())
643+
.status()
644+
.unwrap()
645+
.code()
646+
.unwrap(),
647+
35
648+
);
649+
// TLS 1.2 to the TLS 1.2 only port should succeed.
650+
assert_eq!(
651+
Command::new("curl")
652+
.env("LD_LIBRARY_PATH", "")
653+
.args([
654+
"--cacert",
655+
"test-ca/rsa/ca.cert",
656+
"--tlsv1.2",
657+
"https://localhost:8448/ssl-agreed"
658+
])
659+
.stdout(Stdio::piped())
660+
.output()
661+
.unwrap()
662+
.stdout,
663+
"protocol:TLSv1.2,cipher:ECDHE-RSA-AES256-GCM-SHA384\n".as_bytes()
664+
);
665+
666+
drop(nginx_server);
667+
}
668+
564669
// Return the major and minor version components of the Nginx binary in `$PATH`.
565670
fn nginx_version() -> (u32, u32) {
566671
let nginx_version_output = Command::new("nginx").args(["-v"]).output().unwrap();

0 commit comments

Comments
 (0)