mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-26 20:59:27 +01:00
ircdb: Deduplicate hostmasks in IrcUser.addAuth
If addAuth is called with a hostmask that already exists (exactly, not just equivalent patterns) in self.auth, remove the entry for the old authentication. This essentially updates the timeout for the hostmask. Signed-off-by: James McCoy <jamessan@users.sourceforge.net>
This commit is contained in:
parent
4bc549c1ed
commit
6361b1e856
15
src/ircdb.py
15
src/ircdb.py
@ -1,6 +1,6 @@
|
||||
###
|
||||
# Copyright (c) 2002-2009, Jeremiah Fincher
|
||||
# Copyright (c) 2009, James McCoy
|
||||
# Copyright (c) 2009,2013, James McCoy
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@ -291,9 +291,20 @@ class IrcUser(object):
|
||||
self.hostmasks.remove(hostmask)
|
||||
|
||||
def addAuth(self, hostmask):
|
||||
"""Sets a user's authenticated hostmask. This times out in 1 hour."""
|
||||
"""Sets a user's authenticated hostmask. This times out according to
|
||||
conf.supybot.timeoutIdentification. If hostmask exactly matches an
|
||||
existing, known hostmask, the previous entry is removed."""
|
||||
if self.checkHostmask(hostmask, useAuth=False) or not self.secure:
|
||||
self.auth.append((time.time(), hostmask))
|
||||
knownHostmasks = set()
|
||||
def uniqueHostmask(auth):
|
||||
(_, mask) = auth
|
||||
if mask not in knownHostmasks:
|
||||
knownHostmasks.add(mask)
|
||||
return True
|
||||
return False
|
||||
uniqued = filter(uniqueHostmask, reversed(self.auth))
|
||||
self.auth = list(reversed(uniqued))
|
||||
else:
|
||||
raise ValueError, 'secure flag set, unmatched hostmask'
|
||||
|
||||
|
@ -252,7 +252,7 @@ class IrcUserTestCase(IrcdbTestCase):
|
||||
self.failIf(u.checkHostmask('foo!bar@baz'))
|
||||
finally:
|
||||
conf.supybot.databases.users.timeoutIdentification.setValue(orig)
|
||||
|
||||
|
||||
def testMultipleAuth(self):
|
||||
orig = conf.supybot.databases.users.timeoutIdentification()
|
||||
try:
|
||||
@ -260,6 +260,9 @@ class IrcUserTestCase(IrcdbTestCase):
|
||||
u = ircdb.IrcUser()
|
||||
u.addAuth('foo!bar@baz')
|
||||
self.failUnless(u.checkHostmask('foo!bar@baz'))
|
||||
u.addAuth('foo!bar@baz')
|
||||
self.failUnless(u.checkHostmask('foo!bar@baz'))
|
||||
self.failUnless(len(u.auth) == 1)
|
||||
u.addAuth('boo!far@fizz')
|
||||
self.failUnless(u.checkHostmask('boo!far@fizz'))
|
||||
time.sleep(2.1)
|
||||
|
Loading…
Reference in New Issue
Block a user