test(server): static-site decoy resolves directory requests to index.html (COV-12 review-002)
This commit is contained in:
@@ -286,6 +286,26 @@ mod tests {
|
|||||||
assert_eq!(&bytes[..], b"<p>about</p>");
|
assert_eq!(&bytes[..], b"<p>about</p>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn static_site_decoy_directory_request_resolves_to_index_html() {
|
||||||
|
let dir = tempfile_dir();
|
||||||
|
tokio::fs::create_dir_all(dir.join("docs")).await.unwrap();
|
||||||
|
tokio::fs::write(dir.join("docs").join("index.html"), "dir index")
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
let decoy = DecoyConfig::StaticSite { root: dir };
|
||||||
|
let resp = send(decoy_router(decoy), "/docs").await;
|
||||||
|
assert_eq!(resp.status(), StatusCode::OK);
|
||||||
|
let ctype = resp
|
||||||
|
.headers()
|
||||||
|
.get(header::CONTENT_TYPE)
|
||||||
|
.map(|v| v.to_str().unwrap().to_string());
|
||||||
|
assert!(ctype.as_deref().unwrap_or("").starts_with("text/html"));
|
||||||
|
let bytes = resp.into_body().collect().await.unwrap().to_bytes();
|
||||||
|
assert_eq!(&bytes[..], b"dir index");
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn static_site_decoy_missing_file_returns_fake_404() {
|
async fn static_site_decoy_missing_file_returns_fake_404() {
|
||||||
let dir = tempfile_dir();
|
let dir = tempfile_dir();
|
||||||
|
|||||||
Reference in New Issue
Block a user