Fix broken ACL tests

In keystonemiddleware 2.0.0 the token cache keys are sha256 hashes of the
token key. For versions of keystonemiddleware < 2.0.0 this is not the
case, so this patch is changing the FakeMemcache class to support both.

Change-Id: I14f6a47437ca861d3135bedbfe2b3a54de211182
Closes-Bug: #1466405
(cherry picked from commit 13bcebcaf3)
This commit is contained in:
Lucas Alvares Gomes 2015-06-18 11:34:13 +01:00 committed by Dmitry Tantsur
parent 9579b8122e
commit 46412348d0
1 changed files with 35 additions and 24 deletions

View File

@ -16,6 +16,7 @@ Utils for testing the API service.
"""
import datetime
import hashlib
import json
from ironic.api.controllers.v1 import chassis as chassis_controller
@ -26,35 +27,45 @@ from ironic.tests.db import utils
ADMIN_TOKEN = '4562138218392831'
MEMBER_TOKEN = '4562138218392832'
ADMIN_TOKEN_HASH = hashlib.sha256(ADMIN_TOKEN.encode()).hexdigest()
MEMBER_TOKEN_HASH = hashlib.sha256(MEMBER_TOKEN.encode()).hexdigest()
ADMIN_BODY = {
'access': {
'token': {'id': ADMIN_TOKEN,
'expires': '2100-09-11T00:00:00'},
'user': {'id': 'user_id1',
'name': 'user_name1',
'tenantId': '123i2910',
'tenantName': 'mytenant',
'roles': [{'name': 'admin'}]},
}
}
MEMBER_BODY = {
'access': {
'token': {'id': MEMBER_TOKEN,
'expires': '2100-09-11T00:00:00'},
'user': {'id': 'user_id2',
'name': 'user-good',
'tenantId': 'project-good',
'tenantName': 'goodies',
'roles': [{'name': 'Member'}]},
}
}
class FakeMemcache(object):
"""Fake cache that is used for keystone tokens lookup."""
# NOTE(lucasagomes): keystonemiddleware >= 2.0.0 the token cache
# keys are sha256 hashes of the token key. This was introduced in
# https://review.openstack.org/#/c/186971
_cache = {
'tokens/%s' % ADMIN_TOKEN: {
'access': {
'token': {'id': ADMIN_TOKEN,
'expires': '2100-09-11T00:00:00'},
'user': {'id': 'user_id1',
'name': 'user_name1',
'tenantId': '123i2910',
'tenantName': 'mytenant',
'roles': [{'name': 'admin'}]
},
}
},
'tokens/%s' % MEMBER_TOKEN: {
'access': {
'token': {'id': MEMBER_TOKEN,
'expires': '2100-09-11T00:00:00'},
'user': {'id': 'user_id2',
'name': 'user-good',
'tenantId': 'project-good',
'tenantName': 'goodies',
'roles': [{'name': 'Member'}]
}
}
}
'tokens/%s' % ADMIN_TOKEN: ADMIN_BODY,
'tokens/%s' % ADMIN_TOKEN_HASH: ADMIN_BODY,
'tokens/%s' % MEMBER_TOKEN: MEMBER_BODY,
'tokens/%s' % MEMBER_TOKEN_HASH: MEMBER_BODY,
}
def __init__(self):