mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-21 20:23:39 +09:00
Every test rendered with an empty lookup, so the branch that keeps a live password could be deleted with the suite green. Three fixtures through kubernetesProvider cover what a fresh render never reaches: a helm-owned users Secret is reused, a Secret the release does not own stays out of the manifest while its password still reaches the credentials, and the operator copy rebuilds a missing users Secret. Values with URI-reserved characters cover the userinfo encoding, and both Secrets are asserted Opaque again. Assisted-by: LLM Signed-off-by: Yan Bondarenko <202671653+yankawai@users.noreply.github.com>
355 lines
11 KiB
YAML
355 lines
11 KiB
YAML
suite: credentials tests
|
|
|
|
templates:
|
|
- templates/credentials.yaml
|
|
|
|
release:
|
|
name: test-mongodb
|
|
namespace: tenant-test
|
|
|
|
set:
|
|
_cluster:
|
|
cluster-domain: cozy.local
|
|
|
|
tests:
|
|
- it: renders the operator users Secret and the dashboard Secret
|
|
asserts:
|
|
- hasDocuments:
|
|
count: 2
|
|
- containsDocument:
|
|
apiVersion: v1
|
|
kind: Secret
|
|
name: test-mongodb-percona-server-mongodb-users
|
|
any: true
|
|
- containsDocument:
|
|
apiVersion: v1
|
|
kind: Secret
|
|
name: test-mongodb-credentials
|
|
any: true
|
|
|
|
- it: gives the dashboard a usable password on a first install
|
|
asserts:
|
|
- matchRegex:
|
|
path: stringData.password
|
|
pattern: ^[A-Za-z0-9]{24}$
|
|
documentSelector:
|
|
path: metadata.name
|
|
value: test-mongodb-credentials
|
|
|
|
- it: builds a complete replica-set uri on a first install
|
|
asserts:
|
|
- matchRegex:
|
|
path: stringData.uri
|
|
pattern: ^mongodb://databaseAdmin:[A-Za-z0-9]{24}@test-mongodb-rs0\.tenant-test\.svc\.cozy\.local:27017/admin\?replicaSet=rs0$
|
|
documentSelector:
|
|
path: metadata.name
|
|
value: test-mongodb-credentials
|
|
|
|
- it: sets username to databaseAdmin
|
|
asserts:
|
|
- equal:
|
|
path: stringData.username
|
|
value: databaseAdmin
|
|
documentSelector:
|
|
path: metadata.name
|
|
value: test-mongodb-credentials
|
|
|
|
- it: sets port to 27017
|
|
asserts:
|
|
- equal:
|
|
path: stringData.port
|
|
value: "27017"
|
|
documentSelector:
|
|
path: metadata.name
|
|
value: test-mongodb-credentials
|
|
|
|
- it: uses rs0 service for replica set mode
|
|
set:
|
|
sharding: false
|
|
asserts:
|
|
- equal:
|
|
path: stringData.host
|
|
value: test-mongodb-rs0.tenant-test.svc.cozy.local
|
|
documentSelector:
|
|
path: metadata.name
|
|
value: test-mongodb-credentials
|
|
|
|
- it: uses mongos service and a uri without replicaSet for sharded mode
|
|
set:
|
|
sharding: true
|
|
asserts:
|
|
- equal:
|
|
path: stringData.host
|
|
value: test-mongodb-mongos.tenant-test.svc.cozy.local
|
|
documentSelector:
|
|
path: metadata.name
|
|
value: test-mongodb-credentials
|
|
- matchRegex:
|
|
path: stringData.uri
|
|
pattern: ^mongodb://databaseAdmin:[A-Za-z0-9]{24}@test-mongodb-mongos\.tenant-test\.svc\.cozy\.local:27017/admin$
|
|
documentSelector:
|
|
path: metadata.name
|
|
value: test-mongodb-credentials
|
|
|
|
- it: uses custom cluster domain
|
|
set:
|
|
_cluster:
|
|
cluster-domain: custom.domain
|
|
sharding: false
|
|
asserts:
|
|
- equal:
|
|
path: stringData.host
|
|
value: test-mongodb-rs0.tenant-test.svc.custom.domain
|
|
documentSelector:
|
|
path: metadata.name
|
|
value: test-mongodb-credentials
|
|
|
|
- it: defaults to cozy.local when cluster domain not set
|
|
set:
|
|
_cluster: {}
|
|
sharding: false
|
|
asserts:
|
|
- equal:
|
|
path: stringData.host
|
|
value: test-mongodb-rs0.tenant-test.svc.cozy.local
|
|
documentSelector:
|
|
path: metadata.name
|
|
value: test-mongodb-credentials
|
|
|
|
- it: fills every system user the operator expects
|
|
asserts:
|
|
- equal:
|
|
path: stringData.MONGODB_BACKUP_USER
|
|
value: backup
|
|
documentSelector:
|
|
path: metadata.name
|
|
value: test-mongodb-percona-server-mongodb-users
|
|
- equal:
|
|
path: stringData.MONGODB_CLUSTER_ADMIN_USER
|
|
value: clusterAdmin
|
|
documentSelector:
|
|
path: metadata.name
|
|
value: test-mongodb-percona-server-mongodb-users
|
|
- equal:
|
|
path: stringData.MONGODB_CLUSTER_MONITOR_USER
|
|
value: clusterMonitor
|
|
documentSelector:
|
|
path: metadata.name
|
|
value: test-mongodb-percona-server-mongodb-users
|
|
- equal:
|
|
path: stringData.MONGODB_DATABASE_ADMIN_USER
|
|
value: databaseAdmin
|
|
documentSelector:
|
|
path: metadata.name
|
|
value: test-mongodb-percona-server-mongodb-users
|
|
- equal:
|
|
path: stringData.MONGODB_USER_ADMIN_USER
|
|
value: userAdmin
|
|
documentSelector:
|
|
path: metadata.name
|
|
value: test-mongodb-percona-server-mongodb-users
|
|
|
|
- it: generates a password for every system user
|
|
asserts:
|
|
- matchRegex:
|
|
path: stringData.MONGODB_BACKUP_PASSWORD
|
|
pattern: ^[A-Za-z0-9]{24}$
|
|
documentSelector:
|
|
path: metadata.name
|
|
value: test-mongodb-percona-server-mongodb-users
|
|
- matchRegex:
|
|
path: stringData.MONGODB_CLUSTER_ADMIN_PASSWORD
|
|
pattern: ^[A-Za-z0-9]{24}$
|
|
documentSelector:
|
|
path: metadata.name
|
|
value: test-mongodb-percona-server-mongodb-users
|
|
- matchRegex:
|
|
path: stringData.MONGODB_CLUSTER_MONITOR_PASSWORD
|
|
pattern: ^[A-Za-z0-9]{24}$
|
|
documentSelector:
|
|
path: metadata.name
|
|
value: test-mongodb-percona-server-mongodb-users
|
|
- matchRegex:
|
|
path: stringData.MONGODB_DATABASE_ADMIN_PASSWORD
|
|
pattern: ^[A-Za-z0-9]{24}$
|
|
documentSelector:
|
|
path: metadata.name
|
|
value: test-mongodb-percona-server-mongodb-users
|
|
- matchRegex:
|
|
path: stringData.MONGODB_USER_ADMIN_PASSWORD
|
|
pattern: ^[A-Za-z0-9]{24}$
|
|
documentSelector:
|
|
path: metadata.name
|
|
value: test-mongodb-percona-server-mongodb-users
|
|
|
|
- it: types both Secrets Opaque
|
|
asserts:
|
|
- equal:
|
|
path: type
|
|
value: Opaque
|
|
documentSelector:
|
|
path: metadata.name
|
|
value: test-mongodb-percona-server-mongodb-users
|
|
- equal:
|
|
path: type
|
|
value: Opaque
|
|
documentSelector:
|
|
path: metadata.name
|
|
value: test-mongodb-credentials
|
|
|
|
- it: reuses a helm-owned users Secret instead of rotating it
|
|
kubernetesProvider:
|
|
scheme:
|
|
"v1/Secret":
|
|
gvr:
|
|
version: v1
|
|
resource: secrets
|
|
namespaced: true
|
|
objects:
|
|
- apiVersion: v1
|
|
kind: Secret
|
|
metadata:
|
|
name: test-mongodb-percona-server-mongodb-users
|
|
namespace: tenant-test
|
|
annotations:
|
|
meta.helm.sh/release-name: test-mongodb
|
|
meta.helm.sh/release-namespace: tenant-test
|
|
data:
|
|
MONGODB_DATABASE_ADMIN_USER: ZGF0YWJhc2VBZG1pbg==
|
|
MONGODB_DATABASE_ADMIN_PASSWORD: cmV1c2VkLXB3LTE=
|
|
MONGODB_BACKUP_PASSWORD: YmFja3VwLXB3LTE=
|
|
asserts:
|
|
- hasDocuments:
|
|
count: 2
|
|
- equal:
|
|
path: stringData.password
|
|
value: reused-pw-1
|
|
documentSelector:
|
|
path: metadata.name
|
|
value: test-mongodb-credentials
|
|
- equal:
|
|
path: stringData.uri
|
|
value: mongodb://databaseAdmin:reused-pw-1@test-mongodb-rs0.tenant-test.svc.cozy.local:27017/admin?replicaSet=rs0
|
|
documentSelector:
|
|
path: metadata.name
|
|
value: test-mongodb-credentials
|
|
- equal:
|
|
path: stringData.MONGODB_DATABASE_ADMIN_PASSWORD
|
|
value: reused-pw-1
|
|
documentSelector:
|
|
path: metadata.name
|
|
value: test-mongodb-percona-server-mongodb-users
|
|
- equal:
|
|
path: stringData.MONGODB_BACKUP_PASSWORD
|
|
value: backup-pw-1
|
|
documentSelector:
|
|
path: metadata.name
|
|
value: test-mongodb-percona-server-mongodb-users
|
|
- matchRegex:
|
|
path: stringData.MONGODB_USER_ADMIN_PASSWORD
|
|
pattern: ^[A-Za-z0-9]{24}$
|
|
documentSelector:
|
|
path: metadata.name
|
|
value: test-mongodb-percona-server-mongodb-users
|
|
|
|
- it: leaves a users Secret it does not own out of the manifest and still fills the credentials
|
|
kubernetesProvider:
|
|
scheme:
|
|
"v1/Secret":
|
|
gvr:
|
|
version: v1
|
|
resource: secrets
|
|
namespaced: true
|
|
objects:
|
|
- apiVersion: v1
|
|
kind: Secret
|
|
metadata:
|
|
name: test-mongodb-percona-server-mongodb-users
|
|
namespace: tenant-test
|
|
data:
|
|
MONGODB_BACKUP_USER: YmFja3Vw
|
|
MONGODB_BACKUP_PASSWORD: YmFja3VwLXB3LTE=
|
|
MONGODB_CLUSTER_ADMIN_USER: Y2x1c3RlckFkbWlu
|
|
MONGODB_CLUSTER_ADMIN_PASSWORD: cmV1c2VkLXB3LTE=
|
|
MONGODB_CLUSTER_MONITOR_USER: Y2x1c3Rlck1vbml0b3I=
|
|
MONGODB_CLUSTER_MONITOR_PASSWORD: cmV1c2VkLXB3LTE=
|
|
MONGODB_DATABASE_ADMIN_USER: ZGJhZG1pbg==
|
|
MONGODB_DATABASE_ADMIN_PASSWORD: cEBzczp3L3Jk
|
|
MONGODB_USER_ADMIN_USER: dXNlckFkbWlu
|
|
MONGODB_USER_ADMIN_PASSWORD: cmV1c2VkLXB3LTE=
|
|
asserts:
|
|
- hasDocuments:
|
|
count: 1
|
|
- equal:
|
|
path: metadata.name
|
|
value: test-mongodb-credentials
|
|
- equal:
|
|
path: stringData.username
|
|
value: dbadmin
|
|
- equal:
|
|
path: stringData.password
|
|
value: p@ss:w/rd
|
|
- equal:
|
|
path: stringData.uri
|
|
value: mongodb://dbadmin:p%40ss%3Aw%2Frd@test-mongodb-rs0.tenant-test.svc.cozy.local:27017/admin?replicaSet=rs0
|
|
|
|
- it: rebuilds the users Secret from the operator copy when the per-release Secret is gone
|
|
kubernetesProvider:
|
|
scheme:
|
|
"v1/Secret":
|
|
gvr:
|
|
version: v1
|
|
resource: secrets
|
|
namespaced: true
|
|
objects:
|
|
- apiVersion: v1
|
|
kind: Secret
|
|
metadata:
|
|
name: internal-test-mongodb-users
|
|
namespace: tenant-test
|
|
data:
|
|
MONGODB_DATABASE_ADMIN_USER: ZGF0YWJhc2VBZG1pbg==
|
|
MONGODB_DATABASE_ADMIN_PASSWORD: cmV1c2VkLXB3LTE=
|
|
asserts:
|
|
- hasDocuments:
|
|
count: 2
|
|
- equal:
|
|
path: stringData.MONGODB_DATABASE_ADMIN_PASSWORD
|
|
value: reused-pw-1
|
|
documentSelector:
|
|
path: metadata.name
|
|
value: test-mongodb-percona-server-mongodb-users
|
|
- equal:
|
|
path: stringData.password
|
|
value: reused-pw-1
|
|
documentSelector:
|
|
path: metadata.name
|
|
value: test-mongodb-credentials
|
|
- matchRegex:
|
|
path: stringData.MONGODB_BACKUP_PASSWORD
|
|
pattern: ^[A-Za-z0-9]{24}$
|
|
documentSelector:
|
|
path: metadata.name
|
|
value: test-mongodb-percona-server-mongodb-users
|
|
|
|
- it: refuses to invent a password for a users Secret it does not own
|
|
kubernetesProvider:
|
|
scheme:
|
|
"v1/Secret":
|
|
gvr:
|
|
version: v1
|
|
resource: secrets
|
|
namespaced: true
|
|
objects:
|
|
- apiVersion: v1
|
|
kind: Secret
|
|
metadata:
|
|
name: test-mongodb-percona-server-mongodb-users
|
|
namespace: tenant-test
|
|
data:
|
|
MONGODB_DATABASE_ADMIN_USER: ZGF0YWJhc2VBZG1pbg==
|
|
MONGODB_DATABASE_ADMIN_PASSWORD: cmV1c2VkLXB3LTE=
|
|
asserts:
|
|
- failedTemplate:
|
|
errorPattern: "Secret test-mongodb-percona-server-mongodb-users is not managed by release test-mongodb and neither it nor internal-test-mongodb-users carries MONGODB_BACKUP_PASSWORD"
|