LCOV - code coverage report
Current view: top level - safekeeper/src - auth.rs (source / functions) Coverage Total Hit
Test: 2b0730d767f560e20b6748f57465922aa8bb805e.info Lines: 0.0 % 19 0
Test Date: 2024-09-25 14:04:07 Functions: 0.0 % 1 0

            Line data    Source code
       1              : use utils::auth::{AuthError, Claims, Scope};
       2              : use utils::id::TenantId;
       3              : 
       4              : /// If tenant_id is provided, allow if token (claims) is for this tenant or
       5              : /// whole safekeeper scope (SafekeeperData). Else, allow only if token is
       6              : /// SafekeeperData.
       7            0 : pub fn check_permission(claims: &Claims, tenant_id: Option<TenantId>) -> Result<(), AuthError> {
       8            0 :     match (&claims.scope, tenant_id) {
       9            0 :         (Scope::Tenant, None) => Err(AuthError(
      10            0 :             "Attempt to access management api with tenant scope. Permission denied".into(),
      11            0 :         )),
      12            0 :         (Scope::Tenant, Some(tenant_id)) => {
      13            0 :             if claims.tenant_id.unwrap() != tenant_id {
      14            0 :                 return Err(AuthError("Tenant id mismatch. Permission denied".into()));
      15            0 :             }
      16            0 :             Ok(())
      17              :         }
      18              :         (Scope::Admin | Scope::PageServerApi | Scope::GenerationsApi | Scope::Scrubber, _) => {
      19            0 :             Err(AuthError(
      20            0 :                 format!(
      21            0 :                     "JWT scope '{:?}' is ineligible for Safekeeper auth",
      22            0 :                     claims.scope
      23            0 :                 )
      24            0 :                 .into(),
      25            0 :             ))
      26              :         }
      27            0 :         (Scope::SafekeeperData, _) => Ok(()),
      28              :     }
      29            0 : }
        

Generated by: LCOV version 2.1-beta