diff --git a/integration/ssl/error_self_signed_certificate.err b/integration/ssl/error_self_signed_certificate.err index 9c8e3f93827..55e342d9c30 100644 --- a/integration/ssl/error_self_signed_certificate.err +++ b/integration/ssl/error_self_signed_certificate.err @@ -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 | diff --git a/packages/hurl/src/http/client.rs b/packages/hurl/src/http/client.rs index 198f9fc0649..4944020702f 100644 --- a/packages/hurl/src/http/client.rs +++ b/packages/hurl/src/http/client.rs @@ -36,7 +36,7 @@ pub enum HttpError { FailToConnect, TooManyRedirect, CouldNotParseResponse, - SSLCertificate, + SSLCertificate(Option), InvalidUrl, Timeout, StatuslineIsMissing, @@ -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(), diff --git a/packages/hurl/src/runner/core.rs b/packages/hurl/src/runner/core.rs index f1ce052568c..864917956ea 100644 --- a/packages/hurl/src/runner/core.rs +++ b/packages/hurl/src/runner/core.rs @@ -133,7 +133,7 @@ pub enum RunnerError { Timeout, TooManyRedirect, CouldNotParseResponse, - SSLCertificate, + SSLCertificate(String), UnsupportedContentEncoding(String), CouldNotUncompressResponse(String), diff --git a/packages/hurl/src/runner/entry.rs b/packages/hurl/src/runner/entry.rs index a8fa81e37e9..6b0995b67b4 100644 --- a/packages/hurl/src/runner/entry.rs +++ b/packages/hurl/src/runner/entry.rs @@ -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(), diff --git a/packages/hurl/src/runner/error.rs b/packages/hurl/src/runner/error.rs index f841d6e0a41..9c6bf825387 100644 --- a/packages/hurl/src/runner/error.rs +++ b/packages/hurl/src/runner/error.rs @@ -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(), @@ -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) => { diff --git a/packages/hurl/tests/libcurl.rs b/packages/hurl/tests/libcurl.rs index becea4f005a..3e95ff13914 100644 --- a/packages/hurl/tests/libcurl.rs +++ b/packages/hurl/tests/libcurl.rs @@ -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 {