Skip to content

Commit

Permalink
tests: add negative test for resources
Browse files Browse the repository at this point in the history
Add another test to make sure the KBS won't return resources when the
DenyAll policy is set.

Signed-off-by: Tobin Feldman-Fitzthum <tobin@ibm.com>
  • Loading branch information
fitzthum committed Jan 21, 2025
1 parent 41c84bc commit cfeb40c
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions integration-tests/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,14 @@ const ALLOW_ALL_POLICY: &str = "
allow = true
";

/*
const DENY_ALL_POLICY: &str = "
package policy
allow = false
";
*/

enum PolicyType {
AllowAll,
//DenyAll,
DenyAll,
//Custom(String),
}

Expand Down Expand Up @@ -135,7 +133,7 @@ impl TestHarness {

let policy_bytes = match policy {
PolicyType::AllowAll => ALLOW_ALL_POLICY.as_bytes().to_vec(),
//PolicyType::DenyAll => DENY_ALL_POLICY.as_bytes().to_vec(),
PolicyType::DenyAll => DENY_ALL_POLICY.as_bytes().to_vec(),
//PolicyType::Custom(p) => p.into_bytes(),
};

Expand Down Expand Up @@ -210,3 +208,35 @@ async fn get_secret_allow_all(#[case] test_parameters: TestParameters) -> Result

Ok(())
}

#[rstest]
#[case::ear_deny_all(TestParameters{attestation_token_type: "Ear".to_string() })]
#[case::simple_deny_all(TestParameters{attestation_token_type: "Simple".to_string() })]
#[serial]
#[actix_rt::test]
async fn get_secret_deny_all(#[case] test_parameters: TestParameters) -> Result<()> {
let _ = env_logger::try_init_from_env(env_logger::Env::new().default_filter_or("debug"));
let harness = TestHarness::new(test_parameters)?;

let api_server = ApiServer::new(harness.kbs_config.clone()).await?;

let kbs_server = api_server.server()?;
let kbs_handle = kbs_server.handle();

actix_web::rt::spawn(kbs_server);

harness.wait().await;
harness.set_secret(SECRET_PATH.to_string(), SECRET_BYTES.as_ref().to_vec())
.await?;
harness.set_policy(PolicyType::DenyAll).await?;

let secret = harness.get_secret(SECRET_PATH.to_string()).await;

assert!(secret.is_err());
assert_eq!(secret.unwrap_err().to_string(), "request unauthorized".to_string());
info!("TEST: test completed succesfully");

kbs_handle.stop(true).await;

Ok(())
}

0 comments on commit cfeb40c

Please sign in to comment.