diff options
author | Daniel Mueller <deso@posteo.net> | 2019-01-20 13:56:48 -0800 |
---|---|---|
committer | Daniel Mueller <deso@posteo.net> | 2019-01-20 13:56:48 -0800 |
commit | 37f7800766fe12af43d0cdba13aea9545cbe7755 (patch) | |
tree | ea621deaf425db10494cb8af59ac3a8806c52e8b /nitrocli/src/commands.rs | |
parent | c3f1761ae147e562ec3565c7ba8a9cb1834759c2 (diff) | |
download | nitrocli-37f7800766fe12af43d0cdba13aea9545cbe7755.tar.gz nitrocli-37f7800766fe12af43d0cdba13aea9545cbe7755.tar.bz2 |
Add test for storage hidden subcommand
This change adds a test for the creation, opening, and closing of a
hidden subvolume. In order to support that in a non-interactive fashion,
we introduce and honor the NITROCLI_PASSWORD environment variable, that
prevents an interactive password query.
Diffstat (limited to 'nitrocli/src/commands.rs')
-rw-r--r-- | nitrocli/src/commands.rs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/nitrocli/src/commands.rs b/nitrocli/src/commands.rs index ab70e29..989abbf 100644 --- a/nitrocli/src/commands.rs +++ b/nitrocli/src/commands.rs @@ -327,7 +327,14 @@ pub fn storage_hidden_create( ) -> Result<()> { let device = get_storage_device(ctx)?; let pwd_entry = pinentry::PwdEntry::from(&device)?; - let pwd = pinentry::choose(&pwd_entry)?; + let pwd = if let Some(pwd) = &ctx.password { + pwd + .to_str() + .ok_or_else(|| Error::from("Failed to read password: invalid Unicode data found")) + .map(ToOwned::to_owned) + } else { + pinentry::choose(&pwd_entry) + }?; device .create_hidden_volume(slot, start, end, &pwd) @@ -338,7 +345,14 @@ pub fn storage_hidden_create( pub fn storage_hidden_open(ctx: &mut args::ExecCtx<'_>) -> Result<()> { let device = get_storage_device(ctx)?; let pwd_entry = pinentry::PwdEntry::from(&device)?; - let pwd = pinentry::inquire(&pwd_entry, pinentry::Mode::Query, None)?; + let pwd = if let Some(pwd) = &ctx.password { + pwd + .to_str() + .ok_or_else(|| Error::from("Failed to read password: invalid Unicode data found")) + .map(ToOwned::to_owned) + } else { + pinentry::inquire(&pwd_entry, pinentry::Mode::Query, None) + }?; // We may forcefully close an encrypted volume, if active, so be sure // to flush caches to disk. |