Skip to content

Commit ef16848

Browse files
committed
test(server): cover microsoft s2s token guardrails
Signed-off-by: Alex Fournier <afournier@nvidia.com>
1 parent 68c7531 commit ef16848

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

crates/openshell-sandbox/src/provider_tokens.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,4 +547,30 @@ mod tests {
547547
assert_eq!(err.status, 400);
548548
assert_eq!(err.message, "invalid JSON request body");
549549
}
550+
551+
#[test]
552+
fn parse_token_request_rejects_unknown_path() {
553+
let err = parse_token_request(
554+
"GET /v1/microsoft-agent-s2s/debug HTTP/1.1\r\n\r\n",
555+
Some("api://default"),
556+
"/v1/microsoft-agent-s2s/token/test",
557+
)
558+
.expect_err("unknown path should fail");
559+
560+
assert_eq!(err.status, 404);
561+
assert_eq!(err.message, "token endpoint not found");
562+
}
563+
564+
#[test]
565+
fn parse_token_request_rejects_unsupported_method() {
566+
let err = parse_token_request(
567+
"DELETE /v1/microsoft-agent-s2s/token/test HTTP/1.1\r\n\r\n",
568+
Some("api://default"),
569+
"/v1/microsoft-agent-s2s/token/test",
570+
)
571+
.expect_err("unsupported method should fail");
572+
573+
assert_eq!(err.status, 405);
574+
assert_eq!(err.message, "method not allowed");
575+
}
550576
}

crates/openshell-server/src/grpc/policy.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3598,6 +3598,40 @@ mod tests {
35983598
assert!(err.message().contains("microsoft-agent-s2s"));
35993599
}
36003600

3601+
#[tokio::test]
3602+
async fn mint_sandbox_provider_token_rejects_unallowed_audience() {
3603+
let state = test_server_state().await;
3604+
state
3605+
.store
3606+
.put_message(&test_microsoft_provider("work-microsoft"))
3607+
.await
3608+
.unwrap();
3609+
state
3610+
.store
3611+
.put_message(&test_sandbox(
3612+
"sb-microsoft",
3613+
"microsoft",
3614+
test_policy_with_rule("sandbox_only", "sandbox.example.com"),
3615+
vec!["work-microsoft".to_string()],
3616+
))
3617+
.await
3618+
.unwrap();
3619+
3620+
let err = handle_mint_sandbox_provider_token(
3621+
&state,
3622+
Request::new(MintSandboxProviderTokenRequest {
3623+
sandbox_id: "sb-microsoft".to_string(),
3624+
provider_name: "work-microsoft".to_string(),
3625+
audience: "api://not-allowed".to_string(),
3626+
}),
3627+
)
3628+
.await
3629+
.unwrap_err();
3630+
3631+
assert_eq!(err.code(), Code::FailedPrecondition);
3632+
assert!(err.message().contains("not allowed"));
3633+
}
3634+
36013635
#[tokio::test]
36023636
async fn provider_env_revision_changes_when_attached_provider_record_changes() {
36033637
use openshell_core::proto::GetSandboxProviderEnvironmentRequest;

0 commit comments

Comments
 (0)