From 44da76554febbbf7ab39f263e5cbd5202c912be8 Mon Sep 17 00:00:00 2001 From: Shreelakshmi Iyengar Date: Thu, 13 Aug 2026 15:59:31 +0100 Subject: [PATCH 1/5] fix: strip trailing slash from policy_host --- src/graphql/auth.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/graphql/auth.rs b/src/graphql/auth.rs index 3d85ff0..212b2c5 100644 --- a/src/graphql/auth.rs +++ b/src/graphql/auth.rs @@ -124,10 +124,13 @@ impl PolicyCheck { "Checking authorization against {:?} using {:?} for admin and {:?} for access", endpoint.policy_host, endpoint.admin_query, endpoint.access_query ); + + let host = endpoint.policy_host.trim_end_matches('/'); + Self { client: reqwest::Client::new(), - admin: format!("{}/{}", endpoint.policy_host, endpoint.admin_query), - access: format!("{}/{}", endpoint.policy_host, endpoint.access_query), + admin: format!("{}/{}", host, endpoint.admin_query), + access: format!("{}/{}", host, endpoint.access_query), } } pub async fn check_access( From 841a9d47c1b4946e91c8685ba92552aed9c6cba7 Mon Sep 17 00:00:00 2001 From: Shreelakshmi Iyengar Date: Thu, 13 Aug 2026 16:06:56 +0100 Subject: [PATCH 2/5] tests: add test for trailing slash on policy host --- src/graphql/auth.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/graphql/auth.rs b/src/graphql/auth.rs index 212b2c5..5c15d5b 100644 --- a/src/graphql/auth.rs +++ b/src/graphql/auth.rs @@ -274,6 +274,37 @@ mod tests { mock.assert(); } + #[tokio::test] + async fn successful_check_access_with_trailing_slash_on_host() { + let server = MockServer::start(); + let mock = server + .mock_async(|when, then| { + when.method("POST") + .path("/demo/access") + .json_body_obj(&json!({ + "input": { + "token": "token", + "beamline": "i22", + "visit": 4, + "proposal": 1234, + "audience": "account" + } + })); + then.status(200).json_body_obj(&json!({"result": true})); + }) + .await; + let check = PolicyCheck::new(PolicyOptions { + policy_host: format!("{}/", server.url("")), + access_query: "demo/access".into(), + admin_query: "demo/admin".into(), + }); + check + .check_access(token("token").as_ref(), "i22", "cm1234-4") + .await + .unwrap(); + mock.assert(); + } + #[tokio::test] async fn successful_check_instrument_admin() { let server = MockServer::start(); From ac3f4d1944f8d84013fc6d7a8ab72e3dca9a5c5b Mon Sep 17 00:00:00 2001 From: Shreelakshmi Iyengar Date: Thu, 13 Aug 2026 17:00:23 +0100 Subject: [PATCH 3/5] Update src/graphql/auth.rs Co-authored-by: Peter Holloway --- src/graphql/auth.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graphql/auth.rs b/src/graphql/auth.rs index 5c15d5b..3c10b5f 100644 --- a/src/graphql/auth.rs +++ b/src/graphql/auth.rs @@ -294,7 +294,7 @@ mod tests { }) .await; let check = PolicyCheck::new(PolicyOptions { - policy_host: format!("{}/", server.url("")), + policy_host: server.url("/"), access_query: "demo/access".into(), admin_query: "demo/admin".into(), }); From 72353408e724497a3d6e4a21ad94475a08bc2d06 Mon Sep 17 00:00:00 2001 From: Shreelakshmi Iyengar Date: Thu, 13 Aug 2026 17:08:26 +0100 Subject: [PATCH 4/5] remove potentially leading slashes --- src/graphql/auth.rs | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/graphql/auth.rs b/src/graphql/auth.rs index 3c10b5f..46c9d89 100644 --- a/src/graphql/auth.rs +++ b/src/graphql/auth.rs @@ -129,8 +129,8 @@ impl PolicyCheck { Self { client: reqwest::Client::new(), - admin: format!("{}/{}", host, endpoint.admin_query), - access: format!("{}/{}", host, endpoint.access_query), + admin: format!("{}/{}", host, endpoint.admin_query.trim_start_matches('/')), + access: format!("{}/{}", host, endpoint.access_query.trim_start_matches('/')), } } pub async fn check_access( @@ -305,6 +305,39 @@ mod tests { mock.assert(); } + + #[tokio::test] + async fn successful_check_access_with_leading_slashes() { + let server = MockServer::start(); + let mock = server + .mock_async(|when, then| { + when.method("POST") + .path("/demo/access") + .json_body_obj(&json!({ + "input": { + "token": "token", + "beamline": "i22", + "visit": 4, + "proposal": 1234, + "audience": "account" + } + })); + then.status(200).json_body_obj(&json!({"result": true})); + }) + .await; + let check = PolicyCheck::new(PolicyOptions { + policy_host: server.url(""), + access_query: "/demo/access".into(), + admin_query: "/demo/admin".into(), + }); + check + .check_access(token("token").as_ref(), "i22", "cm1234-4") + .await + .unwrap(); + mock.assert(); + } + + #[tokio::test] async fn successful_check_instrument_admin() { let server = MockServer::start(); From 9b8947a2a877f70b20443e1e8a010047c432766c Mon Sep 17 00:00:00 2001 From: Shreelakshmi Iyengar Date: Thu, 13 Aug 2026 17:16:17 +0100 Subject: [PATCH 5/5] style: add extra missing empty line --- src/graphql/auth.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/graphql/auth.rs b/src/graphql/auth.rs index 46c9d89..54ff884 100644 --- a/src/graphql/auth.rs +++ b/src/graphql/auth.rs @@ -305,7 +305,6 @@ mod tests { mock.assert(); } - #[tokio::test] async fn successful_check_access_with_leading_slashes() { let server = MockServer::start(); @@ -337,7 +336,6 @@ mod tests { mock.assert(); } - #[tokio::test] async fn successful_check_instrument_admin() { let server = MockServer::start();