コード例 #1
0
    def test_api_key_file_from_config_with_lesser_loading_order(self):
        """Let's say we load the default configuration, and then
        stormpath.yml file with client.apiKey.file key. Then we provide
        API key ID and secret through environment variables - which
        have greater loading order than the stormpath.yml.
        """
        load_strategies = [
            # 1. We load the default configuration.
            LoadFileConfigStrategy('tests/assets/default_config.yml', must_exist=True),
            LoadAPIKeyConfigStrategy('i-do-not-exist'),
            # 3. We load stormpath.yml file with client.apiKey.file
            LoadFileConfigStrategy('tests/assets/apiKeyFile.yml'),
            LoadAPIKeyConfigStrategy('i-do-not-exist'),
            LoadFileConfigStrategy('i-do-not-exist'),
            # 6. We load API key id and secret from environment
            #    variables.
            LoadEnvConfigStrategy(prefix='STORMPATH'),
            ExtendConfigStrategy(extend_with={})
        ]
        post_processing_strategies = [LoadAPIKeyFromConfigStrategy()]
        validation_strategies = [ValidateClientConfigStrategy()]

        cl = ConfigLoader(load_strategies, post_processing_strategies, validation_strategies)
        config = cl.load()

        self.assertEqual(config['client']['apiKey']['id'], 'greater order id')
        self.assertEqual(config['client']['apiKey']['secret'], 'greater order secret')
        self.assertFalse('file' in config['client']['apiKey'])
コード例 #2
0
    def test_api_key_from_config_with_lesser_loading_order(self):
        """Similar to the previous test, but with apiKey key.
        """
        client_config = {
            'client': {
                'apiKey': {
                    'id': 'CLIENT_CONFIG_API_KEY_ID',
                    'secret': 'CLIENT_CONFIG_API_KEY_SECRET',
                }
            }
        }

        load_strategies = [
            # 1. We load the default configuration.
            LoadFileConfigStrategy('tests/assets/default_config.yml', must_exist=True),
            LoadAPIKeyConfigStrategy('i-do-not-exist'),
            # 3. We load stormpath.yml file with client.apiKey.file
            LoadFileConfigStrategy('tests/assets/apiKeyApiKey.json'),
            LoadAPIKeyConfigStrategy('i-do-not-exist'),
            LoadFileConfigStrategy('i-do-not-exist'),
            LoadEnvConfigStrategy(prefix='STORMPATH'),
            # 7. Configuration provided through the SDK client
            #    constructor.
            ExtendConfigStrategy(extend_with=client_config)
        ]
        post_processing_strategies = [LoadAPIKeyFromConfigStrategy()]
        validation_strategies = [ValidateClientConfigStrategy()]

        cl = ConfigLoader(load_strategies, post_processing_strategies, validation_strategies)
        config = cl.load()

        self.assertEqual(config['client']['apiKey']['id'], 'CLIENT_CONFIG_API_KEY_ID')
        self.assertEqual(config['client']['apiKey']['secret'], 'CLIENT_CONFIG_API_KEY_SECRET')
コード例 #3
0
    def test_load_non_existent_file_config_with_existing_config(self):
        lfcs = LoadFileConfigStrategy('tests/assets/i-do-not-exist.yml', must_exist=False)
        existing_config = {'application': {'name': 'App Name'}, 'key': 'value'}
        config = lfcs.process(existing_config)

        self.assertEqual(config['application']['name'], 'App Name')
        self.assertEqual(config['key'], 'value')
コード例 #4
0
    def test_config_extending(self):
        client_config = {
            'client': {
                'apiKey': {
                    'id': 'CLIENT_CONFIG_API_KEY_ID',
                    'secret': 'CLIENT_CONFIG_API_KEY_SECRET',
                }
            }
        }

        load_strategies = [
            # 1. We load the default configuration.
            LoadFileConfigStrategy('tests/assets/default_config.yml', must_exist=True),
            LoadAPIKeyConfigStrategy('i-do-not-exist'),
            LoadFileConfigStrategy('i-do-not-exist'),
            LoadAPIKeyConfigStrategy('i-do-not-exist'),
            LoadFileConfigStrategy('i-do-not-exist'),
            LoadEnvConfigStrategy(prefix='STORMPATH'),
            # 7. Configuration provided through the SDK client
            #    constructor.
            ExtendConfigStrategy(extend_with=client_config)
        ]
        post_processing_strategies = [LoadAPIKeyFromConfigStrategy()]
        validation_strategies = [ValidateClientConfigStrategy()]

        cl = ConfigLoader(load_strategies, post_processing_strategies, validation_strategies)
        config = cl.load()

        self.assertTrue('baseUrl' in config['client'])
コード例 #5
0
    def test_load_file_config_with_existing_config(self):
        lfcs = LoadFileConfigStrategy('tests/assets/stormpath.yml', must_exist=False)
        existing_config = {'application': {'name': 'App Name'}, 'key': 'value'}
        config = lfcs.process(existing_config)

        self.assertEqual(config['client']['cacheManager']['defaultTtl'], 301)
        self.assertEqual(config['application']['name'], 'MY_APP')
        self.assertEqual(config['key'], 'value')
コード例 #6
0
    def test_load_non_existent_file_config_with_existing_config(self):
        lfcs = LoadFileConfigStrategy('tests/assets/i-do-not-exist.yml',
                                      must_exist=False)
        existing_config = {'application': {'name': 'App Name'}, 'key': 'value'}
        config = lfcs.process(existing_config)

        self.assertEqual(config['application']['name'], 'App Name')
        self.assertEqual(config['key'], 'value')
