diff options
| author | Dolph Mathews <dolph.mathews@gmail.com> | 2012-08-30 03:15:22 -0500 |
|---|---|---|
| committer | Dolph Mathews <dolph.mathews@gmail.com> | 2012-08-30 03:24:42 -0500 |
| commit | b82a0e2b22a8aff19bf8853e6cd9b2bb25a5281f (patch) | |
| tree | 9c8bd685e66dc2a3230f49a20550dbceb2dffa88 | |
| parent | 2759c2239862ebe9bf7b6656936c65753e5c2cfc (diff) | |
HACKING compliance & staticly init module vars
- HACKING: "When defining global constants, define them before functions
and classes"
- Statically initializing other module variables to None
Change-Id: I8d01e179262a8b16dbe49edef8e23260970c84a0
| -rw-r--r-- | tests/test_auth_token_middleware.py | 124 |
1 files changed, 64 insertions, 60 deletions
diff --git a/tests/test_auth_token_middleware.py b/tests/test_auth_token_middleware.py index db46a9a1..74c0a65f 100644 --- a/tests/test_auth_token_middleware.py +++ b/tests/test_auth_token_middleware.py @@ -32,58 +32,18 @@ from keystone import config from keystone import test -# The data for these tests are signed using openssl and are stored in files -# in the signing subdirectory. In order to keep the values consistent between -# the tests and the signed documents, we read them in for use in the tests. -def setUpModule(self): - signing_path = os.path.join(os.path.dirname(__file__), 'signing') - with open(os.path.join(signing_path, 'auth_token_scoped.pem')) as f: - self.SIGNED_TOKEN_SCOPED = cms.cms_to_token(f.read()) - with open(os.path.join(signing_path, 'auth_token_unscoped.pem')) as f: - self.SIGNED_TOKEN_UNSCOPED = cms.cms_to_token(f.read()) - with open(os.path.join(signing_path, 'auth_token_revoked.pem')) as f: - self.REVOKED_TOKEN = cms.cms_to_token(f.read()) - self.REVOKED_TOKEN_HASH = utils.hash_signed_token(self.REVOKED_TOKEN) - with open(os.path.join(signing_path, 'revocation_list.json')) as f: - self.REVOCATION_LIST = jsonutils.loads(f.read()) - with open(os.path.join(signing_path, 'revocation_list.pem')) as f: - self.VALID_SIGNED_REVOCATION_LIST =\ - jsonutils.dumps({'signed': f.read()}) - - self.TOKEN_RESPONSES[self.SIGNED_TOKEN_SCOPED] = { - 'access': { - 'token': { - 'id': SIGNED_TOKEN_SCOPED, - }, - 'user': { - 'id': 'user_id1', - 'name': 'user_name1', - 'tenantId': 'tenant_id1', - 'tenantName': 'tenant_name1', - 'roles': [ - {'name': 'role1'}, - {'name': 'role2'}, - ], - }, - }, - } - - self.TOKEN_RESPONSES[self.SIGNED_TOKEN_UNSCOPED] = { - 'access': { - 'token': { - 'id': self.SIGNED_TOKEN_UNSCOPED, - }, - 'user': { - 'id': 'user_id1', - 'name': 'user_name1', - 'roles': [ - {'name': 'role1'}, - {'name': 'role2'}, - ], - }, - }, - }, +REVOCATION_LIST = None +REVOKED_TOKEN = None +REVOKED_TOKEN_HASH = None +SIGNED_REVOCATION_LIST = None +SIGNED_TOKEN_SCOPED = None +SIGNED_TOKEN_UNSCOPED = None +VALID_SIGNED_REVOCATION_LIST = None +UUID_TOKEN_DEFAULT = "ec6c0710ec2f471498484c1b53ab4f9d" +UUID_TOKEN_NO_SERVICE_CATALOG = '8286720fbe4941e69fa8241723bb02df' +UUID_TOKEN_UNSCOPED = '731f903721c14827be7b2dc912af7776' +VALID_DIABLO_TOKEN = 'b0cf19b55dbb4f20a6ee18e6c6cf1726' INVALID_SIGNED_TOKEN = string.replace( """AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA @@ -105,16 +65,7 @@ FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF 0000000000000000000000000000000000000000000000000000000000000000 xg==""", "\n", "") -UUID_TOKEN_DEFAULT = "ec6c0710ec2f471498484c1b53ab4f9d" - -VALID_DIABLO_TOKEN = 'b0cf19b55dbb4f20a6ee18e6c6cf1726' - -UUID_TOKEN_UNSCOPED = '731f903721c14827be7b2dc912af7776' - -UUID_TOKEN_NO_SERVICE_CATALOG = '8286720fbe4941e69fa8241723bb02df' - # JSON responses keyed by token ID - TOKEN_RESPONSES = { UUID_TOKEN_DEFAULT: { 'access': { @@ -189,6 +140,59 @@ TOKEN_RESPONSES = { } +# The data for these tests are signed using openssl and are stored in files +# in the signing subdirectory. In order to keep the values consistent between +# the tests and the signed documents, we read them in for use in the tests. +def setUpModule(self): + signing_path = os.path.join(os.path.dirname(__file__), 'signing') + with open(os.path.join(signing_path, 'auth_token_scoped.pem')) as f: + self.SIGNED_TOKEN_SCOPED = cms.cms_to_token(f.read()) + with open(os.path.join(signing_path, 'auth_token_unscoped.pem')) as f: + self.SIGNED_TOKEN_UNSCOPED = cms.cms_to_token(f.read()) + with open(os.path.join(signing_path, 'auth_token_revoked.pem')) as f: + self.REVOKED_TOKEN = cms.cms_to_token(f.read()) + self.REVOKED_TOKEN_HASH = utils.hash_signed_token(self.REVOKED_TOKEN) + with open(os.path.join(signing_path, 'revocation_list.json')) as f: + self.REVOCATION_LIST = jsonutils.loads(f.read()) + with open(os.path.join(signing_path, 'revocation_list.pem')) as f: + self.VALID_SIGNED_REVOCATION_LIST = jsonutils.dumps( + {'signed': f.read()}) + + self.TOKEN_RESPONSES[self.SIGNED_TOKEN_SCOPED] = { + 'access': { + 'token': { + 'id': self.SIGNED_TOKEN_SCOPED, + }, + 'user': { + 'id': 'user_id1', + 'name': 'user_name1', + 'tenantId': 'tenant_id1', + 'tenantName': 'tenant_name1', + 'roles': [ + {'name': 'role1'}, + {'name': 'role2'}, + ], + }, + }, + } + + self.TOKEN_RESPONSES[self.SIGNED_TOKEN_UNSCOPED] = { + 'access': { + 'token': { + 'id': self.SIGNED_TOKEN_UNSCOPED, + }, + 'user': { + 'id': 'user_id1', + 'name': 'user_name1', + 'roles': [ + {'name': 'role1'}, + {'name': 'role2'}, + ], + }, + }, + }, + + class FakeMemcache(object): def __init__(self): self.set_key = None |
