def test_middleware(self, m): simu_req = Simu_Request() from stealth.impl_rax import auth_middleware import stealth.impl_rax.token_validation env = dict() m.post('http://mockurl/tokens', text='{"access": \ {"token": {"id": "the-token", "expires": \ "2025-09-04T14:09:20.236Z"}}}') conf.auth.auth_url = 'http://mockurl' self.auth_redis_client = \ stealth.impl_rax.token_validation.get_auth_redis_client() self.assertIsNotNone(self.auth_redis_client) self.app = auth_middleware.wrap(example_app, self.auth_redis_client) self.app(env, start_response) response = simu_req.simulate_get(self.app, self.srmock, '/', headers={ 'X-PROJECT-ID': 'proj12345'}) self.assertEqual(response, []) response = simu_req.simulate_get(self.app, self.srmock, '/', headers={'X-PROJECT-ID': 'proj12345', 'X-AUTH-TOKEN': 'token12345'}) self.assertEqual(response, []) with mock.patch.object(stealth.impl_rax.token_validation, 'validate_client_token', side_effect=side_effect_validate_client_token): response = simu_req.simulate_get(self.app, self.srmock, '/', headers={ 'X-PROJECT-ID': 'proj12345', 'X-AUTH-TOKEN': 'token12345'}) self.assertEqual(response, []) with mock.patch.object(stealth.impl_rax.token_validation, 'validate_client_impersonation', side_effect=side_effect_validate_client_impersonation): response = simu_req.simulate_get(self.app, self.srmock, '/', headers={ 'X-PROJECT-ID': 'proj12345', 'X-AUTH-TOKEN': 'token12345'}) self.assertEqual(response, [])
# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or # implied. # See the License for the specific language governing permissions and # limitations under the License. import falcon from stealth.impl_rax import auth_token from stealth.impl_rax import auth_token_cache from stealth.impl_rax import token_validation from stealth.impl_rax import auth_middleware # Need to replace with the real app. This one is only an example. def example_app(env, start_response): start_response('204 No Content', []) return [] auth_redis_client = token_validation.get_auth_redis_client() app = auth_middleware.wrap(example_app, auth_redis_client)