twisted.cred.credentials.UsernamePassword

Here are the examples of the python api twisted.cred.credentials.UsernamePassword taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

68 Examples 7

Page 1 Selected Page 2

Example 1

Project: SubliminalCollaborator Source File: test_tap.py
    def test_authFailure(self):
        """
        The checker created by the C{--auth} command-line option returns a
        L{Deferred} that fails with L{UnauthorizedLogin} when
        presented with credentials that are unknown to that checker.
        """
        self.options.parseOptions(['--auth', 'file:' + self.filename])
        checker = self.options['credCheckers'][-1]
        invalid = UsernamePassword(self.usernamePassword[0], 'fake')
        # Wrong password should raise error
        return self.assertFailure(
            checker.requestAvatarId(invalid), error.UnauthorizedLogin)

Example 2

Project: SubliminalCollaborator Source File: test_newcred.py
Function: testgoodcredentials_login
    def testGoodCredentials_login(self):
        goodCreds = [credentials.UsernamePassword(u, p) for u, p in self.users]
        d = defer.gatherResults([self.port.login(c, None, ITestable)
                                 for c in goodCreds])
        d.addCallback(lambda x: [a.original.name for i, a, l in x])
        d.addCallback(self.assertEqual, [u for u, p in self.users])
        return d

Example 3

Project: mythbox Source File: test_newcred.py
Function: testgoodcredentials_login
    def testGoodCredentials_login(self):
        goodCreds = [credentials.UsernamePassword(u, p) for u, p in self.users]
        d = defer.gatherResults([self.port.login(c, None, ITestable)
                                 for c in goodCreds])
        d.addCallback(lambda x: [a.original.name for i, a, l in x])
        d.addCallback(self.assertEquals, [u for u, p in self.users])
        return d

Example 4

Project: SubliminalCollaborator Source File: test_checkers.py
    def test_verifyPassword(self):
        """
        If the encrypted password provided by the getpwnam function is valid
        (verified by the L{verifyCryptedPassword} function), we callback the
        C{requestAvatarId} L{Deferred} with the username.
        """
        def verifyCryptedPassword(crypted, pw):
            return crypted == pw
        def getpwnam(username):
            return [username, username]
        self.patch(checkers, 'verifyCryptedPassword', verifyCryptedPassword)
        checker = checkers.UNIXPasswordDatabase([getpwnam])
        credential = UsernamePassword('username', 'username')
        self.assertLoggedIn(checker.requestAvatarId(credential), 'username')

Example 5

Project: mythbox Source File: test_strcred.py
Function: set_up
    def setUp(self):
        self.admin = credentials.UsernamePassword('admin', 'asdf')
        self.alice = credentials.UsernamePassword('alice', 'foo')
        self.badPass = credentials.UsernamePassword('alice', 'foobar')
        self.badUser = credentials.UsernamePassword('x', 'yz')
        self.filename = self.mktemp()
        FilePath(self.filename).setContent('admin:asdf\nalice:foo\n')
        self.checker = strcred.makeChecker('file:' + self.filename)

Example 6

Project: mythbox Source File: test_newcred.py
Function: test_basic_login
    def testBasicLogin(self):
        l = []; f = []
        self.portal.login(credentials.UsernamePassword("bob", "hello"),
                          self, ITestable).addCallback(
            l.append).addErrback(f.append)
        if f:
            raise f[0]
        # print l[0].getBriefTraceback()
        iface, impl, logout = l[0]
        # whitebox
        self.assertEquals(iface, ITestable)
        self.failUnless(iface.providedBy(impl),
                        "%s does not implement %s" % (impl, iface))
        # greybox
        self.failUnless(impl.original.loggedIn)
        self.failUnless(not impl.original.loggedOut)
        logout()
        self.failUnless(impl.original.loggedOut)

Example 7

