Esempio n. 1
0
    def test_authenticated_client_required(self):
        # Returns catalog if authentication is valid.
        with self.app.test_request_context('/', headers=self.valid_auth):
            result = authenticated_client_from_request(self._db)
            eq_(result, self.client)

        # Returns error if authentication is invalid.
        invalid_auth = 'Basic ' + base64.b64encode('abc:defg')
        with self.app.test_request_context(
                '/', headers=dict(Authorization=invalid_auth)):
            result = authenticated_client_from_request(self._db)
            eq_(True, isinstance(result, ProblemDetail))
            eq_(HTTP_UNAUTHORIZED, result.status_code)

        # Returns errors without authentication.
        with self.app.test_request_context('/'):
            result = authenticated_client_from_request(self._db)
            eq_(True, isinstance(result, ProblemDetail))
Esempio n. 2
0
 def decorated(*args, **kwargs):
     client = authenticated_client_from_request(app._db)
     if isinstance(client, ProblemDetail):
         return client.response
     return f(*args, **kwargs)
Esempio n. 3
0
 def decorated(*args, **kwargs):
     client = authenticated_client_from_request(app._db)
     if isinstance(client, ProblemDetail):
         return client.response
     return f(*args, **kwargs)
Esempio n. 4
0
 def decorated(*args, **kwargs):
     client = authenticated_client_from_request(Conf.db, required=False)
     if isinstance(client, ProblemDetail):
         return client.response
     return f(*args, **kwargs)