Files
khadhroony-solana-project/crates/ksp-store-lib/tests/feature_mismatch.rs
2026-08-29 19:33:43 +02:00

56 lines
2.3 KiB
Rust

// file: crates/ksp-store-lib/tests/feature_mismatch.rs
// version: 4
#![warn(missing_docs)]
#![deny(unreachable_pub)]
#![forbid(unsafe_code)]
//! Feature-selection and pre-I/O PostgreSQL failure canaries for the common Store facade.
fn poll_ready<T>(future: impl std::future::Future<Output = T>) -> T {
let mut future = std::boxed::Box::pin(future);
let waker = std::task::Waker::noop();
let mut context = std::task::Context::from_waker(waker);
return match std::future::Future::poll(future.as_mut(), &mut context) {
std::task::Poll::Ready(value) => value,
std::task::Poll::Pending => panic!("Store pre-I/O feature/config rejection unexpectedly became pending"),
};
}
fn valid_network() -> ksp_store_lib::RawNetworkId {
return match ksp_store_lib::RawNetworkId::new("devnet") {
std::result::Result::Ok(value) => value,
std::result::Result::Err(error) => panic!("valid test network rejected: {error:?}"),
};
}
fn settings(connection_uri: &str) -> ksp_store_lib::StoreSettings {
let postgres = ksp_store_lib::PostgresStoreSettings::new(
connection_uri,
ksp_store_lib::PostgresPoolSettings::default(),
ksp_store_lib::PostgresTlsMode::Disabled,
ksp_store_lib::PostgresBootstrapSettings::default(),
);
return ksp_store_lib::StoreSettings::with_default_shutdown(valid_network(), ksp_store_lib::StoreBackendSettings::Postgres(postgres));
}
#[cfg(not(feature = "postgres"))]
#[test]
fn pre_005_known_postgres_without_feature_returns_stable_error_before_io() {
let result = poll_ready(ksp_store_lib::Store::open(settings("postgresql://operator-supplied-sensitive-value@localhost/ksp")));
let error = result.err();
assert_eq!(error.map(|value| return value.code()), std::option::Option::Some(ksp_store_lib::ERROR_CODE_BACKEND_NOT_COMPILED));
return;
}
#[cfg(feature = "postgres")]
#[test]
fn pre_005_compiled_postgres_rejects_malformed_uri_without_secret_leak_before_io() {
let secret_canary = "not-a-postgresql-uri-secret-canary";
let result = poll_ready(ksp_store_lib::Store::open(settings(secret_canary)));
let error = result.err();
assert_eq!(error.as_ref().map(|value| return value.code()), std::option::Option::Some(ksp_store_lib::ERROR_CODE_POSTGRES_CONFIG_INVALID));
assert!(!format!("{error:?}").contains(secret_canary));
return;
}