Project: SubliminalCollaborator Source File: test_newcred.py
Function: test_basic_login
    def testBasicLogin(self):
        l = []; f = []
        self.portal.login(credentials.UsernamePassword("bob", "hello"),
                          self, ITestable).addCallback(
            l.append).addErrback(f.append)
        if f:
            raise f[0]
        # print l[0].getBriefTraceback()
        iface, impl, logout = l[0]
        # whitebox
        self.assertEqual(iface, ITestable)
        self.failUnless(iface.providedBy(impl),
                        "%s does not implement %s" % (impl, iface))
        # greybox
        self.failUnless(impl.original.loggedIn)
        self.failUnless(not impl.original.loggedOut)
        logout()
        self.failUnless(impl.original.loggedOut)

Example 8

Project: incantus Source File: realm.py
    def connect(self):
        factory = pb.PBClientFactory()
        reactor.connectTCP(self.hostname, self.port, factory)
        cred = credentials.UsernamePassword(self.nickname, TOKEN)
        defrd = factory.login(cred, self)
        #defrd.addErrback(self.shutdown)
        return defrd

Example 9

Project: SubliminalCollaborator Source File: test_service.py
    def _loggedInAvatar(self, name, password, mind):
        creds = credentials.UsernamePassword(name, password)
        self.checker.addUser(name.encode('ascii'), password)
        d = self.realm.createUser(name)
        d.addCallback(lambda ign: self.clientFactory.login(creds, mind))
        return d

Example 10

Project: mythbox Source File: telnet.py
Function: telnet_password
    def telnet_Password(self, line):
        username, password = self.username, line
        del self.username
        def login(ignored):
            creds = credentials.UsernamePassword(username, password)
            d = self.portal.login(creds, None, ITelnetProtocol)
            d.addCallback(self._cbLogin)
            d.addErrback(self._ebLogin)
        self.transport.wont(ECHO).addCallback(login)
        return 'Discard'

Example 11

Project: SubliminalCollaborator Source File: test_checkers.py
    def test_requestAvatarIdInvalidCredential(self):
        """
        If the passed credentials aren't handled by any registered checker,
        L{SSHProtocolChecker} should raise L{UnhandledCredentials}.
        """
        checker = checkers.SSHProtocolChecker()
        d = checker.requestAvatarId(UsernamePassword('test', 'test'))
        return self.assertFailure(d, UnhandledCredentials)

Example 12

Project: ccs-calendarserver Source File: test_principal.py
    @inlineCallbacks
    def test_principalForAuthID(self):
        """
        DirectoryPrincipalProvisioningResource.principalForAuthID()
        """
        provisioningResource = self.principalRootResource

        for user in (
            yield self.directory.recordsWithRecordType(
                self.directory.recordType.user
            )
        ):
            creds = UsernamePassword(user.shortNames[0], "bogus")
            userResource = yield provisioningResource.principalForAuthID(creds)
            if True:  # user.enabled:
                self.failIf(userResource is None)
                self.assertEquals(user, userResource.record)
            else:
                self.failIf(userResource is not None)

Example 13

Project: mythbox Source File: test_checkers.py
    def test_requestAvatarIdInvalidCredential(self):
        """
        If the passed credentials aren't handled by any registered checker,
        L{SSHProtocolChecker} should raise L{UnhandledCredentials}.
        """
        checker = SSHProtocolChecker()
        d = checker.requestAvatarId(UsernamePassword('test', 'test'))
        return self.assertFailure(d, UnhandledCredentials)

Example 14

Project: SubliminalCollaborator Source File: test_checkers.py
    def test_failOnBadPassword(self):
        """
        If the verifyCryptedPassword function doesn't verify the password, the
        login fails with an L{UnauthorizedLogin} exception.
        """
        def verifyCryptedPassword(crypted, pw):
            return False
        def getpwnam(username):
            return [username, username]
        self.patch(checkers, 'verifyCryptedPassword', verifyCryptedPassword)
        checker = checkers.UNIXPasswordDatabase([getpwnam])
        credential = UsernamePassword('username', 'username')
        self.assertUnauthorizedLogin(checker.requestAvatarId(credential))

Example 15

