use axum::http::StatusCode; use http_body_util::BodyExt; use serde_json::Value; mod common; /// Needs a live MariaDB connection (SQL_URI, see src/db.rs) and a live /// gn-auth (AUTH_SERVER_URL) plus GN4_TEST_AUTH_TOKEN (see /// docs/gn-auth.md); skips rather than fails when either is missing, /// same as dataset_probeset_info.rs. Dataset Br_U_0803_M's CreateTime /// is 2003-08-01, so it's publicly readable regardless of its /// public/confidentiality flags (see src/auth.rs) -- a valid token is /// still required, but no gn-auth authorization call happens. #[tokio::test] async fn dataset_probeset_values_returns_strain_values() { if !common::db_available() { eprintln!( "skipping dataset_probeset_values_returns_strain_values: no usable database (check SQL_URI credentials)" ); return; } let Some(token) = common::auth_token().await else { eprintln!( "skipping dataset_probeset_values_returns_strain_values: set GN4_TEST_AUTH_TOKEN (see docs/gn-auth.md)" ); return; }; if !common::auth_server_available() { eprintln!("skipping dataset_probeset_values_returns_strain_values: no gn-auth reachable"); return; } let response = common::get_with_token( "GET /datasets/Br_U_0803_M/probesets/100001_at/values", "/datasets/Br_U_0803_M/probesets/100001_at/values", &token, ) .await; assert_eq!(response.status(), StatusCode::OK); let body = response.into_body().collect().await.unwrap().to_bytes(); let values: Vec = common::data(&body); assert!(!values.is_empty()); let bxd1 = values .iter() .find(|v| v["name"] == "BXD1") .expect("BXD1 in /datasets/Br_U_0803_M/probesets/100001_at/values"); assert!(bxd1["value"].as_f64().is_some()); } #[tokio::test] async fn dataset_probeset_values_without_a_token_returns_401() { if !common::db_available() { eprintln!( "skipping dataset_probeset_values_without_a_token_returns_401: no usable database (check SQL_URI credentials)" ); return; } let response = common::get( "GET /datasets/Br_U_0803_M/probesets/100001_at/values (no token)", "/datasets/Br_U_0803_M/probesets/100001_at/values", ) .await; assert_eq!(response.status(), StatusCode::UNAUTHORIZED); } #[tokio::test] async fn dataset_probeset_values_unknown_dataset_returns_404() { if !common::db_available() { eprintln!( "skipping dataset_probeset_values_unknown_dataset_returns_404: no usable database (check SQL_URI credentials)" ); return; } let Some(token) = common::auth_token().await else { eprintln!( "skipping dataset_probeset_values_unknown_dataset_returns_404: set GN4_TEST_AUTH_TOKEN (see docs/gn-auth.md)" ); return; }; if !common::auth_server_available() { eprintln!( "skipping dataset_probeset_values_unknown_dataset_returns_404: no gn-auth reachable" ); return; } let response = common::get_with_token( "GET /datasets/not-a-real-dataset/probesets/100001_at/values", "/datasets/not-a-real-dataset/probesets/100001_at/values", &token, ) .await; assert_eq!(response.status(), StatusCode::NOT_FOUND); let body = response.into_body().collect().await.unwrap().to_bytes(); let error: Value = serde_json::from_slice(&body).unwrap(); assert_eq!(error["status"], 404); assert_eq!(error["code"], "dataset_not_found"); assert_eq!(error["operation_id"], "dataset_probeset_values"); } #[tokio::test] async fn dataset_probeset_values_unknown_probeset_in_dataset_returns_404() { if !common::db_available() { eprintln!( "skipping dataset_probeset_values_unknown_probeset_in_dataset_returns_404: no usable database (check SQL_URI credentials)" ); return; } let Some(token) = common::auth_token().await else { eprintln!( "skipping dataset_probeset_values_unknown_probeset_in_dataset_returns_404: set GN4_TEST_AUTH_TOKEN (see docs/gn-auth.md)" ); return; }; if !common::auth_server_available() { eprintln!( "skipping dataset_probeset_values_unknown_probeset_in_dataset_returns_404: no gn-auth reachable" ); return; } let response = common::get_with_token( "GET /datasets/Br_U_0803_M/probesets/not-a-real-probeset/values", "/datasets/Br_U_0803_M/probesets/not-a-real-probeset/values", &token, ) .await; assert_eq!(response.status(), StatusCode::NOT_FOUND); let body = response.into_body().collect().await.unwrap().to_bytes(); let error: Value = serde_json::from_slice(&body).unwrap(); assert_eq!(error["status"], 404); assert_eq!(error["code"], "probeset_not_found"); assert_eq!(error["operation_id"], "dataset_probeset_values"); } /// UTHSC_BXD_Cochlea_0225 (public=1, confidentiality=1, created /// 2025-02-13) is neither publicly readable by the flags /// (confidentiality >= 1) nor old enough for the embargo-age rule, and /// has never been linked to a gn-auth resource -- so even the token's /// owner has no privilege on it, and the request must be denied rather /// than silently allowed. #[tokio::test] async fn dataset_probeset_values_non_public_unlinked_dataset_returns_403() { if !common::db_available() { eprintln!( "skipping dataset_probeset_values_non_public_unlinked_dataset_returns_403: no usable database (check SQL_URI credentials)" ); return; } let Some(token) = common::auth_token().await else { eprintln!( "skipping dataset_probeset_values_non_public_unlinked_dataset_returns_403: set GN4_TEST_AUTH_TOKEN (see docs/gn-auth.md)" ); return; }; if !common::auth_server_available() { eprintln!( "skipping dataset_probeset_values_non_public_unlinked_dataset_returns_403: no gn-auth reachable" ); return; } let response = common::get_with_token( "GET /datasets/UTHSC_BXD_Cochlea_0225/probesets/ENSMUSG00000028180/values", "/datasets/UTHSC_BXD_Cochlea_0225/probesets/ENSMUSG00000028180/values", &token, ) .await; assert_eq!(response.status(), StatusCode::FORBIDDEN); let body = response.into_body().collect().await.unwrap().to_bytes(); let error: Value = serde_json::from_slice(&body).unwrap(); assert_eq!(error["code"], "forbidden"); } /// Same as above, but with a dataset genuinely less than a year old /// (UTHSC_BXD_Cochlea_0225 above is real but was already ~20 months /// old by the time this test was written) -- the age-embargo rule and /// the "not yet linked to any gn-auth resource" deny path both need to /// hold for freshly-added data, not just for something that merely /// hasn't aged into public yet. UTHSC_BXD_2wk_Cochlea_0926 /// (public=1, confidentiality=1, created 2026-09-01) is the most /// recently added ProbeSetFreeze in the database as of this writing. #[tokio::test] async fn dataset_probeset_values_recent_non_public_dataset_returns_403() { if !common::db_available() { eprintln!( "skipping dataset_probeset_values_recent_non_public_dataset_returns_403: no usable database (check SQL_URI credentials)" ); return; } let Some(token) = common::auth_token().await else { eprintln!( "skipping dataset_probeset_values_recent_non_public_dataset_returns_403: set GN4_TEST_AUTH_TOKEN (see docs/gn-auth.md)" ); return; }; if !common::auth_server_available() { eprintln!( "skipping dataset_probeset_values_recent_non_public_dataset_returns_403: no gn-auth reachable" ); return; } let response = common::get_with_token( "GET /datasets/UTHSC_BXD_2wk_Cochlea_0926/probesets/ENSMUSG00000028180/values", "/datasets/UTHSC_BXD_2wk_Cochlea_0926/probesets/ENSMUSG00000028180/values", &token, ) .await; assert_eq!(response.status(), StatusCode::FORBIDDEN); let body = response.into_body().collect().await.unwrap().to_bytes(); let error: Value = serde_json::from_slice(&body).unwrap(); assert_eq!(error["code"], "forbidden"); }