Skip to content

Commit

Permalink
test with unprivileged user
Browse files Browse the repository at this point in the history
  • Loading branch information
david-crespo committed Nov 6, 2024
1 parent d05fe87 commit 02d0476
Showing 1 changed file with 45 additions and 4 deletions.
49 changes: 45 additions & 4 deletions nexus/tests/integration_tests/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@ use crate::integration_tests::instances::{
};
use chrono::Utc;
use dropshot::test_util::ClientTestContext;
use dropshot::ResultsPage;
use dropshot::{HttpErrorResponseBody, ResultsPage};
use http::{Method, StatusCode};
use nexus_auth::authn::USER_TEST_UNPRIVILEGED;
use nexus_db_queries::db::fixed_data::silo::DEFAULT_SILO;
use nexus_db_queries::db::identity::{Asset, Resource};
use nexus_test_utils::background::activate_background_task;
use nexus_test_utils::http_testing::{AuthnMode, NexusRequest, RequestBuilder};
use nexus_test_utils::resource_helpers::{
create_default_ip_pool, create_disk, create_instance, create_project,
object_create_error, objects_list_page_authz, DiskTest,
grant_iam, object_create_error, objects_list_page_authz, DiskTest,
};
use nexus_test_utils::ControlPlaneTestContext;
use nexus_test_utils_macros::nexus_test;
use nexus_types::external_api::shared::ProjectRole;
use nexus_types::external_api::views::OxqlQueryResult;
use nexus_types::silo::DEFAULT_SILO_ID;
use omicron_test_utils::dev::poll::{wait_for_condition, CondCheckError};
Expand Down Expand Up @@ -637,8 +641,45 @@ async fn test_project_timeseries_query(
object_create_error(client, url, &body, StatusCode::NOT_FOUND).await;
assert_eq!(result.message, "not found: project with name \"nonexistent\"");

// try a project in your silo that you can't read
// try a project in another silo
// unprivileged user gets 404 on project that exists, but which they can't read
let url = "/v1/timeseries/query/project/project1";
let body = nexus_types::external_api::params::TimeseriesQuery {
query: q1.to_string(),
};
let result = NexusRequest::new(
RequestBuilder::new(client, Method::POST, url)
.body(Some(&body))
.expect_status(Some(StatusCode::NOT_FOUND)),
)
.authn_as(AuthnMode::UnprivilegedUser)
.execute()
.await
.unwrap()
.parsed_body::<HttpErrorResponseBody>()
.unwrap();
assert_eq!(result.message, "not found: project with name \"project1\"");

// now grant the user access to that project only
grant_iam(
client,
"/v1/projects/project1",
ProjectRole::Viewer,
USER_TEST_UNPRIVILEGED.id(),
AuthnMode::PrivilegedUser,
)
.await;

let result = NexusRequest::new(
RequestBuilder::new(client, Method::POST, url)
.body(Some(&body))
.expect_status(Some(StatusCode::OK)),
)
.authn_as(AuthnMode::UnprivilegedUser)
.execute()
.await
.unwrap()
.parsed_body::<OxqlQueryResult>()
.unwrap();
}

#[nexus_test]
Expand Down

0 comments on commit 02d0476

Please sign in to comment.