Skip to content

Commit

Permalink
test(api/hello): revise with TestApp.mock_keystone_auth
Browse files Browse the repository at this point in the history
Signed-off-by: Sandro-Alessio Gierens <[email protected]>
  • Loading branch information
gierens committed Sep 11, 2024
1 parent 01328e9 commit 7d3ffdd
Showing 1 changed file with 3 additions and 56 deletions.
59 changes: 3 additions & 56 deletions api/tests/api/hello.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
use serde_json::json;
use uuid::Uuid;
use wiremock::{
matchers::{header, method, path},
Mock, ResponseTemplate,
};

use crate::helpers::spawn_app;

Expand All @@ -12,24 +7,8 @@ async fn hello_returns_unauthorized_for_missing_token() {
// arrange
let app = spawn_app().await;
let client = reqwest::Client::new();

let token = Uuid::new_v4().to_string();
Mock::given(method("GET"))
.and(path("/auth/tokens/"))
.and(header("X-Subject-Token", &token))
.respond_with(
ResponseTemplate::new(200)
.append_header("X-Subject-Token", &app.keystone_token)
// TODO use id and name from app variable
.set_body_json(json!({
"token": {
"project": {
"id": "project_id",
"name": "project_name",
}
}
})),
)
app.mock_keystone_auth(&token, "project_id", "project_name")
.mount(&app.keystone_server)
.await;

Expand All @@ -49,24 +28,8 @@ async fn hello_returns_unauthorized_for_wrong_token() {
// arrange
let app = spawn_app().await;
let client = reqwest::Client::new();

let token = Uuid::new_v4().to_string();
Mock::given(method("GET"))
.and(path("/auth/tokens/"))
.and(header("X-Subject-Token", &token))
.respond_with(
ResponseTemplate::new(200)
.append_header("X-Subject-Token", &app.keystone_token)
// TODO use id and name from app variable
.set_body_json(json!({
"token": {
"project": {
"id": "project_id",
"name": "project_name",
}
}
})),
)
app.mock_keystone_auth(&token, "project_id", "project_name")
.mount(&app.keystone_server)
.await;

Expand All @@ -88,24 +51,8 @@ async fn hello_works_with_valid_token() {
// arrange
let app = spawn_app().await;
let client = reqwest::Client::new();

let token = Uuid::new_v4().to_string();
Mock::given(method("GET"))
.and(path("/auth/tokens/"))
.and(header("X-Subject-Token", &token))
.respond_with(
ResponseTemplate::new(200)
.append_header("X-Subject-Token", &app.keystone_token)
// TODO use id and name from app variable
.set_body_json(json!({
"token": {
"project": {
"id": "project_id",
"name": "project_name",
}
}
})),
)
app.mock_keystone_auth(&token, "project_id", "project_name")
.mount(&app.keystone_server)
.await;

Expand Down

0 comments on commit 7d3ffdd

Please sign in to comment.