Skip to content

Commit

Permalink
Fix migrate test fixtures.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpfs committed Dec 3, 2023
1 parent 38d51e1 commit 205c206
Show file tree
Hide file tree
Showing 23 changed files with 131 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ target
*.changes
*.sig
*.bundle
*.csv
/*.csv
.homebrew
tests/server_public_key.txt
geiger-report.txt
7 changes: 7 additions & 0 deletions tests/fixtures/migrate/1password-export.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Title,Url,Username,Password,OTPAuth,Favorite,Archived,Tags,Notes
Password (No Username),,,XXX-MOCK-1,,false,false,,
Mock Archive Password,https://example.com,mock-user,XXX-MOCK-2,,false,true,mock;passwords,Mock notes about the mock password that was moved to the archive.
,,,,,false,false,,
Mock Favorite Password,,mock-user,XXX-MOCK-3,,true,false,mock,
Password (No Password),,mock-user,,,false,false,,
Password (No username or password),,,,,false,false,,
3 changes: 3 additions & 0 deletions tests/fixtures/migrate/bitwarden-export.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
folder,favorite,type,name,notes,fields,reprompt,login_uri,login_username,login_password,login_totp
,1,login,Mock Login,Some notes about the login.,,0,https://example.com,mock-user,XXX-MOCK-1,
,,note,Mock Note,This is a mock note.,,0,,,,
2 changes: 2 additions & 0 deletions tests/fixtures/migrate/chrome-export-note.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name,url,username,password,note
mock.example.com,https://mock.example.com/login,[email protected],XXX-MOCK-1,mock note
3 changes: 3 additions & 0 deletions tests/fixtures/migrate/chrome-export.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name,url,username,password
mock.example.com,https://mock.example.com/login,[email protected],XXX-MOCK-1
mock2.example.com,https://mock2.example.com/login,[email protected],XXX-MOCK-2
Binary file modified tests/fixtures/migrate/dashlane-export.zip
Binary file not shown.
3 changes: 3 additions & 0 deletions tests/fixtures/migrate/firefox-export.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"url","username","password","httpRealm","formActionOrigin","guid","timeCreated","timeLastUsed","timePasswordChanged"
"https://mock.example.com","","XXX-MOCK-1",,"https://mock.example.com","{c986d544-97ab-46a8-bdad-507bca1cdb82}","1642647925763","1672972356666","1642647925763"
"https://mock2.example.com","mock-user-1","XXX-MOCK-2",,"https://mock2.example.com","{20bad9ad-a521-42b5-a4b2-2e498e37f327}","1642933004840","1642933004840","1642933004840"
3 changes: 3 additions & 0 deletions tests/fixtures/migrate/macos-export.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Title,Url,Username,Password,OTPAuth
mock.example.com ([email protected]),https://mock.example.com/,[email protected],XXX-MOCK-1,
mock2.example.com (mock-username),https://mock2.example.com,mock-username,XXX-MOCK-2,
2 changes: 2 additions & 0 deletions tests/fixtures/migrate/macos-notes-export.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Title,Url,Username,Password,OTPAuth,Notes
mock.example.com ([email protected]),https://mock.example.com/,[email protected],XXX-MOCK-1,,mock note
4 changes: 2 additions & 2 deletions tests/integration/event_log/move_folder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ async fn integration_events_move_folder() -> Result<()> {
// one for the default folder and one for the imported folder
assert_eq!(2, events.len());
assert!(matches!(
events.get((0)),
events.get(0),
Some(AccountEvent::CreateFolder(_, _))
));
assert!(matches!(
events.get((1)),
events.get(1),
Some(AccountEvent::CreateFolder(_, _))
));

Expand Down
19 changes: 9 additions & 10 deletions tests/integration/local_account/audit_trail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ use secrecy::SecretString;
use std::path::{Path, PathBuf};

use sos_net::{
client::NetworkAccount,
migrate::import::ImportTarget,
sdk::{
account::archive::RestoreOptions,
account::{archive::RestoreOptions, LocalAccount},
events::{AuditEvent, AuditLogFile, EventKind},
passwd::diceware::generate_passphrase,
vault::Summary,
Expand All @@ -26,7 +25,7 @@ async fn integration_audit_trail() -> Result<()> {

let account_name = TEST_ID.to_string();
let (passphrase, _) = generate_passphrase()?;
let (mut owner, new_account) = NetworkAccount::new_account_with_builder(
let (mut owner, new_account) = LocalAccount::new_account_with_builder(
account_name.to_owned(),
passphrase.clone(),
|builder| {
Expand Down Expand Up @@ -122,14 +121,14 @@ async fn integration_audit_trail() -> Result<()> {
}

async fn simulate_session(
owner: &mut NetworkAccount,
owner: &mut LocalAccount,
default_folder: &Summary,
passphrase: SecretString,
data_dir: &PathBuf,
) -> Result<()> {
// Create a secret
let (meta, secret) = mock::note("Audit note", "Note value");
let (id, _) = owner
let (id, _, _, _) = owner
.create_secret(meta, secret, default_folder.clone().into())
.await?;
// Read the secret
Expand All @@ -138,7 +137,7 @@ async fn simulate_session(
// Update the secret
let mut new_meta = secret_data.meta().clone();
new_meta.set_label("Audit note updated".to_string());
let (id, _) = owner
let (id, _, _, _) = owner
.update_secret(
&id,
new_meta,
Expand All @@ -154,15 +153,15 @@ async fn simulate_session(
// Create a new secret so we can archive it
let (meta, secret) =
mock::note("Audit note to archive", "Note value to archive");
let (id, _) = owner
let (id, _, _, _) = owner
.create_secret(meta, secret, default_folder.clone().into())
.await?;
// Archive the secret to generate move event
owner
.archive(default_folder, &id, Default::default())
.await?;
// Create a new folder
let (new_folder, _) =
let (new_folder, _, _, _) =
owner.create_folder("New folder".to_string()).await?;
// Rename the folder
owner
Expand Down Expand Up @@ -201,14 +200,14 @@ async fn simulate_session(
files_dir: None,
};

NetworkAccount::restore_backup_archive(
LocalAccount::restore_backup_archive(
Some(owner),
archive,
restore_options,
Some(data_dir.clone()),
)
.await?;

let unsafe_archive = "target/audit-trail-unsafe-archive.zip";
owner.export_unsafe_archive(unsafe_archive).await?;

Expand Down
6 changes: 2 additions & 4 deletions tests/integration/local_account/contacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ use sos_net::sdk::{
};

const TEST_ID: &str = "contacts";
const CONTACT: &str =
include_str!("../../../tests/fixtures/contact.vcf");
const AVATAR: &str =
include_str!("../../../tests/fixtures/avatar.vcf");
const CONTACT: &str = include_str!("../../../tests/fixtures/contact.vcf");
const AVATAR: &str = include_str!("../../../tests/fixtures/avatar.vcf");

/// Tests importing and exporting contacts from vCard
/// files.
Expand Down
8 changes: 2 additions & 6 deletions tests/integration/local_account/migrate_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ async fn integration_migrate_import() -> Result<()> {

let target = ImportTarget {
format: ImportFormat::OnePasswordCsv,
path: PathBuf::from(
"tests/fixtures/migrate/1password-export.csv",
),
path: PathBuf::from("tests/fixtures/migrate/1password-export.csv"),
folder_name: "1password".to_string(),
};
let mut importer = LocalImport::new(&mut account);
Expand All @@ -62,9 +60,7 @@ async fn integration_migrate_import() -> Result<()> {

let target = ImportTarget {
format: ImportFormat::BitwardenCsv,
path: PathBuf::from(
"tests/fixtures/migrate/bitwarden-export.csv",
),
path: PathBuf::from("tests/fixtures/migrate/bitwarden-export.csv"),
folder_name: "bitwarden".to_string(),
};
let mut importer = LocalImport::new(&mut account);
Expand Down
2 changes: 1 addition & 1 deletion workspace/sdk/src/account/files/external_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ mod test {
let (passphrase, _) = generate_passphrase()?;
let input = "../../tests/fixtures/sample.heic";
let output = "target/file-encrypt-decrypt";

if let Ok(true) = vfs::try_exists(output).await {
vfs::remove_dir_all(output).await?;
}
Expand Down
2 changes: 1 addition & 1 deletion workspace/sdk/src/account/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
account::Account,
migrate::{import::ImportTarget, AccountExport, AccountImport},
vault::Summary,
Result, Error,
Error, Result,
};
use std::path::Path;

Expand Down
14 changes: 10 additions & 4 deletions workspace/sdk/src/migrate/import/csv/bitwarden.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ use super::{
};
use crate::migrate::{import::read_csv_records, Convert, Result};

#[cfg(test)]
use tokio::fs as vfs;
#[cfg(not(test))]
use crate::vfs;
#[cfg(test)]
use tokio::fs as vfs;

const TYPE_LOGIN: &str = "login";
const TYPE_NOTE: &str = "note";
Expand Down Expand Up @@ -161,7 +161,9 @@ mod test {

#[tokio::test]
async fn bitwarden_passwords_csv_parse() -> Result<()> {
let mut records = parse_path("../../tests/fixtures/migrate/bitwarden-export.csv").await?;
let mut records =
parse_path("../../tests/fixtures/migrate/bitwarden-export.csv")
.await?;
assert_eq!(2, records.len());

let first = records.remove(0);
Expand Down Expand Up @@ -189,7 +191,11 @@ mod test {

let key: AccessKey = passphrase.into();
let vault = BitwardenCsv
.convert("../../tests/fixtures/migrate/bitwarden-export.csv".into(), vault, &key)
.convert(
"../../tests/fixtures/migrate/bitwarden-export.csv".into(),
vault,
&key,
)
.await?;

let mut search = SearchIndex::new();
Expand Down
20 changes: 15 additions & 5 deletions workspace/sdk/src/migrate/import/csv/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ use super::{
};
use crate::migrate::{import::read_csv_records, Convert, Result};

#[cfg(test)]
use tokio::fs as vfs;
#[cfg(not(test))]
use crate::vfs;
#[cfg(test)]
use tokio::fs as vfs;

/// Record for an entry in a Chrome passwords CSV export.
#[derive(Deserialize)]
Expand Down Expand Up @@ -111,7 +111,9 @@ mod test {

#[tokio::test]
async fn chrome_passwords_csv_parse() -> Result<()> {
let mut records = parse_path("../../tests/fixtures/migrate/chrome-export.csv").await?;
let mut records =
parse_path("../../tests/fixtures/migrate/chrome-export.csv")
.await?;
assert_eq!(2, records.len());

let first = records.remove(0);
Expand Down Expand Up @@ -145,7 +147,11 @@ mod test {

let key: AccessKey = passphrase.into();
let vault = ChromePasswordCsv
.convert("../../tests/fixtures/migrate/chrome-export.csv".into(), vault, &key)
.convert(
"../../tests/fixtures/migrate/chrome-export.csv".into(),
vault,
&key,
)
.await?;

let mut search = SearchIndex::new();
Expand Down Expand Up @@ -173,7 +179,11 @@ mod test {

let key: AccessKey = passphrase.into();
let vault = ChromePasswordCsv
.convert("../../tests/fixtures/migrate/chrome-export-note.csv".into(), vault, &key)
.convert(
"../../tests/fixtures/migrate/chrome-export-note.csv".into(),
vault,
&key,
)
.await?;

let mut search = SearchIndex::new();
Expand Down
14 changes: 10 additions & 4 deletions workspace/sdk/src/migrate/import/csv/dashlane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ use super::{
};
use crate::migrate::{import::read_csv_records, Convert, Result};

#[cfg(test)]
use tokio::fs as vfs;
#[cfg(not(test))]
use crate::vfs;
#[cfg(test)]
use tokio::fs as vfs;

/// Record used to deserialize dashlane CSV files.
#[derive(Debug)]
Expand Down Expand Up @@ -673,7 +673,9 @@ mod test {

#[tokio::test]
async fn dashlane_csv_parse() -> Result<()> {
let mut records = parse_path("../../tests/fixtures/migrate/dashlane-export.zip").await?;
let mut records =
parse_path("../../tests/fixtures/migrate/dashlane-export.zip")
.await?;
assert_eq!(15, records.len());

let first = records.remove(0);
Expand All @@ -700,7 +702,11 @@ mod test {

let key: AccessKey = passphrase.into();
let vault = DashlaneCsvZip
.convert("../../tests/fixtures/migrate/dashlane-export.zip".into(), vault, &key)
.convert(
"../../tests/fixtures/migrate/dashlane-export.zip".into(),
vault,
&key,
)
.await?;

let mut search = SearchIndex::new();
Expand Down
10 changes: 8 additions & 2 deletions workspace/sdk/src/migrate/import/csv/firefox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ mod test {

#[tokio::test]
async fn firefox_passwords_csv_parse() -> Result<()> {
let mut records = parse_path("../../tests/fixtures/migrate/firefox-export.csv").await?;
let mut records =
parse_path("../../tests/fixtures/migrate/firefox-export.csv")
.await?;
assert_eq!(2, records.len());

let first = records.remove(0);
Expand All @@ -138,7 +140,11 @@ mod test {

let key: AccessKey = passphrase.into();
let vault = FirefoxPasswordCsv
.convert("../../tests/fixtures/migrate/firefox-export.csv".into(), vault, &key)
.convert(
"../../tests/fixtures/migrate/firefox-export.csv".into(),
vault,
&key,
)
.await?;

let mut search = SearchIndex::new();
Expand Down
Loading

0 comments on commit 205c206

Please sign in to comment.