Example #1
0
    def setUp(self):
        self.realm = service.InMemoryWordsRealm("realmname")
        self.checker = checkers.InMemoryUsernamePasswordDatabaseDontUse()
        self.portal = portal.Portal(self.realm, [self.checker])
        self.factory = service.IRCFactory(self.realm, self.portal)

        c = []
        for nick in self.STATIC_USERS:
            c.append(self.realm.createUser(nick))
            self.checker.addUser(nick.encode('ascii'), nick + "_password")
        return DeferredList(c)
Example #2
0
 def setUp(self):
     self.realm = service.InMemoryWordsRealm("realmname")
     self.checker = checkers.InMemoryUsernamePasswordDatabaseDontUse()
     self.portal = portal.Portal(self.realm, [self.checker])
     self.serverFactory = pb.PBServerFactory(self.portal)
     self.serverFactory.protocol = self._protocolFactory
     self.serverFactory.unsafeTracebacks = True
     self.clientFactory = pb.PBClientFactory()
     self.clientFactory.unsafeTracebacks = True
     self.serverPort = reactor.listenTCP(0, self.serverFactory)
     self.clientConn = reactor.connectTCP('127.0.0.1',
                                          self.serverPort.getHost().port,
                                          self.clientFactory)
Example #3
0
    def testGroupAddition(self):
        realm = service.InMemoryWordsRealm("realmname")

        p = service.Group("testgroup")
        d = wFD(realm.addGroup(p))
        yield d
        d.getResult()

        d = wFD(realm.getGroup(u"testGroup"))
        yield d
        group = d.getResult()

        self.assertIdentical(p, group)
Example #4
0
    def testGroupUsernameCollision(self):
        """
        Try creating a group with the same name as an existing user and
        assert that it succeeds, since users and groups should not be in the
        same namespace and collisions should be impossible.
        """
        realm = service.InMemoryWordsRealm("realmname")

        d = wFD(realm.createUser(u"test"))
        yield d
        user = d.getResult()

        d = wFD(realm.createGroup(u"test"))
        yield d
        group = d.getResult()
Example #5
0
    def testGroupRetrieval(self):
        realm = service.InMemoryWordsRealm("realmname")

        d = wFD(realm.createGroup(u"testgroup"))
        yield d
        group = d.getResult()

        d = wFD(realm.getGroup(u"testgroup"))
        yield d
        retrieved = d.getResult()

        self.assertIdentical(group, retrieved)

        d = wFD(realm.getGroup(u"nosuchgroup"))
        yield d
        self.assertRaises(ewords.NoSuchGroup, d.getResult)
Example #6
0
    def testEnumeration(self):
        realm = service.InMemoryWordsRealm("realmname")
        d = wFD(realm.createGroup(u"groupone"))
        yield d
        d.getResult()

        d = wFD(realm.createGroup(u"grouptwo"))
        yield d
        d.getResult()

        groups = wFD(realm.itergroups())
        yield groups
        groups = groups.getResult()

        n = [g.name for g in groups]
        n.sort()
        self.assertEquals(n, ["groupone", "grouptwo"])
Example #7
0
    def testUserAddition(self):
        realm = service.InMemoryWordsRealm("realmname")

        # Create and manually add a user to the realm
        p = service.User("testuser")
        d = wFD(realm.addUser(p))
        yield d
        user = d.getResult()
        self.assertIdentical(p, user)

        # Make sure getting that user returns the same object
        d = wFD(realm.getUser(u"testuser"))
        yield d
        retrieved = d.getResult()
        self.assertIdentical(user, retrieved)

        # Make sure looking up that user returns the same object
        d = wFD(realm.lookupUser(u"testuser"))
        yield d
        lookedUp = d.getResult()
        self.assertIdentical(retrieved, lookedUp)
Example #8
0
    def _entityCreationTest(self, kind):
        # Kind is "user" or "group"
        realm = service.InMemoryWordsRealm("realmname")

        name = u'test' + kind.lower()
        create = getattr(realm, 'create' + kind.title())
        get = getattr(realm, 'get' + kind.title())
        flag = 'create' + kind.title() + 'OnRequest'
        dupExc = getattr(ewords, 'Duplicate' + kind.title())
        noSuchExc = getattr(ewords, 'NoSuch' + kind.title())

        # Creating should succeed
        d = wFD(create(name))
        yield d
        p = d.getResult()
        self.assertEquals(p.name, name)

        # Creating the same user again should not
        d = wFD(create(name))
        yield d
        self.assertRaises(dupExc, d.getResult)

        # Getting a non-existent user should succeed if createUserOnRequest is True
        setattr(realm, flag, True)
        d = wFD(get(u"new" + kind.lower()))
        yield d
        p = d.getResult()
        self.assertEquals(p.name, "new" + kind.lower())

        # Getting that user again should return the same object
        d = wFD(get(u"new" + kind.lower()))
        yield d
        newp = d.getResult()
        self.assertIdentical(p, newp)

        # Getting a non-existent user should fail if createUserOnRequest is False
        setattr(realm, flag, False)
        d = wFD(get(u"another" + kind.lower()))
        yield d
        self.assertRaises(noSuchExc, d.getResult)
Example #9
0
def makeService(config):
    credCheckers = config.get('credCheckers', [])
    wordsRealm = service.InMemoryWordsRealm(config['hostname'])
    wordsPortal = portal.Portal(wordsRealm, credCheckers)

    msvc = MultiService()

    # XXX Attribute lookup on config is kind of bad - hrm.
    for plgName in config.interfacePlugins:
        port = config.get(plgName + '-port')
        if port is not None:
            factory = config.interfacePlugins[plgName].getFactory(
                wordsRealm, wordsPortal)
            svc = strports.service(port, factory)
            svc.setServiceParent(msvc)

    # This is bogus.  createGroup is async.  makeService must be
    # allowed to return a Deferred or some crap.
    for g in config['groups']:
        wordsRealm.createGroup(g)

    return msvc
Example #10
0
    def testUserRetrieval(self):
        realm = service.InMemoryWordsRealm("realmname")

        # Make a user to play around with
        d = wFD(realm.createUser(u"testuser"))
        yield d
        user = d.getResult()

        # Make sure getting the user returns the same object
        d = wFD(realm.getUser(u"testuser"))
        yield d
        retrieved = d.getResult()
        self.assertIdentical(user, retrieved)

        # Make sure looking up the user also returns the same object
        d = wFD(realm.lookupUser(u"testuser"))
        yield d
        lookedUp = d.getResult()
        self.assertIdentical(retrieved, lookedUp)

        # Make sure looking up a user who does not exist fails
        d = wFD(realm.lookupUser(u"nosuchuser"))
        yield d
        self.assertRaises(ewords.NoSuchUser, d.getResult)