def test_existing_player(self):
     joe = FakeClient(self.console, name="Joe", guid="01230123012301230123", groupBits=1)
     joe.connects('1')
     self.assertEqual(joe, self.console.clients['1'])
     when(self.console).write("startserverdemo 1").thenReturn("startserverdemo: recording Joe to serverdemos/2012_04_22_20-16-38_Joe_642817.dm_68")
     self.moderator.says("!startserverdemo joe")
     self.assertListEqual(['startserverdemo: recording Joe to serverdemos/2012_04_22_20-16-38_Joe_642817.dm_68'], self.moderator.message_history)
예제 #2
0
    def test_cmd_plugin_unload_successful(self):
        # GIVEN

        ###### MOCK PLUGIN
        mock_plugin = Mock(spec=Plugin)
        mock_plugin.console = self.console
        mock_plugin.isEnabled = Mock(return_value=False)
        when(self.console).getPlugin("mock").thenReturn(mock_plugin)
        self.console._plugins['mock'] = mock_plugin
        ###### MOCK COMMAND
        mock_func = Mock()
        mock_func.__name__ = 'cmd_mockfunc'
        self.adminPlugin._commands['mockcommand'] = Command(plugin=mock_plugin, cmd='mockcommand', level=100, func=mock_func)
        ###### MOCK EVENT
        mock_plugin.onSay = Mock()
        mock_plugin.registerEvent('EVT_CLIENT_SAY', mock_plugin.onSay)
        ###### MOCK CRON
        mock_plugin.mockCronjob = Mock()
        mock_plugin.mockCrontab = b3.cron.PluginCronTab(mock_plugin, mock_plugin.mockCronjob, minute='*', second= '*/60')
        self.console.cron.add(mock_plugin.mockCrontab)
        self.assertIn(id(mock_plugin.mockCrontab), self.console.cron._tabs)

        superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
        superadmin.connects("1")
        # WHEN
        superadmin.clearMessageHistory()
        superadmin.says("!plugin unload mock")
        # THEN
        self.assertNotIn('mockcommand', self.adminPlugin._commands)
        self.assertIn(self.console.getEventID('EVT_CLIENT_SAY'), self.console._handlers)
        self.assertNotIn(mock_plugin, self.console._handlers[self.console.getEventID('EVT_CLIENT_SAY')])
        self.assertNotIn(id(mock_plugin.mockCrontab), self.console.cron._tabs)
        self.assertListEqual(['Plugin mock has been unloaded'], superadmin.message_history)
class Test_stopserverdemo(PluginTestCase):
    CONF = """\
[commands]
stopserverdemo = 20
"""
    def setUp(self):
        PluginTestCase.setUp(self)
        self.p.onStartup()
        self.moderator = FakeClient(self.console, name="Moderator", exactName="Moderator", guid="654654654654654654", groupBits=8)
        self.moderator.connects('0')
        self.moderator.clearMessageHistory()


    def test_no_parameter(self):
        self.moderator.says("!stopserverdemo")
        self.assertListEqual(["specify a player name or 'all'"], self.moderator.message_history)

    def test_non_existing_player(self):
        self.moderator.says("!stopserverdemo foo")
        self.assertListEqual(['No players found matching foo'], self.moderator.message_history)

    def test_all(self):
        self.p._recording_all_players = True
        when(self.console).write("stopserverdemo all").thenReturn("stopserverdemo: stopped recording laCourge")
        self.moderator.says("!stopserverdemo all")
        self.assertFalse(self.p._recording_all_players)
        self.assertListEqual(['stopserverdemo: stopped recording laCourge'], self.moderator.message_history)

    def test_existing_player(self):
        joe = FakeClient(self.console, name="Joe", guid="01230123012301230123", groupBits=1)
        joe.connects('1')
        self.assertEqual(joe, self.console.clients['1'])
        when(self.console).write("stopserverdemo 1").thenReturn("stopserverdemo: stopped recording Joe")
        self.moderator.says("!stopserverdemo joe")
class Cmd_regulars(Admin_functional_test):
    def setUp(self):
        Admin_functional_test.setUp(self)
        self.init()
        self.joe.message = Mock(wraps=lambda x: sys.stdout.write("\t\t" + x + "\n"))
        self.joe.connects(0)

    def test_no_regular(self):
        # only superadmin joe is connected
        self.joe.says("!regulars")
        self.joe.message.assert_called_with("^7There are no regular players online")

    def test_one_regular(self):
        # GIVEN
        self.mike.connects(1)
        self.joe.says("!makereg mike")
        # WHEN
        self.joe.says("!regs")
        # THEN
        self.joe.message.assert_called_with("^7Regular players online: Mike^7")

    def test_two_regulars(self):
        # GIVEN
        self.mike.connects(1)
        self.joe.says("!makereg mike")
        self.jack = FakeClient(self.console, name="Jack", guid="jackguid", groupBits=1)
        self.jack.connects(2)
        self.joe.says("!makereg jack")
        # WHEN
        self.joe.says("!regs")
        # THEN
        self.joe.message.assert_called_with("^7Regular players online: Mike^7, Jack^7")
