LCOV - code coverage report
Current view: top level - safekeeper/src - auth.rs (source / functions) Coverage Total Hit
Test: 32f4a56327bc9da697706839ed4836b2a00a408f.info Lines: 80.0 % 15 12
Test Date: 2024-02-07 07:37:29 Functions: 100.0 % 1 1

            Line data    Source code
       1              : use utils::auth::{AuthError, Claims, Scope};
       2              : use utils::id::TenantId;
       3              : 
       4          173 : pub fn check_permission(claims: &Claims, tenant_id: Option<TenantId>) -> Result<(), AuthError> {
       5          173 :     match (&claims.scope, tenant_id) {
       6            0 :         (Scope::Tenant, None) => Err(AuthError(
       7            0 :             "Attempt to access management api with tenant scope. Permission denied".into(),
       8            0 :         )),
       9          130 :         (Scope::Tenant, Some(tenant_id)) => {
      10          130 :             if claims.tenant_id.unwrap() != tenant_id {
      11            5 :                 return Err(AuthError("Tenant id mismatch. Permission denied".into()));
      12          125 :             }
      13          125 :             Ok(())
      14              :         }
      15            1 :         (Scope::PageServerApi, _) => Err(AuthError(
      16            1 :             "PageServerApi scope makes no sense for Safekeeper".into(),
      17            1 :         )),
      18           42 :         (Scope::SafekeeperData, _) => Ok(()),
      19              :     }
      20          173 : }
        

Generated by: LCOV version 2.1-beta