Skip to content
Extraits de code Groupes Projets
Non vérifiée Valider fefa1827 rédigé par Will Hunt's avatar Will Hunt Validation de GitHub
Parcourir les fichiers

Merge pull request #137 from Half-Shot/hs/warn-e2e

Warn about encrypted rooms
parents 21fcad62 2599626f
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -102,12 +102,35 @@ export class MatrixRoomHandler { ...@@ -102,12 +102,35 @@ export class MatrixRoomHandler {
log.warn("MatrixRoomHandler", "There was an error sending a matrix event", err); log.warn("MatrixRoomHandler", "There was an error sending a matrix event", err);
}); });
} }
} else if (event.type === "m.room.encryption" && context.rooms.remote) {
return this.HandleEncryptionWarning(event.room_id).catch((err) => {
return Promise.reject(`Failed to handle encrypted room, ${err}`);
});
} else { } else {
log.verbose("MatrixRoomHandler", "Got non m.room.message event"); log.verbose("MatrixRoomHandler", "Got non m.room.message event");
} }
return Promise.reject("Event not processed by bridge"); return Promise.reject("Event not processed by bridge");
} }
public async HandleEncryptionWarning(roomId: string): Promise<void> {
const intent = this.bridge.getIntent();
log.info("MatrixRoomHandler", `User has turned on encryption in ${roomId}, so leaving.`);
/* N.B 'status' is not specced but https://github.com/matrix-org/matrix-doc/pull/828
has been open for over a year with no resolution. */
const sendPromise = intent.sendMessage(roomId, {
msgtype: "m.notice",
status: "critical",
body: "You have turned on encryption in this room, so the service will not bridge any new messages.",
});
const channel = await this.discord.GetChannelFromRoomId(roomId);
await (channel as Discord.TextChannel).send(
"Someone on Matrix has turned on encryption in this room, so the service will not bridge any new messages",
);
await sendPromise;
await intent.leave(roomId);
await this.bridge.getRoomStore().removeEntriesByMatrixRoomId(roomId);
}
public HandleInvite(event: any) { public HandleInvite(event: any) {
log.info("MatrixRoomHandler", "Received invite for " + event.state_key + " in room " + event.room_id); log.info("MatrixRoomHandler", "Received invite for " + event.state_key + " in room " + event.room_id);
if (event.state_key === this.botUserId) { if (event.state_key === this.botUserId) {
......
...@@ -5,4 +5,7 @@ import {MockCollection} from "./collection"; ...@@ -5,4 +5,7 @@ import {MockCollection} from "./collection";
export class MockChannel { export class MockChannel {
public members = new MockCollection<string, MockMember>(); public members = new MockCollection<string, MockMember>();
constructor (public id: string = "", public guild: any = null) { } constructor (public id: string = "", public guild: any = null) { }
public send(data: any): Promise<any> {
return Promise.resolve(data);
}
} }
...@@ -102,11 +102,20 @@ function createRH(opts: any = {}) { ...@@ -102,11 +102,20 @@ function createRH(opts: any = {}) {
}; };
const handler = new MatrixRoomHandler(bot as any, config, "@botuser:localhost", provisioner as any); const handler = new MatrixRoomHandler(bot as any, config, "@botuser:localhost", provisioner as any);
handler.setBridge({ handler.setBridge({
getIntent: () => { return { getIntent: () => {
return {
sendMessage: (roomId, content) => Promise.resolve(content), sendMessage: (roomId, content) => Promise.resolve(content),
leave: (roomId) => Promise.resolve(roomId),
getClient: () => mxClient, getClient: () => mxClient,
}; }, };
}); },
getRoomStore: () => {
return {
removeEntriesByMatrixRoomId: (roomId) => Promise.resolve(roomId),
};
},
},
);
return handler; return handler;
} }
...@@ -195,6 +204,18 @@ describe("MatrixRoomHandler", () => { ...@@ -195,6 +204,18 @@ describe("MatrixRoomHandler", () => {
return expect(handler.OnEvent(buildRequest({ return expect(handler.OnEvent(buildRequest({
type: "m.room.message", content: {body: "abc"}}), context)).to.eventually.equal("processed"); type: "m.room.message", content: {body: "abc"}}), context)).to.eventually.equal("processed");
}); });
it("should alert if encryption is turned on", () => {
const handler = createRH();
const context = {
rooms: {
remote: {
roomId: "_discord_123_456",
},
},
};
return expect(handler.OnEvent(buildRequest({
type: "m.room.encryption", room_id: "!accept:localhost"}), context)).to.eventually.be.fulfilled;
});
it("should process !discord commands", () => { it("should process !discord commands", () => {
const handler = createRH(); const handler = createRH();
handler.ProcessCommand = (ev) => Promise.resolve("processedcmd"); handler.ProcessCommand = (ev) => Promise.resolve("processedcmd");
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter