Beispiel #1
0
def test_run_add_off(hallo_getter):
    hallo, test_server, test_channel, test_user = hallo_getter(
        {"permission_control"})
    # Set up a test hallo and server and channel and user
    hallo1 = Hallo()
    perm0 = PermissionMask()
    hallo1.permission_mask = perm0
    serv1 = ServerMock(hallo1)
    serv1.name = "test_serv1"
    perm1 = PermissionMask()
    serv1.permission_mask = perm1
    hallo1.add_server(serv1)
    chan1 = serv1.get_channel_by_address("test_chan1".lower(), "test_chan1")
    perm2 = PermissionMask()
    chan1.permission_mask = perm2
    user1 = serv1.get_user_by_address("test_user1", "test_user1")
    perm3 = PermissionMask()
    user1.permission_mask = perm3
    # Get permission mask of given channel
    test_right = "test_right"
    hallo.function_dispatcher.dispatch(
        EventMessage(
            serv1,
            chan1,
            user1,
            "permissions server=test_serv1 channel=test_chan1 " + test_right +
            " off",
        ))
    data = serv1.get_send_data(1, chan1, EventMessage)
    assert "error" not in data[0].text.lower()
    assert "set " + test_right + " to false" in data[0].text.lower()
    assert test_right in perm2.rights_map
    assert not perm2.rights_map[test_right]
def test_1_user_just_name_privmsg():
    perm_cont = Permissions()
    # Set up a test server and channel and user
    hallo1 = Hallo()
    perm3 = PermissionMask()
    hallo1.permission_mask = perm3
    serv1 = ServerMock(hallo1)
    serv1.name = "test_serv1"
    perm0 = PermissionMask()
    serv1.permission_mask = perm0
    hallo1.add_server(serv1)
    chan1 = serv1.get_channel_by_address("test_chan1".lower(), "test_chan1")
    perm1 = PermissionMask()
    chan1.permission_mask = perm1
    user1 = serv1.get_user_by_address("test_user1".lower(), "test_user1")
    perm2 = PermissionMask()
    user1.permission_mask = perm2
    chan1.add_user(user1)
    user2 = serv1.get_user_by_address("test_user2".lower(), "test_user2")
    perm4 = PermissionMask()
    user2.permission_mask = perm4
    # Get permissions of specified user group
    try:
        perm_cont.find_permission_mask(["test_user2"], user1, None)
        assert False, "Find permission mask should have failed."
    except hallo.modules.permission_control.PermissionControlException as e:
        assert "error" in str(e).lower()
        assert "i can't find that permission mask" in str(e).lower()
Beispiel #3
0
def test_run_fail_not_bool(hallo_getter):
    hallo, test_server, test_channel, test_user = hallo_getter(
        {"permission_control"})
    # Set up a test hallo and server and channel and user
    hallo1 = Hallo()
    perm0 = PermissionMask()
    hallo1.permission_mask = perm0
    serv1 = ServerMock(hallo1)
    serv1.name = "test_serv1"
    perm1 = PermissionMask()
    serv1.permission_mask = perm1
    hallo1.add_server(serv1)
    chan1 = serv1.get_channel_by_address("test_chan1".lower(), "test_chan1")
    perm2 = PermissionMask()
    chan1.permission_mask = perm2
    user1 = serv1.get_user_by_address("test_user1", "test_user1")
    perm3 = PermissionMask()
    user1.permission_mask = perm3
    # Get permission mask of given channel
    test_right = "test_right"
    perm1.set_right(test_right, True)
    hallo.function_dispatcher.dispatch(
        EventMessage(
            serv1,
            chan1,
            user1,
            "permissions server=test_serv1 " + test_right + " yellow",
        ))
    data = serv1.get_send_data(1, chan1, EventMessage)
    assert "error" in data[0].text.lower()
    assert "don't understand your boolean value" in data[0].text.lower()
    assert test_right in perm1.rights_map
    assert perm1.rights_map[test_right]
def test_1_user_group_name():
    perm_cont = Permissions()
    # Set up a test server and channel and user
    hallo1 = Hallo()
    perm3 = PermissionMask()
    hallo1.permission_mask = perm3
    serv1 = ServerMock(hallo1)
    serv1.name = "test_serv1"
    perm0 = PermissionMask()
    serv1.permission_mask = perm0
    hallo1.add_server(serv1)
    chan1 = serv1.get_channel_by_address("test_chan1".lower(), "test_chan1")
    perm1 = PermissionMask()
    chan1.permission_mask = perm1
    user1 = serv1.get_user_by_address("test_user1".lower(), "test_user1")
    perm2 = PermissionMask()
    user1.permission_mask = perm2
    group1 = UserGroup("test_group1", hallo1)
    perm4 = PermissionMask()
    group1.permission_mask = perm4
    hallo1.add_user_group(group1)
    # Get permissions of specified user group
    data = perm_cont.find_permission_mask(["user_group=test_group1"], user1,
                                          chan1)
    assert data == perm4, "Did not find the correct permission mask."
def test_1_user_just_name():
    perm_cont = Permissions()
    # Set up a test server and channel and user
    hallo1 = Hallo()
    perm3 = PermissionMask()
    hallo1.permission_mask = perm3
    serv1 = ServerMock(hallo1)
    serv1.name = "test_serv1"
    perm0 = PermissionMask()
    serv1.permission_mask = perm0
    hallo1.add_server(serv1)
    chan1 = serv1.get_channel_by_address("test_chan1".lower(), "test_chan1")
    perm1 = PermissionMask()
    chan1.permission_mask = perm1
    user1 = serv1.get_user_by_address("test_user1".lower(), "test_user1")
    perm2 = PermissionMask()
    user1.permission_mask = perm2
    chan1.add_user(user1)
    user2 = serv1.get_user_by_address("test_user2".lower(), "test_user2")
    perm4 = PermissionMask()
    user2.permission_mask = perm4
    chan1.add_user(user2)
    # Get permissions of specified user in channel
    data = perm_cont.find_permission_mask(["test_user2"], user1, chan1)
    assert data == perm4, "Did not find the correct permission mask."
def test_1_user_group_no_name():
    perm_cont = Permissions()
    # Set up a test server and channel and user
    hallo1 = Hallo()
    perm3 = PermissionMask()
    hallo1.permission_mask = perm3
    serv1 = ServerMock(hallo1)
    serv1.name = "test_serv1"
    perm0 = PermissionMask()
    serv1.permission_mask = perm0
    hallo1.add_server(serv1)
    chan1 = serv1.get_channel_by_address("test_chan1".lower(), "test_chan1")
    perm1 = PermissionMask()
    chan1.permission_mask = perm1
    user1 = serv1.get_user_by_address("test_user1".lower(), "test_user1")
    perm2 = PermissionMask()
    user1.permission_mask = perm2
    group1 = UserGroup("test_group1", hallo1)
    perm4 = PermissionMask()
    group1.permission_mask = perm4
    hallo1.add_user_group(group1)
    # Try to get permissions of non-existent user group
    try:
        perm_cont.find_permission_mask(["user_group=test_group2"], user1,
                                       chan1)
        assert False, "Find permission mask should have failed."
    except hallo.modules.permission_control.PermissionControlException as e:
        assert "error" in str(e).lower()
        assert "no user group exists by that name" in str(e).lower()
def test_1_channel_privmsg():
    perm_cont = Permissions()
    # Set up a test server and channel and user
    hallo1 = Hallo()
    perm3 = PermissionMask()
    hallo1.permission_mask = perm3
    serv1 = ServerMock(hallo1)
    serv1.name = "test_serv1"
    perm0 = PermissionMask()
    serv1.permission_mask = perm0
    hallo1.add_server(serv1)
    chan1 = serv1.get_channel_by_address("test_chan1".lower(), "test_chan1")
    perm1 = PermissionMask()
    chan1.permission_mask = perm1
    user1 = serv1.get_user_by_address("test_user1".lower(), "test_user1")
    perm2 = PermissionMask()
    user1.permission_mask = perm2
    # Try to get permissions of current channel from a privmsg
    try:
        perm_cont.find_permission_mask(["channel"], user1, None)
        assert False, "Should not have managed to get permission mask."
    except hallo.modules.permission_control.PermissionControlException as e:
        assert "error" in str(e).lower()
        assert "can't set generic channel permissions in a privmsg" in str(
            e).lower()
def test_1_channel():
    perm_cont = Permissions()
    # Set up a test server and channel and user
    hallo1 = Hallo()
    perm3 = PermissionMask()
    hallo1.permission_mask = perm3
    serv1 = ServerMock(hallo1)
    serv1.name = "test_serv1"
    perm0 = PermissionMask()
    serv1.permission_mask = perm0
    hallo1.add_server(serv1)
    chan1 = serv1.get_channel_by_address("test_chan1".lower(), "test_chan1")
    perm1 = PermissionMask()
    chan1.permission_mask = perm1
    user1 = serv1.get_user_by_address("test_user1".lower(), "test_user1")
    perm2 = PermissionMask()
    user1.permission_mask = perm2
    # Get permissions of current channel
    data = perm_cont.find_permission_mask(["channel"], user1, chan1)
    assert data == perm1, "Did not find the correct permission mask."
def test_1_server_name(hallo_getter):
    hallo_obj, test_server, test_channel, test_user = hallo_getter(
        {"permission_control"})
    perm_cont = Permissions()
    # Set up a test server and channel and user
    hallo1 = Hallo()
    perm3 = PermissionMask()
    hallo1.permission_mask = perm3
    serv1 = ServerMock(hallo1)
    serv1.name = "test_serv1"
    perm0 = PermissionMask()
    serv1.permission_mask = perm0
    hallo1.add_server(serv1)
    chan1 = serv1.get_channel_by_address("test_chan1".lower(), "test_chan1")
    perm1 = PermissionMask()
    chan1.permission_mask = perm1
    user1 = serv1.get_user_by_address("test_user1".lower(), "test_user1")
    perm2 = PermissionMask()
    user1.permission_mask = perm2
    # Get permissions of current server
    data = perm_cont.find_permission_mask(["server=test_serv1"], user1, chan1)
    assert data == perm0, "Did not find correct permission mask"
def test_1_server_no_name():
    perm_cont = Permissions()
    # Set up a test server and channel and user
    hallo1 = Hallo()
    perm3 = PermissionMask()
    hallo1.permission_mask = perm3
    serv1 = ServerMock(hallo1)
    serv1.name = "test_serv1"
    perm0 = PermissionMask()
    serv1.permission_mask = perm0
    hallo1.add_server(serv1)
    chan1 = serv1.get_channel_by_address("test_chan1".lower(), "test_chan1")
    perm1 = PermissionMask()
    chan1.permission_mask = perm1
    user1 = serv1.get_user_by_address("test_user1".lower(), "test_user1")
    perm2 = PermissionMask()
    user1.permission_mask = perm2
    # Get permissions of current server
    try:
        perm_cont.find_permission_mask(["server=test_serv2"], user1, chan1)
        assert False, "Find permission mask should have failed."
    except hallo.modules.permission_control.PermissionControlException as e:
        assert "error" in str(e).lower()
        assert "no server exists by that name" in str(e).lower()