Project: nowin_core Source File: pb.py
    @inlineCallbacks
    def login(self, user, password):
        """Login message bus

        """
        self.logger.debug('Logging in as %s ...', user)
        host = self.hosts[0]
        reactor.connectTCP(host[0], host[1], self.factory)
        cerd = credentials.UsernamePassword(user, password)
        self.avatar = yield self.factory.login(cerd)
        self.avatar.notifyOnDisconnect(self.onDisconnected)
        self.logger.info('Logged in Message Bus Server as %s', user)

Example 16

Project: SubliminalCollaborator Source File: test_ftp_options.py
Function: test_auth_failure
    def test_authFailure(self):
        """
        The checker created by the C{--auth} command-line option returns a
        L{Deferred} that fails with L{UnauthorizedLogin} when
        presented with credentials that are unknown to that checker.
        """
        self.options.parseOptions(['--auth', 'file:' + self.filename])
        checker = self.options['credCheckers'][-1]
        invalid = credentials.UsernamePassword(self.usernamePassword[0], 'fake')
        return (checker.requestAvatarId(invalid)
            .addCallbacks(
                lambda ignore: self.fail("Wrong password should raise error"),
                lambda err: err.trap(error.UnauthorizedLogin)))

Example 17

Project: mythbox Source File: test_newcred.py
Function: testfailedloginname
    def testFailedLoginName(self):
        l = []
        self.portal.login(credentials.UsernamePassword("jay", "hello"),
                          self, ITestable).addErrback(
            lambda x: x.trap(error.UnauthorizedLogin)).addCallback(l.append)
        self.failUnless(l)
        self.failUnlessEqual(error.UnauthorizedLogin, l[0])

Example 18

Project: SubliminalCollaborator Source File: test_newcred.py
Function: testfailedloginname
    def testFailedLoginName(self):
        l = []
        self.portal.login(credentials.UsernamePassword("jay", "hello"),
                          self, ITestable).addErrback(
            lambda x: x.trap(error.UnauthorizedLogin)).addCallback(l.append)
        self.failUnless(l)
        self.assertEqual(error.UnauthorizedLogin, l[0])

Example 19

Project: flumotion Source File: job.py
Function: log_in
    def login(self, username):

        def haveReference(remoteReference):
            self.info('Logged in to worker')
            self.debug('perspective %r connected', remoteReference)
            self.medium.setRemoteReference(remoteReference)

        self.info('Logging in to worker')
        d = pb.PBClientFactory.login(self,
            credentials.UsernamePassword(username, ''),
            self.medium)
        d.addCallback(haveReference)
        return d

Example 20

Project: SubliminalCollaborator Source File: service.py
Function: login_as
    def logInAs(self, nickname, password):
        d = self.factory.portal.login(
            credentials.UsernamePassword(nickname, password),
            self,
            iwords.IUser)
        d.addCallbacks(self._cbLogin, self._ebLogin, errbackArgs=(nickname,))

Example 21

Project: mythbox Source File: test_strcred.py
Function: set_up
    def setUp(self):
        self.admin = credentials.UsernamePassword('admin', 'asdf')
        self.alice = credentials.UsernamePassword('alice', 'foo')
        self.badPass = credentials.UsernamePassword('alice', 'foobar')
        self.badUser = credentials.UsernamePassword('x', 'yz')
        self.checker = strcred.makeChecker('memory:admin:asdf:alice:foo')

Example 22

Project: mythbox Source File: test_strcred.py
Function: set_up
    def setUp(self):
        self.admin = credentials.UsernamePassword('admin', 'asdf')
        self.alice = credentials.UsernamePassword('alice', 'foo')
        self.badPass = credentials.UsernamePassword('alice', 'foobar')
        self.badUser = credentials.UsernamePassword('x', 'yz')
        self.checker = strcred.makeChecker('unix')

        # Hack around the pwd and spwd modules, since we can't really
        # go about reading your /etc/passwd or /etc/shadow files
        if pwd:
            database = UserDatabase()
            for username, password in self.users.items():
                database.addUser(
                    username, crypt.crypt(password, 'F/'),
                    1000, 1000, username, '/home/' + username, '/bin/sh')
            self.patch(pwd, 'getpwnam', database.getpwnam)
        if spwd:
            self._spwd_getspnam = spwd.getspnam
            spwd.getspnam = self._spwd

