Skip to content

Commit a3c6100

Browse files
committedDec 10, 2023
Add a test for the cred helper store action
1 parent a02dde9 commit a3c6100

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed
 

‎src/cred.rs

+31-1
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ mod test {
521521
let td = TempDir::new().unwrap();
522522
let mut cfg = Config::new().unwrap();
523523
cfg.add_file(&td.path().join("cfg"), ConfigLevel::Highest, false).unwrap();
524-
$(cfg.set_str($k, $v).unwrap();)*
524+
$(cfg.set_multivar($k, "DO_NO_MATCH_ANYTHING", $v).unwrap();)*
525525
cfg
526526
}) );
527527

@@ -696,6 +696,36 @@ echo password=$2
696696
assert_eq!(p, "b");
697697
}
698698

699+
#[test]
700+
fn credential_helper10() {
701+
let cache_file = tempfile::NamedTempFile::new().unwrap();
702+
let cache_cmd = format!(
703+
"!f() {{ if [ \"$1\" = store ]; then cat > \"{}\"; fi; }}; f",
704+
cache_file.path().display()
705+
);
706+
let cfg = test_cfg!(
707+
// The output will be ignored in the store phase
708+
"credential.helper" => "!f() { echo username=a; echo password=b; }; f",
709+
"credential.helper" => &cache_cmd
710+
);
711+
let (u, p) = CredentialHelper::new("https://example.com/foo/bar")
712+
.config(&cfg)
713+
.execute()
714+
.unwrap();
715+
assert_eq!(u, "a");
716+
assert_eq!(p, "b");
717+
718+
let mut cache_content = String::new();
719+
cache_file
720+
.as_file()
721+
.read_to_string(&mut cache_content)
722+
.unwrap();
723+
assert!(cache_content.contains("protocol=https\n"));
724+
assert!(cache_content.contains("host=example.com\n"));
725+
assert!(cache_content.contains("username=a\n"));
726+
assert!(cache_content.contains("password=b\n"));
727+
}
728+
699729
#[test]
700730
#[cfg(feature = "ssh")]
701731
fn ssh_key_from_memory() {

0 commit comments

Comments
 (0)