From 838f4ff076f75fb2e977591c2eafd49f3a9bfba7 Mon Sep 17 00:00:00 2001 From: gpcf Date: Sun, 28 Jul 2024 13:24:27 +0200 Subject: Add unit tests for ban functionality --- spec/ban_spec.lua | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 spec/ban_spec.lua (limited to 'spec') diff --git a/spec/ban_spec.lua b/spec/ban_spec.lua new file mode 100644 index 0000000..b990eda --- /dev/null +++ b/spec/ban_spec.lua @@ -0,0 +1,50 @@ +require("mineunit") + +mineunit("core") + +mineunit("common/chatcommands") +mineunit("server") +mineunit("player") +mineunit("settings") +mineunit("auth") + +sourcefile("init") + +mineunit:mods_loaded() +minetest.check_password_entry = function() + return false +end +minetest.kick_player = function () + return +end +local exists = minetest.player_exists +local settings = core.settings +describe("Afk works", function() + local admin = Player("admin", {kick = true, ban = true}) + local newplayer = Player("bannedplayer") + setup(function() + mineunit:execute_on_joinplayer(admin) + mineunit:execute_on_joinplayer(newplayer, {address = "9.9.9.9"}) + mineunit:execute_on_leaveplayer(newplayer) + end) + it("Bans players", function() + admin:send_chat_message("/xban bannedplayer ban message") + mineunit:execute_on_joinplayer(newplayer) + assert.is_not_true(newplayer._online) + end) + it("Bans players from the same IP", function() + local secondplayer = Player("totallynotbannedplayer") + mineunit:execute_on_joinplayer(secondplayer, {address = "9.9.9.9"}) + assert.is_not_true(newplayer._online) + end) + it("Unbans players", function() + admin:send_chat_message("/xunban bannedplayer unban message") + mineunit:execute_on_joinplayer(newplayer) + assert.is_true(newplayer._online) + end) + it("Allows players from the same IP again after unban", function() + local secondplayer = Player("totallynotbannedplayer") + mineunit:execute_on_joinplayer(secondplayer, {address = "9.9.9.9"}) + assert.is_true(newplayer._online) + end) +end) -- cgit v1.2.3