diff options
| author | mo khan <mo@mokhan.ca> | 2025-07-05 11:42:26 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-07-05 11:42:26 -0600 |
| commit | 43ea56f31f1f00b5f6dfb84682ef40b716a327a4 (patch) | |
| tree | 3c4ea3baae815de043cb47354600a0ae771d329d /tests/authorization/check_service_test.rs | |
| parent | 3d821c356af75cdddddf72d8dc9d877972ee8d20 (diff) | |
test: refactor tests to provide multiple sparkle hosts
Diffstat (limited to 'tests/authorization/check_service_test.rs')
| -rw-r--r-- | tests/authorization/check_service_test.rs | 166 |
1 files changed, 44 insertions, 122 deletions
diff --git a/tests/authorization/check_service_test.rs b/tests/authorization/check_service_test.rs index a32f2a2c..f6546802 100644 --- a/tests/authorization/check_service_test.rs +++ b/tests/authorization/check_service_test.rs @@ -129,131 +129,53 @@ mod tests { // {status: tonic::Code::Ok, http: &HTTPRequest{Method: "POST", Path: "/sparkles", Headers: loggedInHeaders}}, // {status: tonic::Code::PermissionDenied, http: &HTTPRequest{Method: "GET", Path: "/dashboard", Headers: invalidHeaders}}, - let test_cases = vec![ - ( - "GET", - "/", - "sparkle.staging.runway.gitlab.net", - tonic::Code::Ok, - ), - ( - "GET", - "/application.js", - "sparkle.staging.runway.gitlab.net", - tonic::Code::Ok, - ), - ( - "GET", - "/callback", - "sparkle.staging.runway.gitlab.net", - tonic::Code::Ok, - ), - ( - "GET", - "/dashboard/nav", - "sparkle.staging.runway.gitlab.net", - tonic::Code::Ok, - ), - ( - "GET", - "/favicon.ico", - "sparkle.staging.runway.gitlab.net", - tonic::Code::Ok, - ), - ( - "GET", - "/favicon.png", - "sparkle.staging.runway.gitlab.net", - tonic::Code::Ok, - ), - ( - "GET", - "/health", - "sparkle.staging.runway.gitlab.net", - tonic::Code::Ok, - ), - ( - "GET", - "/htmx.js", - "sparkle.staging.runway.gitlab.net", - tonic::Code::Ok, - ), - ( - "GET", - "/index.html", - "sparkle.staging.runway.gitlab.net", - tonic::Code::Ok, - ), - ( - "GET", - "/logo.png", - "sparkle.staging.runway.gitlab.net", - tonic::Code::Ok, - ), - ( - "GET", - "/pico.min.css", - "sparkle.staging.runway.gitlab.net", - tonic::Code::Ok, - ), - ( - "GET", - "/signout", - "sparkle.staging.runway.gitlab.net", - tonic::Code::Ok, - ), - ( - "GET", - "/sparkles", - "sparkle.staging.runway.gitlab.net", - tonic::Code::Ok, - ), - ( - "GET", - "/vue.global.js", - "sparkle.staging.runway.gitlab.net", - tonic::Code::Ok, - ), - ( - "POST", - "/sparkles/restore", - "sparkle.staging.runway.gitlab.net", - tonic::Code::Ok, - ), - ( - "GET", - "/dashboard", - "sparkle.staging.runway.gitlab.net", - tonic::Code::Unauthenticated, - ), - ( - "POST", - "/sparkles", - "sparkle.staging.runway.gitlab.net", - tonic::Code::Unauthenticated, - ), + let hosts = vec![ + "sparkle.staging.runway.gitlab.net", + // "sparkle.runway.gitlab.net", ]; - for (method, path, host, expected_status_code) in test_cases { - let request = tonic::Request::new(build_request(|item: &mut HttpRequest| { - item.method = method.to_string(); - item.path = path.to_string(); - item.host = host.to_string(); - item.headers = build_headers(vec![ - (String::from(":path"), path.to_string()), - (String::from(":method"), method.to_string()), - (String::from(":authority"), host.to_string()), - ]); - })); - - let response = subject().check(request).await; - assert!(response.is_ok()); - - let check_response = response.unwrap().into_inner(); - assert!(check_response.status.is_some()); + let routes = vec![ + ("GET", "/", tonic::Code::Ok), + ("GET", "/application.js", tonic::Code::Ok), + ("GET", "/callback", tonic::Code::Ok), + ("GET", "/dashboard/nav", tonic::Code::Ok), + ("GET", "/favicon.ico", tonic::Code::Ok), + ("GET", "/favicon.png", tonic::Code::Ok), + ("GET", "/health", tonic::Code::Ok), + ("GET", "/htmx.js", tonic::Code::Ok), + ("GET", "/index.html", tonic::Code::Ok), + ("GET", "/logo.png", tonic::Code::Ok), + ("GET", "/pico.min.css", tonic::Code::Ok), + ("GET", "/signout", tonic::Code::Ok), + ("GET", "/sparkles", tonic::Code::Ok), + ("GET", "/vue.global.js", tonic::Code::Ok), + ("POST", "/sparkles/restore", tonic::Code::Ok), + ("GET", "/dashboard", tonic::Code::Unauthenticated), + ("POST", "/sparkles", tonic::Code::Unauthenticated), + ]; - let status = check_response.status.unwrap(); - assert_eq!(status.code, expected_status_code as i32); + for host in hosts { + for (method, path, expected_status_code) in &routes { + let request = tonic::Request::new(build_request(|item: &mut HttpRequest| { + item.method = method.to_string(); + item.path = path.to_string(); + item.host = host.to_string(); + item.headers = build_headers(vec![ + (String::from(":path"), path.to_string()), + (String::from(":method"), method.to_string()), + (String::from(":authority"), host.to_string()), + ]); + })); + + let response = subject().check(request).await; + assert!(response.is_ok()); + + let check_response = response.unwrap().into_inner(); + assert!(check_response.status.is_some()); + + let status = check_response.status.unwrap(); + assert_eq!(tonic::Code::from_i32(status.code), *expected_status_code); + } } } } |
