Merge "Validate that connect_as connects as the project"

This commit is contained in:
Zuul 2019-08-15 19:36:59 +00:00 committed by Gerrit Code Review
commit dbaccc8c5d
2 changed files with 36 additions and 6 deletions

View File

@ -420,7 +420,11 @@ class TestCase(base.TestCase):
self.calls = []
self._uri_registry.clear()
def get_keystone_v3_token(self, catalog='catalog-v3.json'):
def get_keystone_v3_token(
self,
catalog='catalog-v3.json',
project_name='admin',
):
catalog_file = os.path.join(self.fixtures_directory, catalog)
with open(catalog_file, 'r') as tokens_file:
return dict(
@ -429,7 +433,31 @@ class TestCase(base.TestCase):
headers={
'X-Subject-Token': self.getUniqueString('KeystoneToken')
},
text=tokens_file.read()
text=tokens_file.read(),
validate=dict(json={
'auth': {
'identity': {
'methods': ['password'],
'password': {
'user': {
'domain': {
'name': 'default',
},
'name': 'admin',
'password': 'password'
}
}
},
'scope': {
'project': {
'domain': {
'name': 'default'
},
'name': project_name
}
}
}
}),
)
def get_keystone_v3_discovery(self):

View File

@ -58,8 +58,9 @@ class TestShade(base.TestCase):
# Do initial auth/catalog steps
# This should authenticate a second time, but should not
# need a second identity discovery
project_name = 'test_project'
self.register_uris([
self.get_keystone_v3_token(),
self.get_keystone_v3_token(project_name=project_name),
self.get_nova_discovery_mock_dict(),
dict(
method='GET',
@ -69,7 +70,7 @@ class TestShade(base.TestCase):
),
])
c2 = self.cloud.connect_as(project_name='test_project')
c2 = self.cloud.connect_as(project_name=project_name)
self.assertEqual(c2.list_servers(), [])
self.assert_calls()
@ -77,8 +78,9 @@ class TestShade(base.TestCase):
# Do initial auth/catalog steps
# This should authenticate a second time, but should not
# need a second identity discovery
project_name = 'test_project'
self.register_uris([
self.get_keystone_v3_token(),
self.get_keystone_v3_token(project_name=project_name),
self.get_nova_discovery_mock_dict(),
dict(
method='GET',
@ -88,7 +90,7 @@ class TestShade(base.TestCase):
),
])
with self.cloud.connect_as(project_name='test_project') as c2:
with self.cloud.connect_as(project_name=project_name) as c2:
self.assertEqual(c2.list_servers(), [])
self.assert_calls()