mirror of
https://gitlab.com/veilid/veilid.git
synced 2024-10-01 01:26:08 -04:00
protected store test
This commit is contained in:
parent
84b1ef5e9e
commit
8aea9ee1ab
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
103
veilid-core/src/tests/common/test_protected_store.rs
Normal file
103
veilid-core/src/tests/common/test_protected_store.rs
Normal 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;
|
||||
}
|
@ -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")]
|
||||
|
@ -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() {
|
||||
|
@ -382,10 +382,8 @@ impl VeilidConfig {
|
||||
// Get the node id from config if one is specified
|
||||
// Must be done -after- protected store startup
|
||||
pub async fn init_node_id(&self, protected_store: intf::ProtectedStore) -> Result<(), String> {
|
||||
let mut inner = self.inner.write();
|
||||
|
||||
let mut node_id = inner.network.node_id;
|
||||
let mut node_id_secret = inner.network.node_id_secret;
|
||||
let mut node_id = self.inner.read().network.node_id;
|
||||
let mut node_id_secret = self.inner.read().network.node_id_secret;
|
||||
// See if node id was previously stored in the protected store
|
||||
if !node_id.valid {
|
||||
debug!("pulling node id from storage");
|
||||
@ -437,8 +435,8 @@ impl VeilidConfig {
|
||||
.save_user_secret_string("node_id_secret", node_id_secret.encode().as_str())
|
||||
.await?;
|
||||
|
||||
inner.network.node_id = node_id;
|
||||
inner.network.node_id_secret = node_id_secret;
|
||||
self.inner.write().network.node_id = node_id;
|
||||
self.inner.write().network.node_id_secret = node_id_secret;
|
||||
|
||||
trace!("init_node_id complete");
|
||||
|
||||
|
@ -76,6 +76,10 @@ impl VeilidCore {
|
||||
self.inner.lock().table_store.as_ref().unwrap().clone()
|
||||
}
|
||||
|
||||
pub(crate) fn protected_store(&self) -> ProtectedStore {
|
||||
self.inner.lock().protected_store.as_ref().unwrap().clone()
|
||||
}
|
||||
|
||||
pub(crate) fn crypto(&self) -> Crypto {
|
||||
self.inner.lock().crypto.as_ref().unwrap().clone()
|
||||
}
|
||||
|
@ -93,7 +93,10 @@ impl JsVeilidCore {
|
||||
"capabilities.protocol_accept_ws" => Self::value_to_bool(val),
|
||||
"capabilities.protocol_connect_wss" => Self::value_to_bool(val),
|
||||
"capabilities.protocol_accept_wss" => Self::value_to_bool(val),
|
||||
"tablestore.directory" => Self::value_to_string(val),
|
||||
"table_store.directory" => Self::value_to_string(val),
|
||||
"protected_store.allow_insecure_fallback" => Self::value_to_bool(val),
|
||||
"protected_store.always_use_insecure_storage" => Self::value_to_bool(val),
|
||||
"protected_store.insecure_fallback_directory" => Self::value_to_string(val),
|
||||
"network.max_connections" => Self::value_to_u32(val),
|
||||
"network.node_id" => Self::value_to_dht_key(val),
|
||||
"network.node_id_secret" => Self::value_to_dht_key_secret(val),
|
||||
|
@ -36,7 +36,10 @@ fn init_callbacks() {
|
||||
case "capabilities.protocol_accept_ws": return false;
|
||||
case "capabilities.protocol_connect_wss": return true;
|
||||
case "capabilities.protocol_accept_wss": return false;
|
||||
case "tablestore.directory": return "";
|
||||
case "table_store.directory": return "";
|
||||
case "protected_store.allow_insecure_fallback": return true;
|
||||
case "protected_store.always_use_insecure_storage": return false;
|
||||
case "protected_store.insecure_fallback_directory": return "";
|
||||
case "network.max_connections": return 16;
|
||||
case "network.node_id": return "ZLd4uMYdP4qYLtxF6GqrzBb32Z6T3rE2FWMkWup1pdY";
|
||||
case "network.node_id_secret": return "s2Gvq6HJOxgQh-3xIgfWSL3I-DWZ2c1RjZLJl2Xmg2E";
|
||||
|
Loading…
Reference in New Issue
Block a user