Skip to content

Commit 9928c26

Browse files
committed
test(crypto-js): Add test for in-room verification (w/ RoomMessageRequest).
1 parent 47262e3 commit 9928c26

File tree

3 files changed

+191
-3
lines changed

3 files changed

+191
-3
lines changed

src/identities.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl UserIdentity {
130130
}
131131

132132
/// Create a `VerificationRequest` object after the verification
133-
/// request content has been sent out. }
133+
/// request content has been sent out.
134134
#[wasm_bindgen(js_name = "requestVerification")]
135135
pub fn request_verification(
136136
&self,

src/machine.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,15 @@ impl OlmMachine {
638638
/// This method can be used to pass verification events that are happening
639639
/// in rooms to the `OlmMachine`. The event should be in the decrypted form.
640640
#[wasm_bindgen(js_name = "receiveVerificationEvent")]
641-
pub fn receive_verification_event(&self, event: &str) -> Result<Promise, JsError> {
642-
let event: ruma::events::AnyMessageLikeEvent = serde_json::from_str(event)?;
641+
pub fn receive_verification_event(
642+
&self,
643+
event: &str,
644+
room_id: &identifiers::RoomId,
645+
) -> Result<Promise, JsError> {
646+
let room_id = room_id.inner.clone();
647+
let event: ruma::events::AnySyncMessageLikeEvent = serde_json::from_str(event)?;
648+
let event = event.into_full_event(room_id);
649+
643650
let me = self.inner.clone();
644651

645652
Ok(future_to_promise(async move {

tests/machine.test.js

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const {
55
DeviceKeyId,
66
DeviceLists,
77
EncryptionSettings,
8+
EventId,
89
InboundGroupSession,
910
KeysClaimRequest,
1011
KeysQueryRequest,
@@ -14,9 +15,11 @@ const {
1415
OwnUserIdentity,
1516
RequestType,
1617
RoomId,
18+
RoomMessageRequest,
1719
SignatureUploadRequest,
1820
ToDeviceRequest,
1921
UserId,
22+
UserIdentity,
2023
VerificationRequest,
2124
VerificationState,
2225
} = require('../pkg/matrix_sdk_crypto_js');
@@ -624,4 +627,182 @@ describe(OlmMachine.name, () => {
624627
});
625628
});
626629
});
630+
631+
describe('can do in-room verification', () => {
632+
let m;
633+
const user = new UserId('@alice:example.org');
634+
const device = new DeviceId('JLAFKJWSCS');
635+
const room = new RoomId('!test:localhost');
636+
637+
beforeAll(async () => {
638+
m = await machine(user, device);
639+
});
640+
641+
test('can inject devices from someone else', async () => {
642+
{
643+
const hypothetical_response = JSON.stringify({
644+
"device_keys": {
645+
"@example:morpheus.localhost": {
646+
"ATRLDCRXAC": {
647+
"algorithms": [
648+
"m.olm.v1.curve25519-aes-sha2",
649+
"m.megolm.v1.aes-sha2"
650+
],
651+
"device_id": "ATRLDCRXAC",
652+
"keys": {
653+
"curve25519:ATRLDCRXAC": "cAVT5Es3Z3F5pFD+2w3HT7O9+R3PstzYVkzD51X/FWQ",
654+
"ed25519:ATRLDCRXAC": "V2w/T/x7i7AXiCCtS6JldrpbvRliRoef3CqTUNqMRHA"
655+
},
656+
"signatures": {
657+
"@example:morpheus.localhost": {
658+
"ed25519:ATRLDCRXAC": "ro2BjO5J6089B/JOANHnFmGrogrC2TIdMlgJbJO00DjOOcGxXfvOezCFIORTwZNHvkHU617YIGl/4keTDIWvBQ"
659+
}
660+
},
661+
"user_id": "@example:morpheus.localhost",
662+
"unsigned": {
663+
"device_display_name": "Element Desktop: Linux"
664+
}
665+
},
666+
"EYYGYTCTNC": {
667+
"algorithms": [
668+
"m.olm.v1.curve25519-aes-sha2",
669+
"m.megolm.v1.aes-sha2"
670+
],
671+
"device_id": "EYYGYTCTNC",
672+
"keys": {
673+
"curve25519:EYYGYTCTNC": "Pqu50fo472wgb6NjKkaUxjuqoAIEAmhln2gw/zSQ7Ek",
674+
"ed25519:EYYGYTCTNC": "Pf/2QPvui8lDty6TCTglVPRVM+irNHYavNNkyv5yFpU"
675+
},
676+
"signatures": {
677+
"@example:morpheus.localhost": {
678+
"ed25519:EYYGYTCTNC": "pnP5BYLEUUaxDgrvdzCznkjNDbvY1/MFBr1JejdnLiXlcmxRULQpIWZUCO7QTbULsCwMsYQNGn50nfmjBQX3CQ"
679+
}
680+
},
681+
"user_id": "@example:morpheus.localhost",
682+
"unsigned": {
683+
"device_display_name": "WeeChat-Matrix-rs"
684+
}
685+
},
686+
"SUMODVLSIU": {
687+
"algorithms": [
688+
"m.olm.v1.curve25519-aes-sha2",
689+
"m.megolm.v1.aes-sha2"
690+
],
691+
"device_id": "SUMODVLSIU",
692+
"keys": {
693+
"curve25519:SUMODVLSIU": "geQXWGWc++gcUHk0JcFmEVSjyzDOnk2mjVsUQwbNqQU",
694+
"ed25519:SUMODVLSIU": "ccktaQ3g+B18E6FwVhTBYie26OlHbvDUzDEtxOQ4Qcs"
695+
},
696+
"signatures": {
697+
"@example:morpheus.localhost": {
698+
"ed25519:SUMODVLSIU": "Yn+AOxHRt1GQpY2xT2Jcqqn8jh5+Vw23ctA7NXyDiWPsLPLNTpjGWHMjZdpUqflQvpiKfhODPICoIa7Pu0iSAg",
699+
"ed25519:rUiMNDjIu6gqsrhJPbj3phyIzuEtuQGrLOEa9mCbtTM": "Cio6k/sq289XNTOvTCWre7Q6zg+A3euzMUe7Uy1T3gPqYFzX+kt7EAxrhbPqx1HyXAEz9zD0D/uw9VEXFCvWBQ"
700+
}
701+
},
702+
"user_id": "@example:morpheus.localhost",
703+
"unsigned": {
704+
"device_display_name": "Element Desktop (Linux)"
705+
}
706+
}
707+
}
708+
},
709+
"failures": {},
710+
"master_keys": {
711+
"@example:morpheus.localhost": {
712+
"user_id": "@example:morpheus.localhost",
713+
"usage": [
714+
"master"
715+
],
716+
"keys": {
717+
"ed25519:ZzU4WCyBfOFitdGmfKCq6F39iQCDk/zhNNTsi+tWH7A": "ZzU4WCyBfOFitdGmfKCq6F39iQCDk/zhNNTsi+tWH7A"
718+
},
719+
"signatures": {
720+
"@example:morpheus.localhost": {
721+
"ed25519:SUMODVLSIU": "RL6WOuuzB/mZ+edfUFG/KeEcmKh+NaWpM6m2bUYmDnJrtTCYyoU+pgHJuL2/6nynemmONo18JEHBuqtNcMq2AQ"
722+
}
723+
}
724+
}
725+
},
726+
"self_signing_keys": {
727+
"@example:morpheus.localhost": {
728+
"user_id": "@example:morpheus.localhost",
729+
"usage": [
730+
"self_signing"
731+
],
732+
"keys": {
733+
"ed25519:rUiMNDjIu6gqsrhJPbj3phyIzuEtuQGrLOEa9mCbtTM": "rUiMNDjIu6gqsrhJPbj3phyIzuEtuQGrLOEa9mCbtTM"
734+
},
735+
"signatures": {
736+
"@example:morpheus.localhost": {
737+
"ed25519:ZzU4WCyBfOFitdGmfKCq6F39iQCDk/zhNNTsi+tWH7A": "uCBn9rpeg6umY8H97ejN26UMp6QDwNL98869t1DoVGL50J8adLN05OZd8lYk9QzwTr2d56ZTGYSYX8kv28SDDA"
738+
}
739+
}
740+
}
741+
},
742+
"user_signing_keys": {
743+
"@example:morpheus.localhost": {
744+
"user_id": "@example:morpheus.localhost",
745+
"usage": [
746+
"user_signing"
747+
],
748+
"keys": {
749+
"ed25519:GLhEKLQ50jnF6IMEPsO2ucpHUNIUEnbBXs5gYbHg4Aw": "GLhEKLQ50jnF6IMEPsO2ucpHUNIUEnbBXs5gYbHg4Aw"
750+
},
751+
"signatures": {
752+
"@example:morpheus.localhost": {
753+
"ed25519:ZzU4WCyBfOFitdGmfKCq6F39iQCDk/zhNNTsi+tWH7A": "4fIyWlVzuz1pgoegNLZASycORXqKycVS0dNq5vmmwsVEudp1yrPhndnaIJ3fjF8LDHvwzXTvohOid7DiU1j0AA"
754+
}
755+
}
756+
}
757+
}
758+
});
759+
const marked = await m.markRequestAsSent('foo', RequestType.KeysQuery, hypothetical_response);
760+
}
761+
});
762+
763+
test('can start an in-room SAS verification', async () => {
764+
let _ = m.bootstrapCrossSigning(true);
765+
const identity = await m.getIdentity(new UserId('@example:morpheus.localhost'));
766+
767+
expect(identity).toBeInstanceOf(UserIdentity);
768+
expect(identity.isVerified()).toStrictEqual(false);
769+
770+
const eventId = new EventId('$Rqnc-F-dvnEYJTyHq_iKxU2bZ1CI92-kuZq3a5lr5Zg');
771+
const verificationRequest = await identity.requestVerification(room, eventId);
772+
expect(verificationRequest).toBeInstanceOf(VerificationRequest);
773+
774+
await m.receiveVerificationEvent(
775+
JSON.stringify({
776+
"sender": "@example:morpheus.localhost",
777+
"type": "m.key.verification.ready",
778+
"event_id": "$QguWmaeMt6Hao7Ea6XHDInvr8ndknev79t9a2eBxlz0",
779+
"origin_server_ts": 1674037263075,
780+
"content": {
781+
"methods": [
782+
"m.sas.v1",
783+
"m.qr_code.show.v1",
784+
"m.reciprocate.v1"
785+
],
786+
"from_device": "SUMODVLSIU",
787+
"m.relates_to": {
788+
"rel_type": "m.reference",
789+
"event_id": eventId.toString(),
790+
}
791+
}
792+
}),
793+
room
794+
);
795+
796+
expect(verificationRequest.roomId.toString()).toStrictEqual(room.toString());
797+
798+
const [_sas, outgoingVerificationRequest] = await verificationRequest.startSas();
799+
800+
expect(outgoingVerificationRequest).toBeInstanceOf(RoomMessageRequest);
801+
expect(outgoingVerificationRequest.id).toBeDefined();
802+
expect(outgoingVerificationRequest.room_id).toStrictEqual(room.toString());
803+
expect(outgoingVerificationRequest.txn_id).toBeDefined();
804+
expect(outgoingVerificationRequest.event_type).toStrictEqual('m.key.verification.start');
805+
expect(outgoingVerificationRequest.content).toBeDefined();
806+
})
807+
});
627808
});

0 commit comments

Comments
 (0)