From 64be3c7636bc6f745a9b33f0702950bbacca318c Mon Sep 17 00:00:00 2001 From: "David A. Ramos" Date: Sun, 15 Jan 2023 19:07:51 -0800 Subject: [PATCH] Allow unit tests to compile for WASM target Also improve diagnostics when attempting to use the incompatible `curl` feature with WASM. --- src/lib.rs | 5 ++++- src/user_info.rs | 13 ++++++++----- src/verification.rs | 4 ++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d12e6d2e..26aa041b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -602,9 +602,12 @@ pub use oauth2::{ pub use oauth2::http; pub use oauth2::url; -#[cfg(feature = "curl")] +#[cfg(all(feature = "curl", not(target_arch = "wasm32")))] pub use oauth2::curl; +#[cfg(all(feature = "curl", target_arch = "wasm32"))] +compile_error!("wasm32 is not supported with the `curl` feature. Use the `reqwest` backend or a custom backend for wasm32 support"); + #[cfg(feature = "reqwest")] pub use oauth2::reqwest; diff --git a/src/user_info.rs b/src/user_info.rs index 5066c859..5f8f5b25 100644 --- a/src/user_info.rs +++ b/src/user_info.rs @@ -496,7 +496,7 @@ mod tests { #[test] fn test_additional_claims() { let claims = UserInfoClaims::::from_json::< - crate::reqwest::HttpClientError, + crate::reqwest::AsyncHttpClientError, >( "{ \"iss\": \"https://server.example.com\", @@ -519,15 +519,18 @@ mod tests { }", ); - UserInfoClaims::::from_json::( + UserInfoClaims::::from_json::< + crate::reqwest::AsyncHttpClientError, + >( "{ \"iss\": \"https://server.example.com\", \"sub\": \"24400320\", \"aud\": [\"s6BhdRkqt3\"] - }".as_bytes(), + }" + .as_bytes(), None, ) - .expect_err("missing claim should fail to deserialize"); + .expect_err("missing claim should fail to deserialize"); } #[derive(Debug, Deserialize, Serialize)] @@ -537,7 +540,7 @@ mod tests { #[test] fn test_catch_all_additional_claims() { let claims = UserInfoClaims::::from_json::< - crate::reqwest::HttpClientError, + crate::reqwest::AsyncHttpClientError, >( "{ \"iss\": \"https://server.example.com\", diff --git a/src/verification.rs b/src/verification.rs index 2a41b9e2..6bd219c6 100644 --- a/src/verification.rs +++ b/src/verification.rs @@ -1945,7 +1945,7 @@ mod tests { // JSON response (default args) assert_eq!( - CoreUserInfoClaims::from_json::( + CoreUserInfoClaims::from_json::( json_claims.as_bytes(), Some(&sub) ) @@ -1958,7 +1958,7 @@ mod tests { ); // Invalid subject - match CoreUserInfoClaims::from_json::( + match CoreUserInfoClaims::from_json::( json_claims.as_bytes(), Some(&SubjectIdentifier::new("wrong_subject".to_string())), ) {