Skip to content

Commit ce53e49

Browse files
committed
test(mongodb): cover TLS modes, splitHorizons, and RBAC
Signed-off-by: Arsolitt <[email protected]> Assisted-By: Claude <[email protected]>
1 parent 208b7fc commit ce53e49

4 files changed

Lines changed: 404 additions & 2 deletions

File tree

‎packages/apps/mongodb/tests/dashboard-resourcemap_test.yaml‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,62 @@ tests:
104104
path: roleRef.apiGroup
105105
value: rbac.authorization.k8s.io
106106
documentIndex: 1
107+
108+
# TLS RBAC: tri-state coverage for rules[1].resourceNames (secrets rule)
109+
110+
- it: Role includes TLS secrets when tls explicitly enabled
111+
release:
112+
name: test-mongodb
113+
namespace: tenant-test
114+
set:
115+
tls:
116+
enabled: true
117+
asserts:
118+
- contains:
119+
path: rules[1].resourceNames
120+
content: test-mongodb-ca-cert
121+
documentIndex: 0
122+
- contains:
123+
path: rules[1].resourceNames
124+
content: test-mongodb-ssl
125+
documentIndex: 0
126+
127+
- it: Role excludes TLS secrets when TLS is off (default)
128+
release:
129+
name: test-mongodb
130+
namespace: tenant-test
131+
asserts:
132+
- notContains:
133+
path: rules[1].resourceNames
134+
content: test-mongodb-ca-cert
135+
documentIndex: 0
136+
- notContains:
137+
path: rules[1].resourceNames
138+
content: test-mongodb-ssl
139+
documentIndex: 0
140+
141+
- it: Role includes TLS secrets when external=true (auto-on tri-state)
142+
release:
143+
name: test-mongodb
144+
namespace: tenant-test
145+
set:
146+
external: true
147+
asserts:
148+
- contains:
149+
path: rules[1].resourceNames
150+
content: test-mongodb-ca-cert
151+
documentIndex: 0
152+
153+
- it: Role excludes TLS secrets when external=true but tls.enabled=false (override)
154+
release:
155+
name: test-mongodb
156+
namespace: tenant-test
157+
set:
158+
external: true
159+
tls:
160+
enabled: false
161+
asserts:
162+
- notContains:
163+
path: rules[1].resourceNames
164+
content: test-mongodb-ca-cert
165+
documentIndex: 0

‎packages/apps/mongodb/tests/mongodb_test.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ tests:
106106
# CR Version #
107107
##################
108108

109-
- it: sets crVersion to 1.21.1
109+
- it: sets crVersion to 1.22.0
110110
release:
111111
name: test-mongodb
112112
namespace: tenant-test
@@ -116,7 +116,7 @@ tests:
116116
asserts:
117117
- equal:
118118
path: spec.crVersion
119-
value: "1.21.1"
119+
value: "1.22.0"
120120
documentIndex: 0
121121

