2005-01-19 14:14:38 +01:00
|
|
|
###
|
2005-01-19 14:33:05 +01:00
|
|
|
# Copyright (c) 2002-2005, Jeremiah Fincher
|
2005-01-19 14:14:38 +01:00
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are met:
|
|
|
|
#
|
|
|
|
# * Redistributions of source code must retain the above copyright notice,
|
|
|
|
# this list of conditions, and the following disclaimer.
|
|
|
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
# this list of conditions, and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
# * Neither the name of the author of this software nor the name of
|
|
|
|
# contributors to this software may be used to endorse or promote products
|
|
|
|
# derived from this software without specific prior written consent.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
###
|
|
|
|
|
2013-01-20 00:09:37 +01:00
|
|
|
import re
|
2005-01-19 14:14:38 +01:00
|
|
|
|
2013-01-20 00:09:37 +01:00
|
|
|
from supybot.test import PluginTestCase, network
|
2005-01-19 14:14:38 +01:00
|
|
|
|
2013-01-20 00:09:37 +01:00
|
|
|
import supybot.conf as conf
|
2005-01-19 14:14:38 +01:00
|
|
|
import supybot.world as world
|
|
|
|
import supybot.ircdb as ircdb
|
2013-01-20 00:09:37 +01:00
|
|
|
import supybot.utils as utils
|
|
|
|
|
2005-01-19 19:05:53 +01:00
|
|
|
class UserTestCase(PluginTestCase):
|
2012-10-29 20:15:14 +01:00
|
|
|
plugins = ('User', 'Admin', 'Config')
|
2016-09-14 19:10:26 +02:00
|
|
|
prefix1 = 'somethingElse!user@host1.tld'
|
|
|
|
prefix2 = 'EvensomethingElse!user@host2.tld'
|
2017-12-30 18:47:09 +01:00
|
|
|
prefix3 = 'Completely!Different@host3.tld__no_testcap__'
|
2012-08-03 23:22:53 +02:00
|
|
|
|
2005-04-15 01:41:18 +02:00
|
|
|
def testHostmaskList(self):
|
|
|
|
self.assertError('hostmask list')
|
2005-01-19 14:14:38 +01:00
|
|
|
original = self.prefix
|
|
|
|
self.prefix = self.prefix1
|
|
|
|
self.assertNotError('register foo bar')
|
|
|
|
self.prefix = original
|
2005-04-15 01:41:18 +02:00
|
|
|
self.assertError('hostmask list foo')
|
|
|
|
self.assertNotError('hostmask add foo [hostmask] bar')
|
|
|
|
self.assertNotError('hostmask add foo')
|
|
|
|
self.assertNotRegexp('hostmask add foo', 'IrcSet')
|
|
|
|
|
2005-06-01 08:20:29 +02:00
|
|
|
def testHostmaskListHandlesEmptyListGracefully(self):
|
|
|
|
self.assertError('hostmask list')
|
|
|
|
self.prefix = self.prefix1
|
|
|
|
self.assertNotError('register foo bar')
|
|
|
|
self.assertNotError('hostmask remove foo %s' % self.prefix1)
|
|
|
|
self.assertNotError('identify foo bar')
|
|
|
|
self.assertRegexp('hostmask list', 'no registered hostmasks')
|
2005-10-14 14:57:21 +02:00
|
|
|
|
2016-09-14 19:10:26 +02:00
|
|
|
def testHostmaskOverlap(self):
|
|
|
|
self.assertNotError('register foo passwd', frm=self.prefix1)
|
|
|
|
self.assertNotError('register bar passwd', frm=self.prefix2)
|
|
|
|
self.assertResponse('whoami', 'foo', frm=self.prefix1)
|
|
|
|
self.assertResponse('whoami', 'bar', frm=self.prefix2)
|
|
|
|
self.assertNotError('hostmask add foo *!*@foobar/b',
|
|
|
|
frm=self.prefix1)
|
2017-12-30 18:47:09 +01:00
|
|
|
|
2016-09-14 19:10:26 +02:00
|
|
|
self.assertResponse('hostmask add bar *!*@foobar/*',
|
2017-12-30 18:47:09 +01:00
|
|
|
'Error: That hostmask is already registered to foo.',
|
2016-09-14 19:10:26 +02:00
|
|
|
frm=self.prefix2)
|
|
|
|
self.assertRegexp('hostmask list foo', '\*!\*@foobar/b',
|
|
|
|
frm=self.prefix1)
|
|
|
|
self.assertNotRegexp('hostmask list bar', 'foobar',
|
|
|
|
frm=self.prefix2)
|
|
|
|
|
2017-12-30 18:47:09 +01:00
|
|
|
def testHostmaskOverlapPrivacy(self):
|
|
|
|
self.assertNotError('register foo passwd', frm=self.prefix1)
|
|
|
|
self.assertNotError('register bar passwd', frm=self.prefix3)
|
|
|
|
self.assertResponse('whoami', 'foo', frm=self.prefix1)
|
|
|
|
self.assertResponse('whoami', 'bar', frm=self.prefix3)
|
|
|
|
self.assertNotError('hostmask add foo *!*@foobar/b',
|
|
|
|
frm=self.prefix1)
|
|
|
|
|
|
|
|
ircdb.users.getUser('bar').addCapability('owner')
|
|
|
|
self.assertResponse('whoami', 'bar',
|
|
|
|
frm=self.prefix3)
|
|
|
|
self.assertResponse('capabilities', '[owner]',
|
|
|
|
frm=self.prefix3)
|
|
|
|
self.assertResponse('hostmask add *!*@foobar/*',
|
|
|
|
'Error: That hostmask is already registered to foo.',
|
|
|
|
frm=self.prefix3)
|
|
|
|
ircdb.users.getUser('bar').removeCapability('owner')
|
|
|
|
self.assertResponse('hostmask add *!*@foobar/*',
|
|
|
|
'Error: That hostmask is already registered.',
|
|
|
|
frm=self.prefix3)
|
|
|
|
|
2005-06-01 08:20:29 +02:00
|
|
|
|
2005-04-15 01:41:18 +02:00
|
|
|
def testHostmask(self):
|
|
|
|
self.assertResponse('hostmask', self.prefix)
|
|
|
|
self.assertError('@hostmask asdf')
|
|
|
|
m = self.irc.takeMsg()
|
2020-01-26 11:13:56 +01:00
|
|
|
self.assertFalse(m is not None, m)
|
2005-01-19 14:14:38 +01:00
|
|
|
|
|
|
|
def testRegisterUnregister(self):
|
|
|
|
self.prefix = self.prefix1
|
|
|
|
self.assertNotError('register foo bar')
|
|
|
|
self.assertError('register foo baz')
|
2020-01-26 11:13:56 +01:00
|
|
|
self.assertTrue(ircdb.users.getUserId('foo'))
|
2005-10-14 14:57:21 +02:00
|
|
|
self.assertError('unregister foo')
|
2005-01-19 14:14:38 +01:00
|
|
|
self.assertNotError('unregister foo bar')
|
|
|
|
self.assertRaises(KeyError, ircdb.users.getUserId, 'foo')
|
|
|
|
|
2005-10-14 14:57:21 +02:00
|
|
|
def testDisallowedUnregistration(self):
|
|
|
|
self.prefix = self.prefix1
|
|
|
|
self.assertNotError('register foo bar')
|
|
|
|
orig = conf.supybot.databases.users.allowUnregistration()
|
|
|
|
conf.supybot.databases.users.allowUnregistration.setValue(False)
|
|
|
|
try:
|
|
|
|
self.assertError('unregister foo')
|
|
|
|
m = self.irc.takeMsg()
|
2020-01-26 11:13:56 +01:00
|
|
|
self.assertFalse(m is not None, m)
|
|
|
|
self.assertTrue(ircdb.users.getUserId('foo'))
|
2005-10-14 14:57:21 +02:00
|
|
|
finally:
|
|
|
|
conf.supybot.databases.users.allowUnregistration.setValue(orig)
|
|
|
|
|
2005-01-19 14:14:38 +01:00
|
|
|
def testList(self):
|
|
|
|
self.prefix = self.prefix1
|
|
|
|
self.assertNotError('register foo bar')
|
|
|
|
self.assertResponse('user list', 'foo')
|
|
|
|
self.prefix = self.prefix2
|
|
|
|
self.assertNotError('register biff quux')
|
|
|
|
self.assertResponse('user list', 'biff and foo')
|
2012-10-29 19:28:59 +01:00
|
|
|
|
|
|
|
self.assertRegexp('user list --capability testcap', 'no matching')
|
|
|
|
self.assertNotError('admin capability add biff testcap')
|
|
|
|
self.assertResponse('user list --capability testcap', 'biff')
|
2012-10-29 20:15:14 +01:00
|
|
|
self.assertNotError('config capabilities.private testcap')
|
|
|
|
self.assertRegexp('user list --capability testcap', 'Error:.*private')
|
|
|
|
self.assertNotError('admin capability add biff admin')
|
|
|
|
self.assertResponse('user list --capability testcap', 'biff')
|
|
|
|
self.assertNotError('admin capability remove biff admin')
|
|
|
|
self.assertRegexp('user list --capability testcap', 'Error:.*private')
|
|
|
|
self.assertNotError('config capabilities.private ""')
|
|
|
|
self.assertResponse('user list --capability testcap', 'biff')
|
2012-10-29 19:28:59 +01:00
|
|
|
self.assertNotError('admin capability remove biff testcap')
|
|
|
|
self.assertRegexp('user list --capability testcap', 'no matching')
|
|
|
|
|
2005-01-19 14:14:38 +01:00
|
|
|
self.assertResponse('user list f', 'biff and foo')
|
|
|
|
self.assertResponse('user list f*', 'foo')
|
|
|
|
self.assertResponse('user list *f', 'biff')
|
|
|
|
self.assertNotError('unregister biff quux')
|
|
|
|
self.assertResponse('user list', 'foo')
|
|
|
|
self.assertNotError('unregister foo bar')
|
|
|
|
self.assertRegexp('user list', 'no registered users')
|
|
|
|
self.assertRegexp('user list asdlfkjasldkj', 'no matching registered')
|
|
|
|
|
|
|
|
def testListHandlesCaps(self):
|
|
|
|
self.prefix = self.prefix1
|
|
|
|
self.assertNotError('register Foo bar')
|
|
|
|
self.assertResponse('user list', 'Foo')
|
|
|
|
self.assertResponse('user list f*', 'Foo')
|
|
|
|
|
|
|
|
def testChangeUsername(self):
|
|
|
|
self.prefix = self.prefix1
|
|
|
|
self.assertNotError('register foo bar')
|
|
|
|
self.prefix = self.prefix2
|
|
|
|
self.assertNotError('register bar baz')
|
|
|
|
self.prefix = self.prefix1
|
|
|
|
self.assertError('changename foo bar')
|
|
|
|
self.assertNotError('changename foo baz')
|
|
|
|
|
|
|
|
def testSetpassword(self):
|
|
|
|
self.prefix = self.prefix1
|
|
|
|
self.assertNotError('register foo bar')
|
|
|
|
password = ircdb.users.getUser(self.prefix).password
|
|
|
|
self.assertNotEqual(password, 'bar')
|
2005-04-15 14:16:37 +02:00
|
|
|
self.assertNotError('set password foo bar baz')
|
2005-01-19 14:14:38 +01:00
|
|
|
self.assertNotEqual(ircdb.users.getUser(self.prefix).password,password)
|
|
|
|
self.assertNotEqual(ircdb.users.getUser(self.prefix).password, 'baz')
|
|
|
|
|
|
|
|
def testStats(self):
|
|
|
|
self.assertNotError('user stats')
|
|
|
|
self.assertNotError('load Lart')
|
|
|
|
self.assertNotError('user stats')
|
|
|
|
|
|
|
|
def testUserPluginAndUserList(self):
|
|
|
|
self.prefix = self.prefix1
|
|
|
|
self.assertNotError('register Foo bar')
|
|
|
|
self.assertResponse('user list', 'Foo')
|
|
|
|
self.assertNotError('load Seen')
|
|
|
|
self.assertResponse('user list', 'Foo')
|
|
|
|
|
2006-02-11 16:52:51 +01:00
|
|
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
2005-01-19 14:14:38 +01:00
|
|
|
|