From ce55c964dde9a6575947f2c2360163af5099b281 Mon Sep 17 00:00:00 2001 From: Johann150 Date: Sat, 27 Feb 2021 10:08:28 +0100 Subject: [PATCH] add tests for vhosts closes #34 --- tests/tests.rs | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/tests/tests.rs b/tests/tests.rs index 4c36cdf..73252e7 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -297,3 +297,66 @@ fn explicit_tls_version() { let mut buf = [0; 10]; tls.read(&mut buf).unwrap(); } + +#[test] +/// - simple vhosts are enabled when multiple hostnames are supplied +/// - the vhosts access the correct files +fn vhosts_example_com() { + let page = get( + &[ + "--addr", + "[::]:1977", + "--hostname", + "example.com", + "--hostname", + "example.org", + ], + addr(1977), + "gemini://example.com/", + ) + .expect("could not get page"); + + assert_eq!(page.header.status, Status::Success); + + assert_eq!( + page.body, + Some( + std::fs::read_to_string(concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/data/content/example.com/index.gmi" + )) + .unwrap() + ) + ); +} + +#[test] +/// - the vhosts access the correct files +fn vhosts_example_org() { + let page = get( + &[ + "--addr", + "[::]:1978", + "--hostname", + "example.com", + "--hostname", + "example.org", + ], + addr(1978), + "gemini://example.org/", + ) + .expect("could not get page"); + + assert_eq!(page.header.status, Status::Success); + + assert_eq!( + page.body, + Some( + std::fs::read_to_string(concat!( + env!("CARGO_MANIFEST_DIR"), + "/tests/data/content/example.org/index.gmi" + )) + .unwrap() + ) + ); +}