예제 #5
0
class StatPluginTestCase(B3TestCase):

    def setUp(self):
        B3TestCase.setUp(self)

        with logging_disabled():
            admin_conf = CfgConfigParser()
            admin_plugin = AdminPlugin(self.console, admin_conf)
            admin_plugin.onLoadConfig()
            admin_plugin.onStartup()
            when(self.console).getPlugin('admin').thenReturn(admin_plugin)

        conf = CfgConfigParser()
        conf.loadFromString(dedent(r"""
            [commands]
            mapstats-stats: 0
            testscore-ts: 0
            topstats-top: 0
            topxp: 0

            [settings]
            startPoints: 100
            resetscore: no
            resetxp: no
            show_awards: no
            show_awards_xp: no
        """))
        self.p = StatsPlugin(self.console, conf)
        self.p.onLoadConfig()
        self.p.onStartup()

        self.joe = FakeClient(self.console, name="Joe", guid="joeguid", groupBits=1, team=TEAM_RED)
        self.mike = FakeClient(self.console, name="Mike", guid="mikeguid", groupBits=1, team=TEAM_RED)
        self.joe.connects(1)
        self.mike.connects(2)
 def test_map_with_correct_parameters(self):
     # GIVEN
     superadmin = FakeClient(self.parser, name="superadmin", guid="guid_superadmin", groupBits=128, team=TEAM_UNKNOWN)
     superadmin.connects("1")
     # WHEN
     superadmin.says("!map market push")
     # THEN
     self.parser.output.write.assert_has_calls([call('changelevel market push')])
예제 #7
0
 def testPlugin5():
     jack = FakeClient(fakeConsole, name="Jack", _maxLevel=0)
     jack.connects(1)
     time.sleep(1.1)
     joe = FakeClient(fakeConsole, name="Joe", _maxLevel=2)
     joe.connects(2)
     moderator.connects(0)
     moderator.says('!makeroom')
예제 #8
0
 def test_SUICIDE(self):  # 16
     # GIVEN
     poorguy = FakeClient(self.parser, name="attacker_name", guid='76561198070138838')
     poorguy.connects("1")
     # WHEN
     self.parser.handlePacket(Packet.decode('\x00\x10\x00\x00\x00\x08\x01\x10\x00\x01\x06\x8c\x87\xd6'))
     # THEN
     self.assert_has_event("EVT_CLIENT_SUICIDE", client=poorguy, target=poorguy, data=(100, None, None))
예제 #9
0
class Test_commands(CustomcommandsTestCase):

    def setUp(self):
        CustomcommandsTestCase.setUp(self)
        self.conf = CfgConfigParser()
        self.p = CustomcommandsPlugin(self.console, self.conf)
        with logging_disabled():
            from b3.fake import FakeClient
        self.guest = FakeClient(console=self.console, name="Guest", guid="GuestGUID", pbid="GuestPBID", group_bits=0)
        self.user = FakeClient(console=self.console, name="User", guid="UserGUID", pbid="UserPBID", group_bits=1)
        self.regular = FakeClient(console=self.console, name="Regular", guid="RegularGUID", pbid="RegularPBID", group_bits=2)
        self.mod = FakeClient(console=self.console, name="Moderator", guid="ModeratorGUID", pbid="ModeratorPBID", group_bits=8)
        self.admin = FakeClient(console=self.console, name="Admin", guid="AdminGUID", pbid="AdminPBID", group_bits=16)
        self.fulladmin = FakeClient(console=self.console, name="FullAdmin", guid="FullAdminGUID", pbid="FullAdminPBID", group_bits=32)
        self.senioradmin = FakeClient(console=self.console, name="SeniorAdmin", guid="SeniorAdminGUID", pbid="SeniorAdminPBID", group_bits=64)
        self.superadmin = FakeClient(console=self.console, name="SuperAdmin", guid="SuperAdminGUID", pbid="SuperAdminPBID", group_bits=128)

    def test_guest(self):
        # GIVEN
        self.conf.loadFromString("""
[guest commands]
# define in this section commands that will be available to all players
f00 = f00 rcon command
        """)
        # WHEN
        self.p.onLoadConfig()
        self.p.onStartup()
        # THEN
        self.assertIn("f00", self.p._adminPlugin._commands)
        # WHEN
        self.guest.connects(cid="guestCID")
        with patch.object(self.console, "write") as write_mock:
            self.guest.says("!f00")
        # THEN
        self.assertListEqual([call("f00 rcon command")], write_mock.mock_calls)
        self.assertListEqual([], self.guest.message_history)

    def test_user(self):
        # GIVEN
        self.console.getPlugin('admin')._warn_command_abusers = True
        self.conf.loadFromString("""
[user commands]
# define in this section commands that will be available to all players
f00 = f00 rcon command
        """)
        self.p.onLoadConfig()
        self.p.onStartup()
        # WHEN
        self.guest.connects(cid="guestCID")
        with patch.object(self.console, "write") as write_mock:
            self.guest.says("!f00")
        # THEN
        self.assertEqual(1, len(self.guest.message_history))
        self.assertIn(self.guest.message_history[0], [
            'You do not have sufficient access to use !f00',
            'You need to be in group User to use !f00'
        ])
        self.assertListEqual([], write_mock.mock_calls)
