Skip to content

Commit

Permalink
Fix wasm tests (#200)
Browse files Browse the repository at this point in the history
* Fix wasm build

* Fix wasm test part 2

* Fix warnings

* fixup

---------

Co-authored-by: Marta Mularczyk <mulmarta@amazon.com>
  • Loading branch information
mulmarta and Marta Mularczyk authored Oct 23, 2024
1 parent 492f03b commit aed6596
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 7 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/wasm_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ env:
CARGO_TERM_COLOR: always
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
WASM_BINDGEN_TEST_TIMEOUT: 1000
RUSTFLAGS: "--cfg mls_build_async"
jobs:
BuildAndTest:
runs-on: [ubuntu-latest]
Expand All @@ -20,9 +21,6 @@ jobs:
- name: WASM mls-rs
working-directory: mls-rs
run: wasm-pack test --headless --chrome --release --lib --test '*' --features test_util
- name: WASM mls-rs-core
working-directory: mls-rs-core
run: wasm-pack test --headless --chrome --release
- name: WASM mls-rs-identity-x509
working-directory: mls-rs-identity-x509
run: wasm-pack test --headless --chrome --release
Expand Down
1 change: 1 addition & 0 deletions mls-rs-core/src/crypto/test_suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use super::{
CipherSuiteProvider, CryptoProvider, HpkeCiphertext, HpkeContextS, HpkePublicKey, HpkeSecretKey,
};

#[cfg(all(not(mls_build_async), not(target_arch = "wasm32"), feature = "std"))]
const PATH: &str = concat!(
env!("CARGO_MANIFEST_DIR"),
"/test_data/crypto_provider.json"
Expand Down
3 changes: 3 additions & 0 deletions mls-rs-crypto-rustcrypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,8 @@ mls-rs-crypto-hpke = { path = "../mls-rs-crypto-hpke", default-features = false,
[target.'cfg(mls_build_async)'.dependencies]
async-trait = "0.1.74"

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
wasm-bindgen-test = { version = "0.3.26", default-features = false }

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(mls_build_async)'] }
10 changes: 10 additions & 0 deletions mls-rs-crypto-rustcrypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ use zeroize::Zeroizing;
use alloc::vec;
use alloc::vec::Vec;

#[cfg(all(test, target_arch = "wasm32"))]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

#[derive(Debug)]
#[cfg_attr(feature = "std", derive(thiserror::Error))]
pub enum RustCryptoError {
Expand Down Expand Up @@ -388,3 +391,10 @@ fn mls_core_tests() {
mls_rs_core::crypto::test_suite::verify_hpke_encap_tests(&mut hpke, cs);
}
}

#[cfg(all(test, target_arch = "wasm32"))]
#[wasm_bindgen_test::wasm_bindgen_test]
async fn mls_rs_core_test() {
let provider = RustCryptoProvider::new();
mls_rs_core::crypto::test_suite::verify_tests(&provider, true).await;
}
4 changes: 2 additions & 2 deletions mls-rs-crypto-webcrypto/src/aead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ impl Aead {
.then_some(())
.ok_or(CryptoError::WrongKeyLength)?;

let mut params = AesGcmParams::new(key_type.algorithm(), &Uint8Array::from(nonce));
let params = AesGcmParams::new(key_type.algorithm(), &Uint8Array::from(nonce));
let aad = Uint8Array::from(aad.unwrap_or_default());
params.additional_data(&aad);
params.set_additional_data(&aad);
let key = key_type.import(&crypto, key).await?;

let out = match key_type {
Expand Down
4 changes: 2 additions & 2 deletions mls-rs-crypto-webcrypto/src/key_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ impl KeyType {
| KeyType::EcdhSecret(curve)
| KeyType::EcdsaPublic(curve)
| KeyType::EcdsaSecret(curve) => {
let mut params = EcKeyImportParams::new(self.algorithm());
params.named_curve(curve);
let params = EcKeyImportParams::new(self.algorithm());
params.set_named_curve(curve);

crypto.import_key_with_object(self.format(), &key, &params, true, &key_usages)?
}
Expand Down
3 changes: 3 additions & 0 deletions mls-rs-identity-x509/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ pub use traits::*;

pub use mls_rs_core::identity::{CertificateChain, DerCertificate};

#[cfg(all(test, target_arch = "wasm32"))]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);

#[derive(Clone, PartialEq, Eq)]
/// X.509 certificate request in DER format.
pub struct DerCertificateRequest(Vec<u8>);
Expand Down

0 comments on commit aed6596

Please sign in to comment.