Skip to content

Commit 03bf984

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 594ec99 commit 03bf984

File tree

1 file changed

+114
-1
lines changed

1 file changed

+114
-1
lines changed

rustls-libssl/tests/runner.rs

Lines changed: 114 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,119 @@ 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+
"
339+
daemon off;
340+
master_process off;
341+
pid nginx.pid;
342+
343+
events {
344+
}
345+
346+
http {
347+
ssl_protocols TLSv1.2 TLSv1.3;
348+
access_log access.log;
349+
350+
server {
351+
listen 8443 ssl;
352+
server_name localhost;
353+
ssl_certificate ../../../test-ca/rsa/server.cert;
354+
ssl_certificate_key ../../../test-ca/rsa/server.key;
355+
356+
location = / {
357+
return 200 \"hello world\n\";
358+
}
359+
360+
location /ssl-agreed {
361+
return 200 \"protocol:$ssl_protocol,cipher:$ssl_cipher\n\";
362+
}
363+
364+
location /ssl-server-name {
365+
return 200 \"server-name:$ssl_server_name\n\";
366+
}
367+
368+
location /ssl-was-reused {
369+
return 200 \"reused:$ssl_session_reused\n\";
370+
}
371+
372+
# not currently implemented:
373+
location /ssl-offer {
374+
return 200 \"ciphers:$ssl_ciphers,curves:$ssl_curves\n\";
375+
}
376+
377+
location /ssl-early-data {
378+
return 200 \"early-data:$ssl_early_data\n\";
379+
}
380+
381+
location /ssl-client-auth {
382+
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\";
383+
}
384+
}
385+
}
386+
",
387+
)
388+
.unwrap();
389+
390+
let big_file = vec![b'a'; 5 * 1024 * 1024];
391+
fs::write("target/nginx-tmp/basic/html/large.html", &big_file).unwrap();
392+
393+
let nginx_server = KillOnDrop(Some(
394+
Command::new("tests/maybe-valgrind.sh")
395+
.args([
396+
"nginx",
397+
"-g",
398+
&format!("error_log stderr {NGINX_LOG_LEVEL};"),
399+
"-p",
400+
"./target/nginx-tmp/basic",
401+
"-c",
402+
"server.conf",
403+
])
404+
.spawn()
405+
.unwrap(),
406+
));
407+
wait_for_port(8443);
408+
409+
// basic single request
410+
assert_eq!(
411+
Command::new("curl")
412+
.env("LD_LIBRARY_PATH", "")
413+
.args(["--cacert", "test-ca/rsa/ca.cert", "https://localhost:8443/"])
414+
.stdout(Stdio::piped())
415+
.output()
416+
.map(print_output)
417+
.unwrap()
418+
.stdout,
419+
b"hello world\n"
420+
);
421+
422+
// big download (throttled by curl to ensure non-blocking writes work)
423+
assert_eq!(
424+
Command::new("curl")
425+
.env("LD_LIBRARY_PATH", "")
426+
.args([
427+
"--cacert",
428+
"test-ca/rsa/ca.cert",
429+
"--limit-rate",
430+
"1M",
431+
"https://localhost:8443/large.html"
432+
])
433+
.stdout(Stdio::piped())
434+
.output()
435+
.unwrap()
436+
.stdout,
437+
big_file
438+
);
439+
440+
drop(nginx_server);
441+
}
442+
330443
struct KillOnDrop(Option<Child>);
331444

332445
impl KillOnDrop {

0 commit comments

Comments
 (0)