Files
cozystack/packages/apps/opensearch/tests/security_test.yaml
T
Aleksei Sviridkin f3c28e91c4 test(opensearch): pin the trust anchor, the name guard and the upgrade
Most of what this chart decides about TLS is invisible in a rendered
manifest until a cluster disagrees with it. The upgrade case is the
sharpest: a release that already runs operator-managed HTTP TLS must
keep working when the chart takes the CA over, and nothing about the
rendered output says whether it will.

The negative assertions carry as much as the positive ones. The trust
anchor must stay out of the resource map, since a name grant there
would outlive the platform's verdict on it, and a null tls value must
leave the chart rendering rather than aborting the whole release. Both
are properties that fail silently and only a test states them.

The bats guard covers what helm-unittest cannot see: which Secrets the
opensearch-rd definition exposes, so a key-bearing one cannot be added
to that surface without the guard going red.

Assisted-by: LLM
Signed-off-by: Aleksei Sviridkin <f@lex.la>
2026-09-11 01:23:22 +03:00

233 lines
5.8 KiB
YAML

suite: security secrets tests
templates:
- templates/security.yaml
tests:
###################
# Basic rendering #
###################
- it: renders three secrets (admin-credentials, security-config, credentials)
release:
name: test-os
namespace: tenant-test
set:
_cluster:
cluster-domain: cozy.local
asserts:
- hasDocuments:
count: 3
###########################
# Admin credentials #
###########################
- it: sets admin-credentials secret name
release:
name: test-os
namespace: tenant-test
set:
_cluster:
cluster-domain: cozy.local
asserts:
- equal:
path: metadata.name
value: test-os-admin-credentials
documentIndex: 0
- it: sets admin username
release:
name: test-os
namespace: tenant-test
set:
_cluster:
cluster-domain: cozy.local
asserts:
- equal:
path: stringData.username
value: admin
documentIndex: 0
- it: generates a 32-char alphanumeric password
release:
name: test-os
namespace: tenant-test
set:
_cluster:
cluster-domain: cozy.local
asserts:
- matchRegex:
path: stringData.password
pattern: "^[a-zA-Z0-9]{32}$"
documentIndex: 0
###########################
# Security config #
###########################
- it: sets security-config secret name
release:
name: test-os
namespace: tenant-test
set:
_cluster:
cluster-domain: cozy.local
asserts:
- equal:
path: metadata.name
value: test-os-security-config
documentIndex: 1
- it: includes config.yml with basic auth
release:
name: test-os
namespace: tenant-test
set:
_cluster:
cluster-domain: cozy.local
asserts:
- exists:
path: stringData["config.yml"]
documentIndex: 1
- it: includes internal_users.yml with bcrypt hash
release:
name: test-os
namespace: tenant-test
set:
_cluster:
cluster-domain: cozy.local
asserts:
- matchRegex:
path: stringData["internal_users.yml"]
pattern: "hash:.*\\$2a\\$"
documentIndex: 1
- it: includes roles_mapping.yml
release:
name: test-os
namespace: tenant-test
set:
_cluster:
cluster-domain: cozy.local
asserts:
- exists:
path: stringData["roles_mapping.yml"]
documentIndex: 1
###########################
# User-facing credentials #
###########################
- it: sets credentials secret name
release:
name: test-os
namespace: tenant-test
set:
_cluster:
cluster-domain: cozy.local
asserts:
- equal:
path: metadata.name
value: test-os-credentials
documentIndex: 2
- it: sets correct host and port
release:
name: test-os
namespace: tenant-test
set:
_cluster:
cluster-domain: cozy.local
asserts:
- equal:
path: stringData.host
value: test-os.tenant-test.svc.cozy.local
documentIndex: 2
- equal:
path: stringData.port
value: "9200"
documentIndex: 2
- it: sets https URI with credentials
release:
name: test-os
namespace: tenant-test
set:
_cluster:
cluster-domain: cozy.local
asserts:
- matchRegex:
path: stringData.uri
pattern: "^https://admin:[a-zA-Z0-9]{32}@test-os\\.tenant-test\\.svc\\.cozy\\.local:9200$"
documentIndex: 2
- it: does not include dashboards fields when dashboards disabled
release:
name: test-os
namespace: tenant-test
set:
_cluster:
cluster-domain: cozy.local
dashboards:
enabled: false
replicas: 1
resourcesPreset: "medium"
resources: {}
asserts:
- notExists:
path: stringData.dashboards-host
documentIndex: 2
- it: includes dashboards fields when dashboards enabled
release:
name: test-os
namespace: tenant-test
set:
_cluster:
cluster-domain: cozy.local
dashboards:
enabled: true
replicas: 1
resourcesPreset: "medium"
resources: {}
asserts:
- equal:
path: stringData.dashboards-host
value: test-os-dashboards.tenant-test.svc.cozy.local
documentIndex: 2
- equal:
path: stringData.dashboards-port
value: "5601"
documentIndex: 2
- matchRegex:
path: stringData.dashboards-uri
pattern: "^https://admin:[a-zA-Z0-9]{32}@test-os-dashboards\\.tenant-test\\.svc\\.cozy\\.local:5601$"
documentIndex: 2
###########################################
# Rendering without the platform's _cluster #
###########################################
# Every case above injects _cluster, which is what the platform does, so none of
# them exercises the read itself. `index` on an absent map is a hard render error
# rather than a miss returning nil, so it takes the whole template down and the
# `| default` that follows never runs. certmanager.yaml has the same read and its
# own suite for this in tls_test.yaml; this is the other half.
#
# No _cluster in `set` on purpose: injecting it is the one thing this case must
# not do. The host assertion is what makes it more than a render check — it says
# the fallback value actually reached the output.
- it: falls back to the default cluster domain when _cluster is absent
release:
name: test-os
namespace: tenant-test
asserts:
- hasDocuments:
count: 3
- equal:
path: stringData.host
value: test-os.tenant-test.svc.cozy.local
documentIndex: 2