Add additional layering + substitution unit tests

This PS adds even more complex layering + substitution unit tests
to catch a variety of edge case with layering followed by
substitution, including with multiple child documents, or
substitution at the same path or different paths as the parent
document.

Change-Id: I172ba9067eaff7b10731f627b83c96d79968a209
This commit is contained in:
Felipe Monteiro 2018-02-02 23:07:37 -05:00 committed by Tin Lam
parent 3c8a65a813
commit 3d278a2b08
1 changed files with 312 additions and 7 deletions

View File

@ -36,7 +36,6 @@ class TestDocumentLayeringWithSubstitution(
"name": "global-cert",
"path": "."
}
}],
"_SITE_DATA_1_": {"data": {"b": 4}},
"_SITE_ACTIONS_1_": {
@ -75,7 +74,6 @@ class TestDocumentLayeringWithSubstitution(
"name": "global-cert",
"path": "."
}
}],
"_SITE_DATA_1_": {"data": {"b": 4}},
"_SITE_ACTIONS_1_": {
@ -118,7 +116,6 @@ class TestDocumentLayeringWithSubstitution(
"name": "site-cert",
"path": "."
}
}],
# No layering should be applied as the document has no parent.
"_SITE_ACTIONS_1_": {
@ -143,9 +140,9 @@ class TestDocumentLayeringWithSubstitution(
global_expected=global_expected,
substitution_sources=[certificate])
def test_parent_and_child_undergo_layering_and_substitution(self):
def test_parent_and_child_layering_and_substitution_different_paths(self):
"""Validate that parent and child documents both undergo layering and
substitution.
substitution where the substitution occurs at different paths.
global -> requires substitution
|
@ -163,7 +160,6 @@ class TestDocumentLayeringWithSubstitution(
"name": "global-cert",
"path": "."
}
}],
"_SITE_DATA_1_": {"data": {"c": "need-site-secret"}},
"_SITE_ACTIONS_1_": {
@ -177,7 +173,6 @@ class TestDocumentLayeringWithSubstitution(
"name": "site-cert",
"path": "."
}
}],
}
doc_factory = factories.DocumentFactory(2, [1, 1])
@ -201,6 +196,316 @@ class TestDocumentLayeringWithSubstitution(
global_expected=global_expected,
substitution_sources=[certificate, certificate_key])
def test_parent_and_child_layering_and_substitution_same_paths(self):
"""Validate that parent and child documents both undergo layering and
substitution where the substitution occurs at the same path.
global -> requires substitution
|
v
site -> requires substitution
"""
mapping = {
"_GLOBAL_DATA_1_": {"data": {"a": {"x": 1, "y": 2}}},
"_GLOBAL_SUBSTITUTIONS_1_": [{
"dest": {
"path": ".b"
},
"src": {
"schema": "deckhand/Certificate/v1",
"name": "global-cert",
"path": "."
}
}],
"_SITE_DATA_1_": {"data": "placeholder"},
"_SITE_ACTIONS_1_": {
"actions": [{"method": "merge", "path": "."}]},
"_SITE_SUBSTITUTIONS_1_": [{
"dest": {
"path": ".b"
},
"src": {
"schema": "deckhand/CertificateKey/v1",
"name": "site-cert",
"path": "."
}
}],
}
doc_factory = factories.DocumentFactory(2, [1, 1])
documents = doc_factory.gen_test(mapping, site_abstract=False,
global_abstract=False)
secrets_factory = factories.DocumentSecretFactory()
global_expected = {'a': {'x': 1, 'y': 2}, 'b': 'global-secret'}
site_expected = {'a': {'x': 1, 'y': 2}, 'b': 'site-secret'}
certificate = secrets_factory.gen_test(
'Certificate', 'cleartext', data='global-secret',
name='global-cert')
certificate_key = secrets_factory.gen_test(
'CertificateKey', 'cleartext', data='site-secret',
name='site-cert')
self._test_layering(
documents, site_expected=site_expected,
global_expected=global_expected,
substitution_sources=[certificate, certificate_key])
def test_parent_with_multi_child_layering_and_sub_different_paths(self):
"""Validate that parent and children documents both undergo layering
and substitution where the substitution occurs at different paths.
global -> requires substitution
|
v
site1 -> requires substitution
site2 -> requires substitution
"""
mapping = {
"_GLOBAL_DATA_1_": {"data": {"a": {"x": 1, "y": 2}}},
"_GLOBAL_SUBSTITUTIONS_1_": [{
"dest": {
"path": ".b"
},
"src": {
"schema": "deckhand/Certificate/v1",
"name": "global-cert",
"path": "."
}
}],
"_SITE_DATA_1_": {"data": "placeholder"},
"_SITE_ACTIONS_1_": {
"actions": [{"method": "merge", "path": "."}]},
"_SITE_SUBSTITUTIONS_1_": [{
"dest": {
"path": ".c"
},
"src": {
"schema": "deckhand/CertificateKey/v1",
"name": "site-1-cert",
"path": "."
}
}],
"_SITE_DATA_2_": {"data": "placeholder"},
"_SITE_ACTIONS_2_": {
"actions": [{"method": "merge", "path": "."}]},
"_SITE_SUBSTITUTIONS_2_": [{
"dest": {
"path": ".d"
},
"src": {
"schema": "deckhand/CertificateKey/v1",
"name": "site-2-cert",
"path": "."
}
}],
}
doc_factory = factories.DocumentFactory(2, [1, 2])
documents = doc_factory.gen_test(mapping, site_abstract=False,
global_abstract=False)
secrets_factory = factories.DocumentSecretFactory()
global_expected = {'a': {'x': 1, 'y': 2}, 'b': 'global-secret'}
site_expected = [
{'a': {'x': 1, 'y': 2}, 'b': 'global-secret', 'c': 'site-1-sec'},
{'a': {'x': 1, 'y': 2}, 'b': 'global-secret', 'd': 'site-2-sec'}]
certificate = secrets_factory.gen_test(
'Certificate', 'cleartext', data='global-secret',
name='global-cert')
certificate_keys = [
secrets_factory.gen_test(
'CertificateKey', 'cleartext', data='site-%d-sec' % idx,
name='site-%d-cert' % idx)
for idx in range(1, 3)
]
self._test_layering(
documents, site_expected=site_expected,
global_expected=global_expected,
substitution_sources=[certificate] + certificate_keys)
def test_parent_with_multi_child_layering_and_sub_same_path(self):
"""Validate that parent and children documents both undergo layering
and substitution where the substitution occurs at the same path.
global -> requires substitution
|
v
site1 -> requires substitution
site2 -> requires substitution
"""
mapping = {
"_GLOBAL_DATA_1_": {"data": {"a": {"x": 1, "y": 2}}},
"_GLOBAL_SUBSTITUTIONS_1_": [{
"dest": {
"path": ".b"
},
"src": {
"schema": "deckhand/Certificate/v1",
"name": "global-cert",
"path": "."
}
}],
"_SITE_DATA_1_": {"data": "placeholder"},
"_SITE_ACTIONS_1_": {
"actions": [{"method": "merge", "path": "."}]},
"_SITE_SUBSTITUTIONS_1_": [{
"dest": {
"path": ".b"
},
"src": {
"schema": "deckhand/CertificateKey/v1",
"name": "site-1-cert",
"path": "."
}
}],
"_SITE_DATA_2_": {"data": "placeholder"},
"_SITE_ACTIONS_2_": {
"actions": [{"method": "merge", "path": "."}]},
"_SITE_SUBSTITUTIONS_2_": [{
"dest": {
"path": ".b"
},
"src": {
"schema": "deckhand/CertificateKey/v1",
"name": "site-2-cert",
"path": "."
}
}],
}
doc_factory = factories.DocumentFactory(2, [1, 2])
documents = doc_factory.gen_test(mapping, site_abstract=False,
global_abstract=False)
secrets_factory = factories.DocumentSecretFactory()
global_expected = {'a': {'x': 1, 'y': 2}, 'b': 'global-secret'}
site_expected = [
{'a': {'x': 1, 'y': 2}, 'b': 'site-1-sec'},
{'a': {'x': 1, 'y': 2}, 'b': 'site-2-sec'}]
certificate = secrets_factory.gen_test(
'Certificate', 'cleartext', data='global-secret',
name='global-cert')
certificate_keys = [
secrets_factory.gen_test(
'CertificateKey', 'cleartext', data='site-%d-sec' % idx,
name='site-%d-cert' % idx)
for idx in range(1, 3)
]
self._test_layering(
documents, site_expected=site_expected,
global_expected=global_expected,
substitution_sources=[certificate] + certificate_keys)
def test_parent_with_multi_child_layering_and_multi_substitutions(self):
"""Validate that parent and children documents both undergo layering
and multiple substitutions.
global -> requires substitution
|
v
site1 -> requires multiple substitutions
site2 -> requires multiple substitutions
"""
mapping = {
"_GLOBAL_DATA_1_": {"data": {"a": {"x": 1, "y": 2}}},
"_GLOBAL_SUBSTITUTIONS_1_": [{
"dest": {
"path": ".b"
},
"src": {
"schema": "deckhand/Certificate/v1",
"name": "global-cert",
"path": "."
}
}],
"_SITE_DATA_1_": {"data": "placeholder"},
"_SITE_ACTIONS_1_": {
"actions": [{"method": "merge", "path": "."}]},
"_SITE_SUBSTITUTIONS_1_": [
{
"dest": {
"path": ".c"
},
"src": {
"schema": "deckhand/CertificateKey/v1",
"name": "site-1-cert-key",
"path": "."
},
},
{
"dest": {
"path": ".d"
},
"src": {
"schema": "deckhand/Certificate/v1",
"name": "site-1-cert",
"path": "."
}
}
],
"_SITE_DATA_2_": {"data": "placeholder"},
"_SITE_ACTIONS_2_": {
"actions": [{"method": "merge", "path": "."}]},
"_SITE_SUBSTITUTIONS_2_": [
{
"dest": {
"path": ".e"
},
"src": {
"schema": "deckhand/CertificateKey/v1",
"name": "site-2-cert-key",
"path": "."
},
},
{
"dest": {
"path": ".f"
},
"src": {
"schema": "deckhand/Certificate/v1",
"name": "site-2-cert",
"path": "."
}
}
]
}
doc_factory = factories.DocumentFactory(2, [1, 2])
documents = doc_factory.gen_test(mapping, site_abstract=False,
global_abstract=False)
secrets_factory = factories.DocumentSecretFactory()
global_expected = {'a': {'x': 1, 'y': 2}, 'b': 'global-secret'}
site_expected = [
{'a': {'x': 1, 'y': 2}, 'b': 'global-secret',
'c': 'site-1-sec-key', 'd': 'site-1-sec'},
{'a': {'x': 1, 'y': 2}, 'b': 'global-secret',
'e': 'site-2-sec-key', 'f': 'site-2-sec'}]
certificate = secrets_factory.gen_test(
'Certificate', 'cleartext', data='global-secret',
name='global-cert')
certificate_keys = [
secrets_factory.gen_test(
'CertificateKey', 'cleartext', data='site-%d-sec-key' % idx,
name='site-%d-cert-key' % idx)
for idx in range(1, 3)
]
certificates = [
secrets_factory.gen_test(
'Certificate', 'cleartext', data='site-%d-sec' % idx,
name='site-%d-cert' % idx)
for idx in range(1, 3)
]
self._test_layering(
documents, site_expected=site_expected,
global_expected=global_expected,
substitution_sources=[certificate] + certificate_keys +
certificates)
@mock.patch('deckhand.engine.layering.LOG', autospec=True)
def test_parent_and_child_undergo_layering_and_substitution_empty_layers(
self, mock_log):