当前位置: 首页>>代码示例>>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;未经允许,请勿转载。