mirror of
https://github.com/kanidm/kanidm.git
synced 2025-02-23 12:37:00 +01:00
Fixing test release (#1983)
* Fixing cargo test --release * more tracing less dbg
This commit is contained in:
parent
83f189fed3
commit
9a6168b67d
|
@ -530,7 +530,7 @@ impl KanidmClient {
|
||||||
warn!(server_version = ?ver, client_version = ?EXPECT_VERSION, "Mismatched client and server version - features may not work, or other unforeseen errors may occur.")
|
warn!(server_version = ?ver, client_version = ?EXPECT_VERSION, "Mismatched client and server version - features may not work, or other unforeseen errors may occur.")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(any(test, debug_assertions))]
|
||||||
if !matching {
|
if !matching {
|
||||||
error!("You're in debug/dev mode, so we're going to quit here.");
|
error!("You're in debug/dev mode, so we're going to quit here.");
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
|
|
|
@ -275,7 +275,7 @@ impl Configuration {
|
||||||
|
|
||||||
// Startup config action, used in kanidmd server etc
|
// Startup config action, used in kanidmd server etc
|
||||||
pub fn update_config_for_server_mode(&mut self, sconfig: &ServerConfig) {
|
pub fn update_config_for_server_mode(&mut self, sconfig: &ServerConfig) {
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(any(test, debug_assertions))]
|
||||||
debug!("update_config_for_server_mode {:?}", sconfig);
|
debug!("update_config_for_server_mode {:?}", sconfig);
|
||||||
self.update_tls(&sconfig.tls_chain, &sconfig.tls_key);
|
self.update_tls(&sconfig.tls_chain, &sconfig.tls_key);
|
||||||
self.update_bind(&sconfig.bindaddress);
|
self.update_bind(&sconfig.bindaddress);
|
||||||
|
|
|
@ -5,8 +5,6 @@ use axum::{
|
||||||
response::Response,
|
response::Response,
|
||||||
TypedHeader,
|
TypedHeader,
|
||||||
};
|
};
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
use http::header::CONTENT_TYPE;
|
|
||||||
use http::HeaderValue;
|
use http::HeaderValue;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
@ -34,21 +32,7 @@ pub struct KOpId {
|
||||||
pub uat: Option<String>,
|
pub uat: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ensure the status code is 200..=299
|
#[cfg(any(test, debug_assertions))]
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
fn from_200_to_299(status: http::StatusCode) -> bool {
|
|
||||||
status.as_u16() >= 200 && status.as_u16() <= 299
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_from_200_to_299() {
|
|
||||||
assert!(from_200_to_299(http::StatusCode::OK));
|
|
||||||
assert!(from_200_to_299(http::StatusCode::IM_USED));
|
|
||||||
assert!(!from_200_to_299(http::StatusCode::BAD_REQUEST));
|
|
||||||
assert!(!from_200_to_299(http::StatusCode::INTERNAL_SERVER_ERROR));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
/// This is a debug middleware to ensure that /v1/ endpoints only return JSON
|
/// This is a debug middleware to ensure that /v1/ endpoints only return JSON
|
||||||
#[instrument(name = "are_we_json_yet", skip_all)]
|
#[instrument(name = "are_we_json_yet", skip_all)]
|
||||||
pub async fn are_we_json_yet<B>(request: Request<B>, next: Next<B>) -> Response {
|
pub async fn are_we_json_yet<B>(request: Request<B>, next: Next<B>) -> Response {
|
||||||
|
@ -56,12 +40,11 @@ pub async fn are_we_json_yet<B>(request: Request<B>, next: Next<B>) -> Response
|
||||||
|
|
||||||
let response = next.run(request).await;
|
let response = next.run(request).await;
|
||||||
|
|
||||||
if uri.starts_with("/v1") && from_200_to_299(response.status()) {
|
if uri.starts_with("/v1") && response.status().is_success() {
|
||||||
let headers = response.headers();
|
let headers = response.headers();
|
||||||
assert!(headers.contains_key(CONTENT_TYPE));
|
assert!(headers.contains_key(http::header::CONTENT_TYPE));
|
||||||
dbg!(headers.get(CONTENT_TYPE));
|
|
||||||
assert!(
|
assert!(
|
||||||
headers.get(CONTENT_TYPE)
|
headers.get(http::header::CONTENT_TYPE)
|
||||||
== Some(&HeaderValue::from_static(crate::https::APPLICATION_JSON))
|
== Some(&HeaderValue::from_static(crate::https::APPLICATION_JSON))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -255,7 +255,8 @@ pub async fn create_https_server(
|
||||||
));
|
));
|
||||||
|
|
||||||
// layer which checks the responses have a content-type of JSON when we're in debug mode
|
// layer which checks the responses have a content-type of JSON when we're in debug mode
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
|
#[cfg(any(test, debug_assertions))]
|
||||||
let app = app.layer(from_fn(middleware::are_we_json_yet));
|
let app = app.layer(from_fn(middleware::are_we_json_yet));
|
||||||
|
|
||||||
let app = app
|
let app = app
|
||||||
|
|
|
@ -168,7 +168,7 @@ mod tests {
|
||||||
let c = e
|
let c = e
|
||||||
.get_ava_set("name_history")
|
.get_ava_set("name_history")
|
||||||
.expect("failed to get primary cred.");
|
.expect("failed to get primary cred.");
|
||||||
dbg!(c.clone());
|
trace!("{:?}", c.clone());
|
||||||
assert!(
|
assert!(
|
||||||
c.contains(&PartialValue::new_utf8s("old_name"))
|
c.contains(&PartialValue::new_utf8s("old_name"))
|
||||||
&& c.contains(&PartialValue::new_utf8s("new_name_1"))
|
&& c.contains(&PartialValue::new_utf8s("new_name_1"))
|
||||||
|
@ -202,7 +202,7 @@ mod tests {
|
||||||
let e = qs
|
let e = qs
|
||||||
.internal_search_uuid(uuid!("d2b496bd-8493-47b7-8142-f568b5cf47e1"))
|
.internal_search_uuid(uuid!("d2b496bd-8493-47b7-8142-f568b5cf47e1"))
|
||||||
.expect("failed to get entry");
|
.expect("failed to get entry");
|
||||||
dbg!(e.get_ava());
|
trace!("{:?}", e.get_ava());
|
||||||
let name_history = e
|
let name_history = e
|
||||||
.get_ava_set("name_history")
|
.get_ava_set("name_history")
|
||||||
.expect("failed to get name_history ava");
|
.expect("failed to get name_history ava");
|
||||||
|
@ -253,7 +253,7 @@ mod tests {
|
||||||
let e = qs
|
let e = qs
|
||||||
.internal_search_uuid(uuid!("d2b496bd-8493-47b7-8142-f568b5cf47ee"))
|
.internal_search_uuid(uuid!("d2b496bd-8493-47b7-8142-f568b5cf47ee"))
|
||||||
.expect("failed to get entry");
|
.expect("failed to get entry");
|
||||||
dbg!(e.get_ava());
|
trace!("{:?}", e.get_ava());
|
||||||
let c = e
|
let c = e
|
||||||
.get_ava_set("name_history")
|
.get_ava_set("name_history")
|
||||||
.expect("failed to get name_history ava :/");
|
.expect("failed to get name_history ava :/");
|
||||||
|
|
|
@ -1115,7 +1115,7 @@ impl QueryServer {
|
||||||
pub async fn write(&self, curtime: Duration) -> QueryServerWriteTransaction<'_> {
|
pub async fn write(&self, curtime: Duration) -> QueryServerWriteTransaction<'_> {
|
||||||
// Guarantee we are the only writer on the thread pool
|
// Guarantee we are the only writer on the thread pool
|
||||||
#[allow(clippy::expect_used)]
|
#[allow(clippy::expect_used)]
|
||||||
let write_ticket = if cfg!(debug_assertions) {
|
let write_ticket = if cfg!(test) {
|
||||||
self.write_ticket
|
self.write_ticket
|
||||||
.try_acquire()
|
.try_acquire()
|
||||||
.expect("unable to acquire writer_ticket for qsw")
|
.expect("unable to acquire writer_ticket for qsw")
|
||||||
|
|
|
@ -313,7 +313,7 @@ impl<'a> QueryServerWriteTransaction<'a> {
|
||||||
|
|
||||||
let norm_cand: Vec<Entry<_, _>> = res?;
|
let norm_cand: Vec<Entry<_, _>> = res?;
|
||||||
|
|
||||||
if cfg!(debug_assertions) {
|
if cfg!(debug_assertions) || cfg!(test) {
|
||||||
pre_candidates
|
pre_candidates
|
||||||
.iter()
|
.iter()
|
||||||
.zip(norm_cand.iter())
|
.zip(norm_cand.iter())
|
||||||
|
|
|
@ -327,7 +327,7 @@ async fn test_oauth2_openid_basic_flow(rsclient: KanidmClient) {
|
||||||
.expect("Failed to send token introspect request.");
|
.expect("Failed to send token introspect request.");
|
||||||
|
|
||||||
assert!(response.status() == reqwest::StatusCode::OK);
|
assert!(response.status() == reqwest::StatusCode::OK);
|
||||||
dbg!(response.headers());
|
tracing::trace!("{:?}", response.headers());
|
||||||
assert!(
|
assert!(
|
||||||
response.headers().get(CONTENT_TYPE) == Some(&HeaderValue::from_static(APPLICATION_JSON))
|
response.headers().get(CONTENT_TYPE) == Some(&HeaderValue::from_static(APPLICATION_JSON))
|
||||||
);
|
);
|
||||||
|
@ -373,7 +373,7 @@ async fn test_oauth2_openid_basic_flow(rsclient: KanidmClient) {
|
||||||
.await
|
.await
|
||||||
.expect("Failed to send userinfo request.");
|
.expect("Failed to send userinfo request.");
|
||||||
|
|
||||||
dbg!(response.headers());
|
tracing::trace!("{:?}", response.headers());
|
||||||
assert!(
|
assert!(
|
||||||
response.headers().get(CONTENT_TYPE) == Some(&HeaderValue::from_static(APPLICATION_JSON))
|
response.headers().get(CONTENT_TYPE) == Some(&HeaderValue::from_static(APPLICATION_JSON))
|
||||||
);
|
);
|
||||||
|
|
|
@ -647,7 +647,7 @@ async fn test_server_rest_posix_auth_lifecycle(rsclient: KanidmClient) {
|
||||||
bad_json,
|
bad_json,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
dbg!(&res);
|
tracing::trace!("{:?}", &res);
|
||||||
assert!(res.is_err());
|
assert!(res.is_err());
|
||||||
|
|
||||||
// test sending a faulty JSON blob to the person unix update endpoint
|
// test sending a faulty JSON blob to the person unix update endpoint
|
||||||
|
@ -661,7 +661,7 @@ async fn test_server_rest_posix_auth_lifecycle(rsclient: KanidmClient) {
|
||||||
bad_json,
|
bad_json,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
dbg!(&res);
|
tracing::trace!("{:?}", &res);
|
||||||
assert!(res.is_err());
|
assert!(res.is_err());
|
||||||
|
|
||||||
// attempt to verify (good, anon-conn)
|
// attempt to verify (good, anon-conn)
|
||||||
|
|
|
@ -18,7 +18,7 @@ use kanidm_unix_common::unix_config::TpmPolicy;
|
||||||
use kanidmd_core::config::{Configuration, IntegrationTestConfig, ServerRole};
|
use kanidmd_core::config::{Configuration, IntegrationTestConfig, ServerRole};
|
||||||
use kanidmd_core::create_server_core;
|
use kanidmd_core::create_server_core;
|
||||||
use tokio::task;
|
use tokio::task;
|
||||||
use tracing::log::debug;
|
use tracing::log::{debug, trace};
|
||||||
|
|
||||||
static PORT_ALLOC: AtomicU16 = AtomicU16::new(28080);
|
static PORT_ALLOC: AtomicU16 = AtomicU16::new(28080);
|
||||||
const ADMIN_TEST_USER: &str = "admin";
|
const ADMIN_TEST_USER: &str = "admin";
|
||||||
|
@ -137,7 +137,7 @@ async fn test_fixture(rsclient: KanidmClient) {
|
||||||
.auth_simple_password("admin", ADMIN_TEST_PASSWORD)
|
.auth_simple_password("admin", ADMIN_TEST_PASSWORD)
|
||||||
.await;
|
.await;
|
||||||
debug!("auth_simple_password res: {:?}", res);
|
debug!("auth_simple_password res: {:?}", res);
|
||||||
dbg!(&res);
|
trace!("{:?}", &res);
|
||||||
assert!(res.is_ok());
|
assert!(res.is_ok());
|
||||||
// Not recommended in production!
|
// Not recommended in production!
|
||||||
rsclient
|
rsclient
|
||||||
|
|
Loading…
Reference in a new issue