Skip to content

Commit

Permalink
feat: improved usage commands permission
Browse files Browse the repository at this point in the history
  • Loading branch information
paulobressan committed Oct 23, 2024
1 parent c85a8f4 commit 2c59be7
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/domain/usage/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::domain::{
auth::{assert_permission, Credential},
error::Error,
metadata::MetadataDriven,
project::cache::ProjectDrivenCache,
project::{cache::ProjectDrivenCache, ProjectUserRole},
Result, PAGE_SIZE_DEFAULT, PAGE_SIZE_MAX,
};

Expand All @@ -20,7 +20,7 @@ pub async fn fetch_report(
project_cache.clone(),
&cmd.credential,
&cmd.project_id,
None,
Some(ProjectUserRole::Owner),
)
.await?;

Expand Down Expand Up @@ -157,4 +157,33 @@ mod tests {
.await;
assert!(result.is_err());
}
#[tokio::test]
async fn it_should_fail_update_project_when_invalid_permission_member() {
let mut project_cache = MockProjectDrivenCache::new();
project_cache
.expect_find_user_permission()
.return_once(|_, _| {
Ok(Some(ProjectUser {
role: ProjectUserRole::Member,
..Default::default()
}))
});

let usage_cache = MockUsageDrivenCache::new();

let metadata = MockMetadataDriven::new();

let cmd = FetchCmd::default();

let result = fetch_report(
Arc::new(project_cache),
Arc::new(usage_cache),
Arc::new(metadata),
cmd,
)
.await;

assert!(result.is_err());
assert!(matches!(result, Err(Error::Unauthorized(_))));
}
}

0 comments on commit 2c59be7

Please sign in to comment.