Files
library-charts/library/common-test/tests/rbac/data_test.yaml
Stavros Kois adb11f62d1 fix(rbac): adds resourceNames (#662)
**Description**
<!--
Please include a summary of the change and which issue is fixed. Please
also include relevant motivation and context. List any dependencies that
are required for this change.
-->
⚒️ Fixes  # <!--(issue)-->

**⚙️ Type of change**

- [ ] ⚙️ Feature/App addition
- [x] 🪛 Bugfix
- [ ] ⚠️ Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] 🔃 Refactor of current code

**🧪 How Has This Been Tested?**
<!--
Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. Please also list any relevant details
for your test configuration
-->

**📃 Notes:**
<!-- Please enter any other relevant information here -->

**✔️ Checklist:**

- [x] ⚖️ My code follows the style guidelines of this project
- [x] 👀 I have performed a self-review of my own code
- [ ] #️⃣ I have commented my code, particularly in hard-to-understand
areas
- [ ] 📄 I have made corresponding changes to the documentation
- [x] ⚠️ My changes generate no new warnings
- [x] 🧪 I have added tests to this description that prove my fix is
effective or that my feature works
- [x] ⬆️ I increased versions for any altered app according to semantic
versioning

** App addition**

If this PR is an app addition please make sure you have done the
following.

- [ ] 🪞 I have opened a PR on
[truecharts/containers](https://github.com/truecharts/containers) adding
the container to TrueCharts mirror repo.
- [ ] 🖼️ I have added an icon in the Chart's root directory called
`icon.png`

---

_Please don't blindly check all the boxes. Read them and only check
those that apply.
Those checkboxes are there for the reviewer to see what is this all
about and
the status of this PR with a quick glance._
2023-12-26 15:04:24 +01:00

258 lines
6.9 KiB
YAML

suite: rbac data test
templates:
- common.yaml
release:
name: test-release-name
namespace: test-release-namespace
tests:
- it: should pass with rules and subjects added with tpl and primary rbac/sa
set:
some_verb: list
some_group: apps
some_resource: deployments
some_kind: some-kind
some_name: some-name
some_api_group: rbac.authorization.k8s.io
serviceAccount:
my-sa:
enabled: true
primary: true
my-other-sa:
enabled: true
primary: false
rbac:
my-rbac:
enabled: true
primary: true
rules:
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- apiGroups:
- "{{ .Values.some_group }}"
resources:
- "{{ .Values.some_resource }}"
resourceNames:
- "{{ .Values.some_name }}"
verbs:
- "{{ .Values.some_verb }}"
subjects:
- kind: a-kind
name: a-name
apiGroup: rbac.authorization.k8s.io
- kind: "{{ .Values.some_kind }}"
name: "{{ .Values.some_name }}"
apiGroup: "{{ .Values.some_api_group }}"
asserts:
- documentIndex: &roleDoc 2
isKind:
of: Role
- documentIndex: *roleDoc
equal:
path: metadata.name
value: test-release-name-common-test
- documentIndex: *roleDoc
equal:
path: rules
value:
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- apiGroups:
- apps
resources:
- deployments
resourceNames:
- some-name
verbs:
- list
- documentIndex: &roleBinding 3
isKind:
of: RoleBinding
- documentIndex: *roleBinding
equal:
path: metadata.name
value: test-release-name-common-test
- documentIndex: *roleBinding
equal:
path: subjects
value:
- kind: ServiceAccount
name: test-release-name-common-test
namespace: test-release-namespace
- kind: a-kind
name: a-name
apiGroup: rbac.authorization.k8s.io
- kind: some-kind
name: some-name
apiGroup: rbac.authorization.k8s.io
- it: should pass with rules and subjects added with tpl and allSA on clusterWide
set:
some_verb: list
some_group: apps
some_resource: deployments
some_kind: some-kind
some_name: some-name
some_api_group: rbac.authorization.k8s.io
serviceAccount:
my-sa:
enabled: true
primary: true
my-other-sa:
enabled: true
primary: false
rbac:
z-rbac:
enabled: true
primary: true
rules:
- apiGroups:
- ""
resources:
- pods
verbs:
- get
my-rbac2:
enabled: true
clusterWide: true
allServiceAccounts: true
rules:
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- apiGroups:
- "{{ .Values.some_group }}"
resources:
- "{{ .Values.some_resource }}"
verbs:
- "{{ .Values.some_verb }}"
subjects:
- kind: a-kind
name: a-name
apiGroup: rbac.authorization.k8s.io
- kind: "{{ .Values.some_kind }}"
name: "{{ .Values.some_name }}"
apiGroup: "{{ .Values.some_api_group }}"
asserts:
- documentIndex: &clusterRoleDoc 2
isKind:
of: ClusterRole
- documentIndex: *clusterRoleDoc
equal:
path: metadata.name
value: test-release-name-common-test-my-rbac2
- documentIndex: *clusterRoleDoc
equal:
path: rules
value:
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- apiGroups:
- apps
resources:
- deployments
verbs:
- list
- documentIndex: &clusterRoleBinding 3
isKind:
of: ClusterRoleBinding
- documentIndex: *clusterRoleBinding
equal:
path: metadata.name
value: test-release-name-common-test-my-rbac2
- documentIndex: *clusterRoleBinding
equal:
path: subjects
value:
- kind: ServiceAccount
name: test-release-name-common-test-my-other-sa
namespace: test-release-namespace
- kind: ServiceAccount
name: test-release-name-common-test
namespace: test-release-namespace
- apiGroup: rbac.authorization.k8s.io
kind: a-kind
name: a-name
- apiGroup: rbac.authorization.k8s.io
kind: some-kind
name: some-name
- it: should pass with serviceAccount selector
set:
serviceAccount:
my-sa:
enabled: true
primary: true
my-other-sa:
enabled: true
primary: false
rbac:
z-rbac:
enabled: true
primary: true
rules:
- apiGroups:
- ""
resources:
- pods
verbs:
- get
my-rbac3:
enabled: true
serviceAccounts:
- my-other-sa
rules:
- apiGroups:
- ""
resources:
- pods
verbs:
- get
asserts:
- documentIndex: &roleDoc 2
isKind:
of: Role
- documentIndex: *roleDoc
equal:
path: metadata.name
value: test-release-name-common-test-my-rbac3
- documentIndex: *roleDoc
equal:
path: rules
value:
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- documentIndex: &roleBinding 3
isKind:
of: RoleBinding
- documentIndex: *roleBinding
equal:
path: metadata.name
value: test-release-name-common-test-my-rbac3
- documentIndex: *roleBinding
equal:
path: subjects
value:
- kind: ServiceAccount
name: test-release-name-common-test-my-other-sa
namespace: test-release-namespace