Example 23

Project: flumotion Source File: test_pbstream.py
    def startClient(self):
        factory = pb.PBClientFactory()
        factory.unsafeTracebacks = 1
        reactor.connectTCP("localhost", self.portno, factory)
        client = Client()
        d = factory.login(credentials.UsernamePassword("client", "pass"),
            client)
        d.addCallback(client.connected)
        self.clientFactory = factory

        return client

Example 24

Project: infrastructure-puppet Source File: svn_buildbot.py
    def sendChanges(self, opts, changes):
        pbcf = pb.PBClientFactory()
        reactor.connectTCP(opts['bbserver'], int(opts['bbport']), pbcf)
        creds = credentials.UsernamePassword(private.pbcsUser, private.pbcsPwd)
        d = pbcf.login(creds)
        d.addCallback(self.sendAllChanges, changes)
        return d

Example 25

Project: mythbox Source File: test_checkers.py
Function: test_check_key
    def _testCheckKey(self, filename):
        self.sshDir.child(filename).setContent(self.content)
        user = UsernamePassword("user", "password")
        user.blob = "foobar"
        self.assertTrue(self.checker.checkKey(user))
        user.blob = "eggspam"
        self.assertTrue(self.checker.checkKey(user))
        user.blob = "notallowed"
        self.assertFalse(self.checker.checkKey(user))

Example 26

Project: SubliminalCollaborator Source File: test_checkers.py
    def test_requestAvatarIdWithNotEnoughAuthentication(self):
        """
        If the client indicates that it is never satisfied, by always returning
        False from _areDone, then L{SSHProtocolChecker} should raise
        L{NotEnoughAuthentication}.
        """
        checker = checkers.SSHProtocolChecker()
        def _areDone(avatarId):
            return False
        self.patch(checker, 'areDone', _areDone)

        passwordDatabase = InMemoryUsernamePasswordDatabaseDontUse()
        passwordDatabase.addUser('test', 'test')
        checker.registerChecker(passwordDatabase)
        d = checker.requestAvatarId(UsernamePassword('test', 'test'))
        return self.assertFailure(d, NotEnoughAuthentication)

Example 27

Project: ccs-calendarserver Source File: basic.py
Function: decode
    def decode(self, response, request):
        """
        Decode the credentials for basic auth.

        @see L{ICredentialFactory.decode}
        """
        try:
            creds = (response + '===').decode('base64')
        except:
            raise error.LoginFailed('Invalid credentials')

        creds = creds.split(':', 1)
        if len(creds) == 2:
            return succeed(credentials.UsernamePassword(*creds))
        else:
            return fail(error.LoginFailed('Invalid credentials'))

Example 28

Project: mythbox Source File: test_checkers.py
    def test_requestAvatarIdWithNotEnoughAuthentication(self):
        """
        If the client indicates that it is never satisfied, by always returning
        False from _areDone, then L{SSHProtocolChecker} should raise
        L{NotEnoughAuthentication}.
        """
        checker = SSHProtocolChecker()
        def _areDone(avatarId):
            return False
        self.patch(checker, 'areDone', _areDone)

        passwordDatabase = InMemoryUsernamePasswordDatabaseDontUse()
        passwordDatabase.addUser('test', 'test')
        checker.registerChecker(passwordDatabase)
        d = checker.requestAvatarId(UsernamePassword('test', 'test'))
        return self.assertFailure(d, NotEnoughAuthentication)

Example 29

Project: SubliminalCollaborator Source File: test_checkers.py
    def test_passInCheckers(self):
        """
        L{UNIXPasswordDatabase} takes a list of functions to check for UNIX
        user information.
        """
        password = crypt.crypt('secret', 'secret')
        userdb = UserDatabase()
        userdb.addUser('anybody', password, 1, 2, 'foo', '/bar', '/bin/sh')
        checker = checkers.UNIXPasswordDatabase([userdb.getpwnam])
        self.assertLoggedIn(
            checker.requestAvatarId(UsernamePassword('anybody', 'secret')),
            'anybody')

