~ubuntu-branches/ubuntu/trusty/python-keystoneclient/trusty-proposed

« back to all changes in this revision

Viewing changes to tests/test_auth_token_middleware.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-01-18 07:44:54 UTC
  • mfrom: (1.1.17)
  • Revision ID: package-import@ubuntu.com-20130118074454-g7w5blpynohn1s48
Tags: 1:0.2.2-0ubuntu1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import os
20
20
import string
21
21
import tempfile
22
 
import unittest2 as unittest
 
22
import testtools
23
23
 
24
24
import webob
25
25
 
335
335
        return resp(env, start_response)
336
336
 
337
337
 
338
 
class BaseAuthTokenMiddlewareTest(unittest.TestCase):
 
338
class BaseAuthTokenMiddlewareTest(testtools.TestCase):
339
339
 
340
340
    def setUp(self, expected_env=None):
 
341
        super(BaseAuthTokenMiddlewareTest, self).setUp()
341
342
        expected_env = expected_env or {}
342
343
 
343
344
        conf = {
537
538
 
538
539
    def test_verify_signed_token_raises_exception_for_revoked_token(self):
539
540
        self.middleware.token_revocation_list = self.get_revocation_list_json()
540
 
        with self.assertRaises(auth_token.InvalidUserToken):
541
 
            self.middleware.verify_signed_token(REVOKED_TOKEN)
 
541
        self.assertRaises(auth_token.InvalidUserToken,
 
542
                          self.middleware.verify_signed_token, REVOKED_TOKEN)
542
543
 
543
544
    def test_verify_signed_token_succeeds_for_unrevoked_token(self):
544
545
        self.middleware.token_revocation_list = self.get_revocation_list_json()
579
580
 
580
581
    def test_invalid_revocation_list_raises_service_error(self):
581
582
        globals()['SIGNED_REVOCATION_LIST'] = "{}"
582
 
        with self.assertRaises(auth_token.ServiceError):
583
 
            self.middleware.fetch_revocation_list()
 
583
        self.assertRaises(auth_token.ServiceError,
 
584
                          self.middleware.fetch_revocation_list)
584
585
 
585
586
    def test_fetch_revocation_list(self):
586
587
        fetched_list = jsonutils.loads(self.middleware.fetch_revocation_list())
652
653
 
653
654
        auth_token.AuthProtocol(FakeApp(), conf)
654
655
 
 
656
    def test_use_cache_from_env(self):
 
657
        env = {'swift.cache': 'CACHE_TEST'}
 
658
        conf = {
 
659
            'admin_token': 'admin_token1',
 
660
            'auth_host': 'keystone.example.com',
 
661
            'auth_port': 1234,
 
662
            'cache': 'swift.cache',
 
663
            'memcache_servers': 'localhost:11211',
 
664
        }
 
665
        auth = auth_token.AuthProtocol(FakeApp(), conf)
 
666
        auth._init_cache(env)
 
667
        self.assertEqual(auth._cache, 'CACHE_TEST')
 
668
 
 
669
    def test_not_use_cache_from_env(self):
 
670
        self.disable_module('memcache')
 
671
        env = {'swift.cache': 'CACHE_TEST'}
 
672
        conf = {
 
673
            'admin_token': 'admin_token1',
 
674
            'auth_host': 'keystone.example.com',
 
675
            'auth_port': 1234,
 
676
            'memcache_servers': 'localhost:11211',
 
677
        }
 
678
        auth = auth_token.AuthProtocol(FakeApp(), conf)
 
679
        auth._init_cache(env)
 
680
        self.assertEqual(auth._cache, None)
 
681
 
655
682
    def test_request_prevent_service_catalog_injection(self):
656
683
        req = webob.Request.blank('/')
657
684
        req.headers['X-Service-Catalog'] = '[]'
668
695
        fortyseconds = datetime.datetime.utcnow() + datetime.timedelta(
669
696
            seconds=40)
670
697
        self.assertFalse(auth_token.will_expire_soon(fortyseconds))
 
698
 
 
699
 
 
700
class TokenEncodingTest(testtools.TestCase):
 
701
    def test_unquoted_token(self):
 
702
        self.assertEqual('foo%20bar', auth_token.safe_quote('foo bar'))
 
703
 
 
704
    def test_quoted_token(self):
 
705
        self.assertEqual('foo%20bar', auth_token.safe_quote('foo%20bar'))