summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas Alvares Gomes <lucasagomes@gmail.com>2015-06-18 11:34:13 +0100
committerDmitry Tantsur <dtantsur@redhat.com>2015-11-26 13:18:16 +0100
commit46412348d02a30b059c05b8b32c7a3fc1eafc369 (patch)
tree46af0dae7cf7e2db565f2a48cf1ac51b43e4de39
parent9579b8122eb433798b94928fe5b2b443126a1821 (diff)
downloadironic-46412348d02a30b059c05b8b32c7a3fc1eafc369.tar.gz
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 13bcebcaf390697d04a69855d8e50013d0312e1d)
-rw-r--r--ironic/tests/api/utils.py59
1 files changed, 35 insertions, 24 deletions
diff --git a/ironic/tests/api/utils.py b/ironic/tests/api/utils.py
index 76d229b0a..2aa570c90 100644
--- a/ironic/tests/api/utils.py
+++ b/ironic/tests/api/utils.py
@@ -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):