Example 30

Project: Piped Source File: spread_provider.py
Function: clientconnectionmade
    def clientConnectionMade(self, broker):
        broker.notifyOnDisconnect(self._consider_retrying)
        pb.PBClientFactory.clientConnectionMade(self, broker)

        self.on_connected(self, broker)

        if self.username:
            creds = credentials.UsernamePassword(self.username, self.password)
            d = self.login(creds)
            d.addCallback(lambda perspective: self.on_got_root_object(self, perspective))
            d.addErrback(self._log_error_getting_root_object)
        else:
            d = self.getRootObject()
            d.addCallback(lambda root_object: self.on_got_root_object(self, root_object))
            d.addErrback(self._log_error_getting_root_object)

Example 31

Project: SubliminalCollaborator Source File: test_checkers.py
    def test_failOnKeyError(self):
        """
        If the getpwnam function raises a KeyError, the login fails with an
        L{UnauthorizedLogin} exception.
        """
        def getpwnam(username):
            raise KeyError(username)
        checker = checkers.UNIXPasswordDatabase([getpwnam])
        credential = UsernamePassword('username', 'username')
        self.assertUnauthorizedLogin(checker.requestAvatarId(credential))

Example 32

Project: mythbox Source File: sip.py
Function: decode
    def decode(self, response):
        # At least one SIP client improperly pads its Base64 encoded messages
        for i in range(3):
            try:
                creds = (response + ('=' * i)).decode('base64')
            except:
                pass
            else:
                break
        else:
            # Totally bogus
            raise SIPError(400)
        p = creds.split(':', 1)
        if len(p) == 2:
            return UsernamePassword(*p)
        raise SIPError(400)

Example 33

Project: SubliminalCollaborator Source File: test_checkers.py
    def test_loopThroughFunctions(self):
        """
        UNIXPasswordDatabase.requestAvatarId loops through each getpwnam
        function associated with it and returns a L{Deferred} which fires with
        the result of the first one which returns a value other than None.
        ones do not verify the password.
        """
        def verifyCryptedPassword(crypted, pw):
            return crypted == pw
        def getpwnam1(username):
            return [username, 'not the password']
        def getpwnam2(username):
            return [username, username]
        self.patch(checkers, 'verifyCryptedPassword', verifyCryptedPassword)
        checker = checkers.UNIXPasswordDatabase([getpwnam1, getpwnam2])
        credential = UsernamePassword('username', 'username')
        self.assertLoggedIn(checker.requestAvatarId(credential), 'username')

Example 34

Project: opencanary Source File: telnet.py
Function: telnet_password
    def telnet_Password(self, line):
        # Body of this method copied from
        # twisted.conch.telnet
        username, password = self.username, line
        del self.username
        def login(ignored):
            creds = credentials.UsernamePassword(username, password)
            d = self.portal.login(creds, None, ITelnetProtocol)
            d.addCallback(self._cbLogin)
            d.addErrback(self._ebLogin)
        self.transport.wont(ECHO).addCallback(login)

        logdata = {'USERNAME': username, 'PASSWORD': password}
        self.factory.canaryservice.log(logdata, transport=self.transport)
        return 'Discard'

Example 35

Project: SubliminalCollaborator Source File: test_tap.py
Function: test_auth_success
    def test_authSuccess(self):
        """
        The checker created by the C{--auth} command-line option returns a
        L{Deferred} that returns the avatar id when presented with credentials
        that are known to that checker.
        """
        self.options.parseOptions(['--auth', 'file:' + self.filename])
        checker = self.options['credCheckers'][-1]
        correct = UsernamePassword(*self.usernamePassword)
        d = checker.requestAvatarId(correct)

        def checkSuccess(username):
            self.assertEqual(username, correct.username)

        return d.addCallback(checkSuccess)

Example 36

