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

Be more specific for SSL Certificate errors #148

Merged
merged 1 commit into from
Feb 7, 2021
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions integration/ssl/error_self_signed_certificate.err
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error: Http Connection
error: SSL Certificate
--> ssl/error_self_signed_certificate.hurl:1:5
|
1 | GET https://localhost:8001/hello
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SSL certificate problem
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SSL certificate problem: self signed certificate
|

6 changes: 4 additions & 2 deletions packages/hurl/src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub enum HttpError {
FailToConnect,
TooManyRedirect,
CouldNotParseResponse,
SSLCertificate,
SSLCertificate(Option<String>),
InvalidUrl,
Timeout,
StatuslineIsMissing,
Expand Down Expand Up @@ -201,7 +201,9 @@ impl Client {
6 => Err(HttpError::CouldNotResolveHost),
7 => Err(HttpError::FailToConnect),
28 => Err(HttpError::Timeout),
60 => Err(HttpError::SSLCertificate),
60 => Err(HttpError::SSLCertificate(
e.extra_description().map(String::from),
)),
_ => Err(HttpError::Other {
code: e.code() as i32, // due to windows build
description: e.description().to_string(),
Expand Down
2 changes: 1 addition & 1 deletion packages/hurl/src/runner/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub enum RunnerError {
Timeout,
TooManyRedirect,
CouldNotParseResponse,
SSLCertificate,
SSLCertificate(String),

UnsupportedContentEncoding(String),
CouldNotUncompressResponse(String),
Expand Down
4 changes: 3 additions & 1 deletion packages/hurl/src/runner/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ pub fn run(
HttpError::Timeout => RunnerError::Timeout,
HttpError::TooManyRedirect => RunnerError::TooManyRedirect,
HttpError::CouldNotParseResponse => RunnerError::CouldNotParseResponse,
HttpError::SSLCertificate => RunnerError::SSLCertificate,
HttpError::SSLCertificate(description) => RunnerError::SSLCertificate(
description.unwrap_or_else(|| "SSL certificate problem".to_string()),
),
HttpError::InvalidUrl => RunnerError::InvalidURL(http_request.url.clone()),
HttpError::StatuslineIsMissing => RunnerError::HttpConnection {
message: "status line is missing".to_string(),
Expand Down
4 changes: 2 additions & 2 deletions packages/hurl/src/runner/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl Error for runner::Error {
RunnerError::Timeout => "Http Connection".to_string(),
RunnerError::TooManyRedirect => "Http Connection".to_string(),
RunnerError::CouldNotParseResponse => "Http Connection".to_string(),
RunnerError::SSLCertificate => "Http Connection".to_string(),
RunnerError::SSLCertificate { .. } => "SSL Certificate".to_string(),
RunnerError::PredicateValue { .. } => "Assert - Predicate Value Failed".to_string(),
RunnerError::InvalidRegex {} => "Invalid regex".to_string(),
RunnerError::FileReadAccess { .. } => "File ReadAccess".to_string(),
Expand Down Expand Up @@ -67,7 +67,7 @@ impl Error for runner::Error {
RunnerError::Timeout => "Timeout has been reached".to_string(),
RunnerError::TooManyRedirect => "Too many redirect".to_string(),
RunnerError::CouldNotParseResponse => "Could not parse response".to_string(),
RunnerError::SSLCertificate => "SSL certificate problem".to_string(),
RunnerError::SSLCertificate(description) => description.clone(),
RunnerError::AssertVersion { actual, .. } => format!("actual value is <{}>", actual),
RunnerError::AssertStatus { actual, .. } => format!("actual value is <{}>", actual),
RunnerError::PredicateValue(value) => {
Expand Down
26 changes: 26 additions & 0 deletions packages/hurl/tests/libcurl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,32 @@ fn test_error_could_not_resolve_proxy_name() {
assert_eq!(error, HttpError::CouldNotResolveProxyName);
}

#[test]
fn test_error_ssl() {
let options = ClientOptions {
follow_location: false,
max_redirect: None,
cookie_input_file: None,
proxy: None,
no_proxy: None,
verbose: false,
insecure: false,
timeout: Default::default(),
connect_timeout: Default::default(),
user: None,
accept_encoding: None,
};
let mut client = Client::init(options);
let request = default_get_request("https://localhost:8001/hello".to_string());
let error = client.execute(&request, 0).err().unwrap();
assert_eq!(
error,
HttpError::SSLCertificate(Some(
"SSL certificate problem: self signed certificate".to_string()
))
);
}

#[test]
fn test_timeout() {
let options = ClientOptions {
Expand Down