3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 09:19:23 +01:00

relay: catch nicks that start with digits and add tests

This commit is contained in:
James Lu 2015-07-12 16:59:49 -07:00
parent 3edee17802
commit 6870e041bc
2 changed files with 45 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import pickle
import sched import sched
import threading import threading
import time import time
import string
import utils import utils
from log import log from log import log
@ -22,6 +23,11 @@ def normalizeNick(irc, nick, separator="/"):
# a protocol violation if there is one. # a protocol violation if there is one.
separator = separator.replace('/', '|') separator = separator.replace('/', '|')
nick = nick.replace('/', '|') nick = nick.replace('/', '|')
if nick.startswith(tuple(string.digits)):
# On TS6 IRCd-s, nicks that start with 0-9 are only allowed if
# they match the UID of the originating server. Otherwise, you'll
# get nasty protocol violations!
nick = '_' + nick
tagnicks = True tagnicks = True
suffix = separator + netname suffix = separator + netname

39
tests/test_relay.py Normal file
View File

@ -0,0 +1,39 @@
import sys
import os
cwd = os.getcwd()
sys.path += [cwd, os.path.join(cwd, 'plugins')]
import unittest
import utils
import classes
import relay
def dummyf():
pass
class TestRelay(unittest.TestCase):
def setUp(self):
self.irc = classes.FakeIRC('unittest', classes.FakeProto(), classes.testconf)
self.irc.maxnicklen = 20
self.irc.proto.__name__ = "test"
self.f = relay.normalizeNick
def testNormalizeNick(self):
self.assertEqual(self.f(self.irc, 'helloworld'), 'helloworld/unittest')
self.assertEqual(self.f(self.irc, 'ObnoxiouslyLongNick'), 'Obnoxiously/unittest')
self.assertEqual(self.f(self.irc, '10XAAAAAA'), '_10XAAAAAA/unittest')
def testNormalizeNickConflict(self):
self.assertEqual(self.f(self.irc, 'helloworld'), 'helloworld/unittest')
self.irc.users['10XAAAAAA'] = classes.IrcUser('helloworld/unittest', 1234, '10XAAAAAA')
# Increase amount of /'s by one
self.assertEqual(self.f(self.irc, 'helloworld'), 'helloworld//unittest')
self.irc.users['10XAAAAAB'] = classes.IrcUser('helloworld//unittest', 1234, '10XAAAAAB')
# Cut off the nick, not the suffix if the result is too long.
self.assertEqual(self.f(self.irc, 'helloworld'), 'helloworl///unittest')
def testNormalizeNickRemovesSlashes(self):
self.irc.proto.__name__ = "charybdis"
self.assertEqual(self.f(self.irc, 'helloworld'), 'helloworld|unittest')
self.assertEqual(self.f(self.irc, 'abcde/eJanus'), 'abcde|eJanu|unittest')
self.assertEqual(self.f(self.irc, 'ObnoxiouslyLongNick'), 'Obnoxiously|unittest')