mirror of
https://github.com/LukeMathWalker/zero-to-production.git
synced 2024-12-18 05:56:35 +00:00
Missing auth test.
This commit is contained in:
parent
e0c67b8747
commit
03edd1e3b6
1 changed files with 19 additions and 0 deletions
|
@ -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"]);
|
||||
}
|
Loading…
Reference in a new issue