Add more testcases
This commit is contained in:
parent
04170079d6
commit
84625939de
30
Cargo.lock
generated
30
Cargo.lock
generated
@ -891,6 +891,22 @@ dependencies = [
|
|||||||
"version_check 0.9.3",
|
"version_check 0.9.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cookie_store"
|
||||||
|
version = "0.12.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3818dfca4b0cb5211a659bbcbb94225b7127407b2b135e650d717bfb78ab10d3"
|
||||||
|
dependencies = [
|
||||||
|
"cookie",
|
||||||
|
"idna",
|
||||||
|
"log",
|
||||||
|
"publicsuffix",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"time 0.2.26",
|
||||||
|
"url",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "copyless"
|
name = "copyless"
|
||||||
version = "0.1.5"
|
version = "0.1.5"
|
||||||
@ -2575,6 +2591,7 @@ version = "0.3.1"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-identity",
|
"actix-identity",
|
||||||
"actix-rt",
|
"actix-rt",
|
||||||
|
"actix-server",
|
||||||
"actix-slog",
|
"actix-slog",
|
||||||
"actix-web",
|
"actix-web",
|
||||||
"actix-web-static-files",
|
"actix-web-static-files",
|
||||||
@ -2606,6 +2623,16 @@ dependencies = [
|
|||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "publicsuffix"
|
||||||
|
version = "1.5.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "95b4ce31ff0a27d93c8de1849cf58162283752f065a90d508f1105fa6c9a213f"
|
||||||
|
dependencies = [
|
||||||
|
"idna",
|
||||||
|
"url",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "qrcode"
|
name = "qrcode"
|
||||||
version = "0.12.0"
|
version = "0.12.0"
|
||||||
@ -2933,6 +2960,8 @@ checksum = "0718f81a8e14c4dbb3b34cf23dc6aaf9ab8a0dfec160c534b3dbca1aaa21f47c"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.13.0",
|
"base64 0.13.0",
|
||||||
"bytes 0.5.6",
|
"bytes 0.5.6",
|
||||||
|
"cookie",
|
||||||
|
"cookie_store",
|
||||||
"encoding_rs",
|
"encoding_rs",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"futures-util",
|
"futures-util",
|
||||||
@ -2951,6 +2980,7 @@ dependencies = [
|
|||||||
"pin-project-lite 0.2.6",
|
"pin-project-lite 0.2.6",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_urlencoded",
|
"serde_urlencoded",
|
||||||
|
"time 0.2.26",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-tls",
|
"tokio-tls",
|
||||||
"url",
|
"url",
|
||||||
|
10
Cargo.toml
10
Cargo.toml
@ -58,12 +58,16 @@ features = ["registry", "env-filter"]
|
|||||||
version = "0.2.17"
|
version = "0.2.17"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
reqwest = "0.10.10"
|
actix-server = "1.0.4"
|
||||||
tempdir = "0.3"
|
tempdir = "0.3"
|
||||||
test_bin = "0.3"
|
test_bin = "0.3"
|
||||||
tokio="0.2.25"
|
tokio = "0.2.25"
|
||||||
|
|
||||||
|
[dev-dependencies.reqwest]
|
||||||
|
features = ["cookies"]
|
||||||
|
version = "0.10.10"
|
||||||
|
|
||||||
[profile]
|
[profile]
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = true #timize for size at cost of compilation speed.
|
lto = true
|
||||||
#codegen-units = 1
|
#codegen-units = 1
|
@ -221,18 +221,32 @@ async fn run_server() {
|
|||||||
|
|
||||||
let server = pslink::webservice(server_config);
|
let server = pslink::webservice(server_config);
|
||||||
|
|
||||||
let neveruse = tokio::spawn(server);
|
let _neveruse = tokio::spawn(server);
|
||||||
println!("Never used: {:?}", neveruse);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_web_paths() {
|
async fn test_web_paths() {
|
||||||
run_server().await;
|
run_server().await;
|
||||||
|
|
||||||
std::thread::sleep(std::time::Duration::new(5, 0));
|
|
||||||
// We need to bring in `reqwest`
|
// We need to bring in `reqwest`
|
||||||
// to perform HTTP requests against our application.
|
// to perform HTTP requests against our application.
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::builder()
|
||||||
|
.cookie_store(true)
|
||||||
|
.redirect(reqwest::redirect::Policy::none())
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
let response = client
|
||||||
|
.get("http://localhost:8080/")
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.expect("Failed to execute request.");
|
||||||
|
|
||||||
|
// The basic redirection is working!
|
||||||
|
assert!(response.status().is_redirection());
|
||||||
|
let location = response.headers().get("location").unwrap();
|
||||||
|
assert!(location.to_str().unwrap().contains("github"));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
let response = client
|
let response = client
|
||||||
@ -241,7 +255,95 @@ async fn test_web_paths() {
|
|||||||
.await
|
.await
|
||||||
.expect("Failed to execute request.");
|
.expect("Failed to execute request.");
|
||||||
|
|
||||||
// Assert
|
// The Loginpage is reachable and contains a password field!
|
||||||
assert!(response.status().is_success());
|
assert!(response.status().is_success());
|
||||||
//assert_eq!(Some(0), response.content_length());
|
let content = response.text().await.unwrap();
|
||||||
|
assert!(
|
||||||
|
content.contains(r#"<input type="password"#),
|
||||||
|
"No password field was found!"
|
||||||
|
);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
let formdata = &[("username", "test"), ("password", "testpw")];
|
||||||
|
let response = client
|
||||||
|
.post("http://localhost:8080/admin/login/")
|
||||||
|
.form(formdata)
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.expect("Failed to execute request.");
|
||||||
|
|
||||||
|
// It is possible to login
|
||||||
|
assert!(response.status().is_redirection());
|
||||||
|
let location = response.headers().get("location").unwrap();
|
||||||
|
assert_eq!("/admin/index/", location.to_str().unwrap());
|
||||||
|
assert!(
|
||||||
|
response.headers().get("set-cookie").is_some(),
|
||||||
|
"A auth cookie is not set even though authentication succeeds"
|
||||||
|
);
|
||||||
|
|
||||||
|
// After login this should return a redirect
|
||||||
|
let response = client
|
||||||
|
.get("http://localhost:8080/admin/login/")
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.expect("Failed to execute request.");
|
||||||
|
|
||||||
|
// The Loginpage redirects to link index when logged in
|
||||||
|
assert!(
|
||||||
|
response.status().is_redirection(),
|
||||||
|
"/admin/login/ is not redirecting correctly when logged in!"
|
||||||
|
);
|
||||||
|
let location = response.headers().get("location").unwrap();
|
||||||
|
assert_eq!("/admin/index/", location.to_str().unwrap());
|
||||||
|
|
||||||
|
// After login this should return a redirect
|
||||||
|
let response = client
|
||||||
|
.get("http://localhost:8080/admin/index/")
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.expect("Failed to execute request.");
|
||||||
|
|
||||||
|
// The Loginpage redirects to link index when logged in
|
||||||
|
assert!(
|
||||||
|
response.status().is_success(),
|
||||||
|
"Could not access /admin/index/"
|
||||||
|
);
|
||||||
|
let content = response.text().await.unwrap();
|
||||||
|
assert!(
|
||||||
|
content.contains(r#"<a href="/admin/logout/">"#),
|
||||||
|
"No Logout Button was found on /admin/index/!"
|
||||||
|
);
|
||||||
|
|
||||||
|
// Act title=haupt&target=http%3A%2F%2Fdas.geht%2Fjetzt%2F&code=tpuah
|
||||||
|
let formdata = &[
|
||||||
|
("title", "haupt"),
|
||||||
|
("target", "https://das.geht/jetzt/"),
|
||||||
|
("code", "tpuah"),
|
||||||
|
];
|
||||||
|
let response = client
|
||||||
|
.post("http://localhost:8080/admin/submit/")
|
||||||
|
.form(formdata)
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.expect("Failed to execute request.");
|
||||||
|
|
||||||
|
// It is possible to login
|
||||||
|
assert!(response.status().is_redirection());
|
||||||
|
let location = response.headers().get("location").unwrap();
|
||||||
|
assert_eq!("/admin/view/link/tpuah", location.to_str().unwrap());
|
||||||
|
|
||||||
|
// Act
|
||||||
|
let response = client
|
||||||
|
.get("http://localhost:8080/tpuah")
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.expect("Failed to execute request.");
|
||||||
|
|
||||||
|
// The basic redirection is working!
|
||||||
|
assert!(response.status().is_redirection());
|
||||||
|
let location = response.headers().get("location").unwrap();
|
||||||
|
assert!(location
|
||||||
|
.to_str()
|
||||||
|
.unwrap()
|
||||||
|
.contains("https://das.geht/jetzt/"));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user