當前位置: 首頁>>代碼示例>>Python>>正文


Python checkers.InMemoryUsernamePasswordDatabaseDontUse方法代碼示例

本文整理匯總了Python中twisted.cred.checkers.InMemoryUsernamePasswordDatabaseDontUse方法的典型用法代碼示例。如果您正苦於以下問題:Python checkers.InMemoryUsernamePasswordDatabaseDontUse方法的具體用法?Python checkers.InMemoryUsernamePasswordDatabaseDontUse怎麽用?Python checkers.InMemoryUsernamePasswordDatabaseDontUse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在twisted.cred.checkers的用法示例。


在下文中一共展示了checkers.InMemoryUsernamePasswordDatabaseDontUse方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: setUp

# 需要導入模塊: from twisted.cred import checkers [as 別名]
# 或者: from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse [as 別名]
def setUp(self):
        """
        Create a realm, portal, and L{HTTPAuthSessionWrapper} to use in the tests.
        """
        self.username = b'foo bar'
        self.password = b'bar baz'
        self.avatarContent = b"contents of the avatar resource itself"
        self.childName = b"foo-child"
        self.childContent = b"contents of the foo child of the avatar"
        self.checker = InMemoryUsernamePasswordDatabaseDontUse()
        self.checker.addUser(self.username, self.password)
        self.avatar = Data(self.avatarContent, 'text/plain')
        self.avatar.putChild(
            self.childName, Data(self.childContent, 'text/plain'))
        self.avatars = {self.username: self.avatar}
        self.realm = Realm(self.avatars.get)
        self.portal = portal.Portal(self.realm, [self.checker])
        self.credentialFactories = []
        self.wrapper = HTTPAuthSessionWrapper(
            self.portal, self.credentialFactories) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:22,代碼來源:test_httpauth.py

示例2: setUp

# 需要導入模塊: from twisted.cred import checkers [as 別名]
# 或者: from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse [as 別名]
def setUp(self):
        self.hostname = b"ssh.example.com"
        self.port = 42022
        self.user = b"user"
        self.password = b"password"
        self.reactor = MemoryReactorClock()
        self.realm = TrivialRealm()
        self.portal = Portal(self.realm)
        self.passwdDB = InMemoryUsernamePasswordDatabaseDontUse()
        self.passwdDB.addUser(self.user, self.password)
        self.portal.registerChecker(self.passwdDB)
        self.factory = CommandFactory()
        self.factory.reactor = self.reactor
        self.factory.portal = self.portal
        self.factory.doStart()
        self.addCleanup(self.factory.doStop)

        self.clientAddress = IPv4Address("TCP", "10.0.0.1", 12345)
        self.serverAddress = IPv4Address("TCP", "192.168.100.200", 54321) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:21,代碼來源:test_endpoints.py

示例3: test_requestAvatarIdWithNotEnoughAuthentication

# 需要導入模塊: from twisted.cred import checkers [as 別名]
# 或者: from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse [as 別名]
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(b'test', b'test')
        checker.registerChecker(passwordDatabase)
        d = checker.requestAvatarId(UsernamePassword(b'test', b'test'))
        return self.assertFailure(d, NotEnoughAuthentication) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:18,代碼來源:test_checkers.py

示例4: test_anonymousLoginNotPermitted

# 需要導入模塊: from twisted.cred import checkers [as 別名]
# 或者: from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse [as 別名]
def test_anonymousLoginNotPermitted(self):
        """
        Verify that without an anonymous checker set up, anonymous login is
        rejected.
        """
        self.portal.registerChecker(
            checkers.InMemoryUsernamePasswordDatabaseDontUse(user='pass'))
        d = self.clientFactory.login(credentials.Anonymous(), "BRAINS!")
        self.assertFailure(d, UnhandledCredentials)

        def cleanup(ignore):
            errors = self.flushLoggedErrors(UnhandledCredentials)
            self.assertEqual(len(errors), 1)
        d.addCallback(cleanup)

        self.establishClientAndServer()
        self.pump.flush()

        return d 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:21,代碼來源:test_pb.py

示例5: test_anonymousLoginWithMultipleCheckers

# 需要導入模塊: from twisted.cred import checkers [as 別名]
# 或者: from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse [as 別名]
def test_anonymousLoginWithMultipleCheckers(self):
        """
        Like L{test_anonymousLogin} but against a portal with a checker for
        both IAnonymous and IUsernamePassword.
        """
        self.portal.registerChecker(checkers.AllowAnonymousAccess())
        self.portal.registerChecker(
            checkers.InMemoryUsernamePasswordDatabaseDontUse(user=b'pass'))
        d = self.clientFactory.login(credentials.Anonymous(), "BRAINS!")

        def cbLogin(perspective):
            return perspective.callRemote('echo', 123)
        d.addCallback(cbLogin)

        d.addCallback(self.assertEqual, 123)

        self.establishClientAndServer()
        self.pump.flush()

        return d 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:22,代碼來源:test_pb.py

