Fixing test release (#1983)

* Fixing cargo test --release

* more tracing less dbg
This commit is contained in:
James Hodgkinson 2023-08-15 15:42:15 +10:00 committed by GitHub
parent 83f189fed3
commit 9a6168b67d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 19 additions and 35 deletions

View file

@ -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.")
}
#[cfg(debug_assertions)]
#[cfg(any(test, debug_assertions))]
if !matching {
error!("You're in debug/dev mode, so we're going to quit here.");
std::process::exit(1);

View file

@ -275,7 +275,7 @@ impl Configuration {
// Startup config action, used in kanidmd server etc
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);
self.update_tls(&sconfig.tls_chain, &sconfig.tls_key);
self.update_bind(&sconfig.bindaddress);

View file

@ -5,8 +5,6 @@ use axum::{
response::Response,
TypedHeader,
};
#[cfg(debug_assertions)]
use http::header::CONTENT_TYPE;
use http::HeaderValue;
use uuid::Uuid;
@ -34,21 +32,7 @@ pub struct KOpId {
pub uat: Option<String>,
}
/// Ensure the status code is 200..=299
#[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)]
#[cfg(any(test, debug_assertions))]
/// This is a debug middleware to ensure that /v1/ endpoints only return JSON
#[instrument(name = "are_we_json_yet", skip_all)]
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;
if uri.starts_with("/v1") && from_200_to_299(response.status()) {
if uri.starts_with("/v1") && response.status().is_success() {
let headers = response.headers();
assert!(headers.contains_key(CONTENT_TYPE));
dbg!(headers.get(CONTENT_TYPE));
assert!(headers.contains_key(http::header::CONTENT_TYPE));
assert!(
headers.get(CONTENT_TYPE)
headers.get(http::header::CONTENT_TYPE)
== Some(&HeaderValue::from_static(crate::https::APPLICATION_JSON))
);
}

View file

@ -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
#[cfg(debug_assertions)]
#[cfg(any(test, debug_assertions))]
let app = app.layer(from_fn(middleware::are_we_json_yet));
let app = app

View file

@ -168,7 +168,7 @@ mod tests {
let c = e
.get_ava_set("name_history")
.expect("failed to get primary cred.");
dbg!(c.clone());
trace!("{:?}", c.clone());
assert!(
c.contains(&PartialValue::new_utf8s("old_name"))
&& c.contains(&PartialValue::new_utf8s("new_name_1"))
@ -202,7 +202,7 @@ mod tests {
let e = qs
.internal_search_uuid(uuid!("d2b496bd-8493-47b7-8142-f568b5cf47e1"))
.expect("failed to get entry");
dbg!(e.get_ava());
trace!("{:?}", e.get_ava());
let name_history = e
.get_ava_set("name_history")
.expect("failed to get name_history ava");
@ -253,7 +253,7 @@ mod tests {
let e = qs
.internal_search_uuid(uuid!("d2b496bd-8493-47b7-8142-f568b5cf47ee"))
.expect("failed to get entry");
dbg!(e.get_ava());
trace!("{:?}", e.get_ava());
let c = e
.get_ava_set("name_history")
.expect("failed to get name_history ava :/");

View file

@ -1115,7 +1115,7 @@ impl QueryServer {
pub async fn write(&self, curtime: Duration) -> QueryServerWriteTransaction<'_> {
// Guarantee we are the only writer on the thread pool
#[allow(clippy::expect_used)]
let write_ticket = if cfg!(debug_assertions) {
let write_ticket = if cfg!(test) {
self.write_ticket
.try_acquire()
.expect("unable to acquire writer_ticket for qsw")

View file

@ -313,7 +313,7 @@ impl<'a> QueryServerWriteTransaction<'a> {
let norm_cand: Vec<Entry<_, _>> = res?;
if cfg!(debug_assertions) {
if cfg!(debug_assertions) || cfg!(test) {
pre_candidates
.iter()
.zip(norm_cand.iter())

View file

@ -327,7 +327,7 @@ async fn test_oauth2_openid_basic_flow(rsclient: KanidmClient) {
.expect("Failed to send token introspect request.");
assert!(response.status() == reqwest::StatusCode::OK);
dbg!(response.headers());
tracing::trace!("{:?}", response.headers());
assert!(
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
.expect("Failed to send userinfo request.");
dbg!(response.headers());
tracing::trace!("{:?}", response.headers());
assert!(
response.headers().get(CONTENT_TYPE) == Some(&HeaderValue::from_static(APPLICATION_JSON))
);

View file

@ -647,7 +647,7 @@ async fn test_server_rest_posix_auth_lifecycle(rsclient: KanidmClient) {
bad_json,
)
.await;
dbg!(&res);
tracing::trace!("{:?}", &res);
assert!(res.is_err());
// 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,
)
.await;
dbg!(&res);
tracing::trace!("{:?}", &res);
assert!(res.is_err());
// attempt to verify (good, anon-conn)

View file

@ -18,7 +18,7 @@ use kanidm_unix_common::unix_config::TpmPolicy;
use kanidmd_core::config::{Configuration, IntegrationTestConfig, ServerRole};
use kanidmd_core::create_server_core;
use tokio::task;
use tracing::log::debug;
use tracing::log::{debug, trace};
static PORT_ALLOC: AtomicU16 = AtomicU16::new(28080);
const ADMIN_TEST_USER: &str = "admin";
@ -137,7 +137,7 @@ async fn test_fixture(rsclient: KanidmClient) {
.auth_simple_password("admin", ADMIN_TEST_PASSWORD)
.await;
debug!("auth_simple_password res: {:?}", res);
dbg!(&res);
trace!("{:?}", &res);
assert!(res.is_ok());
// Not recommended in production!
rsclient