Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crypto store: clear db before integ tests #3644

Merged
merged 3 commits into from
Jul 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Clean up indexeddb store clearance
Add a case that I forgot, and factor repeated code out
  • Loading branch information
richvdh committed Jul 3, 2024
commit 3b145ce4ba20ec46c28008d0b31179e8f1495c74
17 changes: 11 additions & 6 deletions crates/matrix-sdk-indexeddb/src/crypto_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,14 @@ impl IndexeddbCryptoStore {
IndexeddbCryptoStore::open_with_store_cipher(name, None).await
}

/// Delete the IndexedDB databases for the given name.
#[cfg(test)]
pub fn delete_stores(prefix: &str) -> Result<()> {
IdbDatabase::delete_by_name(&format!("{prefix:0}::matrix-sdk-crypto-meta"))?;
IdbDatabase::delete_by_name(&format!("{prefix:0}::matrix-sdk-crypto"))?;
Ok(())
}

fn get_static_account(&self) -> Option<StaticAccountData> {
self.static_account.read().unwrap().clone()
}
Expand Down Expand Up @@ -1724,7 +1732,6 @@ mod wasm_unit_tests {

#[cfg(all(test, target_arch = "wasm32"))]
mod tests {
use indexed_db_futures::IdbDatabase;
use matrix_sdk_crypto::{
cryptostore_integration_tests,
store::{Changes, CryptoStore as _, DeviceChanges, PendingChanges},
Expand All @@ -1742,8 +1749,7 @@ mod tests {
clear_data: bool,
) -> IndexeddbCryptoStore {
if clear_data {
IdbDatabase::delete_by_name(&format!("{name:0}::matrix-sdk-crypto-meta")).unwrap();
IdbDatabase::delete_by_name(&format!("{name:0}::matrix-sdk-crypto")).unwrap();
IndexeddbCryptoStore::delete_stores(name).unwrap();
}
match passphrase {
Some(pass) => IndexeddbCryptoStore::open_with_passphrase(name, pass)
Expand Down Expand Up @@ -1796,7 +1802,6 @@ mod tests {

#[cfg(all(test, target_arch = "wasm32"))]
mod encrypted_tests {
use indexed_db_futures::IdbDatabase;
use matrix_sdk_crypto::{
cryptostore_integration_tests,
olm::Account,
Expand All @@ -1816,8 +1821,7 @@ mod encrypted_tests {
clear_data: bool,
) -> IndexeddbCryptoStore {
if clear_data {
IdbDatabase::delete_by_name(&format!("{name:0}::matrix-sdk-crypto-meta")).unwrap();
IdbDatabase::delete_by_name(&format!("{name:0}::matrix-sdk-crypto")).unwrap();
IndexeddbCryptoStore::delete_stores(name).unwrap();
}

let pass = passphrase.unwrap_or(name);
Expand All @@ -1836,6 +1840,7 @@ mod encrypted_tests {
let b64_passdata = base64_encode(passdata);

// Initialise the store with some account data
IndexeddbCryptoStore::delete_stores(store_name).unwrap();
let store = IndexeddbCryptoStore::open_with_passphrase(&store_name, &b64_passdata)
.await
.expect("Can't create a passphrase-protected store");
Expand Down