|
| 1 | +suite: haproxy config |
| 2 | + |
| 3 | +templates: |
| 4 | + - templates/configmap.yaml |
| 5 | + |
| 6 | +tests: |
| 7 | + - it: names backends so they never collide with frontends |
| 8 | + asserts: |
| 9 | + - matchRegex: |
| 10 | + path: data["haproxy.cfg"] |
| 11 | + pattern: '(?m)^frontend http$' |
| 12 | + - matchRegex: |
| 13 | + path: data["haproxy.cfg"] |
| 14 | + pattern: '(?m)^backend http_backend$' |
| 15 | + - matchRegex: |
| 16 | + path: data["haproxy.cfg"] |
| 17 | + pattern: '(?m)^\s+default_backend http_backend$' |
| 18 | + - notMatchRegex: |
| 19 | + path: data["haproxy.cfg"] |
| 20 | + pattern: '(?m)^backend http$' |
| 21 | + - matchRegex: |
| 22 | + path: data["haproxy.cfg"] |
| 23 | + pattern: '(?m)^frontend https$' |
| 24 | + - matchRegex: |
| 25 | + path: data["haproxy.cfg"] |
| 26 | + pattern: '(?m)^backend https_backend$' |
| 27 | + - matchRegex: |
| 28 | + path: data["haproxy.cfg"] |
| 29 | + pattern: '(?m)^\s+default_backend https_backend$' |
| 30 | + - notMatchRegex: |
| 31 | + path: data["haproxy.cfg"] |
| 32 | + pattern: '(?m)^backend https$' |
| 33 | + |
| 34 | + - it: renders http frontends without whitelist rules by default |
| 35 | + asserts: |
| 36 | + - notMatchRegex: |
| 37 | + path: data["haproxy.cfg"] |
| 38 | + pattern: 'acl whitelist' |
| 39 | + - notMatchRegex: |
| 40 | + path: data["haproxy.cfg"] |
| 41 | + pattern: 'tcp-request content accept if whitelist' |
| 42 | + |
| 43 | + - it: fails when whitelistHTTP is enabled with an empty whitelist |
| 44 | + set: |
| 45 | + whitelistHTTP: true |
| 46 | + whitelist: [] |
| 47 | + asserts: |
| 48 | + - failedTemplate: |
| 49 | + errorPattern: 'whitelistHTTP is enabled but whitelist is empty' |
| 50 | + |
| 51 | + - it: filters http and https when whitelistHTTP is enabled with a whitelist |
| 52 | + set: |
| 53 | + whitelistHTTP: true |
| 54 | + whitelist: |
| 55 | + - 10.0.0.0/8 |
| 56 | + - 192.168.1.1 |
| 57 | + asserts: |
| 58 | + - matchRegex: |
| 59 | + path: data["haproxy.cfg"] |
| 60 | + pattern: '(?m)^frontend http$\n(?:.*\n){0,5}?\s+acl whitelist src 10\.0\.0\.0/8 192\.168\.1\.1$' |
| 61 | + - matchRegex: |
| 62 | + path: data["haproxy.cfg"] |
| 63 | + pattern: '(?m)^frontend https$\n(?:.*\n){0,8}?\s+acl whitelist src 10\.0\.0\.0/8 192\.168\.1\.1$' |
| 64 | + - matchRegex: |
| 65 | + path: data["haproxy.cfg"] |
| 66 | + pattern: '(?m)^\s+tcp-request content accept if whitelist$' |
| 67 | + - matchRegex: |
| 68 | + path: data["haproxy.cfg"] |
| 69 | + pattern: '(?m)^\s+tcp-request content reject$' |
| 70 | + |
| 71 | + - it: renames kubernetes and talos backends |
| 72 | + set: |
| 73 | + kubernetesAndTalos: |
| 74 | + endpoints: |
| 75 | + - 10.1.1.1 |
| 76 | + - 10.1.1.2 |
| 77 | + asserts: |
| 78 | + - matchRegex: |
| 79 | + path: data["haproxy.cfg"] |
| 80 | + pattern: '(?m)^frontend kubernetes$' |
| 81 | + - matchRegex: |
| 82 | + path: data["haproxy.cfg"] |
| 83 | + pattern: '(?m)^\s+default_backend kubernetes_backend$' |
| 84 | + - matchRegex: |
| 85 | + path: data["haproxy.cfg"] |
| 86 | + pattern: '(?m)^backend kubernetes_backend$' |
| 87 | + - notMatchRegex: |
| 88 | + path: data["haproxy.cfg"] |
| 89 | + pattern: '(?m)^backend kubernetes$' |
| 90 | + - matchRegex: |
| 91 | + path: data["haproxy.cfg"] |
| 92 | + pattern: '(?m)^frontend talos$' |
| 93 | + - matchRegex: |
| 94 | + path: data["haproxy.cfg"] |
| 95 | + pattern: '(?m)^\s+default_backend talos_backend$' |
| 96 | + - matchRegex: |
| 97 | + path: data["haproxy.cfg"] |
| 98 | + pattern: '(?m)^backend talos_backend$' |
| 99 | + - notMatchRegex: |
| 100 | + path: data["haproxy.cfg"] |
| 101 | + pattern: '(?m)^backend talos$' |
| 102 | + - matchRegex: |
| 103 | + path: data["haproxy.cfg"] |
| 104 | + pattern: '(?m)^\s+server srv0 10\.1\.1\.1:6443 check\s*$' |
| 105 | + - matchRegex: |
| 106 | + path: data["haproxy.cfg"] |
| 107 | + pattern: '(?m)^\s+server srv1 10\.1\.1\.2:50000 check\s*$' |
| 108 | + |
| 109 | + - it: renders kubernetes and talos without whitelist rules when the whitelist is empty |
| 110 | + set: |
| 111 | + kubernetesAndTalos: |
| 112 | + endpoints: |
| 113 | + - 10.1.1.1 |
| 114 | + asserts: |
| 115 | + - notMatchRegex: |
| 116 | + path: data["haproxy.cfg"] |
| 117 | + pattern: 'acl whitelist' |
| 118 | + - notMatchRegex: |
| 119 | + path: data["haproxy.cfg"] |
| 120 | + pattern: 'tcp-request content accept if whitelist' |
| 121 | + - notMatchRegex: |
| 122 | + path: data["haproxy.cfg"] |
| 123 | + pattern: 'tcp-request content reject' |
| 124 | + |
| 125 | + - it: filters kubernetes and talos when a whitelist is set |
| 126 | + set: |
| 127 | + kubernetesAndTalos: |
| 128 | + endpoints: |
| 129 | + - 10.1.1.1 |
| 130 | + whitelist: |
| 131 | + - 10.0.0.0/8 |
| 132 | + asserts: |
| 133 | + - matchRegex: |
| 134 | + path: data["haproxy.cfg"] |
| 135 | + pattern: '(?m)^frontend kubernetes$\n(?:.*\n){0,3}?\s+acl whitelist src 10\.0\.0\.0/8$' |
| 136 | + - matchRegex: |
| 137 | + path: data["haproxy.cfg"] |
| 138 | + pattern: '(?m)^frontend talos$\n(?:.*\n){0,3}?\s+acl whitelist src 10\.0\.0\.0/8$' |
| 139 | + - matchRegex: |
| 140 | + path: data["haproxy.cfg"] |
| 141 | + pattern: '(?m)^\s+tcp-request content accept if whitelist$' |
| 142 | + - matchRegex: |
| 143 | + path: data["haproxy.cfg"] |
| 144 | + pattern: '(?m)^\s+tcp-request content reject$' |
0 commit comments