diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 88ba5a65..6de223a4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,19 +5,18 @@ on: - master pull_request: - jobs: style: name: Format runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Install Rust - uses: dtolnay/rust-toolchain@stable - with: - components: rustfmt - - name: Check format - run: cargo fmt --check + - uses: actions/checkout@v3 + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt + - name: Check format + run: cargo fmt --check clippy: name: Clippy @@ -36,27 +35,49 @@ jobs: matrix: build: [pinned, stable, nightly] include: - - build: pinned - os: ubuntu-20.04 - rust: 1.67.0 - - build: stable - os: ubuntu-20.04 - rust: stable - - build: nightly - os: ubuntu-20.04 - rust: nightly + - build: pinned + os: ubuntu-20.04 + rust: 1.67.0 + - build: stable + os: ubuntu-20.04 + rust: stable + - build: nightly + os: ubuntu-20.04 + rust: nightly steps: - - uses: actions/checkout@v3 - - name: Install Rust - uses: dtolnay/rust-toolchain@master - with: - toolchain: ${{ matrix.rust }} + - uses: actions/checkout@v3 + - name: Install Rust + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ matrix.rust }} + + - name: Build System Info + run: rustc --version + + - name: Run tests default features + run: cargo test + + - name: Run tests no features + run: cargo test --no-default-features + + wasm: + name: Run tests in wasm + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + with: + targets: wasm32-unknown-unknown + + - uses: actions/setup-node@v4 + + - name: Install wasm-pack + run: cargo install wasm-pack - - name: Build System Info - run: rustc --version + - name: Run tests default features + run: wasm-pack test --node - - name: Run tests default features - run: cargo test + - name: Run tests no features + run: wasm-pack test --node --no-default-features - - name: Run tests no features - run: cargo test --no-default-features diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ed1ddc4..5f17e7da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 9.2.0 (2023-12-01) + +- Add an option to not validate `aud` in the Validation struct +- Get the current timestamp in wasm without using std + ## 9.1.0 (2023-10-21) - Supports deserialization of unsupported algorithms for JWKs diff --git a/Cargo.toml b/Cargo.toml index 13e45a51..e3059967 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jsonwebtoken" -version = "9.1.0" +version = "9.2.0" authors = ["Vincent Prouillet "] license = "MIT" readme = "README.md" @@ -9,30 +9,44 @@ homepage = "https://github.com/Keats/jsonwebtoken" repository = "https://github.com/Keats/jsonwebtoken" keywords = ["jwt", "api", "token", "jwk"] edition = "2021" -include = ["src/**/*", "benches/**/*", "tests/**/*", "LICENSE", "README.md", "CHANGELOG.md"] +include = [ + "src/**/*", + "benches/**/*", + "tests/**/*", + "LICENSE", + "README.md", + "CHANGELOG.md", +] rust-version = "1.67.0" [dependencies] serde_json = "1.0" -serde = {version = "1.0", features = ["derive"] } +serde = { version = "1.0", features = ["derive"] } base64 = "0.21.0" # For PEM decoding -pem = {version = "3", optional = true} -simple_asn1 = {version = "0.6", optional = true} +pem = { version = "3", optional = true } +simple_asn1 = { version = "0.6", optional = true } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] ring = { version = "0.17.4", features = ["std"] } - [target.'cfg(target_arch = "wasm32")'.dependencies] js-sys = "0.3" ring = { version = "0.17.4", features = ["std", "wasm32_unknown_unknown_js"] } [dev-dependencies] +wasm-bindgen-test = "0.3.1" + +[target.'cfg(not(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi")))))'.dev-dependencies] # For the custom time example time = "0.3" criterion = "0.4" +[target.'cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))'.dev-dependencies] +# For the custom time example +time = { version = "0.3", features = ["wasm-bindgen"] } +criterion = { version = "0.4", default-features = false } + [features] default = ["use_pem"] use_pem = ["pem", "simple_asn1"] diff --git a/examples/custom_header.rs b/examples/custom_header.rs index 9bda7d39..5041b773 100644 --- a/examples/custom_header.rs +++ b/examples/custom_header.rs @@ -7,7 +7,7 @@ use jsonwebtoken::{decode, encode, Algorithm, DecodingKey, EncodingKey, Header, struct Claims { sub: String, company: String, - exp: usize, + exp: u64, } fn main() { diff --git a/examples/validation.rs b/examples/validation.rs index fdd0c638..392b6b83 100644 --- a/examples/validation.rs +++ b/examples/validation.rs @@ -7,7 +7,7 @@ struct Claims { aud: String, sub: String, company: String, - exp: usize, + exp: u64, } fn main() { diff --git a/src/algorithms.rs b/src/algorithms.rs index 06ad34a0..e162bab2 100644 --- a/src/algorithms.rs +++ b/src/algorithms.rs @@ -84,9 +84,12 @@ impl Algorithm { #[cfg(test)] mod tests { + use wasm_bindgen_test::wasm_bindgen_test; + use super::*; #[test] + #[wasm_bindgen_test] fn generate_algorithm_enum_from_str() { assert!(Algorithm::from_str("HS256").is_ok()); assert!(Algorithm::from_str("HS384").is_ok()); diff --git a/src/errors.rs b/src/errors.rs index cbec36a3..2edd7df5 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -179,9 +179,12 @@ impl From for Error { #[cfg(test)] mod tests { + use wasm_bindgen_test::wasm_bindgen_test; + use super::*; #[test] + #[wasm_bindgen_test] fn test_error_rendering() { assert_eq!( "InvalidAlgorithmName", diff --git a/src/jwk.rs b/src/jwk.rs index d8b709e9..68575e26 100644 --- a/src/jwk.rs +++ b/src/jwk.rs @@ -439,8 +439,10 @@ mod tests { use crate::serialization::b64_encode; use crate::Algorithm; use serde_json::json; + use wasm_bindgen_test::wasm_bindgen_test; #[test] + #[wasm_bindgen_test] fn check_hs256() { let key = b64_encode("abcdefghijklmnopqrstuvwxyz012345"); let jwks_json = json!({ diff --git a/src/validation.rs b/src/validation.rs index eea6eafb..e0d64a7c 100644 --- a/src/validation.rs +++ b/src/validation.rs @@ -346,6 +346,7 @@ where #[cfg(test)] mod tests { use serde_json::json; + use wasm_bindgen_test::wasm_bindgen_test; use super::{get_current_timestamp, validate, ClaimsForValidation, Validation}; @@ -358,6 +359,7 @@ mod tests { } #[test] + #[wasm_bindgen_test] fn exp_in_future_ok() { let claims = json!({ "exp": get_current_timestamp() + 10000 }); let res = validate(deserialize_claims(&claims), &Validation::new(Algorithm::HS256)); @@ -365,6 +367,7 @@ mod tests { } #[test] + #[wasm_bindgen_test] fn exp_float_in_future_ok() { let claims = json!({ "exp": (get_current_timestamp() as f64) + 10000.123 }); let res = validate(deserialize_claims(&claims), &Validation::new(Algorithm::HS256)); @@ -372,6 +375,7 @@ mod tests { } #[test] + #[wasm_bindgen_test] fn exp_in_past_fails() { let claims = json!({ "exp": get_current_timestamp() - 100000 }); let res = validate(deserialize_claims(&claims), &Validation::new(Algorithm::HS256)); @@ -384,6 +388,7 @@ mod tests { } #[test] + #[wasm_bindgen_test] fn exp_float_in_past_fails() { let claims = json!({ "exp": (get_current_timestamp() as f64) - 100000.1234 }); let res = validate(deserialize_claims(&claims), &Validation::new(Algorithm::HS256)); @@ -396,6 +401,7 @@ mod tests { } #[test] + #[wasm_bindgen_test] fn exp_in_past_but_in_leeway_ok() { let claims = json!({ "exp": get_current_timestamp() - 500 }); let mut validation = Validation::new(Algorithm::HS256); @@ -406,6 +412,7 @@ mod tests { // https://github.com/Keats/jsonwebtoken/issues/51 #[test] + #[wasm_bindgen_test] fn validate_required_fields_are_present() { for spec_claim in ["exp", "nbf", "aud", "iss", "sub"] { let claims = json!({}); @@ -417,6 +424,7 @@ mod tests { } #[test] + #[wasm_bindgen_test] fn exp_validated_but_not_required_ok() { let claims = json!({}); let mut validation = Validation::new(Algorithm::HS256); @@ -427,6 +435,7 @@ mod tests { } #[test] + #[wasm_bindgen_test] fn exp_validated_but_not_required_fails() { let claims = json!({ "exp": (get_current_timestamp() as f64) - 100000.1234 }); let mut validation = Validation::new(Algorithm::HS256); @@ -437,6 +446,7 @@ mod tests { } #[test] + #[wasm_bindgen_test] fn exp_required_but_not_validated_ok() { let claims = json!({ "exp": (get_current_timestamp() as f64) - 100000.1234 }); let mut validation = Validation::new(Algorithm::HS256); @@ -447,6 +457,7 @@ mod tests { } #[test] + #[wasm_bindgen_test] fn exp_required_but_not_validated_fails() { let claims = json!({}); let mut validation = Validation::new(Algorithm::HS256); @@ -457,6 +468,7 @@ mod tests { } #[test] + #[wasm_bindgen_test] fn nbf_in_past_ok() { let claims = json!({ "nbf": get_current_timestamp() - 10000 }); let mut validation = Validation::new(Algorithm::HS256); @@ -468,6 +480,7 @@ mod tests { } #[test] + #[wasm_bindgen_test] fn nbf_float_in_past_ok() { let claims = json!({ "nbf": (get_current_timestamp() as f64) - 10000.1234 }); let mut validation = Validation::new(Algorithm::HS256); @@ -479,6 +492,7 @@ mod tests { } #[test] + #[wasm_bindgen_test] fn nbf_in_future_fails() { let claims = json!({ "nbf": get_current_timestamp() + 100000 }); let mut validation = Validation::new(Algorithm::HS256); @@ -495,6 +509,7 @@ mod tests { } #[test] + #[wasm_bindgen_test] fn nbf_in_future_but_in_leeway_ok() { let claims = json!({ "nbf": get_current_timestamp() + 500 }); let mut validation = Validation::new(Algorithm::HS256); @@ -507,6 +522,7 @@ mod tests { } #[test] + #[wasm_bindgen_test] fn iss_string_ok() { let claims = json!({"iss": ["Keats"]}); let mut validation = Validation::new(Algorithm::HS256); @@ -518,6 +534,7 @@ mod tests { } #[test] + #[wasm_bindgen_test] fn iss_array_of_string_ok() { let claims = json!({"iss": ["UserA", "UserB"]}); let mut validation = Validation::new(Algorithm::HS256); @@ -529,6 +546,7 @@ mod tests { } #[test] + #[wasm_bindgen_test] fn iss_not_matching_fails() { let claims = json!({"iss": "Hacked"}); @@ -546,6 +564,7 @@ mod tests { } #[test] + #[wasm_bindgen_test] fn iss_missing_fails() { let claims = json!({}); @@ -562,6 +581,7 @@ mod tests { } #[test] + #[wasm_bindgen_test] fn sub_ok() { let claims = json!({"sub": "Keats"}); let mut validation = Validation::new(Algorithm::HS256); @@ -573,6 +593,7 @@ mod tests { } #[test] + #[wasm_bindgen_test] fn sub_not_matching_fails() { let claims = json!({"sub": "Hacked"}); let mut validation = Validation::new(Algorithm::HS256); @@ -589,6 +610,7 @@ mod tests { } #[test] + #[wasm_bindgen_test] fn sub_missing_fails() { let claims = json!({}); let mut validation = Validation::new(Algorithm::HS256); @@ -605,6 +627,7 @@ mod tests { } #[test] + #[wasm_bindgen_test] fn aud_string_ok() { let claims = json!({"aud": "Everyone"}); let mut validation = Validation::new(Algorithm::HS256); @@ -616,6 +639,7 @@ mod tests { } #[test] + #[wasm_bindgen_test] fn aud_array_of_string_ok() { let claims = json!({"aud": ["UserA", "UserB"]}); let mut validation = Validation::new(Algorithm::HS256); @@ -627,6 +651,7 @@ mod tests { } #[test] + #[wasm_bindgen_test] fn aud_type_mismatch_fails() { let claims = json!({"aud": ["Everyone"]}); let mut validation = Validation::new(Algorithm::HS256); @@ -643,6 +668,7 @@ mod tests { } #[test] + #[wasm_bindgen_test] fn aud_correct_type_not_matching_fails() { let claims = json!({"aud": ["Everyone"]}); let mut validation = Validation::new(Algorithm::HS256); @@ -659,6 +685,7 @@ mod tests { } #[test] + #[wasm_bindgen_test] fn aud_none_fails() { let claims = json!({"aud": ["Everyone"]}); let mut validation = Validation::new(Algorithm::HS256); @@ -675,6 +702,7 @@ mod tests { } #[test] + #[wasm_bindgen_test] fn aud_validation_skipped() { let claims = json!({"aud": ["Everyone"]}); let mut validation = Validation::new(Algorithm::HS256); @@ -687,6 +715,7 @@ mod tests { } #[test] + #[wasm_bindgen_test] fn aud_missing_fails() { let claims = json!({}); let mut validation = Validation::new(Algorithm::HS256); @@ -704,6 +733,7 @@ mod tests { // https://github.com/Keats/jsonwebtoken/issues/51 #[test] + #[wasm_bindgen_test] fn does_validation_in_right_order() { let claims = json!({ "exp": get_current_timestamp() + 10000 }); @@ -724,6 +754,7 @@ mod tests { // https://github.com/Keats/jsonwebtoken/issues/110 #[test] + #[wasm_bindgen_test] fn aud_use_validation_struct() { let claims = json!({"aud": "my-googleclientid1234.apps.googleusercontent.com"}); diff --git a/tests/ecdsa/mod.rs b/tests/ecdsa/mod.rs index bdb51fdb..8c06910f 100644 --- a/tests/ecdsa/mod.rs +++ b/tests/ecdsa/mod.rs @@ -8,6 +8,7 @@ use serde::{Deserialize, Serialize}; use jsonwebtoken::{decode, encode, Header, Validation}; #[cfg(feature = "use_pem")] use time::OffsetDateTime; +use wasm_bindgen_test::wasm_bindgen_test; #[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] pub struct Claims { @@ -17,6 +18,7 @@ pub struct Claims { } #[test] +#[wasm_bindgen_test] fn round_trip_sign_verification_pk8() { let privkey = include_bytes!("private_ecdsa_key.pk8"); let pubkey = include_bytes!("public_ecdsa_key.pk8"); @@ -31,6 +33,7 @@ fn round_trip_sign_verification_pk8() { #[cfg(feature = "use_pem")] #[test] +#[wasm_bindgen_test] fn round_trip_sign_verification_pem() { let privkey_pem = include_bytes!("private_ecdsa_key.pem"); let pubkey_pem = include_bytes!("public_ecdsa_key.pem"); @@ -49,6 +52,7 @@ fn round_trip_sign_verification_pem() { #[cfg(feature = "use_pem")] #[test] +#[wasm_bindgen_test] fn round_trip_claim() { let privkey_pem = include_bytes!("private_ecdsa_key.pem"); let pubkey_pem = include_bytes!("public_ecdsa_key.pem"); @@ -74,6 +78,7 @@ fn round_trip_claim() { #[cfg(feature = "use_pem")] #[test] +#[wasm_bindgen_test] fn ec_x_y() { let privkey = include_str!("private_ecdsa_key.pem"); let my_claims = Claims { @@ -100,6 +105,7 @@ fn ec_x_y() { #[cfg(feature = "use_pem")] #[test] +#[wasm_bindgen_test] fn ed_jwk() { use jsonwebtoken::jwk::Jwk; use serde_json::json; @@ -138,6 +144,7 @@ fn ed_jwk() { // https://jwt.io/ is often used for examples so ensure their example works with jsonwebtoken #[cfg(feature = "use_pem")] #[test] +#[wasm_bindgen_test] fn roundtrip_with_jwtio_example() { // We currently do not support SEC1 so we use the converted PKCS8 formatted let privkey_pem = include_bytes!("private_jwtio_pkcs8.pem"); diff --git a/tests/eddsa/mod.rs b/tests/eddsa/mod.rs index e451a840..85dd0245 100644 --- a/tests/eddsa/mod.rs +++ b/tests/eddsa/mod.rs @@ -3,6 +3,7 @@ use jsonwebtoken::{ Algorithm, DecodingKey, EncodingKey, }; use serde::{Deserialize, Serialize}; +use wasm_bindgen_test::wasm_bindgen_test; #[cfg(feature = "use_pem")] use jsonwebtoken::{decode, encode, Header, Validation}; @@ -17,6 +18,7 @@ pub struct Claims { } #[test] +#[wasm_bindgen_test] fn round_trip_sign_verification_pk8() { let privkey = include_bytes!("private_ed25519_key.pk8"); let pubkey = include_bytes!("public_ed25519_key.pk8"); @@ -31,6 +33,7 @@ fn round_trip_sign_verification_pk8() { #[cfg(feature = "use_pem")] #[test] +#[wasm_bindgen_test] fn round_trip_sign_verification_pem() { let privkey_pem = include_bytes!("private_ed25519_key.pem"); let pubkey_pem = include_bytes!("public_ed25519_key.pem"); @@ -49,6 +52,7 @@ fn round_trip_sign_verification_pem() { #[cfg(feature = "use_pem")] #[test] +#[wasm_bindgen_test] fn round_trip_claim() { let privkey_pem = include_bytes!("private_ed25519_key.pem"); let pubkey_pem = include_bytes!("public_ed25519_key.pem"); @@ -74,6 +78,7 @@ fn round_trip_claim() { #[cfg(feature = "use_pem")] #[test] +#[wasm_bindgen_test] fn ed_x() { let privkey = include_str!("private_ed25519_key.pem"); let my_claims = Claims { @@ -99,6 +104,7 @@ fn ed_x() { #[cfg(feature = "use_pem")] #[test] +#[wasm_bindgen_test] fn ed_jwk() { use jsonwebtoken::jwk::Jwk; use serde_json::json; diff --git a/tests/header/mod.rs b/tests/header/mod.rs index e31cb86e..997a6cb7 100644 --- a/tests/header/mod.rs +++ b/tests/header/mod.rs @@ -1,9 +1,11 @@ use base64::{engine::general_purpose::STANDARD, Engine}; use jsonwebtoken::Header; +use wasm_bindgen_test::wasm_bindgen_test; static CERT_CHAIN: [&str; 3] = include!("cert_chain.json"); #[test] +#[wasm_bindgen_test] fn x5c_der_empty_chain() { let header = Header { x5c: None, ..Default::default() }; assert_eq!(header.x5c_der().unwrap(), None); @@ -13,6 +15,7 @@ fn x5c_der_empty_chain() { } #[test] +#[wasm_bindgen_test] fn x5c_der_valid_chain() { let der_chain: Vec> = CERT_CHAIN.iter().map(|x| STANDARD.decode(x)).collect::>().unwrap(); @@ -24,6 +27,7 @@ fn x5c_der_valid_chain() { } #[test] +#[wasm_bindgen_test] fn x5c_der_invalid_chain() { let mut x5c: Vec<_> = CERT_CHAIN.iter().map(ToString::to_string).collect(); x5c.push("invalid base64 data".to_string()); diff --git a/tests/hmac.rs b/tests/hmac.rs index a6d44642..47ca4484 100644 --- a/tests/hmac.rs +++ b/tests/hmac.rs @@ -6,6 +6,7 @@ use jsonwebtoken::{ }; use serde::{Deserialize, Serialize}; use time::OffsetDateTime; +use wasm_bindgen_test::wasm_bindgen_test; #[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] pub struct Claims { @@ -15,6 +16,7 @@ pub struct Claims { } #[test] +#[wasm_bindgen_test] fn sign_hs256() { let result = sign(b"hello world", &EncodingKey::from_secret(b"secret"), Algorithm::HS256).unwrap(); @@ -23,6 +25,7 @@ fn sign_hs256() { } #[test] +#[wasm_bindgen_test] fn verify_hs256() { let sig = "c0zGLzKEFWj0VxWuufTXiRMk5tlI5MbGDAYhzaxIYjo"; let valid = verify(sig, b"hello world", &DecodingKey::from_secret(b"secret"), Algorithm::HS256) @@ -31,6 +34,7 @@ fn verify_hs256() { } #[test] +#[wasm_bindgen_test] fn encode_with_custom_header() { let my_claims = Claims { sub: "b@b.com".to_string(), @@ -50,6 +54,7 @@ fn encode_with_custom_header() { } #[test] +#[wasm_bindgen_test] fn round_trip_claim() { let my_claims = Claims { sub: "b@b.com".to_string(), @@ -69,6 +74,7 @@ fn round_trip_claim() { } #[test] +#[wasm_bindgen_test] fn decode_token() { let token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJiQGIuY29tIiwiY29tcGFueSI6IkFDTUUiLCJleHAiOjI1MzI1MjQ4OTF9.9r56oF7ZliOBlOAyiOFperTGxBtPykRQiWNFxhDCW98"; let claims = decode::( @@ -81,6 +87,7 @@ fn decode_token() { } #[test] +#[wasm_bindgen_test] #[should_panic(expected = "InvalidToken")] fn decode_token_missing_parts() { let token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"; @@ -93,6 +100,7 @@ fn decode_token_missing_parts() { } #[test] +#[wasm_bindgen_test] #[should_panic(expected = "InvalidSignature")] fn decode_token_invalid_signature() { let token = @@ -106,6 +114,7 @@ fn decode_token_invalid_signature() { } #[test] +#[wasm_bindgen_test] #[should_panic(expected = "InvalidAlgorithm")] fn decode_token_wrong_algorithm() { let token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJiQGIuY29tIiwiY29tcGFueSI6IkFDTUUifQ.I1BvFoHe94AFf09O6tDbcSB8-jp8w6xZqmyHIwPeSdY"; @@ -118,6 +127,7 @@ fn decode_token_wrong_algorithm() { } #[test] +#[wasm_bindgen_test] #[should_panic(expected = "InvalidAlgorithm")] fn encode_wrong_alg_family() { let my_claims = Claims { @@ -130,6 +140,7 @@ fn encode_wrong_alg_family() { } #[test] +#[wasm_bindgen_test] fn decode_token_with_bytes_secret() { let token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJiQGIuY29tIiwiY29tcGFueSI6IkFDTUUiLCJleHAiOjI1MzI1MjQ4OTF9.Hm0yvKH25TavFPz7J_coST9lZFYH1hQo0tvhvImmaks"; let claims = decode::( @@ -141,6 +152,7 @@ fn decode_token_with_bytes_secret() { } #[test] +#[wasm_bindgen_test] fn decode_header_only() { let token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjb21wYW55IjoiMTIzNDU2Nzg5MCIsInN1YiI6IkpvaG4gRG9lIn0.S"; let header = decode_header(token).unwrap(); @@ -149,6 +161,7 @@ fn decode_header_only() { } #[test] +#[wasm_bindgen_test] fn dangerous_insecure_decode_valid_token() { let token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJiQGIuY29tIiwiY29tcGFueSI6IkFDTUUiLCJleHAiOjI1MzI1MjQ4OTF9.9r56oF7ZliOBlOAyiOFperTGxBtPykRQiWNFxhDCW98"; let mut validation = Validation::new(Algorithm::HS256); @@ -158,6 +171,7 @@ fn dangerous_insecure_decode_valid_token() { } #[test] +#[wasm_bindgen_test] fn dangerous_insecure_decode_token_invalid_signature() { let token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJiQGIuY29tIiwiY29tcGFueSI6IkFDTUUiLCJleHAiOjI1MzI1MjQ4OTF9.wrong"; let mut validation = Validation::new(Algorithm::HS256); @@ -167,6 +181,7 @@ fn dangerous_insecure_decode_token_invalid_signature() { } #[test] +#[wasm_bindgen_test] fn dangerous_insecure_decode_token_wrong_algorithm() { let token = "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJiQGIuY29tIiwiY29tcGFueSI6IkFDTUUiLCJleHAiOjI1MzI1MjQ4OTF9.fLxey-hxAKX5rNHHIx1_Ch0KmrbiuoakDVbsJjLWrx8fbjKjrPuWMYEJzTU3SBnYgnZokC-wqSdqckXUOunC-g"; let mut validation = Validation::new(Algorithm::HS256); @@ -176,6 +191,7 @@ fn dangerous_insecure_decode_token_wrong_algorithm() { } #[test] +#[wasm_bindgen_test] fn dangerous_insecure_decode_token_with_validation_wrong_algorithm() { let token = "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJiQGIuY29tIiwiY29tcGFueSI6IkFDTUUiLCJleHAiOjk1MzI1MjQ4OX0.ONtEUTtP1QmyksYH9ijtPCaXoHjZVHcHKZGX1DuJyPiSyKlT93Y-oKgrp_OSkHSu4huxCcVObLzwsdwF-xwiAQ"; let mut validation = Validation::new(Algorithm::HS256); @@ -186,6 +202,7 @@ fn dangerous_insecure_decode_token_with_validation_wrong_algorithm() { } #[test] +#[wasm_bindgen_test] fn verify_hs256_rfc7517_appendix_a1() { #[derive(Debug, PartialEq, Eq, Clone, Deserialize)] struct C { diff --git a/tests/rsa/mod.rs b/tests/rsa/mod.rs index ea411a1f..3297149f 100644 --- a/tests/rsa/mod.rs +++ b/tests/rsa/mod.rs @@ -3,6 +3,7 @@ use jsonwebtoken::{ Algorithm, DecodingKey, EncodingKey, }; use serde::{Deserialize, Serialize}; +use wasm_bindgen_test::wasm_bindgen_test; #[cfg(feature = "use_pem")] use jsonwebtoken::{decode, encode, Header, Validation}; @@ -27,6 +28,7 @@ pub struct Claims { #[cfg(feature = "use_pem")] #[test] +#[wasm_bindgen_test] fn round_trip_sign_verification_pem_pkcs1() { let privkey_pem = include_bytes!("private_rsa_key_pkcs1.pem"); let pubkey_pem = include_bytes!("public_rsa_key_pkcs1.pem"); @@ -58,6 +60,7 @@ fn round_trip_sign_verification_pem_pkcs1() { #[cfg(feature = "use_pem")] #[test] +#[wasm_bindgen_test] fn round_trip_sign_verification_pem_pkcs8() { let privkey_pem = include_bytes!("private_rsa_key_pkcs8.pem"); let pubkey_pem = include_bytes!("public_rsa_key_pkcs8.pem"); @@ -88,6 +91,7 @@ fn round_trip_sign_verification_pem_pkcs8() { } #[test] +#[wasm_bindgen_test] fn round_trip_sign_verification_der() { let privkey_der = include_bytes!("private_rsa_key.der"); let pubkey_der = include_bytes!("public_rsa_key.der"); @@ -103,6 +107,7 @@ fn round_trip_sign_verification_der() { #[cfg(feature = "use_pem")] #[test] +#[wasm_bindgen_test] fn round_trip_claim() { let my_claims = Claims { sub: "b@b.com".to_string(), @@ -139,6 +144,7 @@ fn round_trip_claim() { #[cfg(feature = "use_pem")] #[test] +#[wasm_bindgen_test] fn rsa_modulus_exponent() { let privkey = include_str!("private_rsa_key_pkcs1.pem"); let my_claims = Claims { @@ -165,6 +171,7 @@ fn rsa_modulus_exponent() { #[cfg(feature = "use_pem")] #[test] +#[wasm_bindgen_test] fn rsa_jwk() { use jsonwebtoken::jwk::Jwk; use serde_json::json; @@ -201,6 +208,7 @@ fn rsa_jwk() { // https://jwt.io/ is often used for examples so ensure their example works with jsonwebtoken #[cfg(feature = "use_pem")] #[test] +#[wasm_bindgen_test] fn roundtrip_with_jwtio_example_jey() { let privkey_pem = include_bytes!("private_jwtio.pem"); let pubkey_pem = include_bytes!("public_jwtio.pem");