|
36 | 36 | PACK_1_PATH = os.path.join(fixturesloader.get_fixtures_packs_base_path(), 'dummy_pack_1') |
37 | 37 | PACK_6_PATH = os.path.join(fixturesloader.get_fixtures_packs_base_path(), 'dummy_pack_6') |
38 | 38 | PACK_19_PATH = os.path.join(fixturesloader.get_fixtures_packs_base_path(), 'dummy_pack_19') |
| 39 | +PACK_11_PATH = os.path.join(fixturesloader.get_fixtures_packs_base_path(), 'dummy_pack_11') |
| 40 | +PACK_22_PATH = os.path.join(fixturesloader.get_fixtures_packs_base_path(), 'dummy_pack_22') |
39 | 41 |
|
40 | 42 |
|
41 | 43 | class ConfigsRegistrarTestCase(CleanDbTestCase): |
@@ -148,3 +150,63 @@ def test_register_all_configs_with_config_schema_validation_validation_failure_2 |
148 | 150 | self.assertRaisesRegexp(ValueError, expected_msg, |
149 | 151 | registrar.register_from_packs, |
150 | 152 | base_dirs=packs_base_paths) |
| 153 | + |
| 154 | + def test_register_all_configs_with_config_schema_validation_validation_failure_3(self): |
| 155 | + # This test checks for values containing "decrypt_kv" jinja filter in the config |
| 156 | + # object where keys have "secret: True" set in the schema. |
| 157 | + |
| 158 | + # Verify DB is empty |
| 159 | + pack_dbs = Pack.get_all() |
| 160 | + config_dbs = Config.get_all() |
| 161 | + |
| 162 | + self.assertEqual(len(pack_dbs), 0) |
| 163 | + self.assertEqual(len(config_dbs), 0) |
| 164 | + |
| 165 | + registrar = ConfigsRegistrar(use_pack_cache=False, fail_on_failure=True, |
| 166 | + validate_configs=True) |
| 167 | + registrar._pack_loader.get_packs = mock.Mock() |
| 168 | + registrar._pack_loader.get_packs.return_value = {'dummy_pack_11': PACK_11_PATH} |
| 169 | + |
| 170 | + # Register ConfigSchema for pack |
| 171 | + registrar._register_pack_db = mock.Mock() |
| 172 | + registrar._register_pack(pack_name='dummy_pack_11', pack_dir=PACK_11_PATH) |
| 173 | + packs_base_paths = content_utils.get_packs_base_paths() |
| 174 | + |
| 175 | + expected_msg = ('Values specified as "secret: True" in config schema are automatically ' |
| 176 | + 'decrypted by default. Use of "decrypt_kv" jinja filter is not allowed ' |
| 177 | + 'for such values. Please check the specified values in the config or ' |
| 178 | + 'the default values in the schema.') |
| 179 | + |
| 180 | + self.assertRaisesRegexp(ValueError, expected_msg, |
| 181 | + registrar.register_from_packs, |
| 182 | + base_dirs=packs_base_paths) |
| 183 | + |
| 184 | + def test_register_all_configs_with_config_schema_validation_validation_failure_4(self): |
| 185 | + # This test checks for default values containing "decrypt_kv" jinja filter for |
| 186 | + # keys which have "secret: True" set. |
| 187 | + |
| 188 | + # Verify DB is empty |
| 189 | + pack_dbs = Pack.get_all() |
| 190 | + config_dbs = Config.get_all() |
| 191 | + |
| 192 | + self.assertEqual(len(pack_dbs), 0) |
| 193 | + self.assertEqual(len(config_dbs), 0) |
| 194 | + |
| 195 | + registrar = ConfigsRegistrar(use_pack_cache=False, fail_on_failure=True, |
| 196 | + validate_configs=True) |
| 197 | + registrar._pack_loader.get_packs = mock.Mock() |
| 198 | + registrar._pack_loader.get_packs.return_value = {'dummy_pack_22': PACK_22_PATH} |
| 199 | + |
| 200 | + # Register ConfigSchema for pack |
| 201 | + registrar._register_pack_db = mock.Mock() |
| 202 | + registrar._register_pack(pack_name='dummy_pack_22', pack_dir=PACK_22_PATH) |
| 203 | + packs_base_paths = content_utils.get_packs_base_paths() |
| 204 | + |
| 205 | + expected_msg = ('Values specified as "secret: True" in config schema are automatically ' |
| 206 | + 'decrypted by default. Use of "decrypt_kv" jinja filter is not allowed ' |
| 207 | + 'for such values. Please check the specified values in the config or ' |
| 208 | + 'the default values in the schema.') |
| 209 | + |
| 210 | + self.assertRaisesRegexp(ValueError, expected_msg, |
| 211 | + registrar.register_from_packs, |
| 212 | + base_dirs=packs_base_paths) |
0 commit comments