コード例 #1
0
    def testGetLoggedInRoot_getLogin(self):
        p = self.createPortal(realmFactory=GetLoggedInRealm)
        p.registerChecker(InMemoryUsernamePasswordDatabaseDontUse(test='test'), IUsernamePassword)
        chan = self.createGuard(p)

        req = chan.makeFakeRequest('%s/__login__?username=test&password=test' % self.getGuardPath()).followAllRedirects()
        self.assertEquals(req.written.getvalue(), "GetLoggedInAvatar")
コード例 #2
0
ファイル: jasmind.py プロジェクト: se7en0502/jasmin
    def startSMPPClientManagerPBService(self):
        "Start SMPP Client Manager PB server"

        SMPPClientPBConfigInstance = SMPPClientPBConfig(self.options['config'])
        self.components['smppcm-pb-factory'] = SMPPClientManagerPB()
        self.components['smppcm-pb-factory'].setConfig(
            SMPPClientPBConfigInstance)

        # Set authentication portal
        p = portal.Portal(JasminPBRealm(self.components['smppcm-pb-factory']))
        if SMPPClientPBConfigInstance.authentication:
            c = InMemoryUsernamePasswordDatabaseDontUse()
            c.addUser(SMPPClientPBConfigInstance.admin_username,
                      SMPPClientPBConfigInstance.admin_password)
            p.registerChecker(c)
        else:
            p.registerChecker(AllowAnonymousAccess())
        jPBPortalRoot = JasminPBPortalRoot(p)

        # Add service
        self.components['smppcm-pb-server'] = reactor.listenTCP(
            SMPPClientPBConfigInstance.port,
            pb.PBServerFactory(jPBPortalRoot),
            interface=SMPPClientPBConfigInstance.bind)

        # AMQP Broker is used to listen to submit_sm queues and publish to deliver_sm/dlr queues
        self.components['smppcm-pb-factory'].addAmqpBroker(
            self.components['amqp-broker-factory'])
        self.components['smppcm-pb-factory'].addRedisClient(
            self.components['rc'])
コード例 #3
0
ファイル: auth.py プロジェクト: ohyeah521/HoneyProxy-1
def addBasicAuth(resource, desc, **users):
    """Add basic auth for a resource.
    Twisteds modulation of everything makes this quite.. messy."""
    realm = SimpleResourceRealm(resource)
    portal = Portal(realm, [InMemoryUsernamePasswordDatabaseDontUse(**users)])
    credentialFactory = BasicCredentialFactory(desc)
    return HTTPAuthSessionWrapper(portal, [credentialFactory])
コード例 #4
0
def main(reactor, duration):
    chunkSize = 16384

    server = BenchmarkSSHFactory()
    server.portal = Portal(BenchmarkRealm())

    checker = InMemoryUsernamePasswordDatabaseDontUse()
    checker.users = {b"username": b"password"}

    server.portal.registerChecker(checker)

    port = reactor.listenTCP(0, server)
    tcpServer = TCP4ClientEndpoint(reactor, '127.0.0.1', port.getHost().port)
    sshServer = SSHCommandClientEndpoint(
        b'chargen', tcpServer,
        lambda command: SSHPasswordUserAuth(b'username', b'password', command))

    client = Client(reactor, sshServer)
    d = client.run(duration, chunkSize)

    def cleanup(passthrough):
        d = port.stopListening()
        d.addCallback(lambda ignored: passthrough)
        return d

    d.addCallback(cleanup)
    return d
コード例 #5
0
ファイル: test_www_auth.py プロジェクト: zhy0313/buildbot
 def test_getLoginResource(self):
     self.auth = auth.TwistedICredAuthBase(
         credentialFactories=[BasicCredentialFactory("buildbot")],
         checkers=[InMemoryUsernamePasswordDatabaseDontUse(good=b'guy')])
     self.auth.master = self.make_master(url='h:/a/b/')
     rsrc = self.auth.getLoginResource()
     self.assertIsInstance(rsrc, HTTPAuthSessionWrapper)
コード例 #6
0
    def startRouterPBService(self):
        "Start Router PB server"

        RouterPBConfigInstance = RouterPBConfig(self.options['config'])
        self.components['router-pb-factory'] = RouterPB()
        self.components['router-pb-factory'].setConfig(RouterPBConfigInstance)

        # Set authentication portal
        p = portal.Portal(JasminPBRealm(self.components['router-pb-factory']))
        if RouterPBConfigInstance.authentication:
            c = InMemoryUsernamePasswordDatabaseDontUse()
            c.addUser(RouterPBConfigInstance.admin_username,
                      RouterPBConfigInstance.admin_password)
            p.registerChecker(c)
        else:
            p.registerChecker(AllowAnonymousAccess())
        jPBPortalRoot = JasminPBPortalRoot(p)

        # Add service
        self.components['router-pb-server'] = reactor.listenTCP(
            RouterPBConfigInstance.port,
            pb.PBServerFactory(jPBPortalRoot),
            interface=RouterPBConfigInstance.bind)

        # AMQP Broker is used to listen to deliver_sm/dlr queues
        return self.components['router-pb-factory'].addAmqpBroker(
            self.components['amqp-broker-factory'])
コード例 #7
0
    def startInterceptorPBService(self):
        "Start Interceptor PB server"

        InterceptorPBConfigInstance = InterceptorPBConfig(
            self.options['config'])
        self.components['interceptor-pb-factory'] = InterceptorPB()
        self.components['interceptor-pb-factory'].setConfig(
            InterceptorPBConfigInstance)

        # Set authentication portal
        p = portal.Portal(
            JasminPBRealm(self.components['interceptor-pb-factory']))
        if InterceptorPBConfigInstance.authentication:
            c = InMemoryUsernamePasswordDatabaseDontUse()
            c.addUser(InterceptorPBConfigInstance.admin_username,
                      InterceptorPBConfigInstance.admin_password)
            p.registerChecker(c)
        else:
            p.registerChecker(AllowAnonymousAccess())
        jPBPortalRoot = JasminPBPortalRoot(p)

        # Add service
        self.components['interceptor-pb-server'] = reactor.listenTCP(
            InterceptorPBConfigInstance.port,
            pb.PBServerFactory(jPBPortalRoot),
            interface=InterceptorPBConfigInstance.bind)
コード例 #8
0
    def setUp(self):
        yield SMPPClientTestCases.setUp(self)

        # Init SMPPServerPB
        SMPPServerPBConfigInstance = SMPPServerPBConfig()
        SMPPServerPBInstance = SMPPServerPB(SMPPServerPBConfigInstance)
        SMPPServerPBInstance.addSmpps(self.smpps_factory)

        p = portal.Portal(JasminPBRealm(SMPPServerPBInstance))
        c = InMemoryUsernamePasswordDatabaseDontUse()
        c.addUser('smppsadmin', md5('smppspwd'.encode('ascii')).digest())
        p.registerChecker(c)
        jPBPortalRoot = JasminPBPortalRoot(p)
        self.SMPPServerPBInstanceServer = reactor.listenTCP(SMPPServerPBConfigInstance.port,
                                                            pb.PBServerFactory(jPBPortalRoot))

        # Init SMPPServerPBClient and connect it to SMPPServerPB
        SMPPServerPBClientConfigInstance = SMPPServerPBClientConfig()
        self.SMPPServerPBProxyInstance = SMPPServerPBProxy()
        yield self.SMPPServerPBProxyInstance.connect(
            SMPPServerPBClientConfigInstance.host,
            SMPPServerPBClientConfigInstance.port,
            SMPPServerPBClientConfigInstance.username,
            SMPPServerPBClientConfigInstance.password,
            retry=False)

        # Lower the timeout config to pass the timeout tests quickly
        self.DLRThrower.config.timeout = 2
        self.DLRThrower.config.retry_delay = 1
        self.DLRThrower.config.max_retries = 2

        # Most important thing:
        # Swap default direct smpps access to perspectivebroker smpps access:
        self.DLRThrower.addSmpps(self.SMPPServerPBProxyInstance)
コード例 #9
0
    def testLoginWithNoSession(self):
        p = self.createPortal()
        p.registerChecker(InMemoryUsernamePasswordDatabaseDontUse(test='test'), IUsernamePassword)
        chan = self.createGuard(p)

        req = chan.makeFakeRequest('%s/__login__/?username=test&password=test' % self.getGuardPath()).followAllRedirects()
        self.assertEquals(req.written.getvalue(), "Yes")
コード例 #10
0
ファイル: test_guard.py プロジェクト: calston/tums
    def test_oldRequestParametersIgnored(self):
        """
        The request parameters from the initial session negotiation request are
        I{not} set on the login request.
        """
        renders = []
        portal = self.createPortal(lambda: SillyRealm(
            authenticatedAvatarFactory=lambda: InspectfulPage(renders)))
        portal.registerChecker(
            InMemoryUsernamePasswordDatabaseDontUse(test='test'),
            IUsernamePassword)
        channel = self.createGuard(portal)

        # Negotiate a session using a request with some parameters.
        request = channel.makeFakeRequest(self.getGuardPath() +
                                          "?foo=bar&bar=baz")
        request = request.followAllRedirects()

        # Perform the login.
        request = channel.makeFakeRequest(
            self.getGuardPath() + '/__login__?username=test&password=test')
        request = request.followAllRedirects()

        self.assertEquals(request.written.getvalue(), '')
        self.assertEqual(renders, [({
            'username': ['test'],
            'password': ['test']
        }, None, '', 'GET', {
            'host': 'fake.com'
        })])
コード例 #11
0
ファイル: test_router.py プロジェクト: se7en0502/jasmin
    def setUp(self, authentication=False):
        # Initiating config objects without any filename
        # will lead to setting defaults and that's what we
        # need to run the tests
        self.RouterPBConfigInstance = RouterPBConfig()

        # Launch the router server
        self.pbRoot_f = RouterPB()

        # Mock callbacks
        # will be used for assertions
        self.pbRoot_f.bill_request_submit_sm_resp_callback = mock.Mock(
            wraps=self.pbRoot_f.bill_request_submit_sm_resp_callback)
        self.pbRoot_f.deliver_sm_callback = mock.Mock(
            wraps=self.pbRoot_f.deliver_sm_callback)

        self.pbRoot_f.setConfig(self.RouterPBConfigInstance)
        p = portal.Portal(JasminPBRealm(self.pbRoot_f))
        if not authentication:
            p.registerChecker(AllowAnonymousAccess())
        else:
            c = InMemoryUsernamePasswordDatabaseDontUse()
            c.addUser('test_user', md5('test_password').digest())
            p.registerChecker(c)
        jPBPortalRoot = JasminPBPortalRoot(p)
        self.PBServer = reactor.listenTCP(0, pb.PBServerFactory(jPBPortalRoot))
        self.pbPort = self.PBServer.getHost().port
コード例 #12
0
ファイル: auth.py プロジェクト: pombreda/buildbot-1
 def __init__(self, users, **kwargs):
     TwistedICredAuthBase.__init__(
         self,
         [DigestCredentialFactory("md5", "buildbot"),
          BasicCredentialFactory("buildbot")],
         [InMemoryUsernamePasswordDatabaseDontUse(**dict(users))],
         **kwargs)
コード例 #13
0
ファイル: taskpb.py プロジェクト: minrk/ipython-svn-archive
def PBServerFactoryFromTaskController(taskController):
    #### TODO: Real authentication here
    portal = Portal(IPythonRealm(taskController))
    checker = InMemoryUsernamePasswordDatabaseDontUse()
    checker.addUser("guest", "guest")
    portal.registerChecker(checker)
    return pb.PBServerFactory(portal)
コード例 #14
0
    def setUp(self, authentication=False):
        "This will launch InterceptorPB and provide a client connected to it."
        # Launch a client in a disconnected state
        # it will be connected on demand through the self.ipb_connect() method
        self.ipb_client = InterceptorPBProxy()

        yield ProvisionWithoutInterceptorPB.setUp(self)

        # Initiating config objects without any filename
        # will lead to setting defaults and that's what we
        # need to run the tests
        InterceptorPBConfigInstance = InterceptorPBConfig()

        # Launch the interceptor server
        pbInterceptor_factory = InterceptorPB(InterceptorPBConfigInstance)

        # Configure portal
        p = portal.Portal(JasminPBRealm(pbInterceptor_factory))
        if not authentication:
            p.registerChecker(AllowAnonymousAccess())
        else:
            c = InMemoryUsernamePasswordDatabaseDontUse()
            c.addUser('test_user',
                      md5('test_password'.encode('ascii')).digest())
            p.registerChecker(c)
        jPBPortalRoot = JasminPBPortalRoot(p)
        self.pbInterceptor_server = reactor.listenTCP(
            0, pb.PBServerFactory(jPBPortalRoot))
        self.pbInterceptor_port = self.pbInterceptor_server.getHost().port
コード例 #15
0
ファイル: conftest.py プロジェクト: wjj11/Uranium
        def __init__(self):
            super().__init__()
            self._success = SuccessfulResource()
            self._timeout = TimeoutResource()

            checkers = [InMemoryUsernamePasswordDatabaseDontUse(user = b"user")]
            portal = Portal(SimpleRealm(), checkers)
            self._auth_resource = guard.HTTPAuthSessionWrapper(portal, [guard.BasicCredentialFactory("auth")])
コード例 #16
0
def main():
    log.startLogging(sys.stdout)
    checkers = [InMemoryUsernamePasswordDatabaseDontUse(joe='blow')]
    wrapper = guard.HTTPAuthSessionWrapper(
        Portal(SimpleRealm(), checkers),
        [guard.DigestCredentialFactory('md5', 'example.com')])
    reactor.listenTCP(8889, server.Site(resource=wrapper))
    reactor.run()
コード例 #17
0
 def setUp(self):
     checker = InMemoryUsernamePasswordDatabaseDontUse(foo='something')
     realm = UserRealm()
     self.clock = task.Clock()
     app = ServerApp(InMemoryTicketStore(reactor=self.clock), realm,
                     [checker], lambda x: True)
     self.app = app
     self.resource = app.app.resource()
コード例 #18
0
ファイル: pbbenchserver.py プロジェクト: SPIN-UMass/SWEET
def main():
    from twisted.cred.portal import Portal
    from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse
    portal = Portal(SimpleRealm())
    checker = InMemoryUsernamePasswordDatabaseDontUse()
    checker.addUser("benchmark", "benchmark")
    portal.registerChecker(checker)
    reactor.listenTCP(8787, pb.PBServerFactory(portal))
    reactor.run()
コード例 #19
0
 def __init__(self, users, **kwargs):
     for user, password in users.items():
         users[user] = unicode2bytes(password)
     TwistedICredAuthBase.__init__(
         self,
         [DigestCredentialFactory(b"md5", b"buildbot"),
          BasicCredentialFactory(b"buildbot")],
         [InMemoryUsernamePasswordDatabaseDontUse(**dict(users))],
         **kwargs)
コード例 #20
0
ファイル: test_client.py プロジェクト: gwartass/fastjsonrpc
    def setUp(self):
        checker = InMemoryUsernamePasswordDatabaseDontUse(user='******')
        portal = Portal(AuthDummyServer(), [checker])
        credentialFactory = BasicCredentialFactory('localhost')
        resource = HTTPAuthSessionWrapper(portal, [credentialFactory])
        site = Site(resource)

        self.port = reactor.listenTCP(0, site)
        self.portNumber = self.port._realPortNumber
コード例 #21
0
def StartServices(username,password):
    from md5 import md5
    password = md5(password).digest()
    
    portal = Portal(SimpleRealm())
    checker = InMemoryUsernamePasswordDatabaseDontUse()
    checker.addUser(username,password)
    portal.registerChecker(checker)
    reactor.listenTCP(7001,pb.PBServerFactory(portal))
コード例 #22
0
ファイル: auth.py プロジェクト: pmisik/buildbot
 def __init__(self, users, **kwargs):
     if isinstance(users, dict):
         users = {user: unicode2bytes(pw) for user, pw in users.items()}
     elif isinstance(users, list):
         users = [(user, unicode2bytes(pw)) for user, pw in users]
     super().__init__([
         DigestCredentialFactory(b"MD5", b"buildbot"),
         BasicCredentialFactory(b"buildbot")
     ], [InMemoryUsernamePasswordDatabaseDontUse(**dict(users))], **kwargs)
コード例 #23
0
    def testGetLoggedInRoot_httpAuthLogin(self):

        p = self.createPortal(realmFactory=GetLoggedInRealm)
        p.registerChecker(InMemoryUsernamePasswordDatabaseDontUse(test='test'), IUsernamePassword)
        chan = self.createGuard(p)
        for x in range(4):
            req = chan.makeFakeRequest('%s/' % self.getGuardPath(), "test", "test")
            self.assertEquals(req.written.getvalue(), "GetLoggedInAvatar")
        self.assertEquals(len(self.sessions),1)
コード例 #24
0
def StartServices():
    #fire up the World Stuff
    portal = Portal(SimpleRealm())
    checker = InMemoryUsernamePasswordDatabaseDontUse()
    from md5 import md5
    password = md5("daemon").digest()
    for x in range(0, 100):
        checker.addUser(str(x), password)
    portal.registerChecker(checker)
    reactor.listenTCP(7000, pb.PBServerFactory(portal))
コード例 #25
0
ファイル: test_guard.py プロジェクト: calston/tums
 def testHttpAuthInit(self):
     p = self.createPortal()
     chan = self.createGuard(p)
     p.registerChecker(InMemoryUsernamePasswordDatabaseDontUse(test='test'),
                       IUsernamePassword)
     for x in range(3):
         req = chan.makeFakeRequest('%s/' % self.getGuardPath(), "test",
                                    "test")
         self.assertEquals(req.written.getvalue(), "Yes")
     self.assertEquals(len(self.sessions), 1)
コード例 #26
0
def main():
    from twisted.internet import reactor
    from twisted.cred.portal import Portal
    from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse
    portal = Portal(SimpleRealm())
    checker = InMemoryUsernamePasswordDatabaseDontUse()
    checker.addUser("guest", "guest")
    portal.registerChecker(checker)
    reactor.listenTCP(pb.portno, pb.PBServerFactory(portal))
    reactor.run()
コード例 #27
0
def main():
    """
    Start the AMP server and the reactor.
    """
    startLogging(stdout)
    checker = InMemoryUsernamePasswordDatabaseDontUse()
    checker.addUser("testuser", "examplepass")
    realm = AdditionRealm()
    factory = CredAMPServerFactory(Portal(realm, [checker]))
    reactor.listenTCP(7805, factory)
    reactor.run()
コード例 #28
0
def setup():
    from twisted.internet import reactor
    from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse


    portal = Portal(SimpleRealm())
    checker = InMemoryUsernamePasswordDatabaseDontUse()
    checker.addUser("guest", "password")
    portal.registerChecker(checker)

    reactor.listenTCP(7777, ConsoleSMTPFactory(portal))
コード例 #29
0
ファイル: twisted-web-ssl.py プロジェクト: hack-bitdust/devel
def main(root):
    log.startLogging(sys.stdout)
    checkers = [InMemoryUsernamePasswordDatabaseDontUse(**USERS)]

    wrapper = guard.HTTPAuthSessionWrapper(
        Portal(SimpleRealm(root), checkers),
        [guard.DigestCredentialFactory('md5', 'whatever.com')])

    reactor.listenSSL(443, server.Site(resource=wrapper),
                      contextFactory=sslContext)
    reactor.run()
コード例 #30
0
ファイル: test_guard.py プロジェクト: calston/tums
    def testErrorPage_getLogin_deep(self):
        """Failed normal login results in anonymous view of the same page."""
        p = self.createPortal()
        p.registerChecker(InMemoryUsernamePasswordDatabaseDontUse(test='test'),
                          IUsernamePassword)
        chan = self.createGuard(p)

        req = chan.makeFakeRequest(
            '%s/__login__/quux/thud?username=test&password=invalid-password' %
            self.getGuardPath()).followAllRedirects()
        self.assertEquals(req.written.getvalue(), 'No')
        self.assertEquals(req.path, '%s/quux/thud' % self.getGuardPath())