Missing auth test.

This commit is contained in:
LukeMathWalker 2021-08-14 19:35:46 +01:00
parent e0c67b8747
commit 03edd1e3b6

View file

@ -126,3 +126,22 @@ async fn newsletters_returns_400_for_invalid_data() {
);
}
}
#[actix_rt::test]
async fn requests_missing_authorization_are_rejected() {
// Arrange
let app = spawn_app().await;
let response = reqwest::Client::new()
.post(&format!("{}/newsletters", &app.address))
// The body should not matter - authentication must be performed
// BEFORE any further processing takes place.
.json(&serde_json::json!({}))
.send()
.await
.expect("Failed to execute request.");
// Assert
assert_eq!(401, response.status().as_u16());
assert_eq!(r#"Basic realm="publish""#, response.headers()["WWW-Authenticate"]);
}