122122
#####################
Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
suite: mongodb TLS CR integration
2+
3+
# Covers the spec.tls block in the PerconaServerMongoDB CR
4+
# and the spec.secrets.ssl reference to the operator-managed leaf secret.
5+
#
6+
# TLS chain is fully managed by the PSMDB operator via its native cert-manager
7+
# integration when spec.secrets.ssl is set. The chart does NOT render
8+
# cert-manager Issuer/Certificate resources — see templates/mongodb.yaml for
9+
# a detailed explanation.
10+
#
11+
# Tri-state matrix:
12+
# (a) external: false, tls.enabled unset → TLS off (no spec.tls, no spec.secrets.ssl)
13+
# (b) external: true, tls.enabled unset → TLS auto-on
14+
# (c) external: true, tls.enabled: false → TLS off (explicit override)
15+
# (d) external: false, tls.enabled: true → TLS on (operator creates cert chain)
16+
17+
release:
18+
name: mg-test
19+
namespace: tenant-test
20+
21+
set:
22+
_cluster:
23+
cluster-domain: cozy.local
24+
25+
templates:
26+
- templates/mongodb.yaml
27+
28+
tests:
29+
############################################################
30+
# (a) external: false, tls.enabled unset → TLS OFF
31+
############################################################
32+
33+
- it: (a) no spec.tls block when external false and tls unset
34+
documentIndex: 0
35+
asserts:
36+
- notExists:
37+
path: spec.tls
38+
39+
- it: (a) no spec.secrets.ssl when external false and tls unset
40+
documentIndex: 0
41+
asserts:
42+
- notExists:
43+
path: spec.secrets.ssl
44+
45+
############################################################
46+
# (b) external: true, tls.enabled unset → TLS AUTO-ON
47+
############################################################
48+
49+
- it: (b) spec.tls.mode is preferTLS when external true and tls unset
50+
set:
51+
external: true
52+
_namespace:
53+
host: example.cozy.local
54+
documentIndex: 0
55+
asserts:
56+
- equal:
57+
path: spec.tls.mode
58+
value: preferTLS
59+
60+
- it: (b) spec.secrets.ssl references the leaf secret when external true and tls unset
61+
set:
62+
external: true
63+
_namespace:
64+
host: example.cozy.local
65+
documentIndex: 0
66+
asserts:
67+
- equal:
68+
path: spec.secrets.ssl
69+
value: mg-test-ssl
70+
71+
############################################################
72+
# (c) external: true, tls.enabled: false → TLS OFF (explicit)
73+
############################################################
74+
75+
- it: (c) no spec.tls block when external true but tls explicitly disabled
76+
set:
77+
external: true
78+
_namespace:
79+
host: example.cozy.local
80+
tls:
81+
enabled: false
82+
documentIndex: 0
83+
asserts:
84+
- notExists:
85+
path: spec.tls
86+
87+
- it: (c) no spec.secrets.ssl when external true but tls explicitly disabled
88+
set:
89+
external: true
90+
_namespace:
91+
host: example.cozy.local
92+
tls:
93+
enabled: false
94+
documentIndex: 0
95+
asserts:
96+
- notExists:
97+
path: spec.secrets.ssl
98+
99+
############################################################
100+
# (d) external: false, tls.enabled: true → TLS ON (internal only)
101+
############################################################
102+
103+
- it: (d) spec.tls.mode is preferTLS when tls explicitly enabled with external false
104+
set:
105+
external: false
106+
tls:
107+
enabled: true
108+
documentIndex: 0
109+
asserts:
110+
- equal:
111+
path: spec.tls.mode
112+
value: preferTLS
113+
114+
- it: (d) spec.secrets.ssl references the leaf secret when tls explicitly enabled
115+
set:
116+
external: false
117+
tls:
118+
enabled: true
119+
documentIndex: 0
120+
asserts:
121+
- equal:
122+
path: spec.secrets.ssl
123+
value: mg-test-ssl
124+
125+
############################################################
126+
# spec.tls does NOT include issuerConf — we pass the secret directly
127+
############################################################
128+
129+
- it: spec.tls has no issuerConf when TLS enabled
130+
set:
131+
tls:
132+
enabled: true
133+
documentIndex: 0
134+
asserts:
135+
- notExists:
136+
path: spec.tls.issuerConf
137+
138+
- it: TLS mode is preferTLS (allows mixed TLS/plaintext for backup compatibility)
139+
# preferTLS is intentional: the backup CronJob does not yet support TLS,
140+
# so requireTLS would break backups. Strict enforcement will be added in a
141+
# follow-up once the backup workflow supports TLS connections.
142+
set:
143+
tls:
144+
enabled: true
145+
documentIndex: 0
146+
asserts:
147+
- equal:
148+
path: spec.tls.mode
149+
value: preferTLS
150+
151+
############################################################
152+
# crVersion gates the operator's splitHorizons → SAN injection
153+
# (cr.CompareVersion("1.22.0") >= 0 in pkg/psmdb/tls/tls.go)
154+
############################################################
155+
156+
- it: crVersion is hardcoded to 1.22.0
157+
documentIndex: 0
158+
asserts:
159+
- equal:
160+
path: spec.crVersion
161+
value: 1.22.0
162+
163+
############################################################
164+
# splitHorizons: per-pod external hostnames for external TLS
165+
############################################################
166+
167+
- it: (b) splitHorizons advertises per-pod external hostnames when external + tls auto-on
168+
set:
169+
external: true
170+
_namespace:
171+
host: example.cozy.local
172+
documentIndex: 0
173+
asserts:
174+
- equal:
175+
path: spec.replsets[0].splitHorizons
176+
value:
177+
mg-test-rs0-0:
178+
external: mg-test-rs0-0.example.cozy.local
179+
mg-test-rs0-1:
180+
external: mg-test-rs0-1.example.cozy.local
181+
mg-test-rs0-2:
182+
external: mg-test-rs0-2.example.cozy.local
183+
184+
- it: splitHorizons honours the replica count
185+
set:
186+
external: true
187+
replicas: 2
188+
_namespace:
189+
host: example.cozy.local
190+
documentIndex: 0
191+
asserts:
192+
- equal:
193+
path: spec.replsets[0].splitHorizons
194+
value:
195+
mg-test-rs0-0:
196+
external: mg-test-rs0-0.example.cozy.local
197+
mg-test-rs0-1:
198+
external: mg-test-rs0-1.example.cozy.local
199+
200+
- it: (b) TLS stays active but splitHorizons is omitted when external true and _namespace.host absent
201+
set:
202+
external: true
203+
# _namespace intentionally absent — controller has not populated host yet
204+
documentIndex: 0
205+
asserts:
206+
- equal:
207+
path: spec.tls.mode
208+
value: preferTLS
209+
- notExists:
210+
path: spec.replsets[0].splitHorizons
211+
212+
- it: (a) no splitHorizons when external false and tls unset
213+
documentIndex: 0
214+
asserts:
215+
- notExists:
216+
path: spec.replsets[0].splitHorizons
217+
218+
- it: (c) no splitHorizons when external true but tls explicitly disabled
219+
set:
220+
external: true
221+
_namespace:
222+
host: example.cozy.local
223+
tls:
224+
enabled: false
225+
documentIndex: 0
226+
asserts:
227+
- notExists:
228+
path: spec.replsets[0].splitHorizons
229+
230+
- it: (d) no splitHorizons when tls enabled but external false (internal-only TLS)
231+
set:
232+
external: false
233+
tls:
234+
enabled: true
235+
documentIndex: 0
236+
asserts:
237+
- notExists:
238+
path: spec.replsets[0].splitHorizons
239+
240+
############################################################
241+
# sharding + TLS combination
242+
############################################################
243+
244+
- it: spec.tls.mode is preferTLS and secrets.ssl is set when tls enabled with sharding
245+
set:
246+
sharding: true
247+
tls:
248+
enabled: true
249+
shardingConfig:
250+
configServers: 3
251+
configServerSize: 3Gi
252+
mongos: 2
253+
shards:
254+
- name: rs0
255+
replicas: 3
256+
size: 10Gi
257+
documentIndex: 0
258+
asserts:
259+
- equal:
260+
path: spec.tls.mode
261+
value: preferTLS
262+
- equal:
263+
path: spec.secrets.ssl
264+
value: mg-test-ssl

0 commit comments

Comments
 (0)