Project: mythbox Source File: test_newcred.py
Function: test_failed_login
    def testFailedLogin(self):
        l = []
        self.portal.login(credentials.UsernamePassword("bob", "h3llo"),
                          self, ITestable).addErrback(
            lambda x: x.trap(error.UnauthorizedLogin)).addCallback(l.append)
        self.failUnless(l)
        self.failUnlessEqual(error.UnauthorizedLogin, l[0])

Example 37

Project: SubliminalCollaborator Source File: test_ftp_options.py
Function: test_auth_success
    def test_authSuccess(self):
        """
        The checker created by the C{--auth} command-line option returns a
        L{Deferred} that returns the avatar id when presented with credentials
        that are known to that checker.
        """
        self.options.parseOptions(['--auth', 'file:' + self.filename])
        checker = self.options['credCheckers'][-1]
        correct = credentials.UsernamePassword(*self.usernamePassword)
        return checker.requestAvatarId(correct).addCallback(
            lambda username: self.assertEqual(username, correct.username)
        )

Example 38

Project: ibid Source File: buildbot.py
    def setup(self):
        self.status = pb.PBClientFactory()
        reactor.connectTCP(self.server, self.status_port, self.status)
        d = self.status.login(credentials.UsernamePassword('statusClient', 'clientpw'))
        d.addCallback(self.store_root, 'status')
        d.addCallback(lambda root: root.callRemote('subscribe', 'builds', 0, self))
        d.addErrback(self.exception)

        self.change = pb.PBClientFactory()
        reactor.connectTCP(self.server, self.change_port, self.change)
        d = self.change.login(credentials.UsernamePassword('change', 'changepw'))
        d.addCallback(self.store_root, 'change')
        d.addErrback(self.exception)

Example 39

Project: SubliminalCollaborator Source File: test_newcred.py
Function: test_failed_login
    def testFailedLogin(self):
        l = []
        self.portal.login(credentials.UsernamePassword("bob", "h3llo"),
                          self, ITestable).addErrback(
            lambda x: x.trap(error.UnauthorizedLogin)).addCallback(l.append)
        self.failUnless(l)
        self.assertEqual(error.UnauthorizedLogin, l[0])

Example 40

Project: mythbox Source File: test_newcred.py
    def testRequestAvatarId(self):
        dbfile = self.mktemp()
        db = checkers.FilePasswordDB(dbfile, caseSensitive=0)
        f = file(dbfile, 'w')
        for (u, p) in self.users:
            f.write('%s:%s\n' % (u, p))
        f.close()
        creds = [credentials.UsernamePassword(u, p) for u, p in self.users]
        d = defer.gatherResults(
            [defer.maybeDeferred(db.requestAvatarId, c) for c in creds])
        d.addCallback(self.assertEquals, [u for u, p in self.users])
        return d

Example 41

Project: SubliminalCollaborator Source File: test_newcred.py
    def testRequestAvatarId(self):
        dbfile = self.mktemp()
        db = checkers.FilePasswordDB(dbfile, caseSensitive=0)
        f = file(dbfile, 'w')
        for (u, p) in self.users:
            f.write('%s:%s\n' % (u, p))
        f.close()
        creds = [credentials.UsernamePassword(u, p) for u, p in self.users]
        d = defer.gatherResults(
            [defer.maybeDeferred(db.requestAvatarId, c) for c in creds])
        d.addCallback(self.assertEqual, [u for u, p in self.users])
        return d

Example 42

Project: vumi-go Source File: test_auth.py
    @inlineCallbacks
    def test_request_avatar_id_bad_password(self):
        checker = GoUserSessionAccessChecker(self.sm)
        creds = UsernamePassword(u"session_id", u"session-unknown")
        errored = False
        try:
            yield checker.requestAvatarId(creds)
        except error.UnauthorizedLogin:
            errored = True
        self.assertTrue(errored)

Example 43

