2
from zope.interface import Interface, implements
3
from twisted.trial import unittest
5
from twisted.cred.portal import Portal, IRealm
6
from twisted.cred.checkers import ICredentialsChecker
7
from twisted.cred.credentials import UsernamePassword
9
from axiom.store import Store
10
from axiom.userbase import LoginAccount, LoginSystem
11
from axiom.item import Item
12
from axiom.attributes import integer
13
from axiom.scripts import axiomatic
16
class IGarbage(Interface):
19
class GarbageProtocolHandler(Item):
21
typeName = 'test_login_garbage'
28
self.store.powerUp(self, IGarbage)
32
class UserBaseTest(unittest.TestCase):
34
def logInAndCheck(self, username, domain='localhost'):
35
s = Store(self.mktemp())
37
l = LoginSystem(store=s)
41
[ICredentialsChecker(s)])
43
a = l.addAccount(username, 'localhost', SECRET)
44
gph = GarbageProtocolHandler(store=a.avatars.open(),
49
p, gph = s.transact(_speedup)
51
def wasItGph((interface, avatar, logout)):
52
self.assertEquals(interface, IGarbage)
53
self.assertEquals(avatar, gph)
56
return p.login(UsernamePassword('bob@localhost', SECRET), None, IGarbage
57
).addCallback(wasItGph)
59
def testBasicLogin(self):
60
self.logInAndCheck('bob')
62
def testUppercaseLogin(self):
63
self.logInAndCheck('BOB')
65
def testMixedCaseLogin(self):
66
self.logInAndCheck('BoB')
69
class CommandTestCase(unittest.TestCase):
70
def testUserBaseInstall(self):
73
'-d', dbdir, 'userbase'])
77
ICredentialsChecker(s)
80
def testUserCreation(self):
83
'-d', dbdir, 'userbase',
89
cc = ICredentialsChecker(s)
90
p = Portal(IRealm(s), [cc])
92
def cb((interface, avatar, logout)):
95
return p.login(UsernamePassword('alice@localhost', SECRET), None, lambda orig, default: orig