Skip to content

Commit 9191068

Browse files
committed
test(postgres,mariadb): cover lookup-backed password rotation paths
The generation and marker suites render without a cluster, so lookup returns nothing and the two paths that define rotation — preserving a password when the counter is unchanged and regenerating it when the counter is bumped — went unexercised. Mock the existing credentials Secret through helm-unittest's kubernetesProvider so lookup resolves, and assert: an unchanged counter keeps the stored password, a bump regenerates it and advances the marker, and a legacy Secret with no marker adopts the current password as the baseline without rotating. For mariadb the bump case also asserts root is left untouched, since it is deliberately excluded from counter rotation. Assisted-by: LLM Signed-off-by: Alexey Artamonov <[email protected]>
1 parent 138b335 commit 9191068

4 files changed

Lines changed: 227 additions & 12 deletions

File tree

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
suite: MariaDB credentials lookup-backed rotation paths
2+
release:
3+
name: mariadb-test
4+
namespace: tenant-test
5+
templates:
6+
- templates/secret.yaml
7+
tests:
8+
- it: preserves existing passwords when the counter is unchanged
9+
kubernetesProvider:
10+
scheme:
11+
"v1/Secret":
12+
gvr:
13+
version: v1
14+
resource: secrets
15+
namespaced: true
16+
objects:
17+
- apiVersion: v1
18+
kind: Secret
19+
metadata:
20+
name: mariadb-test-credentials
21+
namespace: tenant-test
22+
annotations:
23+
mariadb.cozystack.io/password-rotation: "0"
24+
data:
25+
testuser: ZXhpc3RpbmdwYXNzd29yZA==
26+
root: ZXhpc3Rpbmdyb290
27+
set:
28+
users:
29+
testuser:
30+
maxUserConnections: 1000
31+
passwordRotation: 0
32+
documentSelector:
33+
path: metadata.name
34+
value: mariadb-test-credentials
35+
asserts:
36+
- equal:
37+
path: stringData.testuser
38+
value: existingpassword
39+
- equal:
40+
path: stringData.root
41+
value: existingroot
42+
- it: regenerates the app-user password on a bump while leaving root untouched
43+
kubernetesProvider:
44+
scheme:
45+
"v1/Secret":
46+
gvr:
47+
version: v1
48+
resource: secrets
49+
namespaced: true
50+
objects:
51+
- apiVersion: v1
52+
kind: Secret
53+
metadata:
54+
name: mariadb-test-credentials
55+
namespace: tenant-test
56+
annotations:
57+
mariadb.cozystack.io/password-rotation: "0"
58+
data:
59+
testuser: ZXhpc3RpbmdwYXNzd29yZA==
60+
root: ZXhpc3Rpbmdyb290
61+
set:
62+
users:
63+
testuser:
64+
maxUserConnections: 1000
65+
passwordRotation: 1
66+
documentSelector:
67+
path: metadata.name
68+
value: mariadb-test-credentials
69+
asserts:
70+
- notEqual:
71+
path: stringData.testuser
72+
value: existingpassword
73+
- matchRegex:
74+
path: stringData.testuser
75+
pattern: ^[a-zA-Z0-9]{16}$
76+
- equal:
77+
path: stringData.root
78+
value: existingroot
79+
- equal:
80+
path: metadata.annotations["mariadb.cozystack.io/password-rotation"]
81+
value: "1"
82+
- it: legacy secret without marker adopts baseline even when the counter is bumped
83+
kubernetesProvider:
84+
scheme:
85+
"v1/Secret":
86+
gvr:
87+
version: v1
88+
resource: secrets
89+
namespaced: true
90+
objects:
91+
- apiVersion: v1
92+
kind: Secret
93+
metadata:
94+
name: mariadb-test-credentials
95+
namespace: tenant-test
96+
data:
97+
testuser: ZXhpc3RpbmdwYXNzd29yZA==
98+
root: ZXhpc3Rpbmdyb290
99+
set:
100+
users:
101+
testuser:
102+
maxUserConnections: 1000
103+
passwordRotation: 1
104+
documentSelector:
105+
path: metadata.name
106+
value: mariadb-test-credentials
107+
asserts:
108+
- equal:
109+
path: stringData.testuser
110+
value: existingpassword
111+
- equal:
112+
path: stringData.root
113+
value: existingroot
114+
- equal:
115+
path: metadata.annotations["mariadb.cozystack.io/password-rotation"]
116+
value: "1"