示例6: test_authenticatedLoginWithMultipleCheckers

# 需要導入模塊: from twisted.cred import checkers [as 別名]
# 或者: from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse [as 別名]
def test_authenticatedLoginWithMultipleCheckers(self):
        """
        Like L{test_anonymousLoginWithMultipleCheckers} but check that
        username/password authentication works.
        """
        self.portal.registerChecker(checkers.AllowAnonymousAccess())
        self.portal.registerChecker(
            checkers.InMemoryUsernamePasswordDatabaseDontUse(user=b'pass'))
        d = self.clientFactory.login(
            credentials.UsernamePassword(b'user', b'pass'), "BRAINS!")

        def cbLogin(perspective):
            return perspective.callRemote('add', 100, 23)
        d.addCallback(cbLogin)

        d.addCallback(self.assertEqual, 123)

        self.establishClientAndServer()
        self.pump.flush()

        return d 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:23,代碼來源:test_pb.py

示例7: test_view

# 需要導入模塊: from twisted.cred import checkers [as 別名]
# 或者: from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse [as 別名]
def test_view(self):
        """
        Verify that a viewpoint can be retrieved after authenticating with
        cred.
        """
        self.portal.registerChecker(
            checkers.InMemoryUsernamePasswordDatabaseDontUse(user=b'pass'))
        d = self.clientFactory.login(
            credentials.UsernamePassword(b"user", b"pass"), "BRAINS!")

        def cbLogin(perspective):
            return perspective.callRemote("getViewPoint")
        d.addCallback(cbLogin)

        def cbView(viewpoint):
            return viewpoint.callRemote("check")
        d.addCallback(cbView)

        d.addCallback(self.assertTrue)

        self.establishClientAndServer()
        self.pump.flush()

        return d 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:26,代碼來源:test_pb.py

示例8: generateChecker

# 需要導入模塊: from twisted.cred import checkers [as 別名]
# 或者: from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse [as 別名]
def generateChecker(self, argstring):
        """
        This checker factory expects to get a list of
        username:password pairs, with each pair also separated by a
        colon. For example, the string 'alice:f:bob:g' would generate
        two users, one named 'alice' and one named 'bob'.
        """
        checker = InMemoryUsernamePasswordDatabaseDontUse()
        if argstring:
            pieces = argstring.split(':')
            if len(pieces) % 2:
                from twisted.cred.strcred import InvalidAuthArgumentString
                raise InvalidAuthArgumentString(
                    "argstring must be in format U:P:...")
            for i in range(0, len(pieces), 2):
                username, password = pieces[i], pieces[i+1]
                checker.addUser(username, password)
        return checker 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:20,代碼來源:cred_memory.py

示例9: setUp

# 需要導入模塊: from twisted.cred import checkers [as 別名]
# 或者: from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse [as 別名]
def setUp(self):
        """
        Create a portal and add an in memory checker to it.

        Then set up a protectedResource that will be wrapped in each test.
        """
        self.portal = portal.Portal(TestAuthRealm())
        c = checkers.InMemoryUsernamePasswordDatabaseDontUse()
        c.addUser('username', 'password')

        self.portal.registerChecker(c)

        self.credFactory = basic.BasicCredentialFactory('test realm')

        self.protectedResource = ProtectedResource()
        self.protectedResource.responseText = "You shouldn't see me." 
開發者ID:apple,項目名稱:ccs-calendarserver,代碼行數:18,代碼來源:test_httpauth.py

示例10: setUp

# 需要導入模塊: from twisted.cred import checkers [as 別名]
# 或者: from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse [as 別名]
def setUp(self):
        """
        Create a realm, portal, and L{HTTPAuthSessionWrapper} to use in the tests.
        """
        self.username = 'foo bar'
        self.password = 'bar baz'
        self.avatarContent = "contents of the avatar resource itself"
        self.childName = "foo-child"
        self.childContent = "contents of the foo child of the avatar"
        self.checker = InMemoryUsernamePasswordDatabaseDontUse()
        self.checker.addUser(self.username, self.password)
        self.avatar = Data(self.avatarContent, 'text/plain')
        self.avatar.putChild(
            self.childName, Data(self.childContent, 'text/plain'))
        self.avatars = {self.username: self.avatar}
        self.realm = Realm(self.avatars.get)
        self.portal = portal.Portal(self.realm, [self.checker])
        self.credentialFactories = []
        self.wrapper = HTTPAuthSessionWrapper(
            self.portal, self.credentialFactories) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:22,代碼來源:test_httpauth.py

