def test_auth_client_without_guid_but_with_known_pbid(self): # GIVEN # known superadmin named Snoopy superadmin = Client(console=self.parser, name='Snoopy', guid='EA_AAAAAAAABBBBBBBBBBBBBB00000000000012222', pbid='300000aaaaaabbbbbbccccc111223300', group_bits=128, connections=21) superadmin.save() # bf3 server failing to provide guid def write(data): if data == ('admin.listPlayers', 'player', 'Snoopy'): return ['7', 'name', 'guid', 'teamId', 'squadId', 'kills', 'deaths', 'score', '1', 'Snoopy', '', '2', '8', '0', '0', '0'] else: return DEFAULT self.write_mock.side_effect = write # WHEN self.assertFalse('Snoopy' in self.parser.clients) self.parser.OnPBPlayerGuid(match=re.match(self.regex_for_OnPBPlistItem, self.event_raw_data), data=self.event_raw_data) # THEN # B3 should have authed Snoopy self.assertTrue('Snoopy' in self.parser.clients) snoopy = self.parser.clients['Snoopy'] self.assertTrue(snoopy.authed) for attb in ('name', 'pbid', 'guid', 'groupBits'): self.assertEqual(getattr(superadmin, attb), getattr(snoopy, attb))
class Test_Client_events(B3TestCase): def setUp(self): B3TestCase.setUp(self) self.queueEvent_patcher = patch.object(self.console, 'queueEvent') self.queueEvent_mock = self.queueEvent_patcher.start() self.admin = Client(console=self.console) self.client = Client(console=self.console) self.client.save() def tearDown(self): B3TestCase.tearDown(self) self.queueEvent_patcher.stop() def test_warn(self): with self.assertRaiseEvent(event_type="EVT_CLIENT_WARN", event_client=self.client, event_data={ 'reason': 'insulting admin', 'duration': 5*60, 'data': 'foobar', 'admin': self.admin, 'timeExpire': ANY }, event_target=None): self.client.warn(duration='5h', warning='insulting admin', keyword=None, admin=self.admin, data='foobar') def test_notice(self): with self.assertRaiseEvent(event_type="EVT_CLIENT_NOTICE", event_client=self.client, event_data={ 'notice': "keep a eye on this guy", 'admin': self.admin, 'timeAdd': ANY }): self.client.notice(notice="keep a eye on this guy", spare=None, admin=self.admin)
def test_known_client__guid(self): # GIVEN known_client = Client(console=self.parser, guid="12312312312312312", name="courgette", connections=15) known_client.save() self.assertEqual(1, len(self.parser.clients)) self.assertDictContainsSubset({'clients': 2}, self.parser.storage.getCounts()) # WHEN client = self.parser.getClientOrCreate(guid="12312312312312312", name="newName", team="0") # THEN self.assertIsInstance(client, Client) self.assertEqual(known_client.id, client.id) self.assertEqual("12312312312312312", client.cid) self.assertEqual("12312312312312312", client.guid) self.assertEqual("newName", client.name) self.assertEqual(TEAM_SCAVENGERS, client.team) self.assertEqual(16, client.connections) self.assertTrue(client.authed) self.assertEqual(2, len(self.parser.clients)) self.assertDictContainsSubset({'clients': 2}, self.parser.storage.getCounts())
def test_two_bans_with_reason(self): # GIVEN when(self.console).time().thenReturn(0) player1 = Client(console=self.console, guid='player1GUID', name="P1") player1.save() penalty1 = ClientBan(clientId=player1.id, timeExpire=-1, adminId=0, reason="test reason") player2 = Client(console=self.console, guid='player2GUID', name="P2") player2.save() penalty2 = ClientTempBan(clientId=player2.id, timeExpire=self.console.time() + 60 * 2, adminId=0, reason="test reason f00") when(self.console.storage).getLastPenalties(types=whatever(), num=whatever()).thenReturn( [penalty1, penalty2]) # WHEN self.lastbans() # THEN self.mock_command.sayLoudOrPM.assert_has_calls([ call(self.player, u'^2@1^7 P1^7^7 (Perm) test reason'), call(self.player, u'^2@2^7 P2^7^7 (2 minutes remaining) test reason f00'), ])
def test_one_ban_with_reason(self): # GIVEN player1 = Client(console=self.console, guid='BillGUID', name="Bill") player1.save() penalty1 = ClientBan(clientId=player1.id, timeExpire=-1, adminId=0, reason="test reason") when(self.console.storage).getLastPenalties(types=whatever(), num=whatever()).thenReturn([penalty1]) # WHEN self.lastbans() # THEN self.mock_command.sayLoudOrPM.assert_called_once_with(self.player, u'^2@1^7 Bill^7^7 (Perm) test reason')
def test_one_ban(self): # GIVEN player1 = Client(console=self.console, guid='BillGUID', name="Bill") player1.save() penalty1 = ClientBan(clientId=player1.id, timeExpire=-1, adminId=0) when(self.console.storage).getLastPenalties(types=whatever(), num=whatever()).thenReturn( [penalty1]) # WHEN self.lastbans() # THEN self.mock_command.sayLoudOrPM.assert_called_once_with( self.player, u'^2@1^7 Bill^7^7 (Perm)')
def test_known_client_by_cid(self): # GIVEN known_client = Client(console=self.parser, guid="AAAAAAAAAAAA000000000000000", name="theName") known_client.save() self.assertEqual(1, len(self.parser.clients)) self.assertDictContainsSubset({'clients': 2}, self.parser.storage.getCounts()) # WHEN client = self.parser.getClientOrCreate(cid="2", guid="AAAAAAAAAAAA000000000000000", name="newName", team="CT") # THEN self.assertIsInstance(client, Client) self.assertEqual(known_client.id, client.id) self.assertEqual("2", client.cid) self.assertEqual("AAAAAAAAAAAA000000000000000", client.guid) self.assertEqual("newName", client.name) self.assertEqual(TEAM_RED, client.team) self.assertTrue(client.authed) self.assertEqual(2, len(self.parser.clients)) self.assertDictContainsSubset({'clients': 2}, self.parser.storage.getCounts())
def test_two_bans_with_reason(self): # GIVEN when(self.console).time().thenReturn(0) player1 = Client(console=self.console, guid='player1GUID', name="P1") player1.save() penalty1 = ClientBan(clientId=player1.id, timeExpire=-1, adminId=0, reason="test reason") player2 = Client(console=self.console, guid='player2GUID', name="P2") player2.save() penalty2 = ClientTempBan(clientId=player2.id, timeExpire=self.console.time() + 60*2, adminId=0, reason="test reason f00") when(self.console.storage).getLastPenalties(types=whatever(), num=whatever()).thenReturn([penalty1, penalty2]) # WHEN self.lastbans() # THEN self.mock_command.sayLoudOrPM.assert_has_calls([ call(self.player, u'^2@1^7 P1^7^7 (Perm) test reason'), call(self.player, u'^2@2^7 P2^7^7 (2 minutes remaining) test reason f00'), ])