aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorgpcf <gpcf@gpcf.eu>2024-07-28 13:24:27 +0200
committergpcf <gpcf@gpcf.eu>2024-07-28 13:24:27 +0200
commit838f4ff076f75fb2e977591c2eafd49f3a9bfba7 (patch)
tree040c9fb58aa01d83d05bded4db994a3ac21f1d72 /spec
parent52173903e17625c44c108b4ca2e7bc22f3b76465 (diff)
downloadxban2-838f4ff076f75fb2e977591c2eafd49f3a9bfba7.tar.gz
xban2-838f4ff076f75fb2e977591c2eafd49f3a9bfba7.tar.bz2
xban2-838f4ff076f75fb2e977591c2eafd49f3a9bfba7.zip
Add unit tests for ban functionality
Diffstat (limited to 'spec')
-rw-r--r--spec/ban_spec.lua50
1 files changed, 50 insertions, 0 deletions
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)