示例11: test_requestAvatarIdWithNotEnoughAuthentication

# 需要導入模塊: from twisted.cred import checkers [as 別名]
# 或者: from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse [as 別名]
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) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:18,代碼來源:test_checkers.py

示例12: connectedServerAndClient

# 需要導入模塊: from twisted.cred import checkers [as 別名]
# 或者: from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse [as 別名]
def connectedServerAndClient():
    """
    Returns a 3-tuple: (client, server, pump).
    """
    clientBroker = pb.Broker()
    checker = checkers.InMemoryUsernamePasswordDatabaseDontUse(guest='guest')
    factory = pb.PBServerFactory(portal.Portal(DummyRealm(), [checker]))
    serverBroker = factory.buildProtocol(('127.0.0.1',))

    clientTransport = StringIO()
    serverTransport = StringIO()
    clientBroker.makeConnection(protocol.FileWrapper(clientTransport))
    serverBroker.makeConnection(protocol.FileWrapper(serverTransport))
    pump = IOPump(clientBroker, serverBroker, clientTransport, serverTransport)
    # Challenge-response authentication:
    pump.flush()
    return clientBroker, serverBroker, pump 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:19,代碼來源:test_pb.py

示例13: test_anonymousLoginNotPermitted

# 需要導入模塊: from twisted.cred import checkers [as 別名]
# 或者: from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse [as 別名]
def test_anonymousLoginNotPermitted(self):
        """
        Verify that without an anonymous checker set up, anonymous login is
        rejected.
        """
        self.portal.registerChecker(
            checkers.InMemoryUsernamePasswordDatabaseDontUse(user='pass'))
        factory = pb.PBClientFactory()
        d = factory.login(credentials.Anonymous(), "BRAINS!")
        self.assertFailure(d, UnhandledCredentials)

        def cleanup(ignore):
            errors = self.flushLoggedErrors(UnhandledCredentials)
            self.assertEquals(len(errors), 1)
            return self._disconnect(None, factory)
        d.addCallback(cleanup)

        connector = reactor.connectTCP('127.0.0.1', self.portno, factory)
        self.addCleanup(connector.disconnect)
        return d 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:22,代碼來源:test_pb.py

示例14: test_anonymousLoginWithMultipleCheckers

# 需要導入模塊: from twisted.cred import checkers [as 別名]
# 或者: from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse [as 別名]
def test_anonymousLoginWithMultipleCheckers(self):
        """
        Like L{test_anonymousLogin} but against a portal with a checker for
        both IAnonymous and IUsernamePassword.
        """
        self.portal.registerChecker(checkers.AllowAnonymousAccess())
        self.portal.registerChecker(
            checkers.InMemoryUsernamePasswordDatabaseDontUse(user='pass'))
        factory = pb.PBClientFactory()
        d = factory.login(credentials.Anonymous(), "BRAINS!")

        def cbLogin(perspective):
            return perspective.callRemote('echo', 123)
        d.addCallback(cbLogin)

        d.addCallback(self.assertEqual, 123)

        d.addCallback(self._disconnect, factory)

        connector = reactor.connectTCP('127.0.0.1', self.portno, factory)
        self.addCleanup(connector.disconnect)
        return d 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:24,代碼來源:test_pb.py

示例15: test_authenticatedLoginWithMultipleCheckers

# 需要導入模塊: from twisted.cred import checkers [as 別名]
# 或者: from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse [as 別名]
def test_authenticatedLoginWithMultipleCheckers(self):
        """
        Like L{test_anonymousLoginWithMultipleCheckers} but check that
        username/password authentication works.
        """
        self.portal.registerChecker(checkers.AllowAnonymousAccess())
        self.portal.registerChecker(
            checkers.InMemoryUsernamePasswordDatabaseDontUse(user='pass'))
        factory = pb.PBClientFactory()
        d = factory.login(
            credentials.UsernamePassword('user', 'pass'), "BRAINS!")

        def cbLogin(perspective):
            return perspective.callRemote('add', 100, 23)
        d.addCallback(cbLogin)

        d.addCallback(self.assertEqual, 123)

        d.addCallback(self._disconnect, factory)

        connector = reactor.connectTCP('127.0.0.1', self.portno, factory)
        self.addCleanup(connector.disconnect)
        return d 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:25,代碼來源:test_pb.py


注:本文中的twisted.cred.checkers.InMemoryUsernamePasswordDatabaseDontUse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。