Skip to content

Commit

Permalink
Update reqwest requirement from 0.11 to 0.12 (#244)
Browse files Browse the repository at this point in the history
* Update reqwest requirement from 0.11 to 0.12

Updates the requirements on [reqwest](https://github.com/seanmonstar/reqwest) to permit the latest version.
- [Release notes](https://github.com/seanmonstar/reqwest/releases)
- [Changelog](https://github.com/seanmonstar/reqwest/blob/master/CHANGELOG.md)
- [Commits](seanmonstar/reqwest@v0.11.0...v0.12.2)

---
updated-dependencies:
- dependency-name: reqwest
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update changelog

Signed-off-by: dependabot[bot] <support@github.com>

* Fix untrusted cert tests

Signed-off-by: Thomas Farr <tsfarr@amazon.com>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Thomas Farr <tsfarr@amazon.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: dependabot[bot] <dependabot[bot]@users.noreply.github.com>
Co-authored-by: Thomas Farr <tsfarr@amazon.com>
(cherry picked from commit a0f1c9c)
  • Loading branch information
dependabot[bot] authored and github-actions[bot] committed Apr 8, 2024
1 parent e42b5db commit b73ad70
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 116 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Bumps `hyper` from 0.14 to 1 in tests ([#221](https://github.com/opensearch-project/opensearch-rs/pull/221))
- Bumps `sysinfo` from 0.29.0 to 0.30.5
- Bumps `base64` from 0.21 to 0.22
- Bumps `reqwest` from 0.11 to 0.12

### Changed

Expand Down
2 changes: 1 addition & 1 deletion api_generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ proc-macro2 = "1.0"
quote = "1.0"
reduce = "0.1.2"
regex = "1.3.1"
reqwest = { version = "0.11", features = ["blocking"] }
reqwest = { version = "0.12", features = ["blocking"] }
semver = "1.0.14"
serde = { version = "1", features = ["derive"] }
serde_json = "~1"
Expand Down
2 changes: 1 addition & 1 deletion opensearch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ bytes = "1.0"
dyn-clone = "1"
lazy_static = "1.4"
percent-encoding = "2.1.0"
reqwest = { version = "0.11", default-features = false, features = ["gzip", "json"] }
reqwest = { version = "0.12", default-features = false, features = ["gzip", "json"] }
url = "2.1"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
Expand Down
151 changes: 38 additions & 113 deletions opensearch/tests/cert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,74 +28,50 @@ pub mod common;
use common::*;

use anyhow::anyhow;
use opensearch::cert::{Certificate, CertificateValidation};
use opensearch::{
cert::{Certificate, CertificateValidation},
http::response::Response,
Error,
};

static CA_CERT: &[u8] = include_bytes!("../../.ci/certs/root-ca.crt");
static CA_CHAIN_CERT: &[u8] = include_bytes!("../../.ci/certs/ca-chain.crt");
static ESNODE_CERT: &[u8] = include_bytes!("../../.ci/certs/esnode.crt");
static ESNODE_NO_SAN_CERT: &[u8] = include_bytes!("../../.ci/certs/esnode-no-san.crt");

#[cfg(feature = "native-tls")]
fn expected_error_message() -> &'static str {
if cfg!(windows) {
fn assert_is_untrusted_cert_error(res: Result<Response, Error>) {
let e = res.expect_err("Result should be an untrusted cert error");

let untrusted_cert_error = if cfg!(windows) {
"terminated in a root certificate which is not trusted by the trust provider"
} else if cfg!(target_os = "macos") {
"The certificate was not trusted"
} else {
"unable to get local issuer certificate"
}
}

/// Default certificate validation with a self signed certificate
#[tokio::test]
#[cfg(feature = "native-tls")]
async fn default_certificate_validation() -> anyhow::Result<()> {
let client = client::create_with(|b| b.cert_validation(CertificateValidation::Default));
};

match client.ping().send().await {
Ok(response) => Err(anyhow!(
"Expected error but response was {}",
response.status_code()
)),
Err(e) => {
let expected = expected_error_message();
let actual = e.to_string();
match actual.contains(expected) {
true => Ok(()),
false => Err(anyhow!(
"Expected error message to contain '{}' but was '{}'",
expected,
actual
)),
}
let mut source: Option<&dyn std::error::Error> = Some(&e);
while let Some(err) = source {
if err.to_string().contains(untrusted_cert_error) {
return;
}

source = err.source();
}

panic!(
"Expected error message to contain '{}' but was {:#?}",
untrusted_cert_error, e
)
}

/// Default certificate validation with a self signed certificate and rustls-tls
/// Default certificate validation with a self signed certificate
#[tokio::test]
#[cfg(all(feature = "rustls-tls", not(feature = "native-tls")))]
async fn default_certificate_validation_rustls_tls() -> anyhow::Result<()> {
#[cfg(any(feature = "native-tls", feature = "rustls-tls"))]
async fn default_certificate_validation() {
let client = client::create_with(|b| b.cert_validation(CertificateValidation::Default));

match client.ping().send().await {
Ok(response) => Err(anyhow!(
"Expected error but response was {}",
response.status_code()
)),
Err(e) => {
let expected = expected_error_message();
let actual = e.to_string();
match actual.contains(expected) {
true => Ok(()),
false => Err(anyhow!(
"Expected error message to contain '{}' but was '{}'",
expected,
actual
)),
}
}
}
let res = client.ping().send().await;
assert_is_untrusted_cert_error(res);
}

/// Allows any certificate through
Expand Down Expand Up @@ -163,28 +139,11 @@ async fn full_certificate_validation_rustls_tls() -> anyhow::Result<()> {
/// it appears that it also needs the CA for the cert
#[tokio::test]
#[cfg(all(unix, feature = "native-tls"))]
async fn full_certificate_validation() -> anyhow::Result<()> {
let cert = Certificate::from_pem(ESNODE_CERT)?;
async fn full_certificate_validation() {
let cert = Certificate::from_pem(ESNODE_CERT).unwrap();
let client = client::create_with(|b| b.cert_validation(CertificateValidation::Full(cert)));

match client.ping().send().await {
Ok(response) => Err(anyhow!(
"Expected error but response was {}",
response.status_code()
)),
Err(e) => {
let expected = expected_error_message();
let actual = e.to_string();
match actual.contains(expected) {
true => Ok(()),
false => Err(anyhow!(
"Expected error message to contain '{}' but was '{}'",
expected,
actual
)),
}
}
}
let res = client.ping().send().await;
assert_is_untrusted_cert_error(res);
}

/// Certificate provided by the server is the one given to the client
Expand All @@ -202,29 +161,12 @@ async fn certificate_certificate_validation() -> anyhow::Result<()> {
/// it appears that it also needs the CA for the cert
#[tokio::test]
#[cfg(all(unix, feature = "native-tls"))]
async fn certificate_certificate_validation() -> anyhow::Result<()> {
let cert = Certificate::from_pem(ESNODE_CERT)?;
async fn certificate_certificate_validation() {
let cert = Certificate::from_pem(ESNODE_CERT).unwrap();
let client =
client::create_with(|b| b.cert_validation(CertificateValidation::Certificate(cert)));

match client.ping().send().await {
Ok(response) => Err(anyhow!(
"Expected error but response was {}",
response.status_code()
)),
Err(e) => {
let expected = expected_error_message();
let actual = e.to_string();
match actual.contains(expected) {
true => Ok(()),
false => Err(anyhow!(
"Expected error message to contain '{}' but was '{}'",
expected,
actual
)),
}
}
}
let res = client.ping().send().await;
assert_is_untrusted_cert_error(res);
}

/// Certificate provided by the server contains the one given to the client
Expand All @@ -242,27 +184,10 @@ async fn certificate_certificate_ca_validation() -> anyhow::Result<()> {
/// Certificate provided by the server does not match the one given to the client
#[tokio::test]
#[cfg(feature = "native-tls")]
async fn fail_certificate_certificate_validation() -> anyhow::Result<()> {
let cert = Certificate::from_pem(ESNODE_NO_SAN_CERT)?;
async fn fail_certificate_certificate_validation() {
let cert = Certificate::from_pem(ESNODE_NO_SAN_CERT).unwrap();
let client =
client::create_with(|b| b.cert_validation(CertificateValidation::Certificate(cert)));

match client.ping().send().await {
Ok(response) => Err(anyhow!(
"Expected error but response was {}",
response.status_code()
)),
Err(e) => {
let expected = expected_error_message();
let actual = e.to_string();
match actual.contains(expected) {
true => Ok(()),
false => Err(anyhow!(
"Expected error message to contain '{}' but was '{}'",
expected,
actual
)),
}
}
}
let res = client.ping().send().await;
assert_is_untrusted_cert_error(res);
}
2 changes: 1 addition & 1 deletion yaml_test_runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ path-slash = "0.2"
proc-macro2 = "1.0"
quote = "1.0"
regex = "1.3.1"
reqwest = { version = "0.11", features = ["blocking"] }
reqwest = { version = "0.12", features = ["blocking"] }
semver = "1.0"
serde = "1"
serde_yaml = "0.9"
Expand Down

0 comments on commit b73ad70

Please sign in to comment.