mirror of
https://github.com/jlu5/PyLink.git
synced 2024-12-25 04:02:45 +01:00
tests for spawnServer and SQUIT, make server name case-insensitive
This commit is contained in:
parent
942f97352d
commit
8ea62c31de
@ -250,7 +250,7 @@ def handle_server(irc, numeric, command, args):
|
||||
# SERVER is sent by our uplink or any other server to introduce others.
|
||||
# <- :00A SERVER test.server * 1 00C :testing raw message syntax
|
||||
# <- :70M SERVER millennium.overdrive.pw * 1 1ML :a relatively long period of time... (Fremont, California)
|
||||
servername = args[0]
|
||||
servername = args[0].lower()
|
||||
sid = args[3]
|
||||
irc.servers[sid] = IrcServer(numeric, servername)
|
||||
|
||||
@ -304,8 +304,11 @@ def handle_squit(irc, numeric, command, args):
|
||||
def handle_rsquit(irc, numeric, command, args):
|
||||
# <- :1MLAAAAIG RSQUIT :ayy.lmao
|
||||
# <- :1MLAAAAIG RSQUIT ayy.lmao :some reason
|
||||
# If we receive a remote SQUIT from an oper, split the target server
|
||||
# only if they're identified with us.
|
||||
# RSQUIT is sent by opers to squit remote servers.
|
||||
# Strangely, it takes a server name instead of a SID, and is
|
||||
# allowed to be ignored entirely.
|
||||
# If we receive a remote SQUIT, split the target server
|
||||
# ONLY if the sender is identified with us.
|
||||
target = args[0]
|
||||
for (sid, server) in irc.servers.items():
|
||||
if server.name == target:
|
||||
@ -334,7 +337,7 @@ def handle_events(irc, data):
|
||||
args = data.split()
|
||||
if args and args[0] == 'SERVER':
|
||||
# SERVER whatever.net abcdefgh 0 10X :something
|
||||
servername = args[1]
|
||||
servername = args[1].lower()
|
||||
numeric = args[4]
|
||||
if args[2] != irc.serverdata['recvpass']:
|
||||
# Check if recvpass is correct
|
||||
|
@ -83,5 +83,57 @@ class TestInspIRCdProtocol(unittest.TestCase):
|
||||
self.proto.nickClient(self.irc, self.u, 'NotPyLink')
|
||||
self.assertEqual('NotPyLink', self.irc.users[self.u].nick)
|
||||
|
||||
def testSpawnServer(self):
|
||||
# Incorrect SID length
|
||||
self.assertRaises(Exception, self.proto.spawnServer, self.irc, 'subserver.pylink', '34Q0')
|
||||
self.proto.spawnServer(self.irc, 'subserver.pylink', '34Q')
|
||||
# Duplicate server name
|
||||
self.assertRaises(Exception, self.proto.spawnServer, self.irc, 'Subserver.PyLink', '34Z')
|
||||
# Duplicate SID
|
||||
self.assertRaises(Exception, self.proto.spawnServer, self.irc, 'another.Subserver.PyLink', '34Q')
|
||||
self.assertIn('34Q', self.irc.servers)
|
||||
# Are we bursting properly?
|
||||
self.assertIn(':34Q ENDBURST', self.irc.takeMsgs())
|
||||
|
||||
def testSpawnClientOnServer(self):
|
||||
self.proto.spawnServer(self.irc, 'subserver.pylink', '34Q')
|
||||
u = self.proto.spawnClient(self.irc, 'person1', 'person', 'users.overdrive.pw', server='34Q')
|
||||
# We're spawning clients on the right server, hopefully...
|
||||
self.assertIn(u.uid, self.irc.servers['34Q'].users)
|
||||
self.assertNotIn(u.uid, self.irc.servers[self.irc.sid].users)
|
||||
|
||||
def testSquit(self):
|
||||
# Spawn a messy network map, just because!
|
||||
self.proto.spawnServer(self.irc, 'level1.pylink', '34P')
|
||||
self.proto.spawnServer(self.irc, 'level2.pylink', '34Q', uplink='34P')
|
||||
self.proto.spawnServer(self.irc, 'level3.pylink', '34Z', uplink='34Q')
|
||||
self.proto.spawnServer(self.irc, 'level4.pylink', '34Y', uplink='34Z')
|
||||
self.assertEqual(self.irc.servers['34Y'].uplink, '34Z')
|
||||
s4u = self.proto.spawnClient(self.irc, 'person1', 'person', 'users.overdrive.pw', server='34Y').uid
|
||||
s3u = self.proto.spawnClient(self.irc, 'person2', 'person', 'users.overdrive.pw', server='34Z').uid
|
||||
self.proto.joinClient(self.irc, s3u, '#pylink')
|
||||
self.proto.joinClient(self.irc, s4u, '#pylink')
|
||||
self.proto.handle_squit(self.irc, '9PY', 'SQUIT', ['34Y'])
|
||||
self.assertNotIn(s4u, self.irc.users)
|
||||
self.assertNotIn('34Y', self.irc.servers)
|
||||
# Netsplits are obviously recursive, so all these should be removed.
|
||||
self.proto.handle_squit(self.irc, '9PY', 'SQUIT', ['34P'])
|
||||
self.assertNotIn(s3u, self.irc.users)
|
||||
self.assertNotIn('34P', self.irc.servers)
|
||||
self.assertNotIn('34Q', self.irc.servers)
|
||||
self.assertNotIn('34Z', self.irc.servers)
|
||||
|
||||
def testRSquit(self):
|
||||
u = self.proto.spawnClient(self.irc, 'person1', 'person', 'users.overdrive.pw')
|
||||
u.identified = 'admin'
|
||||
self.proto.spawnServer(self.irc, 'level1.pylink', '34P')
|
||||
self.irc.run(':%s RSQUIT level1.pylink :some reason' % self.u)
|
||||
# No SQUIT yet, since the 'PyLink' client isn't identified
|
||||
self.assertNotIn('SQUIT', self.irc.takeCommands(self.irc.takeMsgs()))
|
||||
# The one we just spawned however, is.
|
||||
self.irc.run(':%s RSQUIT level1.pylink :some reason' % u.uid)
|
||||
self.assertIn('SQUIT', self.irc.takeCommands(self.irc.takeMsgs()))
|
||||
self.assertNotIn('34P', self.irc.servers)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
Reference in New Issue
Block a user