]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | try: |
2 | import mock | |
3 | except ImportError: | |
4 | import unittest.mock as mock | |
11fdf7f2 TL |
5 | |
6 | from . import ControllerTestCase | |
7 | from ..controllers.rgw import RgwUser | |
8 | ||
9 | ||
10 | class RgwUserControllerTestCase(ControllerTestCase): | |
11 | @classmethod | |
12 | def setup_server(cls): | |
13 | RgwUser._cp_config['tools.authenticate.on'] = False # pylint: disable=protected-access | |
14 | cls.setup_controllers([RgwUser], '/test') | |
15 | ||
16 | @mock.patch('dashboard.controllers.rgw.RgwRESTController.proxy') | |
17 | def test_user_list(self, mock_proxy): | |
18 | mock_proxy.side_effect = [{ | |
19 | 'count': 3, | |
20 | 'keys': ['test1', 'test2', 'test3'], | |
21 | 'truncated': False | |
22 | }] | |
23 | self._get('/test/api/rgw/user') | |
24 | self.assertStatus(200) | |
25 | mock_proxy.assert_has_calls([ | |
26 | mock.call('GET', 'user?list', {}) | |
27 | ]) | |
28 | self.assertJsonBody(['test1', 'test2', 'test3']) | |
29 | ||
30 | @mock.patch('dashboard.controllers.rgw.RgwRESTController.proxy') | |
31 | def test_user_list_marker(self, mock_proxy): | |
32 | mock_proxy.side_effect = [{ | |
33 | 'count': 3, | |
34 | 'keys': ['test1', 'test2', 'test3'], | |
35 | 'marker': 'foo:bar', | |
36 | 'truncated': True | |
37 | }, { | |
38 | 'count': 1, | |
39 | 'keys': ['admin'], | |
40 | 'truncated': False | |
41 | }] | |
42 | self._get('/test/api/rgw/user') | |
43 | self.assertStatus(200) | |
44 | mock_proxy.assert_has_calls([ | |
45 | mock.call('GET', 'user?list', {}), | |
46 | mock.call('GET', 'user?list', {'marker': 'foo:bar'}) | |
47 | ]) | |
48 | self.assertJsonBody(['test1', 'test2', 'test3', 'admin']) | |
49 | ||
50 | @mock.patch('dashboard.controllers.rgw.RgwRESTController.proxy') | |
51 | def test_user_list_duplicate_marker(self, mock_proxy): | |
52 | mock_proxy.side_effect = [{ | |
53 | 'count': 3, | |
54 | 'keys': ['test1', 'test2', 'test3'], | |
55 | 'marker': 'foo:bar', | |
56 | 'truncated': True | |
57 | }, { | |
58 | 'count': 3, | |
59 | 'keys': ['test4', 'test5', 'test6'], | |
60 | 'marker': 'foo:bar', | |
61 | 'truncated': True | |
62 | }, { | |
63 | 'count': 1, | |
64 | 'keys': ['admin'], | |
65 | 'truncated': False | |
66 | }] | |
67 | self._get('/test/api/rgw/user') | |
68 | self.assertStatus(500) | |
69 | ||
70 | @mock.patch('dashboard.controllers.rgw.RgwRESTController.proxy') | |
71 | def test_user_list_invalid_marker(self, mock_proxy): | |
72 | mock_proxy.side_effect = [{ | |
73 | 'count': 3, | |
74 | 'keys': ['test1', 'test2', 'test3'], | |
75 | 'marker': 'foo:bar', | |
76 | 'truncated': True | |
77 | }, { | |
78 | 'count': 3, | |
79 | 'keys': ['test4', 'test5', 'test6'], | |
80 | 'marker': '', | |
81 | 'truncated': True | |
82 | }, { | |
83 | 'count': 1, | |
84 | 'keys': ['admin'], | |
85 | 'truncated': False | |
86 | }] | |
87 | self._get('/test/api/rgw/user') | |
88 | self.assertStatus(500) | |
9f95a23c TL |
89 | |
90 | @mock.patch('dashboard.controllers.rgw.RgwRESTController.proxy') | |
91 | @mock.patch.object(RgwUser, '_keys_allowed') | |
92 | def test_user_get_with_keys(self, keys_allowed, mock_proxy): | |
93 | keys_allowed.return_value = True | |
94 | mock_proxy.return_value = { | |
95 | 'tenant': '', | |
96 | 'user_id': 'my_user_id', | |
97 | 'keys': [], | |
98 | 'swift_keys': [] | |
99 | } | |
100 | self._get('/test/api/rgw/user/testuser') | |
101 | self.assertStatus(200) | |
102 | self.assertInJsonBody('keys') | |
103 | self.assertInJsonBody('swift_keys') | |
104 | ||
105 | @mock.patch('dashboard.controllers.rgw.RgwRESTController.proxy') | |
106 | @mock.patch.object(RgwUser, '_keys_allowed') | |
107 | def test_user_get_without_keys(self, keys_allowed, mock_proxy): | |
108 | keys_allowed.return_value = False | |
109 | mock_proxy.return_value = { | |
110 | 'tenant': '', | |
111 | 'user_id': 'my_user_id', | |
112 | 'keys': [], | |
113 | 'swift_keys': [] | |
114 | } | |
115 | self._get('/test/api/rgw/user/testuser') | |
116 | self.assertStatus(200) | |
117 | self.assertNotIn('keys', self.json_body()) | |
118 | self.assertNotIn('swift_keys', self.json_body()) |