Files
NLnetLabs-krill/tests/auth_check.rs
T
Ximon EighteenandGitHub 248807ebc7 Fix master token access restrictions when not using the multi-user feature. (#415)
* Add a test that should (but doesn't in non-multi-user mode) panic because it tries to create a CA using the wrong master token.

* cargo fmt

* Add some comments explaining what the test does and how it works.

* FIX: Don't permit anonymous users to perform restricted actions in non-multi-user mode (this regression was introduced in the v0.8.1-bis branch, it was never released).
2021-02-10 11:21:30 +01:00

31 lines
1.2 KiB
Rust

//! Rust integration test to verify that invoking the restricted create CA REST API requires a valid bearer token.
use std::str::FromStr;
use krill::{
commons::api::{Handle, Token},
test::{init_ca, start_krill, test_config, tmp_dir},
};
extern crate krill;
#[tokio::test]
#[should_panic]
async fn auth_check() {
// Use a copy of the default test Krill config but change the server master token thereby hopefully causing the
// bearer token sent by the test suite support functions not to match and thus be rejected which in turn should
// cause a Rust panic.
let dir = tmp_dir();
let mut config = test_config(&dir);
config.auth_token = Token::from("wrong secret");
// Start Krill with the customized config
start_krill(Some(config), false).await;
// Try and create a CA. The test suite support function `init_ca()` will invoke the create CA REST API passing the
// bearer token that is hard-coded into the test support suite functions ('secret').
let ca_handle = Handle::from_str("dummy_ca").unwrap();
init_ca(&ca_handle).await;
// A Rust panic should have occured. If not, this test will fail due to the use of the #[should_panic] attribute.
}