From 46412348d02a30b059c05b8b32c7a3fc1eafc369 Mon Sep 17 00:00:00 2001 From: Lucas Alvares Gomes Date: Thu, 18 Jun 2015 11:34:13 +0100 Subject: 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) --- ironic/tests/api/utils.py | 59 ++++++++++++++++++++++++++++------------------- 1 file 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): -- cgit v1.2.1