-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test password query ACL/acls basic tests Tests for /mc Test ACL removal Remove print from channel ban test
- Loading branch information
Showing
5 changed files
with
273 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,34 @@ | ||
# Basic configuration | ||
beerchat.colorize_channels = * | ||
beerchat.moderator_channel_name = mod | ||
|
||
# Plugin configuration | ||
|
||
beerchat.enable_alias = true | ||
beerchat.moderator_channel_name = mod | ||
|
||
beerchat.enable_announce = true | ||
# Enable plugins | ||
|
||
beerchat.enable_mute = true | ||
beerchat.enable_me = true | ||
beerchat.enable_hash = true | ||
beerchat.enable_acl = true | ||
beerchat.enable_pm = true | ||
beerchat.enable_whisper = true | ||
beerchat.enable_jail = true | ||
beerchat.enable_ban = true | ||
|
||
beerchat.enable_remote_mute = true | ||
beerchat.enable_cleaner = true | ||
beerchat.enable_override = true | ||
beerchat.enable_colorize = true | ||
beerchat.enable_announce = true | ||
beerchat.enable_force2channel = true | ||
beerchat.enable_password = true | ||
beerchat.enable_event-logging = true | ||
beerchat.enable_alias = true | ||
|
||
beerchat.enable_jail = true | ||
beerchat.jail.channel_name = jailchannel | ||
# Plugin configuration | ||
|
||
beerchat.enable_remote_mute = true | ||
beerchat.jail.channel_name = jailchannel | ||
beerchat.colorize_channels = * | ||
|
||
# Web relay | ||
|
||
secure.http_mods = beerchat | ||
beerchat.matterbridge_url = http://matterbridge:4242 | ||
beerchat.matterbridge_token = mytoken |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
require("mineunit") | ||
|
||
mineunit("core") | ||
mineunit("player") | ||
mineunit("server") | ||
|
||
describe("ACL/acls", function() | ||
|
||
-- Load bare acls.lua, assuming no dependencies other than channels table. | ||
_G.beerchat = { | ||
channels = { | ||
TEST = {} | ||
} | ||
} | ||
|
||
local acls | ||
local SX = Player("SX", { shout = 1, fast = 1 }) | ||
setup(function() mineunit:execute_on_joinplayer(SX) end) | ||
teardown(function() mineunit:execute_on_leaveplayer(SX) end) | ||
before_each(function() acls = sourcefile("plugin/acl/acls")(nil, function() end) end) | ||
|
||
it("acls:set_role", function() | ||
acls:set_role("TEST", "SX", "read") | ||
assert.same(acls.data.TEST, { SX = "read" }) | ||
end) | ||
|
||
it("acls:set_role privilege", function() | ||
acls:set_role("TEST", "$fast", "write") | ||
assert.same(acls.data.TEST, { ["$fast"] = "write" }) | ||
end) | ||
|
||
it("acls:get_role", function() | ||
assert.is_nil(acls:get_role("TEST", "SX")) | ||
end) | ||
|
||
it("acls:get_role non player", function() | ||
assert.is_nil(acls:get_role("TEST", "?")) | ||
end) | ||
|
||
it("acls:get_privilege_role", function() | ||
assert.is_nil(acls:get_privilege_role("TEST", "SX")) | ||
end) | ||
|
||
it("acls:get_privilege_role non player", function() | ||
assert.is_nil(acls:get_privilege_role("TEST", "?")) | ||
end) | ||
|
||
it("acls:write_storage", function() | ||
acls:write_storage() | ||
end) | ||
|
||
it("acls:check_access", function() | ||
assert.is_nil(acls:check_access("TEST", "SX")) | ||
end) | ||
|
||
it("returns correct player role", function() | ||
acls:set_role("TEST", "SX", "deny") | ||
acls:set_role("TEST", "SX", "manager") | ||
assert.equals(acls:get_role("TEST", "SX"), "manager") | ||
acls:set_role("TEST", "SX", "deny") | ||
assert.equals(acls:get_role("TEST", "SX"), "deny") | ||
end) | ||
|
||
it("returns correct privilege role", function() | ||
acls:set_role("TEST", "$fast", "deny") | ||
acls:set_role("TEST", "$fast", "manager") | ||
assert.equals(acls:get_role("TEST", "SX"), "manager") | ||
acls:set_role("TEST", "$fast", "deny") | ||
assert.equals(acls:get_role("TEST", "SX"), "deny") | ||
end) | ||
|
||
it("acls:check_access deny", function() | ||
acls:set_role("TEST", "$fast", "deny") | ||
assert.is_false(acls:check_access("TEST", "SX")) | ||
assert.is_false(acls:check_access("TEST", "SX", "read")) | ||
assert.is_false(acls:check_access("TEST", "SX", "write")) | ||
assert.is_false(acls:check_access("TEST", "SX", "manager")) | ||
assert.is_false(acls:check_access("TEST", "SX", "owner")) | ||
end) | ||
|
||
it("acls:check_access write", function() | ||
acls:set_role("TEST", "$fast", "write") | ||
assert.is_nil(acls:check_access("TEST", "SX")) | ||
assert.is_nil(acls:check_access("TEST", "SX", "read")) | ||
assert.is_nil(acls:check_access("TEST", "SX", "write")) | ||
assert.is_false(acls:check_access("TEST", "SX", "manager")) | ||
assert.is_false(acls:check_access("TEST", "SX", "owner")) | ||
end) | ||
|
||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
require("mineunit") | ||
|
||
mineunit("core") | ||
mineunit("player") | ||
mineunit("server") | ||
|
||
sourcefile("init") | ||
|
||
describe("ACL", function() | ||
|
||
local M = function(s) return require("luassert.match").matches(s) end | ||
local ANY = require("luassert.match")._ | ||
assert:register("matcher", "has_channel", function(_, args) | ||
return function(msg) | ||
return type(msg) == "table" and msg.channel == args[1] | ||
end | ||
end) | ||
local CHANNEL = require("luassert.match").has_channel | ||
|
||
local SX = Player("SX", { shout = 1 }) | ||
local Sam = Player("Sam", { shout = 1 }) | ||
|
||
setup(function() | ||
mineunit:execute_on_joinplayer(SX) | ||
mineunit:execute_on_joinplayer(Sam) | ||
-- Test channels | ||
beerchat.channels["acl-password"] = { owner = "SX", color = beerchat.default_channel_color } | ||
beerchat.channels["acl-default-role"] = { owner = "SX", color = beerchat.default_channel_color } | ||
beerchat.channels["acl-owner-role"] = { owner = "SX", color = beerchat.default_channel_color } | ||
beerchat.channels["acl-manager-role"] = { owner = "SX", color = beerchat.default_channel_color } | ||
beerchat.channels["acl-write-role"] = { owner = "SX", color = beerchat.default_channel_color } | ||
beerchat.channels["acl-read-role"] = { owner = "SX", color = beerchat.default_channel_color } | ||
beerchat.channels["acl-update-role"] = { owner = "SX", color = beerchat.default_channel_color } | ||
beerchat.channels["acl-delete-role"] = { owner = "SX", color = beerchat.default_channel_color } | ||
beerchat.channels["acl-chat"] = { owner = "SX", color = beerchat.default_channel_color } | ||
end) | ||
|
||
before_each(function() | ||
beerchat.set_player_channel("SX", "main") | ||
beerchat.set_player_channel("Sam", "main") | ||
end) | ||
|
||
teardown(function() | ||
mineunit:execute_on_leaveplayer(Sam) | ||
mineunit:execute_on_leaveplayer(SX) | ||
end) | ||
|
||
it("checks password", function() | ||
SX:send_chat_message("/cc #acl-password,qwerty") | ||
spy.on(minetest, "chat_send_player") | ||
-- Initiate password protected join, it should ask for password and should not join channel | ||
Sam:send_chat_message("/jc #acl-password") | ||
assert.spy(minetest.chat_send_player).called_with("Sam", M(".+assword.+lease.+assword")) | ||
assert.spy(minetest.chat_send_player).not_called_with("SX", ANY) | ||
assert.is_nil(beerchat.playersChannels["Sam"]["acl-password"]) | ||
-- Password is not visible to other players | ||
Sam:send_chat_message("qwerty") | ||
assert.spy(minetest.chat_send_player).not_called_with("SX", ANY) | ||
assert.not_nil(beerchat.playersChannels["Sam"]["acl-password"]) | ||
-- Next messages will be visible to other players | ||
Sam:send_chat_message("qwerty") | ||
assert.spy(minetest.chat_send_player).called_with("SX", ANY) | ||
end) | ||
|
||
it("/invite_channel sets default role", function() | ||
spy.on(minetest, "chat_send_player") | ||
SX:send_chat_message("/invite_channel #acl-default-role Sam") | ||
assert.spy(minetest.chat_send_player).called_with("SX", M("Invite sent.+Sam")) | ||
assert.spy(minetest.chat_send_player).called_with("Sam", M("SX.+invite.+join.+channel")) | ||
end) | ||
|
||
it("/invite_channel sets owner role", function() | ||
spy.on(minetest, "chat_send_player") | ||
SX:send_chat_message("/invite_channel #acl-owner-role Sam owner") | ||
assert.spy(minetest.chat_send_player).called_with("SX", M("Invite sent.+Sam")) | ||
assert.spy(minetest.chat_send_player).called_with("Sam", M("SX.+invite.+join.+channel")) | ||
end) | ||
|
||
it("/invite_channel sets manager role", function() | ||
spy.on(minetest, "chat_send_player") | ||
SX:send_chat_message("/invite_channel #acl-manager-role Sam manager") | ||
assert.spy(minetest.chat_send_player).called_with("SX", M("Invite sent.+Sam")) | ||
assert.spy(minetest.chat_send_player).called_with("Sam", M("SX.+invite.+join.+channel")) | ||
end) | ||
|
||
it("/invite_channel sets write role", function() | ||
spy.on(minetest, "chat_send_player") | ||
SX:send_chat_message("/invite_channel #acl-write-role Sam write") | ||
assert.spy(minetest.chat_send_player).called_with("SX", M("Invite sent.+Sam")) | ||
assert.spy(minetest.chat_send_player).called_with("Sam", M("SX.+invite.+join.+channel")) | ||
end) | ||
|
||
it("/invite_channel sets read role", function() | ||
spy.on(minetest, "chat_send_player") | ||
SX:send_chat_message("/invite_channel #acl-read-role Sam read") | ||
assert.spy(minetest.chat_send_player).called_with("SX", M("Invite sent.+Sam")) | ||
assert.spy(minetest.chat_send_player).called_with("Sam", M("SX.+invite.+join.+channel")) | ||
end) | ||
|
||
it("/invite_channel updates role", function() | ||
SX:send_chat_message("/invite_channel #acl-update-role Sam read") | ||
spy.on(minetest, "chat_send_player") | ||
SX:send_chat_message("/invite_channel #acl-update-role Sam manager") | ||
assert.spy(minetest.chat_send_player).not_called_with("Sam", ANY) | ||
assert.spy(minetest.chat_send_player).called_with("SX", M("update.+manager")) | ||
end) | ||
|
||
it("/invite_channel removes role", function() | ||
SX:send_chat_message("/invite_channel #acl-delete-role Sam manager") | ||
spy.on(minetest, "chat_send_player") | ||
SX:send_chat_message("/invite_channel #acl-delete-role -d Sam") | ||
assert.spy(minetest.chat_send_player).not_called_with("Sam", ANY) | ||
assert.spy(minetest.chat_send_player).called_with("SX", M("emoved.+elete")) | ||
end) | ||
|
||
it("read role allows reading messages", function() | ||
beerchat.set_player_channel("SX", "acl-chat") | ||
beerchat.set_player_channel("Sam", "acl-chat") | ||
SX:send_chat_message("/channel_acl #acl-chat Sam read") | ||
spy.on(minetest, "chat_send_player") | ||
SX:send_chat_message("Test message") | ||
-- Channel message allowed and delivered | ||
assert.spy(minetest.chat_send_player).called_with("Sam", M("Test message")) | ||
assert.spy(minetest.chat_send_player).called_with("SX", M("Test message")) | ||
end) | ||
|
||
it("read role disallows sending messages", function() | ||
beerchat.set_player_channel("SX", "acl-chat") | ||
beerchat.set_player_channel("Sam", "acl-chat") | ||
SX:send_chat_message("/channel_acl #acl-chat Sam read") | ||
spy.on(minetest, "chat_send_player") | ||
Sam:send_chat_message("Test message") | ||
-- Channel message disallowed and player informed | ||
assert.spy(minetest.chat_send_player).not_called_with("SX", ANY) | ||
assert.spy(minetest.chat_send_player).not_called_with("Sam", M("Test message")) | ||
assert.spy(minetest.chat_send_player).called_with("Sam", ANY) | ||
end) | ||
|
||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters