Files
NLnetLabs-krill/tests/auth_check.rs
Martin HoffmannandGitHub 4acdd84ab9 Refactoring and reorganizing. (#1258)
This PR refactors and reorganizes a lot of code. It attempts to organize
things in a way that allows to keep more things private. Conversely, it
made the fields of many data-only structs pub and removed the creator,
accessor, and unpack methods for those.

The PR deliberately avoid any functional code changes given that due to
its sheer size, it is essentially unreviewable.

This is also why it stopped short of re-organizing the structure of the
actual server, ie., the Krillserver and the daemon::http module which
currently have a rather blurry distinction. A follow-up PR will create a
more clear separation but this requires code changes.
2025-03-21 15:20:36 +01:00

33 lines
870 B
Rust

//! Rust integration test to verify that invoking the restricted create CA
//! REST API requires a valid bearer token.
use hyper::StatusCode;
use krill::commons::httpclient;
mod common;
#[tokio::test]
async fn auth_check() {
let (server, _tempdir) = common::KrillServer::start().await;
// Get a client and change its auth token.
let mut client = server.client().clone();
client.set_token("wrong secret".into());
// Now try and create a CA. This should fail with a “Forbidden” error.
let res = client.ca_add(common::ca_handle("dummy_ca")).await;
dbg!(&res);
assert!(
matches!(
res,
Err(
httpclient::Error::ErrorResponseWithJson(
_, StatusCode::UNAUTHORIZED, _
)
| httpclient::Error::Forbidden(_)
)
)
);
}