diff options
author | gpcf <gpcf@gpcf.eu> | 2024-07-28 11:58:39 +0200 |
---|---|---|
committer | gpcf <gpcf@gpcf.eu> | 2024-07-28 11:58:39 +0200 |
commit | 52173903e17625c44c108b4ca2e7bc22f3b76465 (patch) | |
tree | bc588f78bbfd985a422cac7750505a2bd007b55a /spec | |
parent | c7f0dbbbdac8ffdc4d6b90eb38a2221977f36666 (diff) | |
download | xban2-52173903e17625c44c108b4ca2e7bc22f3b76465.tar.gz xban2-52173903e17625c44c108b4ca2e7bc22f3b76465.tar.bz2 xban2-52173903e17625c44c108b4ca2e7bc22f3b76465.zip |
Add unit tests
Diffstat (limited to 'spec')
-rw-r--r-- | spec/afk_spec.lua | 63 | ||||
-rw-r--r-- | spec/fixtures/moderate.conf | 1 | ||||
-rw-r--r-- | spec/fixtures/xban.db | 19 |
3 files changed, 83 insertions, 0 deletions
diff --git a/spec/afk_spec.lua b/spec/afk_spec.lua new file mode 100644 index 0000000..fb63339 --- /dev/null +++ b/spec/afk_spec.lua @@ -0,0 +1,63 @@ +require("mineunit") + +mineunit("core") + +mineunit("common/chatcommands") +mineunit("server") +mineunit("player") +mineunit("settings") +mineunit("auth") + +sourcefile("init") + +mineunit:mods_loaded() + +local exists = minetest.player_exists +local settings = core.settings +describe("Afk works", function() + local admin = Player("admin", {kick = true, ban = true}) + setup(function() + minetest.check_password_entry = function() + return false + end + mineunit:execute_on_joinplayer(admin) + end) + it("Sets afk status correctly", function () + admin:send_chat_message('/mod_afk on') + assert.equals(xban.present["admin"],nil) + admin:send_chat_message('/mod_afk off') + assert.equals(xban.present["admin"],true) + end) + it("Allows new players to join by default", function() + minetest.player_exists = function() + return false + end + local newplayer = Player("newplayer") + mineunit:execute_on_joinplayer(newplayer) + assert.is_true(newplayer._online) + end) + it("Rejects players if no moderator is active", function() + local newplayer = Player("newplayer2") + xban.present = {} + minetest.settings = Settings("moderate.conf") + mineunit:execute_on_joinplayer(newplayer) + assert.is_not_true(newplayer._online) + end) + it("Allows a new player if there is an online moderator", function () + local newplayer = Player("newplayer3") + admin:send_chat_message('/mod_afk off') + mineunit:execute_on_joinplayer(newplayer) + assert.is_true(newplayer._online) + end) + it("Bans passwordless accounts and allows accounts with password", function () + local newplayer = Player("newplayer3") + mineunit:execute_on_joinplayer(newplayer) + assert.is_true(newplayer._online) + minetest.check_password_entry = function() + return true + end + local newplayer2 = Player("newplayer4") + mineunit:execute_on_joinplayer(admin) + assert.is_false(newplayer2._online) + end) +end) diff --git a/spec/fixtures/moderate.conf b/spec/fixtures/moderate.conf new file mode 100644 index 0000000..127f3d6 --- /dev/null +++ b/spec/fixtures/moderate.conf @@ -0,0 +1 @@ +moderate_new_accounts = true
\ No newline at end of file diff --git a/spec/fixtures/xban.db b/spec/fixtures/xban.db new file mode 100644 index 0000000..d4d43e5 --- /dev/null +++ b/spec/fixtures/xban.db @@ -0,0 +1,19 @@ +{ + "entries" : + [ + { + "banned" : false, + "last_seen" : 1722115454.0, + "names" : + { + "127.0.0.1" : 1722115454.0, + "admin" : true, + "foobar" : true, + "survivalg" : true + }, + "record" : null + } + ], + "nextclean" : 1722115717.0, + "timestamp" : 1722115470.0 +} |