Open configured vault folders
This commit is contained in:
@@ -6,6 +6,7 @@ use ironstorage::presentation::DEFAULT_CLIPBOARD_TIMEOUT;
|
||||
use ironstorage::{
|
||||
authentication::{DEFAULT_AUTHENTICATION_TIMEOUT, MAX_AUTHENTICATION_TIMEOUT},
|
||||
config::{ConfigError, ConfigLoader, EditorSource},
|
||||
desktop::DesktopStorage,
|
||||
};
|
||||
use tempfile::TempDir;
|
||||
|
||||
@@ -177,6 +178,97 @@ fn native_default_path_is_used_without_an_explicit_path() -> TestResult {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn desktop_vault_switch_preserves_and_reloads_the_shared_configuration() -> TestResult {
|
||||
let fixture = ConfigurationFixture::new()?;
|
||||
fs::create_dir_all(fixture.temporary.path().join("cwd/vault"))?;
|
||||
let selected = fixture.temporary.path().join("selected-vault");
|
||||
fs::create_dir(&selected)?;
|
||||
let keys = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/compatibility/keys");
|
||||
let contents = fixture
|
||||
.valid_contents()
|
||||
.replace(
|
||||
"0123456789ABCDEF0123456789ABCDEF01234567",
|
||||
"7E5C5241B25F6FFAAD717EBFA132DCB2DC23AE30",
|
||||
)
|
||||
.replace(
|
||||
"key_material = \"keys\"",
|
||||
&format!("key_material = {keys:?}"),
|
||||
)
|
||||
.replace(
|
||||
"editor = [\"code\", \"--wait\"]",
|
||||
"editor = [\"code\", \"--wait\"]\n[security]\ninactivity_timeout_seconds = 300",
|
||||
);
|
||||
fixture.write_explicit(&contents)?;
|
||||
|
||||
let storage = DesktopStorage::load(Some(&fixture.explicit_path()))?;
|
||||
let switched = storage.switch_vault(&selected)?;
|
||||
assert_eq!(switched.vault(), fs::canonicalize(&selected)?);
|
||||
|
||||
let mut settings = switched.settings();
|
||||
settings.set_default_key("B37027B56FC406BD3F6A622B2AC03492B992D06F".to_owned());
|
||||
settings.set_editor(Some(vec!["nano".to_owned(), "-w".to_owned()]));
|
||||
settings.set_authentication_timeout(Duration::from_secs(600));
|
||||
let updated = switched.update_settings(settings)?;
|
||||
|
||||
let reloaded = fixture.loader().load(Some(&fixture.explicit_path()))?;
|
||||
assert_eq!(reloaded.vault(), fs::canonicalize(&selected)?);
|
||||
assert_eq!(
|
||||
reloaded.default_key().as_str(),
|
||||
"B37027B56FC406BD3F6A622B2AC03492B992D06F"
|
||||
);
|
||||
assert_eq!(
|
||||
reloaded.authentication_timeout().duration(),
|
||||
Duration::from_secs(600)
|
||||
);
|
||||
let editor = reloaded.configured_editor().expect("configured editor");
|
||||
assert_eq!(editor.program(), "nano");
|
||||
assert_eq!(editor.arguments(), ["-w"]);
|
||||
assert_eq!(reloaded.git_remotes().len(), 1);
|
||||
|
||||
let before_rejection = fs::read(fixture.explicit_path())?;
|
||||
let mut invalid = updated.settings();
|
||||
invalid.set_default_key("missing-key".to_owned());
|
||||
assert!(updated.update_settings(invalid).is_err());
|
||||
assert_eq!(fs::read(fixture.explicit_path())?, before_rejection);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejected_vault_switches_leave_configuration_and_session_unchanged() -> TestResult {
|
||||
let fixture = ConfigurationFixture::new()?;
|
||||
fs::create_dir_all(fixture.temporary.path().join("cwd/vault"))?;
|
||||
fixture.write_explicit(fixture.valid_contents())?;
|
||||
let before = fs::read(fixture.explicit_path())?;
|
||||
let storage = DesktopStorage::load(Some(&fixture.explicit_path()))?;
|
||||
let current = storage.vault().to_owned();
|
||||
|
||||
for invalid in [
|
||||
fixture.temporary.path().join("missing"),
|
||||
fixture.temporary.path().join("ordinary-file"),
|
||||
] {
|
||||
if invalid.file_name() == Some(OsStr::new("ordinary-file")) {
|
||||
fs::write(&invalid, b"not a folder")?;
|
||||
}
|
||||
assert!(storage.switch_vault(&invalid).is_err());
|
||||
assert_eq!(storage.vault(), current);
|
||||
assert_eq!(fs::read(fixture.explicit_path())?, before);
|
||||
}
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::fs::symlink;
|
||||
|
||||
let target = fixture.temporary.path().join("symlink-target");
|
||||
let link = fixture.temporary.path().join("symlink-vault");
|
||||
fs::create_dir(&target)?;
|
||||
symlink(&target, &link)?;
|
||||
assert!(storage.switch_vault(&link).is_err());
|
||||
assert_eq!(storage.vault(), current);
|
||||
assert_eq!(fs::read(fixture.explicit_path())?, before);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn editor_precedence_and_argument_splitting_are_storage_owned() -> TestResult {
|
||||
let fixture = ConfigurationFixture::new()?;
|
||||
|
||||
Reference in New Issue
Block a user