|
1 | 1 | package kube |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "github.com/stretchr/testify/assert" |
4 | 5 | "os" |
5 | 6 | "reflect" |
6 | 7 | "regexp" |
@@ -87,6 +88,63 @@ func TestToYAML_Missing_PlaceholdersSpecificPath(t *testing.T) { |
87 | 88 | } |
88 | 89 | } |
89 | 90 |
|
| 91 | +func TestToYAML_BinaryValueInjectedToStringData(t *testing.T) { |
| 92 | + mv := helpers.MockVault{} |
| 93 | + |
| 94 | + d := Template{ |
| 95 | + Resource{ |
| 96 | + Kind: "Secret", |
| 97 | + Annotations: map[string]string{ |
| 98 | + types.AVPPathAnnotation: "path/to/secret", |
| 99 | + }, |
| 100 | + TemplateData: map[string]interface{}{ |
| 101 | + "apiVersion": "v1", |
| 102 | + "kind": "Secret", |
| 103 | + "metadata": map[string]interface{}{ |
| 104 | + "namespace": "default", |
| 105 | + "name": "some-resource", |
| 106 | + "annotations": map[string]string{ |
| 107 | + types.AVPPathAnnotation: "path/to/secret", |
| 108 | + }, |
| 109 | + }, |
| 110 | + "data": map[string]interface{}{ |
| 111 | + "d-yscs": "<yaml-safe-control-chars>", |
| 112 | + "d-ubd": "<unsafe-binary-data>", |
| 113 | + "d-realistic": "<realistic>", |
| 114 | + }, |
| 115 | + "stringData": map[string]interface{}{ |
| 116 | + "sd-yscc": "<yaml-safe-control-chars>", |
| 117 | + "sd-ubd": "<unsafe-binary-data>", |
| 118 | + "sd-realistic": "<realistic>", |
| 119 | + }, |
| 120 | + }, |
| 121 | + Backend: &mv, |
| 122 | + Data: map[string]interface{}{ |
| 123 | + // Tab and linebreak chars are safe |
| 124 | + "yaml-safe-control-chars": "\x09first\x0D\x0A\x09second\n", |
| 125 | + "unsafe-binary-data": "as\u0001df\nas\x0bdf", |
| 126 | + "realistic": "�\u0001\f\u0003�c�ţ8h�\u0001\a�R�\nڒp��Y4���E�m���+��W�%\u000FH��$�(���]�\u000E&\u000E�zi�@�O�X(\f��ߞ\u0003\a�\u000EN(�a#��\u000F��5LF1�}��ݗ��\u000Fk\u0010�i5\u000FcJOϐ\u001F�.\u0000sp)�(5��\u0004a\u0015���\u0004�'�9�\u0002��\ak��M4\u0004~\u007F��:�Y�:�\u001A=]c�\u0004;����\u0013�ʼ��ױ;۹�C\u0001��+o+=��r�\u0011�*d�\u0018����Z�赁\u0004��Ża�\n�.հ\u0014H����\u0017�y�\u0006R�xv�X�i)\u0000��-^�\u0006L�ٲfQsfz�\u001D�ͩ8T6^E��5zk�غ%��B\u0001A�Ը�^\u0005��~�\u0084�\u0004ă����\nq��;�e�f�Ic��\f�\u000F4H]�+ܭU��×�D��\u0017�x�c��\u0017\u0017�{", |
| 127 | + }, |
| 128 | + }, |
| 129 | + } |
| 130 | + |
| 131 | + expectedErr := []string{ |
| 132 | + "Replace: could not replace all placeholders in Template:", |
| 133 | + "placeholder resolved to binary content in sd-ubd: <unsafe-binary-data>", |
| 134 | + "placeholder resolved to binary content in sd-realistic: <realistic>", |
| 135 | + "placeholder resolved to binary content in d-ubd: <unsafe-binary-data>", |
| 136 | + "placeholder resolved to binary content in d-realistic: <realistic>", |
| 137 | + } |
| 138 | + |
| 139 | + err := d.Replace() |
| 140 | + if err == nil { |
| 141 | + yaml, _ := d.ToYAML() |
| 142 | + t.Fatalf("expected error %s but got success, producing: %s", expectedErr, yaml) |
| 143 | + } |
| 144 | + |
| 145 | + assert.ElementsMatch(t, strings.Split(err.Error(), "\n"), expectedErr) |
| 146 | +} |
| 147 | + |
90 | 148 | func TestToYAML_RemoveMissing(t *testing.T) { |
91 | 149 | mv := helpers.MockVault{} |
92 | 150 |
|
|
0 commit comments