Skip to content

Commit

Permalink
Allow unit tests to compile for WASM target
Browse files Browse the repository at this point in the history
Also improve diagnostics when attempting to use the incompatible `curl`
feature with WASM.
  • Loading branch information
ramosbugs committed Jan 16, 2023
1 parent e57ce08 commit 64be3c7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 8 additions & 5 deletions src/user_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ mod tests {
#[test]
fn test_additional_claims() {
let claims = UserInfoClaims::<TestClaims, CoreGenderClaim>::from_json::<
crate::reqwest::HttpClientError,
crate::reqwest::AsyncHttpClientError,
>(
"{
\"iss\": \"https://server.example.com\",
Expand All @@ -519,15 +519,18 @@ mod tests {
}",
);

UserInfoClaims::<TestClaims, CoreGenderClaim>::from_json::<crate::reqwest::HttpClientError>(
UserInfoClaims::<TestClaims, CoreGenderClaim>::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)]
Expand All @@ -537,7 +540,7 @@ mod tests {
#[test]
fn test_catch_all_additional_claims() {
let claims = UserInfoClaims::<AllOtherClaims, CoreGenderClaim>::from_json::<
crate::reqwest::HttpClientError,
crate::reqwest::AsyncHttpClientError,
>(
"{
\"iss\": \"https://server.example.com\",
Expand Down
4 changes: 2 additions & 2 deletions src/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1945,7 +1945,7 @@ mod tests {

// JSON response (default args)
assert_eq!(
CoreUserInfoClaims::from_json::<crate::reqwest::HttpClientError>(
CoreUserInfoClaims::from_json::<crate::reqwest::AsyncHttpClientError>(
json_claims.as_bytes(),
Some(&sub)
)
Expand All @@ -1958,7 +1958,7 @@ mod tests {
);

// Invalid subject
match CoreUserInfoClaims::from_json::<crate::reqwest::HttpClientError>(
match CoreUserInfoClaims::from_json::<crate::reqwest::AsyncHttpClientError>(
json_claims.as_bytes(),
Some(&SubjectIdentifier::new("wrong_subject".to_string())),
) {
Expand Down

0 comments on commit 64be3c7

Please sign in to comment.