protected store test

This commit is contained in:
John Smith
2022-01-09 00:13:47 -05:00
parent 84b1ef5e9e
commit 8aea9ee1ab
9 changed files with 138 additions and 121 deletions

View File

@@ -3,6 +3,7 @@ pub mod test_crypto;
pub mod test_dht_key;
pub mod test_envelope_receipt;
pub mod test_host_interface;
pub mod test_protected_store;
pub mod test_table_store;
pub mod test_veilid_config;
pub mod test_veilid_core;

View File

@@ -429,115 +429,6 @@ pub async fn test_split_url() {
assert_split_url_parse!("s://s");
}
pub async fn test_protected_store() {
info!("testing protected store");
xxx move into its own test
let _ = intf::remove_user_secret("test", "_test_key").await;
let _ = intf::remove_user_secret("test", "_test_broken").await;
let d1: [u8; 0] = [];
assert_eq!(
intf::save_user_secret("test", "_test_key", &[2u8, 3u8, 4u8]).await,
Ok(false)
);
info!("testing saving user secret");
assert_eq!(
intf::save_user_secret("test", "_test_key", &d1).await,
Ok(true)
);
info!("testing loading user secret");
assert_eq!(
intf::load_user_secret("test", "_test_key").await,
Ok(Some(d1.to_vec()))
);
info!("testing loading user secret again");
assert_eq!(
intf::load_user_secret("test", "_test_key").await,
Ok(Some(d1.to_vec()))
);
info!("testing loading broken user secret");
assert_eq!(
intf::load_user_secret("test", "_test_broken").await,
Ok(None)
);
info!("testing loading broken user secret again");
assert_eq!(
intf::load_user_secret("test", "_test_broken").await,
Ok(None)
);
info!("testing remove user secret");
assert_eq!(
intf::remove_user_secret("test", "_test_key").await,
Ok(true)
);
info!("testing remove user secret again");
assert_eq!(
intf::remove_user_secret("test", "_test_key").await,
Ok(false)
);
info!("testing remove broken user secret");
assert_eq!(
intf::remove_user_secret("test", "_test_broken").await,
Ok(false)
);
info!("testing remove broken user secret again");
assert_eq!(
intf::remove_user_secret("test", "_test_broken").await,
Ok(false)
);
let d2: [u8; 10] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
assert_eq!(
intf::save_user_secret("test", "_test_key", &[2u8, 3u8, 4u8]).await,
Ok(false)
);
assert_eq!(
intf::save_user_secret("test", "_test_key", &d2).await,
Ok(true)
);
assert_eq!(
intf::load_user_secret("test", "_test_key").await,
Ok(Some(d2.to_vec()))
);
assert_eq!(
intf::load_user_secret("test", "_test_key").await,
Ok(Some(d2.to_vec()))
);
assert_eq!(
intf::load_user_secret("test", "_test_broken").await,
Ok(None)
);
assert_eq!(
intf::load_user_secret("test", "_test_broken").await,
Ok(None)
);
assert_eq!(
intf::remove_user_secret("test", "_test_key").await,
Ok(true)
);
assert_eq!(
intf::remove_user_secret("test", "_test_key").await,
Ok(false)
);
assert_eq!(
intf::remove_user_secret("test", "_test_broken").await,
Ok(false)
);
assert_eq!(
intf::remove_user_secret("test", "_test_broken").await,
Ok(false)
);
let _ = intf::remove_user_secret("test", "_test_key").await;
let _ = intf::remove_user_secret("test", "_test_broken").await;
}
cfg_if! {
if #[cfg(not(target_arch = "wasm32"))] {
pub async fn test_network_interfaces() {
@@ -653,5 +544,4 @@ pub async fn test_all() {
test_eventual_value_clone().await;
test_interval().await;
test_timeout().await;
test_protected_store().await;
}

View File

@@ -0,0 +1,103 @@
use super::test_veilid_config::*;
use crate::intf::*;
use crate::xx::*;
use crate::*;
fn setup_veilid_core() -> VeilidCoreSetup {
VeilidCoreSetup {
state_change_callback: Arc::new(
move |change: VeilidStateChange| -> SystemPinBoxFuture<()> {
Box::pin(async move {
trace!("state_change_callback: {:?}", change);
})
},
),
config_callback: Arc::new(config_callback),
}
}
async fn startup(core: VeilidCore) -> VeilidAPI {
trace!("test_table_store: starting");
core.startup(setup_veilid_core())
.await
.expect("startup failed")
}
async fn shutdown(api: VeilidAPI) {
trace!("test_table_store: shutting down");
api.shutdown().await;
trace!("test_table_store: finished");
}
pub async fn test_protected_store(ps: ProtectedStore) {
info!("testing protected store");
let _ = ps.remove_user_secret("_test_key").await;
let _ = ps.remove_user_secret("_test_broken").await;
let d1: [u8; 0] = [];
assert_eq!(
ps.save_user_secret("_test_key", &[2u8, 3u8, 4u8]).await,
Ok(false)
);
info!("testing saving user secret");
assert_eq!(ps.save_user_secret("_test_key", &d1).await, Ok(true));
info!("testing loading user secret");
assert_eq!(
ps.load_user_secret("_test_key").await,
Ok(Some(d1.to_vec()))
);
info!("testing loading user secret again");
assert_eq!(
ps.load_user_secret("_test_key").await,
Ok(Some(d1.to_vec()))
);
info!("testing loading broken user secret");
assert_eq!(ps.load_user_secret("_test_broken").await, Ok(None));
info!("testing loading broken user secret again");
assert_eq!(ps.load_user_secret("_test_broken").await, Ok(None));
info!("testing remove user secret");
assert_eq!(ps.remove_user_secret("_test_key").await, Ok(true));
info!("testing remove user secret again");
assert_eq!(ps.remove_user_secret("_test_key").await, Ok(false));
info!("testing remove broken user secret");
assert_eq!(ps.remove_user_secret("_test_broken").await, Ok(false));
info!("testing remove broken user secret again");
assert_eq!(ps.remove_user_secret("_test_broken").await, Ok(false));
let d2: [u8; 10] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
assert_eq!(
ps.save_user_secret("_test_key", &[2u8, 3u8, 4u8]).await,
Ok(false)
);
assert_eq!(ps.save_user_secret("_test_key", &d2).await, Ok(true));
assert_eq!(
ps.load_user_secret("_test_key").await,
Ok(Some(d2.to_vec()))
);
assert_eq!(
ps.load_user_secret("_test_key").await,
Ok(Some(d2.to_vec()))
);
assert_eq!(ps.load_user_secret("_test_broken").await, Ok(None));
assert_eq!(ps.load_user_secret("_test_broken").await, Ok(None));
assert_eq!(ps.remove_user_secret("_test_key").await, Ok(true));
assert_eq!(ps.remove_user_secret("_test_key").await, Ok(false));
assert_eq!(ps.remove_user_secret("_test_broken").await, Ok(false));
assert_eq!(ps.remove_user_secret("_test_broken").await, Ok(false));
let _ = ps.remove_user_secret("_test_key").await;
let _ = ps.remove_user_secret("_test_broken").await;
}
pub async fn test_all() {
let core = VeilidCore::new();
let api = startup(core.clone()).await;
let ps = core.protected_store();
test_protected_store(ps.clone()).await;
shutdown(api).await;
}

View File

@@ -167,7 +167,7 @@ pub fn config_callback(key: String) -> Result<Box<dyn core::any::Any>, String> {
"capabilities.protocol_accept_ws" => Ok(Box::new(true)),
"capabilities.protocol_connect_wss" => Ok(Box::new(true)),
"capabilities.protocol_accept_wss" => Ok(Box::new(true)),
"tablestore.directory" => Ok(Box::new(get_table_store_path())),
"table_store.directory" => Ok(Box::new(get_table_store_path())),
"protected_store.allow_insecure_fallback" => Ok(Box::new(true)),
"protected_store.always_use_insecure_storage" => Ok(Box::new(false)),
"protected_store.insecure_fallback_directory" => Ok(Box::new(get_protected_store_path())),
@@ -252,6 +252,7 @@ pub async fn test_config() {
unreachable!();
}
}
let inner = vc.get();
assert_eq!(inner.program_name, String::from("Veilid"));
assert_eq!(inner.namespace, String::from(""));
@@ -271,8 +272,8 @@ pub async fn test_config() {
);
assert_eq!(inner.network.max_connections, 16);
assert_eq!(inner.network.connection_initial_timeout, 2_000_000u64);
assert!(inner.network.node_id.valid);
assert!(inner.network.node_id_secret.valid);
assert!(!inner.network.node_id.valid);
assert!(!inner.network.node_id_secret.valid);
assert_eq!(
inner.network.bootstrap,
vec![String::from("asdf"), String::from("qwer")]

View File

@@ -57,6 +57,8 @@ pub fn run_all_tests() {
exec_test_connection_table();
info!("TEST: exec_test_table_store");
exec_test_table_store();
info!("TEST: exec_test_protected_store");
exec_test_protected_store();
info!("TEST: exec_test_crypto");
exec_test_crypto();
info!("TEST: exec_test_envelope_receipt");
@@ -100,6 +102,11 @@ fn exec_test_table_store() {
test_table_store::test_all().await;
})
}
fn exec_test_protected_store() {
async_std::task::block_on(async {
test_protected_store::test_all().await;
})
}
fn exec_test_crypto() {
async_std::task::block_on(async {
test_crypto::test_all().await;
@@ -180,6 +187,13 @@ cfg_if! {
exec_test_table_store();
}
#[test]
#[serial]
fn run_test_protected_store() {
setup();
exec_test_protected_store();
}
#[test]
#[serial]
fn run_test_crypto() {