Use test helpers from js-sdk for encrypted events (#12364)
* Use test helpers from js-sdk for encrypted events Rather than gut-wrenching into the matrix-js-sdk, let's use the newly-exported test helpers to generate encrypted events. * Fix up
This commit is contained in:
parent
8f22550f19
commit
64806d0490
4 changed files with 57 additions and 110 deletions
|
@ -36,7 +36,6 @@ import {
|
|||
IPushRules,
|
||||
RelationType,
|
||||
JoinRule,
|
||||
IEventDecryptionResult,
|
||||
OidcClientConfig,
|
||||
} from "matrix-js-sdk/src/matrix";
|
||||
import { KnownMembership } from "matrix-js-sdk/src/types";
|
||||
|
@ -404,50 +403,6 @@ export function mkEvent(opts: MakeEventProps): MatrixEvent {
|
|||
return mxEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an m.room.encrypted event
|
||||
*
|
||||
* @param opts - Values for the event
|
||||
* @param opts.room - The ID of the room for the event
|
||||
* @param opts.user - The sender of the event
|
||||
* @param opts.plainType - The type the event will have, once it has been decrypted
|
||||
* @param opts.plainContent - The content the event will have, once it has been decrypted
|
||||
*/
|
||||
export async function mkEncryptedEvent(opts: {
|
||||
room: Room["roomId"];
|
||||
user: User["userId"];
|
||||
plainType: string;
|
||||
plainContent: IContent;
|
||||
}): Promise<MatrixEvent> {
|
||||
// we construct an event which has been decrypted by stubbing out CryptoBackend.decryptEvent and then
|
||||
// calling MatrixEvent.attemptDecryption.
|
||||
|
||||
const mxEvent = mkEvent({
|
||||
type: "m.room.encrypted",
|
||||
room: opts.room,
|
||||
user: opts.user,
|
||||
event: true,
|
||||
content: {},
|
||||
});
|
||||
|
||||
const decryptionResult: IEventDecryptionResult = {
|
||||
claimedEd25519Key: "",
|
||||
clearEvent: {
|
||||
type: opts.plainType,
|
||||
content: opts.plainContent,
|
||||
},
|
||||
forwardingCurve25519KeyChain: [],
|
||||
senderCurve25519Key: "",
|
||||
untrusted: false,
|
||||
};
|
||||
|
||||
const mockCrypto = {
|
||||
decryptEvent: async (_ev): Promise<IEventDecryptionResult> => decryptionResult,
|
||||
} as Parameters<MatrixEvent["attemptDecryption"]>[0];
|
||||
await mxEvent.attemptDecryption(mockCrypto);
|
||||
return mxEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an m.room.member event.
|
||||
* @param {Object} opts Values for the membership.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue