コード例 #1
0
 def test_constructor_with_classes(self):
     conf = {
         'delay_401': True
     }
     m = middleware.create_middleware(interfaces.Identifies,
                                      interfaces.Authenticates, **conf)
     self.assertTrue(isinstance(m, middleware.Middleware))
     self.assertTrue(isinstance(m.identifiers[0], interfaces.Identifies))
     self.assertTrue(isinstance(m.authenticators[0],
                     interfaces.Authenticates))
コード例 #2
0
 def test_constructor_with_classes(self):
     conf = {'delay_401': True}
     m = middleware.create_middleware(interfaces.Identifies,
                                      interfaces.Authenticates,
                                      interfaces.Authorizes, **conf)
     self.assertTrue(isinstance(m, middleware.Middleware))
     self.assertTrue(isinstance(m.identifiers[0], interfaces.Identifies))
     self.assertTrue(
         isinstance(m.authenticators[0], interfaces.Authenticates))
     self.assertTrue(isinstance(m.authorizer, interfaces.Authorizes))
コード例 #3
0
    def __init__(self):
        """
        Constructor for the authentication middleware.
        """
        authenticator = Authenticator(drupal_auth, system_authenticator)
        authorizer = Authorizer(authorize, SystemAuthorize().authorize)
        self._auth_middleware = middleware.create_middleware(
            identify_with=[Identifier],
            authenticate_with=authenticator,
            authorize_with=authorizer)

        self._auth_middleware.raise_401_no_identity = self._raise_no_ident
        self._auth_middleware.raise_401_fail_authenticate = self._raise_failed
コード例 #4
0
ファイル: aduana-server.py プロジェクト: MohnSnow/aduana
    middlewares = []
    passwds = settings('PASSWDS')
    if passwds:
        def authenticate(identity):
            try:
                return identity.key == passwds[identity.login]
            except KeyError:
                return False

        def authorize(identity, request_action):
            return True

        auth = middleware.create_middleware(
            identify_with=[basicauth.Identifier],
            authenticate_with=external.Authenticator(
                external_authn_callable=authenticate),
            authorize_with=external.Authorizer(
                external_authz_callable=authorize)
        )
        middlewares.append(auth)

    crawled = Crawled(scheduler)
    request = Request(scheduler, settings('DEFAULT_REQS'))
    app = application = falcon.API(before=middlewares)
    app.add_route('/crawled', crawled)
    app.add_route('/request', request)

    key_path = settings('SSL_KEY')
    cert_path = settings('SSL_CERT')

    if (key_path and not cert_path) or (cert_path and not key_path):
コード例 #5
0
 def test_wrong_args(self):
     i = mock.MagicMock(spec=interfaces.Identifies)
     a = mock.MagicMock(spec=interfaces.Authenticates)
     with testtools.ExpectedException(exc.BadConfiguration):
         middleware.create_middleware(None, None)
     with testtools.ExpectedException(exc.BadConfiguration):
         middleware.create_middleware(i, None)
     with testtools.ExpectedException(exc.BadConfiguration):
         middleware.create_middleware(None, a)
     with testtools.ExpectedException(exc.BadConfiguration):
         middleware.create_middleware(dict(i=i), None)
     with testtools.ExpectedException(exc.BadConfiguration):
         middleware.create_middleware(None, dict(a=a))
     with testtools.ExpectedException(exc.BadConfiguration):
         middleware.create_middleware(a, i)
     with testtools.ExpectedException(exc.BadConfiguration):
         middleware.create_middleware(interfaces.Authenticates,
                                      interfaces.Identifies)
     with testtools.ExpectedException(exc.BadConfiguration):
         middleware.create_middleware(interfaces.Identifies,
                                      interfaces.Authenticates,
                                      interfaces.Identifies)
コード例 #6
0
    middlewares = []
    passwds = settings('PASSWDS')
    if passwds:

        def authenticate(identity):
            try:
                return identity.key == passwds[identity.login]
            except KeyError:
                return False

        def authorize(identity, request_action):
            return True

        auth = middleware.create_middleware(
            identify_with=[basicauth.Identifier],
            authenticate_with=external.Authenticator(
                external_authn_callable=authenticate),
            authorize_with=external.Authorizer(
                external_authz_callable=authorize))
        middlewares.append(auth)

    crawled = Crawled(scheduler)
    request = Request(scheduler, settings('DEFAULT_REQS'))
    app = application = falcon.API(before=middlewares)
    app.add_route('/crawled', crawled)
    app.add_route('/request', request)

    key_path = settings('SSL_KEY')
    cert_path = settings('SSL_CERT')

    if (key_path and not cert_path) or (cert_path and not key_path):
        print(
コード例 #7
0
 def test_wrong_args(self):
     i = mock.MagicMock(spec=interfaces.Identifies)
     a = mock.MagicMock(spec=interfaces.Authenticates)
     with testtools.ExpectedException(exc.BadConfiguration):
         middleware.create_middleware(None, None)
     with testtools.ExpectedException(exc.BadConfiguration):
         middleware.create_middleware(i, None)
     with testtools.ExpectedException(exc.BadConfiguration):
         middleware.create_middleware(None, a)
     with testtools.ExpectedException(exc.BadConfiguration):
         middleware.create_middleware(dict(i=i), None)
     with testtools.ExpectedException(exc.BadConfiguration):
         middleware.create_middleware(None, dict(a=a))
     with testtools.ExpectedException(exc.BadConfiguration):
         middleware.create_middleware(a, i)
     with testtools.ExpectedException(exc.BadConfiguration):
         middleware.create_middleware(interfaces.Authenticates,
                                      interfaces.Identifies)
     with testtools.ExpectedException(exc.BadConfiguration):
         middleware.create_middleware(interfaces.Identifies,
                                      interfaces.Authenticates,
                                      interfaces.Identifies)