From a2a91efaad09e71122e714fd4bb7151ad1c0cedf Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar Date: Tue, 1 Dec 2026 15:34:45 +0000 Subject: [PATCH] fix(branding): a workspace the registry refuses still reads its branding (#1102) --- compliance-agent/src/api/server.rs | 21 ++++++++ compliance-agent/tests/member_blocked.rs | 61 +++++++++++++++++++++++- 2 files changed, 81 insertions(+), 1 deletion(-) diff --git a/compliance-agent/src/api/server.rs b/compliance-agent/src/api/server.rs index 7d96aae..af2a8dc 100644 --- a/compliance-agent/src/api/server.rs +++ b/compliance-agent/src/api/server.rs @@ -125,6 +125,7 @@ pub async fn require_entitlement( // carry no tenant context here): the registry also says whether this // member is blocked in the tenant. let user = Some(ctx.user_id.as_str()).filter(|u| !u.is_empty()); + let open = open_when_not_entitled(&request); match registry.check_entitlement(&ctx.tenant_id, None, user).await { Ok(check) if check.allowed => { let mut ctx = ctx; @@ -137,6 +138,15 @@ pub async fn require_entitlement( request.extensions_mut().insert(ctx); next.run(request).await } + // The registry knows the workspace but refuses it (expired, blocked): + // its branding is still read, so the screen that says so keeps the + // workspace's frame and logo. Read-only, and nothing else. + Ok(_) if open => { + let mut ctx = ctx; + ctx.status = TenantStatus::Restricted; + request.extensions_mut().insert(ctx); + next.run(request).await + } Ok(check) if check.member_blocked() => ( StatusCode::FORBIDDEN, Json(serde_json::json!({ @@ -166,6 +176,17 @@ pub async fn require_entitlement( } } +/// The routes a workspace the registry refuses still reads: its branding +/// (#1087), so a lockout screen keeps its frame and logo. GET only; the +/// acknowledgement and everything else stay refused. +const OPEN_WHEN_NOT_ENTITLED: [&str; 2] = ["/api/v1/branding", "/api/v1/branding/logo"]; + +/// Whether `request` reads one of [`OPEN_WHEN_NOT_ENTITLED`]. +fn open_when_not_entitled(request: &Request) -> bool { + request.method() == axum::http::Method::GET + && OPEN_WHEN_NOT_ENTITLED.contains(&request.uri().path()) +} + /// 503 when the registry cannot answer: access is never widened on doubt. fn entitlement_unavailable() -> Response { ( diff --git a/compliance-agent/tests/member_blocked.rs b/compliance-agent/tests/member_blocked.rs index bbfc12b..2f4add6 100644 --- a/compliance-agent/tests/member_blocked.rs +++ b/compliance-agent/tests/member_blocked.rs @@ -34,9 +34,13 @@ async fn fake_registry(seen: Seen) -> String { "/v1/internal/entitlements/check", post(|State(seen): State, Json(body): Json| async move { let blocked = body["user_id"].as_str() == Some("u-blocked"); + let expired = body["user_id"].as_str() == Some("u-expired"); seen.lock().unwrap().push(body); Json(if blocked { serde_json::json!({ "allowed": false, "status": "active", "reason": "member_blocked" }) + } else if expired { + serde_json::json!({ "allowed": false, "status": "expired", "reason": "entitlement_expired", + "branding": { "color": "#0082c9" } }) } else { serde_json::json!({ "allowed": true, "status": "active" }) }) @@ -84,6 +88,17 @@ async fn agent(registry: &str) -> Option> { /// GET /r as `ctx` through the entitlement middleware. async fn call(agent: Arc, ctx: TenantContext) -> (StatusCode, serde_json::Value) { + call_at(agent, ctx, "GET", "/r").await +} + +/// `method` `path` as `ctx` through the entitlement middleware; every route +/// answers "ok". +async fn call_at( + agent: Arc, + ctx: TenantContext, + method: &str, + path: &str, +) -> (StatusCode, serde_json::Value) { let inject = move |mut req: Request, next: Next| { let ctx = ctx.clone(); async move { @@ -93,10 +108,19 @@ async fn call(agent: Arc, ctx: TenantContext) -> (StatusCode, s }; let app = Router::new() .route("/r", get(|| async { "ok" })) + .route("/api/v1/branding", get(|| async { "ok" })) + .route("/api/v1/branding/logo", get(|| async { "ok" })) + .route("/api/v1/branding/ack", post(|| async { "ok" })) .layer(from_fn_with_state(agent, require_entitlement)) .layer(from_fn(inject)); let resp = app - .oneshot(Request::builder().uri("/r").body(Body::empty()).unwrap()) + .oneshot( + Request::builder() + .method(method) + .uri(path) + .body(Body::empty()) + .unwrap(), + ) .await .unwrap(); let status = resp.status(); @@ -138,6 +162,41 @@ async fn a_blocked_member_is_refused_and_others_are_not() { assert_eq!(seen.lock().unwrap().len(), calls); } +#[tokio::test] +async fn a_refused_workspace_still_reads_its_branding_and_nothing_else() { + let seen: Seen = Arc::default(); + let base = fake_registry(seen).await; + let Some(agent) = agent(&base).await else { + return; + }; + // Its frame and logo, for the screen that says it is refused. + for path in ["/api/v1/branding", "/api/v1/branding/logo"] { + let (status, _) = call_at(agent.clone(), member("u-expired"), "GET", path).await; + assert_eq!(status, StatusCode::OK, "{path}"); + } + // Everything else, the acknowledgement included, stays refused. + let (status, body) = call(agent.clone(), member("u-expired")).await; + assert_eq!(status, StatusCode::FORBIDDEN); + assert_eq!(body["error"], "not_entitled"); + let (status, _) = call_at( + agent.clone(), + member("u-expired"), + "POST", + "/api/v1/branding/ack", + ) + .await; + assert_eq!(status, StatusCode::FORBIDDEN); + // A blocked member sees the frame too, and nothing else. + let (status, _) = call_at( + agent.clone(), + member("u-blocked"), + "GET", + "/api/v1/branding", + ) + .await; + assert_eq!(status, StatusCode::OK); +} + #[tokio::test] async fn an_unreachable_registry_still_refuses_as_before() { // Not a block decision: the entitlement check itself fails closed when