Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for adding member with no key package #980

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions xmtp_mls/src/groups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2963,4 +2963,33 @@ mod tests {
.unwrap();
assert_eq!(alix_member.installation_ids.len(), 1);
}
// This test will start failing when we update the backend to block adding identity updates that
// add installations with no key packages
#[tokio::test(flavor = "multi_thread")]
async fn test_add_member_with_no_key_package() {
// Alix is a normal user
let alix = ClientBuilder::new_test_client(&generate_local_wallet()).await;

// Bo has two installations. One with a key package and one without
let bo_wallet = generate_local_wallet();
let bo_good = ClientBuilder::new_test_client(&bo_wallet).await;
let bo_bad = ClientBuilder::new_test_client_without_key_package(&bo_wallet).await;
assert_eq!(bo_bad.inbox_id(), bo_good.inbox_id());

let alix_group = alix
.create_group(None, GroupMetadataOptions::default())
.unwrap();

// Currently fails here
assert_eq!(
alix_group
.add_members_by_inbox_id(&alix, vec![bo_good.inbox_id()])
.await
.err()
.unwrap()
.to_string(),
"Errors occurred during sync [Client(KeyPackageVerification(TlsError(EndOfStream)))]"
.to_string()
);
}
}
46 changes: 42 additions & 4 deletions xmtp_mls/src/utils/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use rand::{
use std::sync::Arc;
use tokio::{sync::Notify, time::error::Elapsed};
use xmtp_api_grpc::grpc_api_helper::Client as GrpcClient;
use xmtp_id::associations::{generate_inbox_id, RecoverableEcdsaSignature};
use xmtp_id::associations::{
builder::SignatureRequest, generate_inbox_id, RecoverableEcdsaSignature,
};

use crate::{
builder::ClientBuilder,
Expand Down Expand Up @@ -132,6 +134,39 @@ impl ClientBuilder<TestClient> {

client
}

/**
* This will break once a future PR goes in to xmtp-node-go to disallow
* creating a client without a key package.
*/
pub async fn new_test_client_without_key_package(
owner: &impl InboxOwner,
) -> Client<TestClient> {
let nonce = 1;
let inbox_id = generate_inbox_id(&owner.get_address(), &nonce);

let client = Self::new(IdentityStrategy::CreateIfNotFound(
inbox_id,
owner.get_address(),
nonce,
None,
))
.temp_store()
.local_client()
.await
.build()
.await
.unwrap();

let mut signature_request = client.context.signature_request().unwrap();
sign_with_wallet(&mut signature_request, owner).await;
client
.apply_signature_request(signature_request)
.await
.unwrap();

client
}
}

/// wrapper over a `Notify` with a 60-scond timeout for waiting
Expand Down Expand Up @@ -170,16 +205,19 @@ impl Client<TestClient> {
}
}

pub async fn register_client<T: XmtpApi>(client: &Client<T>, owner: &impl InboxOwner) {
let mut signature_request = client.context.signature_request().unwrap();
pub async fn sign_with_wallet(signature_request: &mut SignatureRequest, wallet: &impl InboxOwner) {
let signature_text = signature_request.signature_text();
signature_request
.add_signature(Box::new(RecoverableEcdsaSignature::new(
signature_text.clone(),
owner.sign(&signature_text).unwrap().into(),
wallet.sign(&signature_text).unwrap().into(),
)))
.await
.unwrap();
}

pub async fn register_client<T: XmtpApi>(client: &Client<T>, owner: &impl InboxOwner) {
let mut signature_request = client.context.signature_request().unwrap();
sign_with_wallet(&mut signature_request, owner).await;
client.register_identity(signature_request).await.unwrap();
}
Loading