keystonemiddleware.tests package

Submodules

keystonemiddleware.tests.client_fixtures module

class keystonemiddleware.tests.client_fixtures.Examples

Bases: fixtures.fixture.Fixture

Example tokens and certs loaded from the examples directory.

To use this class correctly, the module needs to override the test suite class to use testresources.OptimisingTestSuite (otherwise the files will be read on every test). This is done by defining a load_tests function in the module, like this:

def load_tests(loader, tests, pattern):
return testresources.OptimisingTestSuite(tests)

(see http://docs.python.org/2/library/unittest.html#load-tests-protocol )

setUp()

keystonemiddleware.tests.test_auth_token_middleware module

class keystonemiddleware.tests.test_auth_token_middleware.BaseAuthTokenMiddlewareTest(*args, **kwargs)

Bases: testtools.testcase.TestCase

Base test class for auth_token middleware.

All the tests allow for running with auth_token configured for receiving v2 or v3 tokens, with the choice being made by passing configuration data into setUp().

The base class will, by default, run all the tests expecting v2 token formats. Child classes can override this to specify, for instance, v3 format.

assertLastPath(path)
setUp(expected_env=None, auth_version=None, fake_app=None)
set_middleware(expected_env=None, conf=None)

Configure the class ready to call the auth_token middleware.

Set up the various fake items needed to run the middleware. Individual tests that need to further refine these can call this function to override the class defaults.

start_fake_response(status, headers)
class keystonemiddleware.tests.test_auth_token_middleware.CachePoolTest(*args, **kwargs)

Bases: keystonemiddleware.tests.test_auth_token_middleware.BaseAuthTokenMiddlewareTest

test_multiple_context_managers_share_single_client()
test_nested_context_managers_create_multiple_clients()
test_not_use_cache_from_env()

If swift.cache is set in the environment but cache isn’t set in the config then the env cache isn’t used.

test_use_cache_from_env()

If swift.cache is set in the environment and cache is set in the config then the env cache is used.

class keystonemiddleware.tests.test_auth_token_middleware.CatalogConversionTests(*args, **kwargs)

Bases: keystonemiddleware.tests.test_auth_token_middleware.BaseAuthTokenMiddlewareTest

ADMIN_URL = 'http://admin:35357/v2.0'
INTERNAL_URL = 'http://internal:5000/v2.0'
PUBLIC_URL = 'http://server:5000/v2.0'
REGION_ONE = 'RegionOne'
REGION_THREE = 'RegionThree'
REGION_TWO = 'RegionTwo'
test_basic_convert()
test_multi_region()
class keystonemiddleware.tests.test_auth_token_middleware.CommonAuthTokenMiddlewareTest

Bases: object

These tests are run once using v2 tokens and again using v3 tokens.

assertIsValidJSON(text)
assert_kerberos_bind(token, bind_level, use_kerberos=True, success=True)
assert_valid_request_200(token, with_catalog=True)
get_revocation_list_json(token_ids=None, mode=None)
test_cached_revoked_pki()
test_cached_revoked_uuid()
test_expired()
test_fetch_revocation_list()
test_get_revocation_list_returns_current_list_from_disk()
test_get_revocation_list_returns_current_list_from_memory()
test_get_revocation_list_returns_fetched_list()
test_get_token_revocation_list_fetched_time_returns_min()
test_get_token_revocation_list_fetched_time_returns_mtime()
test_get_token_revocation_list_fetched_time_returns_utc()
test_get_token_revocation_list_fetched_time_returns_value()
test_http_error_not_cached_token()

Test to don’t cache token as invalid on network errors.

We use UUID tokens since they are the easiest one to reach get_http_connection.

test_http_request_max_retries()
test_init_by_ipv6Addr_auth_host()
test_init_does_not_call_http()
test_invalid_revocation_list_raises_service_error()
test_is_signed_token_revoked_returns_false()
test_is_signed_token_revoked_returns_true()
test_is_signed_token_revoked_returns_true_sha256()
test_memcache()
test_memcache_set_expired(extra_conf={}, extra_environ={})
test_memcache_set_invalid_signed()
test_memcache_set_invalid_signed_sha256()
test_memcache_set_invalid_signed_sha256_md5()
test_memcache_set_invalid_uuid()
test_nocatalog()
test_request_blank_token()
test_request_invalid_signed_pkiz_token()
test_request_invalid_signed_token()
test_request_invalid_uuid_token()
test_request_no_token()
test_request_no_token_http()
test_request_no_token_log_message()
test_revoked_hashed_pki_token()
test_revoked_token_receives_401()
test_revoked_token_receives_401_md5_secondary()
test_revoked_token_receives_401_sha256()
test_swift_memcache_set_expired()
test_uuid_bind_token_disabled_with_incorrect_ticket()
test_uuid_bind_token_disabled_with_kerb_user()
test_uuid_bind_token_named_kerberos_with_incorrect_ticket()
test_uuid_bind_token_named_kerberos_with_kerb_user()
test_uuid_bind_token_named_kerberos_with_unknown_bind()
test_uuid_bind_token_named_kerberos_without_bind()
test_uuid_bind_token_named_kerberos_without_kerb_user()
test_uuid_bind_token_permissive_with_incorrect_ticket()
test_uuid_bind_token_permissive_with_kerb_user()
test_uuid_bind_token_permissive_with_unknown_bind()
test_uuid_bind_token_permissive_without_kerb_user()
test_uuid_bind_token_required_with_kerb_user()
test_uuid_bind_token_required_with_unknown_bind()
test_uuid_bind_token_required_without_bind()
test_uuid_bind_token_required_without_kerb_user()
test_uuid_bind_token_strict_with_kerb_user()
test_uuid_bind_token_strict_with_kerbout_user()
test_uuid_bind_token_strict_with_unknown_bind()
test_uuid_bind_token_with_unknown_named_FOO()
test_valid_signed_compressed_request()
test_valid_signed_request()
test_valid_uuid_request()
test_valid_uuid_request_with_auth_fragments()
test_verify_signed_compressed_token_succeeds_for_unrevoked_token()
test_verify_signed_token_raises_exception_for_revoked_pkiz_token()
test_verify_signed_token_raises_exception_for_revoked_token()
test_verify_signed_token_raises_exception_for_revoked_token_s256()
test_verify_signed_token_succeeds_for_unrevoked_token()
test_verify_signed_token_succeeds_for_unrevoked_token_sha256()
test_verify_signing_dir_create_while_missing()
class keystonemiddleware.tests.test_auth_token_middleware.CrossVersionAuthTokenMiddlewareTest(*args, **kwargs)

Bases: keystonemiddleware.tests.test_auth_token_middleware.BaseAuthTokenMiddlewareTest, testresources.ResourcedTestCase

resources = [('examples', <testresources.FixtureResource object at 0x7f4f56803050>)]
test_valid_uuid_request_forced_to_2_0(*args, **kw)

Test forcing auth_token to use lower api version.

By installing the v3 http hander, auth_token will be get a version list that looks like a v3 server - from which it would normally chose v3.0 as the auth version. However, here we specify v2.0 in the configuration - which should force auth_token to use that version instead.

class keystonemiddleware.tests.test_auth_token_middleware.DiabloAuthTokenMiddlewareTest(*args, **kwargs)

Bases: keystonemiddleware.tests.test_auth_token_middleware.BaseAuthTokenMiddlewareTest, testresources.ResourcedTestCase

resources = [('examples', <testresources.FixtureResource object at 0x7f4f56803050>)]

Auth Token middleware should understand Diablo keystone responses.

setUp()
test_valid_diablo_response()
class keystonemiddleware.tests.test_auth_token_middleware.FakeApp(expected_env=None)

Bases: object

This represents a WSGI app protected by the auth_token middleware.

SUCCESS = 'SUCCESS'
class keystonemiddleware.tests.test_auth_token_middleware.GeneralAuthTokenMiddlewareTest(*args, **kwargs)

Bases: keystonemiddleware.tests.test_auth_token_middleware.BaseAuthTokenMiddlewareTest, testresources.ResourcedTestCase

These tests are not affected by the token format (see CommonAuthTokenMiddlewareTest).

resources = [('examples', <testresources.FixtureResource object at 0x7f4f56803050>)]
test_assert_valid_memcache_protection_config()
test_config_revocation_cache_timeout()
test_encrypt_cache_data()
test_no_memcache_protection()
test_sign_cache_data()
test_token_is_v2_accepts_v2()
test_token_is_v2_rejects_v3()
test_token_is_v3_accepts_v3()
test_token_is_v3_rejects_v2()
test_will_expire_soon()
class keystonemiddleware.tests.test_auth_token_middleware.MultiStepAuthTokenMiddlewareTest(*args, **kwargs)

Bases: keystonemiddleware.tests.test_auth_token_middleware.BaseAuthTokenMiddlewareTest, testresources.ResourcedTestCase

resources = [('examples', <testresources.FixtureResource object at 0x7f4f56803050>)]
test_fetch_revocation_list_with_expire(*args, **kw)
class keystonemiddleware.tests.test_auth_token_middleware.NoMemcacheAuthToken(*args, **kwargs)

Bases: keystonemiddleware.tests.test_auth_token_middleware.BaseAuthTokenMiddlewareTest

These tests will not have the memcache module available.

setUp()
test_nomemcache()
class keystonemiddleware.tests.test_auth_token_middleware.TimezoneFixture(new_tz)

Bases: fixtures.fixture.Fixture

cleanup()
setUp()
static supported()
class keystonemiddleware.tests.test_auth_token_middleware.TokenEncodingTest(*args, **kwargs)

Bases: testtools.testcase.TestCase

test_quoted_token()
test_unquoted_token()
class keystonemiddleware.tests.test_auth_token_middleware.TokenExpirationTest(*args, **kwargs)

Bases: keystonemiddleware.tests.test_auth_token_middleware.BaseAuthTokenMiddlewareTest

create_v2_token_fixture(expires=None)
create_v3_token_fixture(expires=None)
setUp()
test_bad_data()
test_cached_token_expired()
test_cached_token_not_expired()
test_cached_token_not_expired_with_old_style_nix_timestamp()

Ensure we cannot retrieve a token from the cache.

Getting a token from the cache should return None when the token data in the cache stores the expires time as a *nix style timestamp.

test_cached_token_with_timezone_offset_expired()
test_cached_token_with_timezone_offset_not_expired()
test_no_data()
test_v2_token_expired()
test_v2_token_not_expired()
test_v2_token_with_timezone_offset_expired(*args, **keywargs)
test_v2_token_with_timezone_offset_not_expired(*args, **keywargs)
test_v3_token_expired()
test_v3_token_not_expired()
test_v3_token_with_timezone_offset_expired(*args, **keywargs)
test_v3_token_with_timezone_offset_not_expired(*args, **keywargs)
class keystonemiddleware.tests.test_auth_token_middleware.V2CertDownloadMiddlewareTest(*args, **kwargs)

Bases: keystonemiddleware.tests.test_auth_token_middleware.BaseAuthTokenMiddlewareTest, testresources.ResourcedTestCase

resources = [('examples', <testresources.FixtureResource object at 0x7f4f56803050>)]
setUp()
test_fetch_signing_ca()
test_fetch_signing_cert()
test_prefix_trailing_slash()
test_request_no_token_dummy()
test_without_prefix()
class keystonemiddleware.tests.test_auth_token_middleware.V3CertDownloadMiddlewareTest(*args, **kwargs)

Bases: keystonemiddleware.tests.test_auth_token_middleware.V2CertDownloadMiddlewareTest

keystonemiddleware.tests.test_auth_token_middleware.cleanup_revoked_file(filename)
keystonemiddleware.tests.test_auth_token_middleware.load_tests(loader, tests, pattern)
keystonemiddleware.tests.test_auth_token_middleware.memcached_available()

Do a sanity check against memcached.

Returns True if the following conditions are met (otherwise, returns False):

  • python-memcached is installed
  • a usable memcached instance is available via MEMCACHED_SERVERS
  • the client is able to set and get a key/value pair
keystonemiddleware.tests.test_auth_token_middleware.network_error_response(method, uri, headers)
class keystonemiddleware.tests.test_auth_token_middleware.v2AuthTokenMiddlewareTest(*args, **kwargs)

Bases: keystonemiddleware.tests.test_auth_token_middleware.BaseAuthTokenMiddlewareTest, keystonemiddleware.tests.test_auth_token_middleware.CommonAuthTokenMiddlewareTest, testresources.ResourcedTestCase

v2 token specific tests.

There are some differences between how the auth-token middleware handles v2 and v3 tokens over and above the token formats, namely:

  • A v3 keystone server will auto scope a token to a user’s default project if no scope is specified. A v2 server assumes that the auth-token middleware will do that.
  • A v2 keystone server may issue a token without a catalog, even with a tenant

The tests below were originally part of the generic AuthTokenMiddlewareTest class, but now, since they really are v2 specific, they are included here.

assert_unscoped_default_tenant_auto_scopes(token)

Unscoped v2 requests with a default tenant should “auto-scope.”

The implied scope is the user’s tenant ID.

assert_unscoped_token_receives_401(token)

Unscoped requests with no default tenant ID should be rejected.

assert_valid_last_url(token_id)
resources = [('examples', <testresources.FixtureResource object at 0x7f4f56803050>)]
setUp()
test_default_tenant_signed_token()
test_default_tenant_uuid_token()
test_request_prevent_service_catalog_injection()
test_unscoped_pki_token_receives_401()
test_unscoped_uuid_token_receives_401()
class keystonemiddleware.tests.test_auth_token_middleware.v3AuthTokenMiddlewareTest(*args, **kwargs)

Bases: keystonemiddleware.tests.test_auth_token_middleware.BaseAuthTokenMiddlewareTest, keystonemiddleware.tests.test_auth_token_middleware.CommonAuthTokenMiddlewareTest, testresources.ResourcedTestCase

Test auth_token middleware with v3 tokens.

Re-execute the AuthTokenMiddlewareTest class tests, but with the auth_token middleware configured to expect v3 tokens back from a keystone server.

This is done by configuring the AuthTokenMiddlewareTest class via its Setup(), passing in v3 style data that will then be used by the tests themselves. This approach has been used to ensure we really are running the same tests for both v2 and v3 tokens.

There a few additional specific test for v3 only:

  • We allow an unscoped token to be validated (as unscoped), where as for v2 tokens, the auth_token middleware is expected to try and auto-scope it (and fail if there is no default tenant)
  • Domain scoped tokens

Since we don’t specify an auth version for auth_token to use, by definition we are thefore implicitely testing that it will use the highest available auth version, i.e. v3.0

assert_valid_last_url(token_id)
resources = [('examples', <testresources.FixtureResource object at 0x7f4f56803050>)]
setUp()
test_domain_scoped_uuid_request()
test_gives_v2_catalog()
test_valid_unscoped_uuid_request()
token_response(request, uri, headers)
class keystonemiddleware.tests.test_auth_token_middleware.v3FakeApp(expected_env=None)

Bases: keystonemiddleware.tests.test_auth_token_middleware.FakeApp

This represents a v3 WSGI app protected by the auth_token middleware.

keystonemiddleware.tests.test_memcache_crypt module

class keystonemiddleware.tests.test_memcache_crypt.MemcacheCryptPositiveTests(*args, **kwargs)

Bases: testtools.testcase.TestCase

test_constant_time_compare()
test_derive_keys()
test_encryption()
test_key_strategy_diff()
test_no_pycrypt()
test_protect_wrappers()
test_sign_data()

keystonemiddleware.tests.test_opts module

class keystonemiddleware.tests.test_opts.OptsTestCase(*args, **kwargs)

Bases: keystonemiddleware.tests.utils.TestCase

test_entry_point()
test_list_auth_token_opts()

keystonemiddleware.tests.test_s3_token_middleware module

class keystonemiddleware.tests.test_s3_token_middleware.FakeApp

Bases: object

This represents a WSGI app protected by the auth_token middleware.

class keystonemiddleware.tests.test_s3_token_middleware.S3TokenMiddlewareTestBad(*args, **kwargs)

Bases: keystonemiddleware.tests.test_s3_token_middleware.S3TokenMiddlewareTestBase

setUp()
test_bad_reply()
test_bogus_authorization()
test_fail_to_connect_to_keystone()
test_unauthorized_token()
class keystonemiddleware.tests.test_s3_token_middleware.S3TokenMiddlewareTestBase(*args, **kwargs)

Bases: keystonemiddleware.tests.utils.TestCase

TEST_HOST = 'fakehost'
TEST_PORT = 35357
TEST_PROTOCOL = 'https'
TEST_URL = 'https://fakehost:35357/v2.0/s3tokens'
setUp()
start_fake_response(status, headers)
class keystonemiddleware.tests.test_s3_token_middleware.S3TokenMiddlewareTestGood(*args, **kwargs)

Bases: keystonemiddleware.tests.test_s3_token_middleware.S3TokenMiddlewareTestBase

setUp()
test_authorization_nova_toconnect()
test_authorized()
test_authorized_http()
test_insecure(*args, **keywargs)
test_no_path_request()
test_without_auth_storage_token()
test_without_authorization()
class keystonemiddleware.tests.test_s3_token_middleware.S3TokenMiddlewareTestUtil(*args, **kwargs)

Bases: testtools.testcase.TestCase

test_split_path_failed()
test_split_path_invalid_path()
test_split_path_success()

keystonemiddleware.tests.utils module

class keystonemiddleware.tests.utils.DisableModuleFixture(module, *args, **kw)

Bases: fixtures.fixture.Fixture

A fixture to provide support for unloading/disabling modules.

clear_module()
setUp()

Ensure ImportError for the specified module.

tearDown()
class keystonemiddleware.tests.utils.NoModuleFinder(module)

Bases: object

Disallow further imports of ‘module’.

find_module(fullname, path)
class keystonemiddleware.tests.utils.TestCase(*args, **kwargs)

Bases: testtools.testcase.TestCase

TEST_DOMAIN_ID = '1'
TEST_DOMAIN_NAME = 'aDomain'
TEST_GROUP_ID = '0e7980325c59403993c45175d8662b50'
TEST_ROLE_ID = '2d17689ecc2a4580b062c44e2aceca9f'
TEST_ROOT_URL = 'http://127.0.0.1:5000/'
TEST_TENANT_ID = '1'
TEST_TENANT_NAME = 'aTenant'
TEST_TOKEN = 'aToken'
TEST_TRUST_ID = 'aTrust'
TEST_USER = 'test'
TEST_USER_ID = '1264e210e3b044858317b2d097736ce8'
assertQueryStringContains(**kwargs)
assertQueryStringIs(qs='')

Verify the QueryString matches what is expected.

The qs parameter should be of the format ‘foo=bar&abc=xyz’

assertRequestBodyIs(body=None, json=None)
assertRequestHeaderEqual(name, val)

Verify that the last request made contains a header and its value

The request must have already been made and httpretty must have been activated for the request.

setUp()
stub_url(method, parts=None, base_url=None, json=None, **kwargs)
tearDown()
class keystonemiddleware.tests.utils.TestResponse(data)

Bases: requests.models.Response

Class used to wrap requests.Response and provide some convenience to initialize with a dict.

text

Module contents