From bc12305ca1cdbc968ee150a4e314756889ec32da Mon Sep 17 00:00:00 2001 From: mathrock Date: Sat, 12 Apr 2014 00:45:27 -0400 Subject: [PATCH] Fix typo of ANS1 to ASN1 Replace all occurrences of 'ANS1|ans1' with 'ASN1|asn1'. Keep cms.is_ans1_token() around for backwards compatibility. Change-Id: I89da78b89aa9daf2637754dc93031d7ca81e85cb Closes-bug: 1306874 --- keystoneclient/common/cms.py | 17 ++++++++++++----- keystoneclient/middleware/auth_token.py | 2 +- keystoneclient/tests/test_cms.py | 8 ++++---- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/keystoneclient/common/cms.py b/keystoneclient/common/cms.py index 8f6576f58..a22b5aba7 100644 --- a/keystoneclient/common/cms.py +++ b/keystoneclient/common/cms.py @@ -29,7 +29,7 @@ from keystoneclient import exceptions subprocess = None LOG = logging.getLogger(__name__) -PKI_ANS1_PREFIX = 'MII' +PKI_ASN1_PREFIX = 'MII' def _ensure_subprocess(): @@ -166,7 +166,7 @@ def verify_token(token, signing_cert_file_name, ca_file_name): ca_file_name) -def is_ans1_token(token): +def is_asn1_token(token): """Determine if a token appears to be PKI-based. thx to ayoung for sorting this out. @@ -213,7 +213,14 @@ def is_ans1_token(token): It's not practical to support a token of this length or greater in http therefore, we will check for MII only and ignore the case of larger tokens """ - return token[:3] == PKI_ANS1_PREFIX + return token[:3] == PKI_ASN1_PREFIX + + +def is_ans1_token(token): + """Deprecated. Use is_asn1_token() instead.""" + LOG.warning("The function is_ans1_token() is deprecated, " + "use is_asn1_token() instead.") + return is_asn1_token(token) def cms_sign_text(text, signing_cert_file_name, signing_key_file_name): @@ -264,12 +271,12 @@ def cms_to_token(cms_text): def cms_hash_token(token_id, mode='md5'): """Hash PKI tokens. - return: for ans1_token, returns the hash of the passed in token + return: for asn1_token, returns the hash of the passed in token otherwise, returns what it was passed in. """ if token_id is None: return None - if is_ans1_token(token_id): + if is_asn1_token(token_id): hasher = hashlib.new(mode) if isinstance(token_id, six.text_type): token_id = token_id.encode('utf-8') diff --git a/keystoneclient/middleware/auth_token.py b/keystoneclient/middleware/auth_token.py index 9c5a709eb..4594ffb32 100644 --- a/keystoneclient/middleware/auth_token.py +++ b/keystoneclient/middleware/auth_token.py @@ -847,7 +847,7 @@ class AuthProtocol(object): cached = self._cache_get(token_id) if cached: return cached - if cms.is_ans1_token(user_token): + if cms.is_asn1_token(user_token): verified = self.verify_signed_token(user_token) data = jsonutils.loads(verified) else: diff --git a/keystoneclient/tests/test_cms.py b/keystoneclient/tests/test_cms.py index e5fe55bcd..2f00522d4 100644 --- a/keystoneclient/tests/test_cms.py +++ b/keystoneclient/tests/test_cms.py @@ -48,9 +48,9 @@ class CMSTest(utils.TestCase, testresources.ResourcedTestCase): self.examples.SIGNED_TOKEN_SCOPED)) self.assertEqual(tok, self.examples.SIGNED_TOKEN_SCOPED) - def test_ans1_token(self): - self.assertTrue(cms.is_ans1_token(self.examples.SIGNED_TOKEN_SCOPED)) - self.assertFalse(cms.is_ans1_token('FOOBAR')) + def test_asn1_token(self): + self.assertTrue(cms.is_asn1_token(self.examples.SIGNED_TOKEN_SCOPED)) + self.assertFalse(cms.is_asn1_token('FOOBAR')) def test_cms_sign_token_no_files(self): self.assertRaises(subprocess.CalledProcessError, @@ -119,7 +119,7 @@ class CMSTest(utils.TestCase, testresources.ResourcedTestCase): def test_cms_hash_token_not_pki(self): """If the token_id is not a PKI token then it returns the token_id.""" token = 'something' - self.assertFalse(cms.is_ans1_token(token)) + self.assertFalse(cms.is_asn1_token(token)) self.assertThat(cms.cms_hash_token(token), matchers.Is(token)) def test_cms_hash_token_default_md5(self):