Skip to content

Commit 108e2a3

Browse files
committed
add couple of tests for parse_client_tls_opts
Signed-off-by: Rajat Jindal <[email protected]>
1 parent dc78e99 commit 108e2a3

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

crates/trigger/src/runtime_config.rs

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,57 @@ mod tests {
531531
Ok(())
532532
}
533533

534+
#[test]
535+
fn test_parsing_valid_hosts_in_client_opts() {
536+
let input = ClientTlsOpts {
537+
component_ids: vec!["component-id-foo".to_string()],
538+
hosts: vec!["fermyon.com".to_string(), "fermyon.com:5443".to_string()],
539+
custom_root_ca_file: None,
540+
cert_chain_file: None,
541+
private_key_file: None,
542+
};
543+
544+
let parsed = parse_client_tls_opts(&input);
545+
assert!(parsed.is_ok());
546+
assert_eq!(parsed.unwrap().hosts.len(), 2)
547+
}
548+
549+
#[test]
550+
fn test_parsing_empty_hosts_in_client_opts() {
551+
let input = ClientTlsOpts {
552+
component_ids: vec!["component-id-foo".to_string()],
553+
hosts: vec!["".to_string(), "fermyon.com:5443".to_string()],
554+
custom_root_ca_file: None,
555+
cert_chain_file: None,
556+
private_key_file: None,
557+
};
558+
559+
let parsed = parse_client_tls_opts(&input);
560+
assert!(parsed.is_err());
561+
assert_eq!(
562+
"failed to parse uri ''. error: InvalidUri(Empty)",
563+
parsed.unwrap_err().to_string()
564+
)
565+
}
566+
567+
#[test]
568+
fn test_parsing_invalid_hosts_in_client_opts() {
569+
let input = ClientTlsOpts {
570+
component_ids: vec!["component-id-foo".to_string()],
571+
hosts: vec!["perc%ent:443".to_string(), "fermyon.com:5443".to_string()],
572+
custom_root_ca_file: None,
573+
cert_chain_file: None,
574+
private_key_file: None,
575+
};
576+
577+
let parsed = parse_client_tls_opts(&input);
578+
assert!(parsed.is_err());
579+
assert_eq!(
580+
"failed to parse uri 'perc%ent:443'. error: InvalidUri(InvalidAuthority)",
581+
parsed.unwrap_err().to_string()
582+
)
583+
}
584+
534585
fn merge_config_toml(config: &mut RuntimeConfig, value: toml::Value) {
535586
let data = toml::to_vec(&value).expect("encode toml");
536587
let mut file = NamedTempFile::new().expect("temp file");
@@ -581,7 +632,7 @@ fn parse_client_tls_opts(inp: &ClientTlsOpts) -> Result<ParsedClientTlsOpts, any
581632
.into_iter()
582633
.map(|s| {
583634
s.parse::<Authority>()
584-
.map_err(|e| anyhow::anyhow!("failed to parse uri {:?}", e))
635+
.map_err(|e| anyhow::anyhow!("failed to parse uri '{}'. error: {:?}", s, e))
585636
})
586637
.collect::<Result<Vec<Authority>, anyhow::Error>>()?;
587638

0 commit comments

Comments
 (0)