Skip to content

Commit ce800dc

Browse files
author
Ferass El Hafidi
committed
spec/integ/kicking: add ban tests
Signed-off-by: Ferass El Hafidi <[email protected]>
1 parent e490011 commit ce800dc

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed

spec/integ/kicking.spec.js

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,118 @@ describe("Kicking", () => {
176176
});
177177

178178

179+
describe("Banning", () => {
180+
181+
const {env, config, test} = envBundle();
182+
183+
const mxUser = {
184+
id: "@flibble:wibble",
185+
nick: "M-flibble"
186+
};
187+
188+
const ircUser = {
189+
nick: "bob",
190+
localpart: config._server + "_bob",
191+
id: `@${config._server}_bob:${config.homeserver.domain}`
192+
};
193+
194+
const ircUserKicker = {
195+
nick: "KickerNick",
196+
localpart: config._server + "_KickerNick",
197+
id: "@" + config._server + "_KickerNick:" + config.homeserver.domain
198+
};
199+
200+
beforeEach(async () => {
201+
await test.beforeEach(env);
202+
203+
// accept connection requests from eeeeeeeeveryone!
204+
env.ircMock._autoConnectNetworks(
205+
config._server, mxUser.nick, config._server
206+
);
207+
env.ircMock._autoConnectNetworks(
208+
config._server, ircUser.nick, config._server
209+
);
210+
env.ircMock._autoConnectNetworks(
211+
config._server, config._botnick, config._server
212+
);
213+
// accept join requests from eeeeeeeeveryone!
214+
env.ircMock._autoJoinChannels(
215+
config._server, mxUser.nick, config._chan
216+
);
217+
env.ircMock._autoJoinChannels(
218+
config._server, ircUser.nick, config._chan
219+
);
220+
env.ircMock._autoJoinChannels(
221+
config._server, config._botnick, config._chan
222+
);
223+
224+
// we also don't care about registration requests for the irc user
225+
env.clientMock._intent(ircUser.id)._onHttpRegister({
226+
expectLocalpart: ircUser.localpart,
227+
returnUserId: ircUser.id
228+
});
229+
230+
await test.initEnv(env);
231+
232+
// make the matrix user be on IRC
233+
await env.mockAppService._trigger("type:m.room.message", {
234+
content: {
235+
body: "let me in",
236+
msgtype: "m.text"
237+
},
238+
user_id: mxUser.id,
239+
room_id: config._roomid,
240+
type: "m.room.message"
241+
});
242+
const botIrcClient = await env.ircMock._findClientAsync(config._server, config._botnick);
243+
// make the IRC user be on Matrix
244+
botIrcClient.emit("message", ircUser.nick, config._chan, "let me in");
245+
});
246+
247+
afterEach(async () => test.afterEach(env));
248+
249+
describe("IRC users on Matrix", () => {
250+
it("should make the virtual IRC client set MODE +b and KICK the real IRC user", async () => {
251+
let reason = "Get some help.";
252+
let userBannedPromise = new Promise(function(resolve, reject) {
253+
env.ircMock._whenClient(config._server, mxUser.nick, "send",
254+
function(client, cmd, chan, arg1, arg2) {
255+
expect(client.nick).toEqual(mxUser.nick);
256+
expect(client.addr).toEqual(config._server);
257+
expect(chan).toEqual(config._chan);
258+
if (cmd !== "KICK") {
259+
// We sent a MODE
260+
expect(cmd).toEqual("MODE");
261+
expect(arg1).toEqual("+b"); // mode +b => ban
262+
expect(arg2).toEqual(`${ircUser.nick}!*@*`); // argument to +b
263+
}
264+
else {
265+
expect(cmd).toEqual("KICK");
266+
expect(arg1).toEqual(ircUser.nick); // nick
267+
expect(arg2.indexOf(reason)).not.toEqual(-1, // kick reason
268+
`kick reason was not mirrored to IRC. Got '${arg2}',
269+
expected '${reason}'.`);
270+
}
271+
resolve();
272+
});
273+
});
274+
275+
await env.mockAppService._trigger("type:m.room.member", {
276+
content: {
277+
reason: reason,
278+
membership: "ban"
279+
},
280+
user_id: mxUser.id,
281+
state_key: ircUser.id,
282+
room_id: config._roomid,
283+
type: "m.room.member"
284+
});
285+
await userBannedPromise;
286+
});
287+
});
288+
});
289+
290+
179291
describe("Kicking on IRC join", () => {
180292
const {env, config, test} = envBundle();
181293

0 commit comments

Comments
 (0)