‎packages/apps/mariadb/tests/credentials_test.yaml‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ suite: MariaDB credentials generation and rotation
55
# data-driven trigger: the `mariadb.cozystack.io/password-rotation` annotation on
66
# the credentials Secret tracks .Values.passwordRotation.
77
#
8-
# lookup() returns nothing under helm-unittest (no cluster), so every render here
9-
# generates fresh passwords and writes the marker equal to the requested counter.
10-
# The idempotent-preserve and counter-bump-regenerate paths both depend on a live
11-
# lookup of an existing Secret, which helm-unittest cannot mock, so they are NOT
12-
# exercised here and are not yet covered by an e2e assertion either — verify them
13-
# manually against a cluster until such coverage exists.
8+
# This suite renders without a kubernetesProvider, so lookup() returns nothing and
9+
# every render generates fresh passwords and writes the marker equal to the requested
10+
# counter. The lookup-backed paths — preserve-on-unchanged-counter, regenerate-on-bump,
11+
# and root-left-untouched — are covered in credentials_lookup_test.yaml, which mocks the
12+
# existing Secret via kubernetesProvider.
1413

1514
release:
1615
name: mariadb-test
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
suite: postgres credentials lookup-backed rotation paths
2+
release:
3+
name: pg-test
4+
namespace: tenant-test
5+
templates:
6+
- templates/init-script.yaml
7+
tests:
8+
- it: preserves an existing password when the counter is unchanged
9+
kubernetesProvider:
10+
scheme:
11+
"v1/Secret":
12+
gvr:
13+
version: v1
14+
resource: secrets
15+
namespaced: true
16+
objects:
17+
- apiVersion: v1
18+
kind: Secret
19+
metadata:
20+
name: pg-test-credentials
21+
namespace: tenant-test
22+
annotations:
23+
postgres.cozystack.io/password-rotation: "0"
24+
data:
25+
testuser: ZXhpc3RpbmdwYXNzd29yZA==
26+
set:
27+
users:
28+
testuser: {}
29+
passwordRotation: 0
30+
documentSelector:
31+
path: metadata.name
32+
value: pg-test-credentials
33+
asserts:
34+
- equal:
35+
path: stringData.testuser
36+
value: existingpassword
37+
- it: regenerates the password when the counter is bumped
38+
kubernetesProvider:
39+
scheme:
40+
"v1/Secret":
41+
gvr:
42+
version: v1
43+
resource: secrets
44+
namespaced: true
45+
objects:
46+
- apiVersion: v1
47+
kind: Secret
48+
metadata:
49+
name: pg-test-credentials
50+
namespace: tenant-test
51+
annotations:
52+
postgres.cozystack.io/password-rotation: "0"
53+
data:
54+
testuser: ZXhpc3RpbmdwYXNzd29yZA==
55+
set:
56+
users:
57+
testuser: {}
58+
passwordRotation: 1
59+
documentSelector:
60+
path: metadata.name
61+
value: pg-test-credentials
62+
asserts:
63+
- notEqual:
64+
path: stringData.testuser
65+
value: existingpassword
66+
- matchRegex:
67+
path: stringData.testuser
68+
pattern: ^[a-zA-Z0-9]{16}$
69+
- equal:
70+
path: metadata.annotations["postgres.cozystack.io/password-rotation"]
71+
value: "1"
72+
- it: legacy secret without marker adopts baseline even when the counter is bumped
73+
kubernetesProvider:
74+
scheme:
75+
"v1/Secret":
76+
gvr:
77+
version: v1
78+
resource: secrets
79+
namespaced: true
80+
objects:
81+
- apiVersion: v1
82+
kind: Secret
83+
metadata:
84+
name: pg-test-credentials
85+
namespace: tenant-test
86+
data:
87+
testuser: ZXhpc3RpbmdwYXNzd29yZA==
88+
set:
89+
users:
90+
testuser: {}
91+
passwordRotation: 1
92+
documentSelector:
93+
path: metadata.name
94+
value: pg-test-credentials
95+
asserts:
96+
- equal:
97+
path: stringData.testuser
98+
value: existingpassword
99+
- equal:
100+
path: metadata.annotations["postgres.cozystack.io/password-rotation"]
101+
value: "1"

‎packages/apps/postgres/tests/credentials_test.yaml‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ suite: postgres credentials generation and rotation
55
# the `postgres.cozystack.io/password-rotation` annotation on the credentials Secret
66
# tracks .Values.passwordRotation.
77
#
8-
# lookup() returns nothing under helm-unittest (no cluster), so every render here
9-
# generates fresh passwords and writes the marker equal to the requested counter.
10-
# The idempotent-preserve and counter-bump-regenerate paths both depend on a live
11-
# lookup of an existing Secret, which helm-unittest cannot mock, so they are NOT
12-
# exercised here and are not yet covered by an e2e assertion either — verify them
13-
# manually against a cluster until such coverage exists.
8+
# This suite renders without a kubernetesProvider, so lookup() returns nothing and
9+
# every render generates fresh passwords and writes the marker equal to the requested
10+
# counter. The lookup-backed paths — preserve-on-unchanged-counter and
11+
# regenerate-on-bump — are covered in credentials_lookup_test.yaml, which mocks the
12+
# existing Secret via kubernetesProvider.
1413

1514
release:
1615
name: pg-test

0 commit comments

Comments
 (0)