Skip to content

Commit

Permalink
Fix path_regex to match docs for stdin.
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedcharles authored and gibbz00 committed Mar 20, 2024
1 parent 29fab87 commit 49b6d4b
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions crates/cli/src/args/encrypt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,24 @@ impl ConfigArg for EncryptArgs {

impl MergeConfig for EncryptArgs {
fn merge_config(&mut self, config: Config) {
// stdin regarded as empty path
let file_path = self.input_args.file.as_deref().unwrap_or(Path::new(""));
let file_path = file_path.to_string_lossy();
for creation_rule in config.creation_rules {
if let Some(file_path) = &self.input_args.file {
if creation_rule.path_regex.is_match(&file_path.to_string_lossy()) {
self.integration_keys.merge(creation_rule.integration_keys);
if creation_rule.path_regex.is_match(&file_path) {
self.integration_keys.merge(creation_rule.integration_keys);

if self.mac_only_encrypted.is_none() {
self.mac_only_encrypted = creation_rule.mac_only_encrypted;
}
if self.mac_only_encrypted.is_none() {
self.mac_only_encrypted = creation_rule.mac_only_encrypted;
}

if self.partial_encryption_args.is_none() {
if let Some(partial_encryption_config) = creation_rule.partial_encryption {
self.partial_encryption_args = Some(partial_encryption_config.into());
}
if self.partial_encryption_args.is_none() {
if let Some(partial_encryption_config) = creation_rule.partial_encryption {
self.partial_encryption_args = Some(partial_encryption_config.into());
}

break;
}

break;
}
}
}
Expand All @@ -71,10 +72,22 @@ mod mock {

#[cfg(test)]
mod test {
use regex::Regex;
use rops::{file::metadata::PartialEncryptionConfig, test_utils::*};

use super::*;

#[test]
fn merges_configuration_for_stdin_with_fallback_regex() {
let mut encrypted_args = EncryptArgs::mock();
encrypted_args.input_args.file = None;
assert_eq!(1, encrypted_args.integration_keys.age.len());
let mut config = Config::mock_other();
config.creation_rules[0].path_regex = Regex::new("").unwrap();
encrypted_args.merge_config(config);
assert_eq!(2, encrypted_args.integration_keys.age.len());
}

#[test]
fn merges_integration_keys_from_config() {
let mut encrypted_args = EncryptArgs::mock();
Expand Down

0 comments on commit 49b6d4b

Please sign in to comment.