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

            Line data    Source code
       1              : use utils::auth::{AuthError, Claims, Scope};
       2              : use utils::id::TenantId;
       3              : 
       4          190 : pub fn check_permission(claims: &Claims, tenant_id: Option<TenantId>) -> Result<(), AuthError> {
       5          190 :     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          149 :         (Scope::Tenant, Some(tenant_id)) => {
      10          149 :             if claims.tenant_id.unwrap() != tenant_id {
      11            5 :                 return Err(AuthError("Tenant id mismatch. Permission denied".into()));
      12          144 :             }
      13          144 :             Ok(())
      14              :         }
      15            1 :         (Scope::PageServerApi, _) => Err(AuthError(
      16            1 :             "PageServerApi scope makes no sense for Safekeeper".into(),
      17            1 :         )),
      18           40 :         (Scope::SafekeeperData, _) => Ok(()),
      19              :     }
      20          190 : }
        

Generated by: LCOV version 2.1-beta