Skip to content

Commit d345b47

Browse files
committed
Set up nginx integration test
This uses the system nginx (assumed to be available) to start a server, then grabs a small html file and a larger 5MB download with the system curl (using system openssl).
1 parent 141d799 commit d345b47

File tree

2 files changed

+113
-1
lines changed

2 files changed

+113
-1
lines changed

rustls-libssl/tests/nginx.conf

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
daemon off;
2+
master_process off;
3+
pid nginx.pid;
4+
5+
events {
6+
}
7+
8+
http {
9+
ssl_protocols TLSv1.2 TLSv1.3;
10+
access_log access.log;
11+
12+
server {
13+
listen 8443 ssl;
14+
server_name localhost;
15+
ssl_certificate ../../../test-ca/rsa/server.cert;
16+
ssl_certificate_key ../../../test-ca/rsa/server.key;
17+
18+
location = / {
19+
return 200 \"hello world\n\";
20+
}
21+
22+
location /ssl-agreed {
23+
return 200 \"protocol:$ssl_protocol,cipher:$ssl_cipher\n\";
24+
}
25+
26+
location /ssl-server-name {
27+
return 200 \"server-name:$ssl_server_name\n\";
28+
}
29+
30+
location /ssl-was-reused {
31+
return 200 \"reused:$ssl_session_reused\n\";
32+
}
33+
34+
# not currently implemented:
35+
location /ssl-offer {
36+
return 200 \"ciphers:$ssl_ciphers,curves:$ssl_curves\n\";
37+
}
38+
39+
location /ssl-early-data {
40+
return 200 \"early-data:$ssl_early_data\n\";
41+
}
42+
43+
location /ssl-client-auth {
44+
return 200 \"s-dn:$ssl_client_s_dn\ni-dn:$ssl_client_i_dn\nserial:$ssl_client_serial\nfp:$ssl_client_fingerprint\nverify:$ssl_client_verify\nv-start:$ssl_client_v_start\nv-end:$ssl_client_v_end\nv-remain:$ssl_client_v_remain\ncert:\n$ssl_client_cert\n\";
45+
}
46+
}
47+
}

rustls-libssl/tests/runner.rs

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::io::Read;
22
use std::process::{Child, Command, Output, Stdio};
3-
use std::{net, thread, time};
3+
use std::{fs, net, thread, time};
44

55
/* Note:
66
*
@@ -327,6 +327,71 @@ fn server() {
327327
assert_eq!(openssl_output, rustls_output);
328328
}
329329

330+
const NGINX_LOG_LEVEL: &str = "info";
331+
332+
#[test]
333+
#[ignore]
334+
fn nginx() {
335+
fs::create_dir_all("target/nginx-tmp/basic/html").unwrap();
336+
fs::write(
337+
"target/nginx-tmp/basic/server.conf",
338+
include_str!("nginx.conf"),
339+
)
340+
.unwrap();
341+
342+
let big_file = vec![b'a'; 5 * 1024 * 1024];
343+
fs::write("target/nginx-tmp/basic/html/large.html", &big_file).unwrap();
344+
345+
let nginx_server = KillOnDrop(Some(
346+
Command::new("tests/maybe-valgrind.sh")
347+
.args([
348+
"nginx",
349+
"-g",
350+
&format!("error_log stderr {NGINX_LOG_LEVEL};"),
351+
"-p",
352+
"./target/nginx-tmp/basic",
353+
"-c",
354+
"server.conf",
355+
])
356+
.spawn()
357+
.unwrap(),
358+
));
359+
wait_for_port(8443);
360+
361+
// basic single request
362+
assert_eq!(
363+
Command::new("curl")
364+
.env("LD_LIBRARY_PATH", "")
365+
.args(["--cacert", "test-ca/rsa/ca.cert", "https://localhost:8443/"])
366+
.stdout(Stdio::piped())
367+
.output()
368+
.map(print_output)
369+
.unwrap()
370+
.stdout,
371+
b"hello world\n"
372+
);
373+
374+
// big download (throttled by curl to ensure non-blocking writes work)
375+
assert_eq!(
376+
Command::new("curl")
377+
.env("LD_LIBRARY_PATH", "")
378+
.args([
379+
"--cacert",
380+
"test-ca/rsa/ca.cert",
381+
"--limit-rate",
382+
"1M",
383+
"https://localhost:8443/large.html"
384+
])
385+
.stdout(Stdio::piped())
386+
.output()
387+
.unwrap()
388+
.stdout,
389+
big_file
390+
);
391+
392+
drop(nginx_server);
393+
}
394+
330395
struct KillOnDrop(Option<Child>);
331396

332397
impl KillOnDrop {

0 commit comments

Comments
 (0)