Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing amqps URL without query params #128

Merged
merged 2 commits into from
May 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions amqprs/src/api/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,17 @@ impl TryFrom<&str> for OpenConnectionArguments {
args.virtual_host(&pu_path[1..]);
}

if scheme == AMQPS_SCHEME {
#[cfg(feature = "tls")]
args.tls_adaptor(
TlsAdaptor::without_client_auth(None, host.to_string())
.map_err(|e| Error::UriError(format!("error creating TLS adaptor: {}", e)))?,
);

#[cfg(not(feature = "tls"))]
return Err(Error::UriError("can't create amqps url without the `tls` feature enabled".to_string()));
}

// Check & apply query
let pu_q = pu.query().map(|v| v.as_str()).ok_or(|| "").unwrap_or("");

Expand Down Expand Up @@ -520,17 +531,6 @@ impl TryFrom<&str> for OpenConnectionArguments {
.unwrap_or(DEFAULT_HEARTBEAT);
args.heartbeat(heartbeat);

if scheme == AMQPS_SCHEME {
#[cfg(feature = "tls")]
args.tls_adaptor(
TlsAdaptor::without_client_auth(None, host.to_string())
.map_err(|e| Error::UriError(format!("error creating TLS adaptor: {}", e)))?,
);

#[cfg(not(feature = "tls"))]
return Err(Error::UriError("can't create amqps url without the `tls` feature enabled".to_string()));
}

Ok(args)
}
}
Expand Down Expand Up @@ -1506,6 +1506,18 @@ mod tests {
assert_eq!(tls_adaptor.domain, "localhost");
}

#[cfg(all(feature = "urispec", feature = "tls"))]
#[test]
fn test_urispec_amqps_simple() {
let args = OpenConnectionArguments::try_from("amqps://localhost")
.unwrap();
assert_eq!(args.host, "localhost");
assert_eq!(args.port, 5671);
assert_eq!(args.virtual_host, "/");
let tls_adaptor = args.tls_adaptor.unwrap();
assert_eq!(tls_adaptor.domain, "localhost");
}

#[cfg(all(feature = "urispec", feature = "tls"))]
#[tokio::test]
#[should_panic(expected = "UriError")]
Expand Down
Loading