75 | 75 |
self.key_mgr._barbican_client = self.mock_barbican
|
76 | 76 |
self.key_mgr._current_context = self.ctxt
|
77 | 77 |
|
|
78 |
def test_barbican_endpoint(self):
|
|
79 |
endpoint_data = mock.Mock()
|
|
80 |
endpoint_data.url = 'http://localhost:9311'
|
|
81 |
|
|
82 |
auth = mock.Mock(spec=['service_catalog'])
|
|
83 |
auth.service_catalog.endpoint_data_for.return_value = endpoint_data
|
|
84 |
|
|
85 |
endpoint = self.key_mgr._get_barbican_endpoint(auth, mock.Mock())
|
|
86 |
self.assertEqual(endpoint, 'http://localhost:9311')
|
|
87 |
auth.service_catalog.endpoint_data_for.assert_called_once_with(
|
|
88 |
service_type='key-manager', interface='public',
|
|
89 |
region_name=None)
|
|
90 |
|
|
91 |
def test_barbican_endpoint_with_endpoint_type(self):
|
|
92 |
self.key_mgr.conf.barbican.barbican_endpoint_type = 'internal'
|
|
93 |
|
|
94 |
endpoint_data = mock.Mock()
|
|
95 |
endpoint_data.url = 'http://localhost:9311'
|
|
96 |
|
|
97 |
auth = mock.Mock(spec=['service_catalog'])
|
|
98 |
auth.service_catalog.endpoint_data_for.return_value = endpoint_data
|
|
99 |
|
|
100 |
endpoint = self.key_mgr._get_barbican_endpoint(auth, mock.Mock())
|
|
101 |
self.assertEqual(endpoint, 'http://localhost:9311')
|
|
102 |
auth.service_catalog.endpoint_data_for.assert_called_once_with(
|
|
103 |
service_type='key-manager', interface='internal',
|
|
104 |
region_name=None)
|
|
105 |
|
|
106 |
def test_barbican_endpoint_with_region_name(self):
|
|
107 |
self.key_mgr.conf.barbican.barbican_region_name = 'regionOne'
|
|
108 |
|
|
109 |
endpoint_data = mock.Mock()
|
|
110 |
endpoint_data.url = 'http://localhost:9311'
|
|
111 |
|
|
112 |
auth = mock.Mock(spec=['service_catalog'])
|
|
113 |
auth.service_catalog.endpoint_data_for.return_value = endpoint_data
|
|
114 |
|
|
115 |
endpoint = self.key_mgr._get_barbican_endpoint(auth, mock.Mock())
|
|
116 |
self.assertEqual(endpoint, 'http://localhost:9311')
|
|
117 |
auth.service_catalog.endpoint_data_for.assert_called_once_with(
|
|
118 |
service_type='key-manager', interface='public',
|
|
119 |
region_name='regionOne')
|
|
120 |
|
|
121 |
def test_barbican_endpoint_from_config(self):
|
|
122 |
self.key_mgr.conf.barbican.barbican_endpoint = 'http://localhost:9311'
|
|
123 |
|
|
124 |
endpoint = self.key_mgr._get_barbican_endpoint(
|
|
125 |
mock.Mock(), mock.Mock())
|
|
126 |
self.assertEqual(endpoint, 'http://localhost:9311')
|
|
127 |
|
|
128 |
def test_barbican_endpoint_by_get_endpoint(self):
|
|
129 |
auth = mock.Mock(spec=['get_endppint'])
|
|
130 |
sess = mock.Mock()
|
|
131 |
auth.get_endpoint = mock.Mock(return_value='http://localhost:9311')
|
|
132 |
|
|
133 |
endpoint = self.key_mgr._get_barbican_endpoint(auth, sess)
|
|
134 |
self.assertEqual(endpoint, 'http://localhost:9311')
|
|
135 |
auth.get_endpoint.assert_called_once_with(
|
|
136 |
sess, service_type='key-manager', interface='public',
|
|
137 |
region_name=None)
|
|
138 |
|
|
139 |
def test_barbican_endpoint_by_get_endpoint_with_endpoint_type(self):
|
|
140 |
self.key_mgr.conf.barbican.barbican_endpoint_type = 'internal'
|
|
141 |
|
|
142 |
auth = mock.Mock(spec=['get_endppint'])
|
|
143 |
sess = mock.Mock()
|
|
144 |
auth.get_endpoint = mock.Mock(return_value='http://localhost:9311')
|
|
145 |
|
|
146 |
endpoint = self.key_mgr._get_barbican_endpoint(auth, sess)
|
|
147 |
self.assertEqual(endpoint, 'http://localhost:9311')
|
|
148 |
auth.get_endpoint.assert_called_once_with(
|
|
149 |
sess, service_type='key-manager', interface='internal',
|
|
150 |
region_name=None)
|
|
151 |
|
|
152 |
def test_barbican_endpoint_by_get_endpoint_with_region_name(self):
|
|
153 |
self.key_mgr.conf.barbican.barbican_region_name = 'regionOne'
|
|
154 |
|
|
155 |
auth = mock.Mock(spec=['get_endppint'])
|
|
156 |
sess = mock.Mock()
|
|
157 |
auth.get_endpoint = mock.Mock(return_value='http://localhost:9311')
|
|
158 |
|
|
159 |
endpoint = self.key_mgr._get_barbican_endpoint(auth, sess)
|
|
160 |
self.assertEqual(endpoint, 'http://localhost:9311')
|
|
161 |
auth.get_endpoint.assert_called_once_with(
|
|
162 |
sess, service_type='key-manager', interface='public',
|
|
163 |
region_name='regionOne')
|
|
164 |
|
78 | 165 |
def test_base_url_old_version(self):
|
79 | 166 |
version = "v1"
|
80 | 167 |
self.key_mgr.conf.barbican.barbican_api_version = version
|
|
107 | 194 |
endpoint)
|
108 | 195 |
self.assertEqual(endpoint + "/" + endpoint_data.api_version, base_url)
|
109 | 196 |
auth.service_catalog.endpoint_data_for.assert_called_once_with(
|
110 | |
service_type='key-manager')
|
|
197 |
service_type='key-manager', interface='public',
|
|
198 |
region_name=None)
|
|
199 |
|
|
200 |
def test_base_url_service_catalog_with_endpoint_type(self):
|
|
201 |
self.key_mgr.conf.barbican.barbican_endpoint_type = 'internal'
|
|
202 |
|
|
203 |
endpoint_data = mock.Mock()
|
|
204 |
endpoint_data.api_version = 'v321'
|
|
205 |
|
|
206 |
auth = mock.Mock(spec=['service_catalog'])
|
|
207 |
auth.service_catalog.endpoint_data_for.return_value = endpoint_data
|
|
208 |
|
|
209 |
endpoint = "http://localhost/key_manager"
|
|
210 |
|
|
211 |
base_url = self.key_mgr._create_base_url(auth,
|
|
212 |
mock.Mock(),
|
|
213 |
endpoint)
|
|
214 |
self.assertEqual(endpoint + "/" + endpoint_data.api_version, base_url)
|
|
215 |
auth.service_catalog.endpoint_data_for.assert_called_once_with(
|
|
216 |
service_type='key-manager', interface='internal',
|
|
217 |
region_name=None)
|
|
218 |
|
|
219 |
def test_base_url_service_catalog_with_region_name(self):
|
|
220 |
self.key_mgr.conf.barbican.barbican_region_name = 'regionOne'
|
|
221 |
|
|
222 |
endpoint_data = mock.Mock()
|
|
223 |
endpoint_data.api_version = 'v321'
|
|
224 |
|
|
225 |
auth = mock.Mock(spec=['service_catalog'])
|
|
226 |
auth.service_catalog.endpoint_data_for.return_value = endpoint_data
|
|
227 |
|
|
228 |
endpoint = "http://localhost/key_manager"
|
|
229 |
|
|
230 |
base_url = self.key_mgr._create_base_url(auth,
|
|
231 |
mock.Mock(),
|
|
232 |
endpoint)
|
|
233 |
self.assertEqual(endpoint + "/" + endpoint_data.api_version, base_url)
|
|
234 |
auth.service_catalog.endpoint_data_for.assert_called_once_with(
|
|
235 |
service_type='key-manager', interface='public',
|
|
236 |
region_name='regionOne')
|
111 | 237 |
|
112 | 238 |
def test_base_url_raise_exception(self):
|
113 | 239 |
auth = mock.Mock(spec=['get_discovery'])
|