mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-07 23:44:53 -04:00
Add a convenience method to check if we have all cross-signing keys
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user