Browse Source

Include tests of secret_handlers from config yaml and some of that's implementation details

pull/1140/head
Ross McFarland 2 years ago
parent
commit
6d778b3b67
No known key found for this signature in database GPG Key ID: 943B179E15D3B22A
4 changed files with 54 additions and 1 deletions
  1. +2
    -1
      octodns/manager.py
  2. +19
    -0
      tests/config/secrets.yaml
  3. +1
    -0
      tests/helpers.py
  4. +32
    -0
      tests/test_octodns_manager.py

+ 2
- 1
octodns/manager.py View File

@ -428,7 +428,8 @@ class Manager(object):
# they're sensitive so just provide the key, and even
# that only at debug level.
self.log.debug(
'_build_kwargs: no handler found for the value of {k}'
'_build_kwargs: failed to find handler for key "%sp ',
k,
)
else:
v = handler.fetch(name, source)


+ 19
- 0
tests/config/secrets.yaml View File

@ -0,0 +1,19 @@
---
secret_handlers:
dummy:
class: helpers.DummySecrets
prefix: in_config/
requires-env:
class: helpers.DummySecrets
# things can pull from env, it prexists
prefix: env/FROM_ENV_WILL_WORK
requires-dummy:
class: helpers.DummySecrets
# things can't pull from other handlers, the order they're configured in is
# indeterminent so it's not safe, they're also all added at once
prefix: dummy/FROM_DUMMY_WONT_WORK
# Not needed, but required key
providers: {}
# Not needed, but required key
zones: {}

+ 1
- 0
tests/helpers.py View File

@ -140,6 +140,7 @@ class CountingProcessor(BaseProcessor):
class DummySecrets(BaseSecrets):
def __init__(self, name, prefix):
super().__init__(name)
self.log.info('__init__: name=%s, prefix=%s', name, prefix)
self.prefix = prefix
def fetch(self, name, source):


+ 32
- 0
tests/test_octodns_manager.py View File

@ -8,6 +8,7 @@ from unittest import TestCase
from unittest.mock import MagicMock, patch
from helpers import (
DummySecrets,
DynamicProvider,
GeoProvider,
NoSshFpProvider,
@ -1249,6 +1250,37 @@ class TestManager(TestCase):
self.assertTrue(sh)
self.assertEqual('pre-thing', sh.fetch('thing', None))
# test configuring secret handlers
environ['FROM_ENV_WILL_WORK'] = 'fetched_from_env/'
manager = Manager(get_config_filename('secrets.yaml'))
# dummy was configured
self.assertTrue('dummy' in manager.secret_handlers)
dummy = manager.secret_handlers['dummy']
self.assertIsInstance(dummy, DummySecrets)
# and has the prefix value explicitly stated in the yaml
self.assertEqual('in_config/hello', dummy.fetch('hello', None))
# requires-env was configured
self.assertTrue('requires-env' in manager.secret_handlers)
requires_env = manager.secret_handlers['requires-env']
self.assertIsInstance(requires_env, DummySecrets)
# and successfully pulled a value from env as its prefix
self.assertEqual(
'fetched_from_env/hello', requires_env.fetch('hello', None)
)
# requires-dummy was created
self.assertTrue('requires-dummy' in manager.secret_handlers)
requires_dummy = manager.secret_handlers['requires-dummy']
self.assertIsInstance(requires_dummy, DummySecrets)
# but failed to fetch a secret from dummy so we just get the configured
# value as it was in the yaml for prefix
self.assertEqual(
'dummy/FROM_DUMMY_WONT_WORK:hello',
requires_dummy.fetch(':hello', None),
)
class TestMainThreadExecutor(TestCase):
def test_success(self):


Loading…
Cancel
Save