Coverage for manila/tests/api/middleware/test_auth.py: 100%

34 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2026-02-18 22:19 +0000

1# Copyright (c) 2012 OpenStack, LLC 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); you may 

4# not use this file except in compliance with the License. You may obtain 

5# a copy of the License at 

6# 

7# http://www.apache.org/licenses/LICENSE-2.0 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 

11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 

12# License for the specific language governing permissions and limitations 

13# under the License. 

14 

15import webob 

16 

17import manila.api.middleware.auth 

18from manila import test 

19 

20 

21class TestManilaKeystoneContextMiddleware(test.TestCase): 

22 

23 def setUp(self): 

24 super(TestManilaKeystoneContextMiddleware, self).setUp() 

25 

26 @webob.dec.wsgify() 

27 def fake_app(req): 

28 self.context = req.environ['manila.context'] 

29 return webob.Response() 

30 

31 self.context = None 

32 self.middleware = (manila.api.middleware.auth 

33 .ManilaKeystoneContext(fake_app)) 

34 self.request = webob.Request.blank('/') 

35 self.request.headers['X_TENANT_ID'] = 'testtenantid' 

36 self.request.headers['X_AUTH_TOKEN'] = 'testauthtoken' 

37 

38 def test_no_user_or_user_id(self): 

39 response = self.request.get_response(self.middleware) 

40 self.assertEqual('401 Unauthorized', response.status) 

41 

42 def test_user_only(self): 

43 self.request.headers['X_USER_ID'] = 'testuserid' 

44 response = self.request.get_response(self.middleware) 

45 self.assertEqual('200 OK', response.status) 

46 self.assertEqual('testuserid', self.context.user_id) 

47 

48 def test_user_id_only(self): 

49 self.request.headers['X_USER'] = 'testuser' 

50 response = self.request.get_response(self.middleware) 

51 self.assertEqual('200 OK', response.status) 

52 self.assertEqual('testuser', self.context.user_id) 

53 

54 def test_user_id_trumps_user(self): 

55 self.request.headers['X_USER_ID'] = 'testuserid' 

56 self.request.headers['X_USER'] = 'testuser' 

57 response = self.request.get_response(self.middleware) 

58 self.assertEqual('200 OK', response.status) 

59 self.assertEqual('testuserid', self.context.user_id)