mirror of
https://github.com/agersant/polaris
synced 2024-11-10 10:14:12 +00:00
Added tests that auth cookie headers are not emitted in all requests
This commit is contained in:
parent
e1934a8e92
commit
2eed57cc47
1 changed files with 25 additions and 0 deletions
|
@ -18,6 +18,18 @@ fn validate_cookies<T>(response: &Response<T>) {
|
|||
assert!(cookies.iter().any(|c| c.name() == dto::COOKIE_ADMIN));
|
||||
}
|
||||
|
||||
fn validate_no_cookies<T>(response: &Response<T>) {
|
||||
let cookies: Vec<Cookie> = response
|
||||
.headers()
|
||||
.get_all(http::header::SET_COOKIE)
|
||||
.iter()
|
||||
.map(|c| Cookie::parse(c.to_str().unwrap()).unwrap())
|
||||
.collect();
|
||||
assert!(!cookies.iter().any(|c| c.name() == dto::COOKIE_SESSION));
|
||||
assert!(!cookies.iter().any(|c| c.name() == dto::COOKIE_USERNAME));
|
||||
assert!(!cookies.iter().any(|c| c.name() == dto::COOKIE_ADMIN));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_login_rejects_bad_username() {
|
||||
let mut service = ServiceType::new(&test_name!());
|
||||
|
@ -52,6 +64,19 @@ fn test_login_golden_path() {
|
|||
validate_cookies(&response);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_requests_without_auth_header_do_not_set_cookies() {
|
||||
let mut service = ServiceType::new(&test_name!());
|
||||
service.complete_initial_setup();
|
||||
service.login();
|
||||
|
||||
let request = service.request_builder().random();
|
||||
let response = service.fetch(&request);
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
|
||||
validate_no_cookies(&response);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_authentication_via_http_header_rejects_bad_username() {
|
||||
let mut service = ServiceType::new(&test_name!());
|
||||
|
|
Loading…
Reference in a new issue