1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-06-13 02:39:32 +00:00

Add failing test case for newline in files

This commit is contained in:
Sven-Hendrik Haase 2024-01-05 17:57:36 +01:00
parent 561cc440b2
commit 1e54f87366
No known key found for this signature in database
GPG key ID: 39E4B877E62EB915

View file

@ -568,6 +568,26 @@ mod tests {
assert_eq!(bytes, data);
}
#[actix_rt::test]
async fn test_static_files_with_newlines() {
// Create the file we want to test against ad-hoc. We can't check it in as otherwise
// Windows can't even checkout this repository.
let tmpdir = tempfile::tempdir().unwrap();
let file_with_newlines = tmpdir.path().join("test\nnewline.text");
fs::write(&file_with_newlines, "Look at my newlines").unwrap();
let srv = test::init_service(
App::new().service(Files::new("", tmpdir.path()).index_file("Cargo.toml")),
)
.await;
let request = TestRequest::get().uri("/test%0Anewline.text").to_request();
let response = test::call_service(&srv, request).await;
assert_eq!(response.status(), StatusCode::OK);
let bytes = test::read_body(response).await;
let data = web::Bytes::from(fs::read(file_with_newlines).unwrap());
assert_eq!(bytes, data);
}
#[actix_rt::test]
async fn test_files_not_allowed() {
let srv = test::init_service(App::new().service(Files::new("/", "."))).await;
@ -842,7 +862,7 @@ mod tests {
async fn test_percent_encoding_2() {
let tmpdir = tempfile::tempdir().unwrap();
let filename = match cfg!(unix) {
true => "ض:?#[]{}<>()@!$&'`|*+,;= %20.test",
true => "ض:?#[]{}<>()@!$&'`|*+,;= %20\n.test",
false => "ض#[]{}()@!$&'`+,;= %20.test",
};
let filename_encoded = filename