Add a convenience method to check if we have all cross-signing keys

This commit is contained in:
Damir Jelić
2023-09-26 12:52:42 +02:00
parent dc92ce8b40
commit cd310d52d4
2 changed files with 56 additions and 0 deletions

View File

@@ -109,6 +109,13 @@ pub struct CrossSigningStatus {
pub has_user_signing: bool,
}
impl CrossSigningStatus {
/// Do we have all the cross signing keys locally stored.
pub fn is_complete(&self) -> bool {
self.has_master && self.has_user_signing && self.has_self_signing
}
}
impl PrivateCrossSigningIdentity {
/// Get the user id that this identity belongs to.
pub fn user_id(&self) -> &UserId {

View File

@@ -526,3 +526,52 @@ async fn get_own_device() {
"The device ID of the client and our own device should match"
);
}
#[cfg(feature = "e2e-encryption")]
#[async_test]
async fn cross_signing_status() {
let (client, server) = logged_in_client().await;
Mock::given(method("POST"))
.and(path("/_matrix/client/unstable/keys/device_signing/upload"))
.respond_with(ResponseTemplate::new(200).set_body_json(json!({})))
.expect(1)
.mount(&server)
.await;
Mock::given(method("POST"))
.and(path("/_matrix/client/unstable/keys/signatures/upload"))
.respond_with(ResponseTemplate::new(200).set_body_json(json!({
"failures": {}
})))
.mount(&server)
.await;
let status = client
.encryption()
.cross_signing_status()
.await
.expect("We should be able to fetch our cross-signing status");
assert!(
!status.has_master && !status.has_self_signing && !status.has_user_signing,
"Initially we shouldn't have any cross-signing keys"
);
client.encryption().bootstrap_cross_signing(None).await.unwrap();
client
.encryption()
.cross_signing_status()
.await
.expect("We should be able to fetch our cross-signing status");
let status = client
.encryption()
.cross_signing_status()
.await
.expect("We should have the private cross-signing keys after the bootstrap process");
assert!(status.is_complete(), "We should have all the private cross-signing keys locally");
server.verify().await;
}