コード例 #7
0
    def test_load_file_config_with_existing_config(self):
        lfcs = LoadFileConfigStrategy('tests/assets/stormpath.yml',
                                      must_exist=False)
        existing_config = {'application': {'name': 'App Name'}, 'key': 'value'}
        config = lfcs.process(existing_config)

        self.assertEqual(config['client']['cacheManager']['defaultTtl'], 301)
        self.assertEqual(config['application']['name'], 'MY_APP')
        self.assertEqual(config['key'], 'value')
コード例 #8
0
    def test_empty_api_key_properties_file_after_default_config(self):
        lfcs = LoadFileConfigStrategy("tests/assets/default_config.yml")
        config = lfcs.process()
        lapcs = LoadAPIKeyConfigStrategy("tests/assets/empty_apiKey.properties")
        returned_config = lapcs.process(config)

        self.assertEqual(returned_config, config)
        self.assertEqual(config["client"]["cacheManager"]["defaultTtl"], 300)
        self.assertIsNone(config["client"]["apiKey"]["id"])
        self.assertIsNone(config["client"]["apiKey"]["secret"])
    def test_empty_api_key_properties_file_after_default_config(self):
        lfcs = LoadFileConfigStrategy('tests/assets/default_config.yml')
        config = lfcs.process()
        lapcs = LoadAPIKeyConfigStrategy(
            'tests/assets/empty_apiKey.properties')
        returned_config = lapcs.process(config)

        self.assertEqual(returned_config, config)
        self.assertEqual(config['client']['cacheManager']['defaultTtl'], 300)
        self.assertIsNone(config['client']['apiKey']['id'])
        self.assertIsNone(config['client']['apiKey']['secret'])
コード例 #10
0
    def test_load_file_json_config_with_existing_config(self):
        config = {'application': {'name': 'App Name'}, 'key': 'value'}
        lfcs = LoadFileConfigStrategy('tests/assets/stormpath.json')
        config = lfcs.process(config)

        self.assertEqual(config['client']['cacheManager']['defaultTtl'], 302)
        self.assertEqual(config['client']['apiKey']['id'], 'MY_JSON_CONFIG_API_KEY_ID')
        self.assertEqual(config['client']['apiKey']['secret'], 'MY_JSON_CONFIG_API_KEY_SECRET')
        self.assertEqual(config['client']['connectionTimeout'], None)
        self.assertEqual(config['application']['name'], 'MY_JSON_APP')
        self.assertEqual(config['key'], 'value')
コード例 #11
0
    def test_load_file_json_config_with_existing_config(self):
        config = {'application': {'name': 'App Name'}, 'key': 'value'}
        lfcs = LoadFileConfigStrategy('tests/assets/stormpath.json')
        config = lfcs.process(config)

        self.assertEqual(config['client']['cacheManager']['defaultTtl'], 302)
        self.assertEqual(config['client']['apiKey']['id'],
                         'MY_JSON_CONFIG_API_KEY_ID')
        self.assertEqual(config['client']['apiKey']['secret'],
                         'MY_JSON_CONFIG_API_KEY_SECRET')
        self.assertEqual(config['client']['connectionTimeout'], None)
        self.assertEqual(config['application']['name'], 'MY_JSON_APP')
        self.assertEqual(config['key'], 'value')
コード例 #12
0
    def setUp(self):
        client_config = {
            'application': {
                'name': 'CLIENT_CONFIG_APP',
                'href': None
            },
            'client': {
                'apiKey': {
                    'id': 'CLIENT_CONFIG_API_KEY_ID',
                    'secret': 'CLIENT_CONFIG_API_KEY_SECRET',
                }
            }
        }

        self.load_strategies = [
            # 1. Default configuration.
            LoadFileConfigStrategy('tests/assets/default_config.yml', must_exist=True),

            # 2. apiKey.properties file from ~/.stormpath directory.
            LoadAPIKeyConfigStrategy('tests/assets/apiKey.properties'),

            # 3. stormpath.[json or yaml] file from ~/.stormpath
            #    directory.
            LoadFileConfigStrategy('tests/assets/stormpath.yml'),

            # 4. apiKey.properties file from application directory.
            LoadAPIKeyConfigStrategy('tests/assets/no_apiKey.properties'),

            # 5. stormpath.[json or yaml] file from application
            #    directory.
            LoadFileConfigStrategy('tests/assets/stormpath.json'),

            # 6. Environment variables.
            LoadEnvConfigStrategy(prefix='STORMPATH'),

            # 7. Configuration provided through the SDK client
            #    constructor.
            ExtendConfigStrategy(extend_with=client_config)
        ]
        self.post_processing_strategies = [
            # Post-processing: If the key client.apiKey.file isn't
            # empty, then a apiKey.properties file should be loaded
            # from that path.
            LoadAPIKeyFromConfigStrategy(),
        ]
        self.validation_strategies = [
            # Post-processing: Validation
            ValidateClientConfigStrategy()
        ]
コード例 #13
0
    def test_load_file_config(self):
        lfcs = LoadFileConfigStrategy('tests/assets/default_config.yml')
        config = lfcs.process()

        self.assertEqual(config['client']['cacheManager']['defaultTtl'], 300)
コード例 #14
0
    def test_load_file_config(self):
        lfcs = LoadFileConfigStrategy('tests/assets/default_config.yml')
        config = lfcs.process()

        self.assertEqual(config['client']['cacheManager']['defaultTtl'], 300)