예제 #10
0
 def test_client_say__no_team(self):
     # GIVEN
     player = FakeClient(self.parser, name="Spoon", guid="STEAM_1:0:10000000", team=TEAM_UNKNOWN)
     player.connects("2")
     # WHEN
     self.clear_events()
     self.parser.parseLine('''L 09/16/2012 - 04:55:17: "Spoon<2><STEAM_1:0:10000000><>" say "!h"''')
     # THEN
     self.assert_has_event("EVT_CLIENT_SAY", "!h", player)
예제 #11
0
 def test_high_level_no_password_set(self):
     # GIVEN
     joe = FakeClient(self.console, name="Joe", guid="joeguid", groupBits=128)
     # WHEN
     joe.clearMessageHistory()
     joe.connects("0")
     # THEN
     self.assertEqual(['You need a password to use all your privileges: ask the administrator to set a password for you'], joe.message_history)
     self.assertEqual(2, joe.groupBits)
예제 #12
0
 def test_cmd_plugin_load_with_invalid_plugin_name(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!plugin load fake")
     # THEN
     self.assertListEqual(['Missing fake plugin python module', 'Please put the plugin module in @b3/extplugins/'], superadmin.message_history)
예제 #13
0
 def test_player_disconnect(self):
     # GIVEN
     bravo17 = FakeClient(self.parser, name="Bravo17", guid="80a5885ebe2420bab5e158a310fcbc7d")
     bravo17.connects("12")
     self.clear_events()
     # WHEN
     self.parser.routeBattleyeEvent("""Player #12 Bravo17 disconnected""")
     # THEN
     self.assert_has_event("EVT_CLIENT_DISCONNECT", client=bravo17, data='12')
 def test_checkbadnames(self):
     # GIVEN
     p1 = FakeClient(self.console, name="all", guid="p1guid")
     p1.warn = Mock()
     p1.connects("1")
     # WHEN
     self.p.namecheck()
     # THEN
     p1.warn.assert_has_calls([call(ANY, ANY, 'badname', None, '')])
예제 #15
0
 def test_Lobby_chat(self):
     # GIVEN
     bravo17 = FakeClient(self.parser, name="Bravo17", guid="80a5885ebe2420bab5e158a310fcbc7d")
     bravo17.connects("12")
     self.clear_events()
     # WHEN
     self.parser.routeBattleyeEvent("""(Lobby) Bravo17: hello b3""")
     # THEN
     self.assert_has_event("EVT_CLIENT_SAY", client=bravo17, data='hello b3 (Lobby)')
예제 #16
0
 def test_TEAM_CHANGED_1(self):  # 13
     # GIVEN
     player = FakeClient(self.parser, name="Pheonix", guid="76561198070138838")
     player.connects("1")
     self.assertEqual(TEAM_UNKNOWN, player.team)
     # WHEN
     self.parser.handlePacket(Packet.decode('\x00\r\x00\x00\x00\x0c\x01\x10\x00\x01\x06\x8c\x87\xd6\x00\x00\x00\x01'))
     # THEN
     self.assertEqual(1, player.team)
예제 #17
0
 def test_cmd_spamins_uppercase(self):
     # GIVEN
     mike = FakeClient(self.console, name="Mike")
     mike.connects("3")
     # WHEN
     self.superadmin.clearMessageHistory()
     self.superadmin.says("!spamins MIKE")
     # THEN
     self.assertListEqual(['Mike currently has 0 spamins, peak was 0'], self.superadmin.message_history)
예제 #18
0
 def test_low_level(self):
     # GIVEN
     joe = FakeClient(self.console, name="Joe", guid="joeguid", groupBits=8)
     # WHEN
     joe.clearMessageHistory()
     joe.connects("0")
     # THEN
     self.assertEqual([], joe.message_history)
     self.assertEqual(8, joe.groupBits)
예제 #19
0
 def test_Command_chat(self):
     # GIVEN
     bravo17 = FakeClient(self.parser, name="Bravo17", guid="80a5885ebe2420bab5e158a310fcbc7d")
     bravo17.connects("12")
     self.clear_events()
     # WHEN
     self.parser.routeBattleyeEvent("""(Command) Bravo17: test command channel""")
     # THEN
     self.assert_has_event("EVT_CLIENT_SAY", client=bravo17, data='test command channel (Command)')
예제 #20
0
 def test_Verified_guid__with_connected_player(self):
     # GIVEN
     bravo17 = FakeClient(self.parser, name="Bravo17")
     bravo17.connects("0")
     self.clear_events()
     # WHEN
     self.parser.routeBattleyeEvent("""Verified GUID (80a5885ebe2420bab5e158a310fcbc7d) of player #0 Bravo17""")
     # THEN
     self.assert_has_event("EVT_CLIENT_AUTH", data=bravo17, client=bravo17)
예제 #21
0
 def test_cmd_plugin_with_invalid_command_name(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!plugin fake")
     # THEN
     self.assertListEqual(['usage: !plugin <disable|enable|info|list|load|unload> [<data>]'], superadmin.message_history)
예제 #22
0
 def test_cmd_plugin_enable_protected(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!plugin enable admin")
     # THEN
     self.assertListEqual(['Plugin admin is protected'], superadmin.message_history)
예제 #23
0
 def test_client_teamsay(self):
     # GIVEN
     player = FakeClient(self.parser, name="courgette", guid="STEAM_1:0:1111111", team=TEAM_BLUE)
     player.connects("2")
     # WHEN
     self.clear_events()
     self.parser.parseLine('''L 08/26/2012 - 05:04:44: "courgette<2><STEAM_1:0:1111111><CT>" say_team "team say"''')
     # THEN
     self.assert_has_event("EVT_CLIENT_TEAM_SAY", "team say", player)
예제 #24
0
 def test_clantag(self):
     # GIVEN
     player = FakeClient(self.parser, name="courgette", guid="STEAM_1:0:1111111", team=TEAM_BLUE)
     player.connects("2")
     # WHEN
     self.assertFalse(hasattr(player, "clantag"))
     self.parser.parseLine('''L 08/26/2012 - 05:43:31: "courgette<2><STEAM_1:0:1111111><CT>" triggered "clantag" (value "f00")''')
     # THEN
     self.assertEqual("f00", player.clantag)
예제 #25
0
 def test_bot_entered(self):
     # GIVEN
     bot22 = FakeClient(self.parser, name="Pheonix", guid="BOT_22")
     bot22.connects("22")
     # WHEN
     self.clear_events()
     self.parser.parseLine('''L 08/26/2012 - 05:29:48: "Pheonix<22><BOT><>" entered the game''')
     # THEN
     self.assert_has_event("EVT_CLIENT_JOIN", client=bot22)
예제 #26
0
 def test_cmd_plugin_list(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!plugin list")
     # THEN
     self.assertListEqual(['Loaded plugins: admin, pluginmanager'], superadmin.message_history)
예제 #27
0
 def test_cmd_plugin_enable_with_no_plugin_name(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!plugin enable")
     # THEN
     self.assertListEqual(['usage: !plugin enable <name/s>'], superadmin.message_history)
예제 #28
0
 def test_player_entered(self):
     # GIVEN
     player = FakeClient(self.parser, name="courgette", guid="STEAM_1:0:1111111")
     player.connects("2")
     # WHEN
     self.clear_events()
     self.parser.parseLine('''L 08/26/2012 - 05:38:36: "courgette<2><STEAM_1:0:1111111><>" entered the game''')
     # THEN
     self.assert_has_event("EVT_CLIENT_JOIN", client=player)
예제 #29
0
 def test_cmd_plugin_no_parameters(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!plugin")
     # THEN
     self.assertListEqual(['invalid data, try !help plugin'], superadmin.message_history)
예제 #30
0
 def test_cmd_plugin_enable_with_invalid_plugin_name(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!plugin enable fake")
     # THEN
     self.assertListEqual(['Plugin fake is not loaded'], superadmin.message_history)
예제 #31
0
 def test_cmdalias_update_alias(self):
     # GIVEN
     superadmin = FakeClient(self.console,
                             name="superadmin",
                             guid="superadminguid",
                             groupBits=128)
     superadmin.connects("1")
     self.assert_cmd_alias("help", "h")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdalias help newhelp")
     # THEN
     self.assertListEqual(['updated alias for command help: newhelp'],
                          superadmin.message_history)
     self.assert_cmd_alias("help", "newhelp")
예제 #32
0
 def test_killed(self):
     # GIVEN
     p1 = FakeClient(self.parser, guid="11111111111111")
     p1.connects("11111111111111")
     self.queueEvent_mock.reset_mock()
     self.clear_events()
     # WHEN
     self.parser.route_game_event(
         '''"Name1<11111111111111><0>" killed  with UTDmgType_VehicleCollision'''
     )
     # THEN
     self.assert_has_event('EVT_CLIENT_SUICIDE',
                           data=(100, "UTDmgType_VehicleCollision", 'body'),
                           client=p1,
                           target=p1)
예제 #33
0
 def testAutomation4():
     from b3.fake import superadmin, joe
     p._automation_enabled = True
     p._delay = 0
     p._total_slots = 3
     p._min_free_slots = 1
     joe.connects(0)
     time.sleep(.3)
     superadmin.connects(1)
     time.sleep(.3)
     jack = FakeClient(fakeConsole,
                       name="Jack",
                       guid="qsd654sqf",
                       _maxLevel=2)
     jack.connects(2)
예제 #34
0
 def test_cmdlevel_single_invalid_minlevel(self):
     # GIVEN
     superadmin = FakeClient(self.console,
                             name="superadmin",
                             guid="superadminguid",
                             groupBits=128)
     superadmin.connects("1")
     self.assert_cmd_groups("help", "^2guest")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdlevel help fakegroup")
     # THEN
     self.assertListEqual(['invalid level specified: fakegroup'],
                          superadmin.message_history)
     self.assert_cmd_groups("help", "^2guest")
예제 #35
0
    def test_cmdlevel_single_valid_minlevel(self):
        # GIVEN
        superadmin = FakeClient(self.console,
                                name="superadmin",
                                guid="superadminguid",
                                groupBits=128)
        superadmin.connects("1")

        # WHEN
        superadmin.clearMessageHistory()
        superadmin.says("!cmdlevel help admin")
        # THEN
        self.assertListEqual(['command help level changed: admin'],
                             superadmin.message_history)
        self.assert_cmd_groups("help", "^2admin")
예제 #36
0
 def test_cmdalias_already_in_use(self):
     # GIVEN
     superadmin = FakeClient(self.console,
                             name="superadmin",
                             guid="superadminguid",
                             groupBits=128)
     superadmin.connects("1")
     self.assert_cmd_alias("ban", "b")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdalias ban tempban")
     # THEN
     self.assertListEqual(['command tempban is already in use'],
                          superadmin.message_history)
     self.assert_cmd_alias("ban", "b")
예제 #37
0
 def test_cmdalias_add_alias(self):
     # GIVEN
     superadmin = FakeClient(self.console,
                             name="superadmin",
                             guid="superadminguid",
                             groupBits=128)
     superadmin.connects("1")
     self.assert_cmd_alias("register", None)
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdalias register newregister")
     # THEN
     self.assertListEqual(['added alias for command register: newregister'],
                          superadmin.message_history)
     self.assert_cmd_alias("register", "newregister")
예제 #38
0
 def test_SUICIDE(self):  # 16
     # GIVEN
     poorguy = FakeClient(self.parser,
                          name="attacker_name",
                          guid='76561198070138838')
     poorguy.connects("1")
     # WHEN
     self.parser.handlePacket(
         Packet.decode(
             b'\x00\x10\x00\x00\x00\x08\x01\x10\x00\x01\x06\x8c\x87\xd6'))
     # THEN
     self.assert_has_event("EVT_CLIENT_SUICIDE",
                           client=poorguy,
                           target=poorguy,
                           data=(100, None, None))
예제 #39
0
 def test_cmdalias_invalid_alias_specified(self):
     # GIVEN
     superadmin = FakeClient(self.console,
                             name="superadmin",
                             guid="superadminguid",
                             groupBits=128)
     superadmin.connects("1")
     self.assert_cmd_alias("help", "h")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdalias help !")
     # THEN
     self.assertListEqual(['invalid data, try !help cmdalias'],
                          superadmin.message_history)
     self.assert_cmd_alias("help", "h")
 def test_cmdrevoke_with_previously_given_grant_and_high_group_level(self):
     # GIVEN
     superadmin = FakeClient(self.console, name="superadmin", guid="superadminguid", groupBits=128)
     superadmin.connects("1")
     mike = FakeClient(self.console, name="mike", guid="mikeguid", groupBits=1)
     mike.connects("2")
     # WHEN
     superadmin.says("!cmdgrant mike cmdlevel")
     mike.groupBits = 64     # this 2 lines simulate mike being added as senioradmin
     mike._maxLevel = 80     # after he obtained a grant for command !cmdlevel he couldn't access before
     superadmin.clearMessageHistory()
     superadmin.says("!cmdrevoke mike cmdlevel")
     # THEN
     self.assertListEqual(['mike\'s grant for cmdlevel command has been removed',
                           'but his group level is high enough to access the command'], superadmin.message_history)
예제 #41
0
 def test_cmd_plugin_load_with_already_loaded_plugin(self):
     # GIVEN
     mock_plugin = Mock(spec=Plugin)
     when(self.console).getPlugin("mock").thenReturn(mock_plugin)
     superadmin = FakeClient(self.console,
                             name="superadmin",
                             guid="superadminguid",
                             groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!plugin load mock")
     # THEN
     self.assertListEqual(['Plugin mock is already loaded'],
                          superadmin.message_history)
예제 #42
0
 def test_cmd_plugin_load_with_invalid_plugin_name(self):
     # GIVEN
     superadmin = FakeClient(self.console,
                             name="superadmin",
                             guid="superadminguid",
                             groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!plugin load fake")
     # THEN
     self.assertListEqual([
         'Missing fake plugin python module',
         'Please put the plugin module in @b3/extplugins/'
     ], superadmin.message_history)
예제 #43
0
 def test_cmd_plugin_disable_succeed(self):
     # GIVEN
     mock_plugin = Mock(spec=Plugin)
     mock_plugin.isEnabled = Mock(return_value=True)
     when(self.console).getPlugin("mock").thenReturn(mock_plugin)
     superadmin = FakeClient(self.console,
                             name="superadmin",
                             guid="superadminguid",
                             groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!plugin disable mock")
     # THEN
     self.assertListEqual(['Plugin mock is now disabled'],
                          superadmin.message_history)
예제 #44
0
 def test_cmdlevel_double_minlevel_greater_than_maxlevel(self):
     # GIVEN
     superadmin = FakeClient(self.console,
                             name="superadmin",
                             guid="superadminguid",
                             groupBits=128)
     superadmin.connects("1")
     self.assert_cmd_groups("help", "^2guest")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdlevel help fulladmin-admin")
     # THEN
     self.assertListEqual(
         ['invalid level: fulladmin is greater than admin'],
         superadmin.message_history)
     self.assert_cmd_groups("help", "^2guest")
예제 #45
0
 def test_client_changed_name__known_client(self):
     # GIVEN
     player = FakeClient(self.parser,
                         name="courgette",
                         guid="STEAM_1:0:1111111",
                         team=TEAM_UNKNOWN)
     player.connects("194")
     # WHEN
     self.clear_events()
     self.parser.parseLine(
         'L 02/07/2015 - 19:36:25: "courgette<194><STEAM_1:0:1111111><#Team_Security>" changed name to "fooobar"'
     )
     # THEN
     self.assert_has_event("EVT_CLIENT_NAME_CHANGE",
                           client=player,
                           data="fooobar")
예제 #46
0
 def test_PLAYER_CHAT_team(self):  # 3
     # GIVEN
     player = FakeClient(self.parser,
                         name="Pheonix",
                         guid="76561198038608801")
     player.connects("1")
     self.clear_events()
     player.team = 0  # ugly, until chiv team ids got converted into b3 team ids
     # WHEN
     self.parser.handlePacket(
         Packet.decode(
             '\x00\x03\x00\x00\x00\x17\x01\x10\x00\x01\x04\xabk\xa1\x00\x00\x00\x07 sorry \x00\x00\x00\x00'
         ))
     # THEN
     self.assert_has_event("EVT_CLIENT_TEAM_SAY",
                           data='sorry',
                           client=player)
예제 #47
0
class Test_player_connect_event(PluginTestCase):
    CONF = """\
[commands]
startserverdemo = 20
stopserverdemo = 20
"""

    def setUp(self):
        PluginTestCase.setUp(self)
        self.p.onStartup()

        self.joe = FakeClient(self.console,
                              name="Joe",
                              guid="01230123012301230123",
                              groupBits=1)
        self.joe.clearMessageHistory()

        self.p.start_recording_player = Mock(
            return_value="startserverdemo: recording ")
        self.p.start_recording_player.reset_mock()

    def test_auto_start_demo_of_connecting_players(self):
        # GIVEN
        self.p._recording_all_players = True

        # WHEN
        self.joe.connects("2")
        self.console.queueEvent(
            Event(self.console.getEventID('EVT_CLIENT_JOIN'), self.joe,
                  self.joe))

        # THEN
        sleep(.5)  # sleep so the thread has time of doing its job
        self.assertTrue(self.p.start_recording_player.called)
        self.p.start_recording_player.assert_called_with(self.joe, None)

    def test_do_not_auto_start_demo_of_connecting_players(self):
        # GIVEN
        self.p._recording_all_players = False

        # WHEN
        self.joe.connects("2")

        # THEN
        sleep(.5)  # sleep so the thread has time of doing its job
        self.assertFalse(self.p.start_recording_player.called)
예제 #48
0
 def test_kill_enemy_2(self):
     # GIVEN
     p1 = FakeClient(self.parser, guid="76561000000000000")
     p1.connects("76561000000000000")
     p2 = FakeClient(self.parser, guid="70000000000000005")
     p2.connects("70000000000000005")
     self.queueEvent_mock.reset_mock()
     self.clear_events()
     # WHEN
     self.parser.route_game_event(
         '''"txsniper<76561000000000000><1>" killed "Killer Badger<70000000000000005><0>" with R_DmgType_SniperPrimary'''
     )
     # THEN
     self.assert_has_event('EVT_CLIENT_KILL',
                           data=(100, "R_DmgType_SniperPrimary", 'body'),
                           client=p1,
                           target=p2)
예제 #49
0
 def test_kill_teammate(self):
     # GIVEN
     p1 = FakeClient(self.parser, guid="11111111111111")
     p1.connects("11111111111111")
     p2 = FakeClient(self.parser, guid="2222222222222")
     p2.connects("2222222222222")
     self.queueEvent_mock.reset_mock()
     self.clear_events()
     # WHEN
     self.parser.route_game_event(
         '''"Name1<11111111111111><0>" killed "Name2<2222222222222><0>" with "the_weapon"'''
     )
     # THEN
     self.assert_has_event('EVT_CLIENT_KILL_TEAM',
                           data=(100, "the_weapon", 'body'),
                           client=p1,
                           target=p2)
예제 #50
0
 def test_cmd_plugin_enable_mixed_multiple(self):
     # GIVEN
     mock_pluginA = Mock(spec=Plugin)
     mock_pluginA.isEnabled = Mock(return_value=False)
     when(self.console).getPlugin("mock").thenReturn(mock_pluginA)
     superadmin = FakeClient(self.console,
                             name="superadmin",
                             guid="superadminguid",
                             groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!plugin enable mock fake")
     # THEN
     self.assertListEqual(
         ['Plugin mock is now enabled', 'Plugin fake is not loaded'],
         superadmin.message_history)
예제 #51
0
class Test_game_specific_spam(SpamcontrolTestCase):
    def setUp(self):
        SpamcontrolTestCase.setUp(self)

        with open(b3.getAbsolutePath(
                '@b3/conf/plugin_spamcontrol.ini')) as default_conf:
            self.init_plugin(default_conf.read())

        self.joe = FakeClient(self.console,
                              name="Joe",
                              exactName="Joe",
                              guid="zaerezarezar",
                              groupBits=1)
        self.joe.connects("1")

        # let's say our game has a new event : EVT_CLIENT_RADIO
        EVT_CLIENT_RADIO = self.console.Events.createEvent(
            'EVT_CLIENT_RADIO', 'Event client radio')

        # teach the Spamcontrol plugin how to react on such events
        def onRadio(this, event):
            new_event = Event(type=event.type,
                              client=event.client,
                              target=event.target,
                              data=event.data['text'])
            this.onChat(new_event)

        self.p.onRadio = new.instancemethod(onRadio, self.p, SpamcontrolPlugin)
        self.p.registerEvent('EVT_CLIENT_RADIO', self.p.onRadio)

        # patch joe to make him able to send radio messages
        def radios(me, text):
            me.console.queueEvent(
                Event(type=EVT_CLIENT_RADIO, client=me, data={'text': text}))

        self.joe.radios = new.instancemethod(radios, self.joe, FakeClient)

    def test_radio_spam(self):
        when(self.p).getTime().thenReturn(0)
        self.joe.warn = Mock()
        self.joe.says("doh 1")
        self.joe.radios("doh 2")
        self.joe.says("doh 3")
        self.joe.radios("doh 4")
        self.joe.says("doh 5")
        self.assertEqual(1, self.joe.warn.call_count)
예제 #52
0
 def test_cmd_plugin_info_with_valid_plugin_name_and_email_escape(self):
     # GIVEN
     mock_module = Mock()
     mock_module.__setattr__('__author__', 'Mocker - [email protected]')
     mock_module.__setattr__('__version__', '1.1')
     when(self.console).pluginImport('mock').thenReturn(mock_module)
     superadmin = FakeClient(self.console,
                             name="superadmin",
                             guid="superadminguid",
                             groupBits=128)
     superadmin.connects("1")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!plugin info mock")
     # THEN
     self.assertListEqual(['You are running plugin mock v1.1 by Mocker'],
                          superadmin.message_history)
class Test_stopserverdemo(PluginTestCase):
    CONF = """\
[commands]
stopserverdemo = 20
"""

    def setUp(self):
        PluginTestCase.setUp(self)
        self.p.onStartup()
        self.moderator = FakeClient(self.console,
                                    name="Moderator",
                                    exactName="Moderator",
                                    guid="654654654654654654",
                                    groupBits=8)
        self.moderator.connects('0')
        self.moderator.clearMessageHistory()

    def test_no_parameter(self):
        self.moderator.says("!stopserverdemo")
        self.assertListEqual(["specify a player name or 'all'"],
                             self.moderator.message_history)

    def test_non_existing_player(self):
        self.moderator.says("!stopserverdemo foo")
        self.assertListEqual(['No players found matching foo'],
                             self.moderator.message_history)

    def test_all(self):
        self.p._recording_all_players = True
        when(self.console).write("stopserverdemo all").thenReturn(
            "stopserverdemo: stopped recording laCourge")
        self.moderator.says("!stopserverdemo all")
        self.assertFalse(self.p._recording_all_players)
        self.assertListEqual(['stopserverdemo: stopped recording laCourge'],
                             self.moderator.message_history)

    def test_existing_player(self):
        joe = FakeClient(self.console,
                         name="Joe",
                         guid="01230123012301230123",
                         groupBits=1)
        joe.connects('1')
        self.assertEqual(joe, self.console.clients['1'])
        when(self.console).write("stopserverdemo 1").thenReturn(
            "stopserverdemo: stopped recording Joe")
        self.moderator.says("!stopserverdemo joe")
예제 #54
0
 def test_cmdrevoke_with_no_grant_given(self):
     # GIVEN
     superadmin = FakeClient(self.console,
                             name="superadmin",
                             guid="superadminguid",
                             groupBits=128)
     superadmin.connects("1")
     mike = FakeClient(self.console,
                       name="mike",
                       guid="mikeguid",
                       groupBits=64)
     mike.connects("2")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdrevoke mike cmdlevel")
     # THEN
     self.assertListEqual(['mike has no grant for cmdlevel command'],
                          superadmin.message_history)
예제 #55
0
 def test_cmduse_access(self):
     # GIVEN
     superadmin = FakeClient(self.console,
                             name="superadmin",
                             guid="superadminguid",
                             groupBits=128)
     superadmin.connects("1")
     mike = FakeClient(self.console,
                       name="mike",
                       guid="mikeguid",
                       groupBits=64)
     mike.connects("2")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmduse mike cmdlevel")
     # THEN
     self.assertListEqual(['mike has access to cmdlevel command'],
                          superadmin.message_history)
예제 #56
0
 def test_cmdgrant_with_invalid_command(self):
     # GIVEN
     superadmin = FakeClient(self.console,
                             name="superadmin",
                             guid="superadminguid",
                             groupBits=128)
     superadmin.connects("1")
     mike = FakeClient(self.console,
                       name="mike",
                       guid="mikeguid",
                       groupBits=1)
     mike.connects("2")
     # WHEN
     superadmin.clearMessageHistory()
     superadmin.says("!cmdgrant mike fakecommand")
     # THEN
     self.assertListEqual(['could not find command fakecommand'],
                          superadmin.message_history)
예제 #57
0
    def test_gamerules(self):
        def assertGR(state, event_type):
            self.parser.parseLine("Gamerules: entering state '%s'" % state)
            self.assert_has_event(event_type)

        # GIVEN
        player = FakeClient(self.parser,
                            name="courgette",
                            guid="STEAM_1:0:1111111",
                            team=TEAM_BLUE)
        player.connects("194")
        # THEN
        assertGR("GR_STATE_PREGAME", "EVT_GAME_WARMUP")
        assertGR("GR_STATE_STARTGAME", "EVT_CLIENT_JOIN")
        # assertGR("GR_STATE_PREROUND", "xxxxxxxxxxxx")
        assertGR("GR_STATE_RND_RUNNING", "EVT_GAME_ROUND_START")
        assertGR("GR_STATE_POSTROUND", "EVT_GAME_ROUND_END")
        assertGR("GR_STATE_GAME_OVER", "EVT_GAME_EXIT")
예제 #58
0
 def test_change_someone_else(self):
     # GIVEN
     self.joe.connects("0")
     self.joe._groupBits = 128  # force superadmin
     jack = FakeClient(self.console, name="Jack", guid="jackguid")
     jack.connects("1")
     self.assertEqual('', jack.password)
     jack_db = self.p._get_client_from_db(jack.id)
     self.assertEqual('', jack_db.password)
     # WHEN
     self.joe.clearMessageHistory()
     self.joe.says("!setpassword f00 jack")
     # THEN
     self.assertEqual(['New password for Jack saved'],
                      self.joe.message_history)
     self.assertEqual(F00_MD5, jack.password)
     jack_db = self.p._get_client_from_db(jack.id)
     self.assertEqual(F00_MD5, jack_db.password)
예제 #59
0
    def test_event_EVT_1337_PORT(self):
        # GIVEN
        self.p._haxbusterurt_demo_duration = (1.0 / 60) / 8 # will make the auto-stop timer end after 125ms
        self.p.start_recording_player = Mock()
        self.p.stop_recording_player = Mock()
        joe = FakeClient(console=self.console, name="Joe", guid="JOE_GUID")
        joe.connects("2")

        # WHEN the haxbusterurt plugin detects that Joe has a contestable guid
        self.console.queueEvent(Event(self.console.getEventID('EVT_1337_PORT'), data=joe.guid, client=joe))

        # THEN
        sleep(.5) # sleep so the thread has time of doing its job
        self.p.start_recording_player.assert_called_with(joe, None)

        # WHEN
        sleep(.5) # sleep so the thread has time of doing its job
        self.p.stop_recording_player.assert_called_with(joe)
예제 #60
0
    def test_cmd_plugin_unload_successful(self):
        # GIVEN

        ###### MOCK PLUGIN
        mock_plugin = Mock(spec=Plugin)
        mock_plugin.console = self.console
        mock_plugin.isEnabled = Mock(return_value=False)
        when(self.console).getPlugin("mock").thenReturn(mock_plugin)
        self.console._plugins['mock'] = mock_plugin
        ###### MOCK COMMAND
        mock_func = Mock()
        mock_func.__name__ = 'cmd_mockfunc'
        self.adminPlugin._commands['mockcommand'] = Command(plugin=mock_plugin,
                                                            cmd='mockcommand',
                                                            level=100,
                                                            func=mock_func)
        ###### MOCK EVENT
        mock_plugin.onSay = Mock()
        mock_plugin.registerEvent('EVT_CLIENT_SAY', mock_plugin.onSay)
        ###### MOCK CRON
        mock_plugin.mockCronjob = Mock()
        mock_plugin.mockCrontab = b3.cron.PluginCronTab(
            mock_plugin, mock_plugin.mockCronjob, minute='*', second='*/60')
        self.console.cron.add(mock_plugin.mockCrontab)
        self.assertIn(id(mock_plugin.mockCrontab), self.console.cron._tabs)

        superadmin = FakeClient(self.console,
                                name="superadmin",
                                guid="superadminguid",
                                groupBits=128)
        superadmin.connects("1")
        # WHEN
        superadmin.clearMessageHistory()
        superadmin.says("!plugin unload mock")
        # THEN
        self.assertNotIn('mockcommand', self.adminPlugin._commands)
        self.assertIn(self.console.getEventID('EVT_CLIENT_SAY'),
                      self.console._handlers)
        self.assertNotIn(
            mock_plugin,
            self.console._handlers[self.console.getEventID('EVT_CLIENT_SAY')])
        self.assertNotIn(id(mock_plugin.mockCrontab), self.console.cron._tabs)
        self.assertListEqual(['Plugin mock has been unloaded'],
                             superadmin.message_history)