Project: SubliminalCollaborator Source File: basic.py
Function: decode
    def decode(self, response, request):
        """
        Parse the base64-encoded, colon-separated username and password into a
        L{credentials.UsernamePassword} instance.
        """
        try:
            creds = binascii.a2b_base64(response + '===')
        except binascii.Error:
            raise error.LoginFailed('Invalid credentials')

        creds = creds.split(':', 1)
        if len(creds) == 2:
            return credentials.UsernamePassword(*creds)
        else:
            raise error.LoginFailed('Invalid credentials')

Example 44

Project: mythbox Source File: test_newcred.py
Function: test_bad_credentials
    def testBadCredentials(self):
        badCreds = [credentials.UsernamePassword(u, 'wrong password')
                    for u, p in self.users]
        d = defer.DeferredList([self.port.login(c, None, ITestable)
                                for c in badCreds], consumeErrors=True)
        d.addCallback(self._assertFailures, error.UnauthorizedLogin)
        return d

Example 45

Project: mythbox Source File: userauth.py
    def auth_password(self, packet):
        """
        Password authentication.  Payload::
            string password

        Make a UsernamePassword credential and verify it with our portal.
        """
        password = getNS(packet[1:])[0]
        c = credentials.UsernamePassword(self.user, password)
        return self.portal.login(c, None, interfaces.IConchUser).addErrback(
                                                        self._ebPassword)

Example 46

Project: vumi-go Source File: test_auth.py
    @inlineCallbacks
    def test_request_avatar_id(self):
        checker = GoUserSessionAccessChecker(self.sm)
        session = {}
        self.sm.set_user_account_key(session, u"user-1")
        yield self.sm.save_session(u"session-1", session, 10)
        creds = UsernamePassword(u"session_id", u"session-1")
        user = yield checker.requestAvatarId(creds)
        self.assertEqual(user, u"user-1")

Example 47

Project: vumi-go Source File: test_auth.py
    @inlineCallbacks
    def test_request_avatar_id_bad_username(self):
        checker = GoUserSessionAccessChecker(self.sm)
        session = {}
        self.sm.set_user_account_key(session, u"user-1")
        yield self.sm.save_session(u"session-1", session, 10)
        creds = UsernamePassword(u"session_id_BAD", u"session-1")
        try:
            yield checker.requestAvatarId(creds)
        except error.UnauthorizedLogin:
            errored = True
        self.assertTrue(errored)

Example 48

Project: cournal Source File: network.py
    def connect(self, hostname, port):
        """
        Connect to a server
        
        Positional arguments:
        hostname -- The hostname of the server
        port -- The port to connect to
        """
        if self.docuement is None:
            return
        self.factory = pb.PBClientFactory()
        reactor.connectTCP(hostname, port, self.factory)
        
        d = self.factory.login(credentials.UsernamePassword(USERNAME, PASSWORD),
                               client=self)
        d.addCallbacks(self.connected, self.connection_failed)
        return d

Example 49

Project: mythbox Source File: test_checkers.py
    def test_requestAvatarId(self):
        """
        L{SSHProtocolChecker.requestAvatarId} should defer to one if its
        registered checkers to authenticate a user.
        """
        checker = SSHProtocolChecker()
        passwordDatabase = InMemoryUsernamePasswordDatabaseDontUse()
        passwordDatabase.addUser('test', 'test')
        checker.registerChecker(passwordDatabase)
        d = checker.requestAvatarId(UsernamePassword('test', 'test'))
        def _callback(avatarId):
            self.assertEquals(avatarId, 'test')
        return d.addCallback(_callback)

Example 50

Project: SubliminalCollaborator Source File: test_checkers.py
    def test_requestAvatarId(self):
        """
        L{SSHProtocolChecker.requestAvatarId} should defer to one if its
        registered checkers to authenticate a user.
        """
        checker = checkers.SSHProtocolChecker()
        passwordDatabase = InMemoryUsernamePasswordDatabaseDontUse()
        passwordDatabase.addUser('test', 'test')
        checker.registerChecker(passwordDatabase)
        d = checker.requestAvatarId(UsernamePassword('test', 'test'))
        def _callback(avatarId):
            self.assertEqual(avatarId, 'test')
        return d.addCallback(_callback)
See More Examples - Go to Next Page
Page 1 Selected Page 2