Skip to content

Commit 23fa0b5

Browse files
committed
feat: stripe cloudprofiles and namespacedloudprofiles of providerconfig, except for openstack and metall as provider
1 parent a3a62e7 commit 23fa0b5

15 files changed

Lines changed: 688 additions & 32 deletions

backend/__fixtures__/index.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const resourcequotas = require('./resourcequotas')
2525
const projects = require('./projects')
2626
const serviceaccounts = require('./serviceaccounts')
2727
const cloudprofiles = require('./cloudprofiles')
28-
const namespacedCloudProfiles = require('./namespacedCloudProfiles')
28+
const namespacedcloudprofiles = require('./namespacedcloudpofiles.cjs')
2929
const nodes = require('./nodes')
3030
const terminals = require('./terminals')
3131
const github = require('./github')
@@ -59,7 +59,7 @@ const fixtures = {
5959
projects,
6060
serviceaccounts,
6161
cloudprofiles,
62-
namespacedCloudProfiles,
62+
namespacedcloudprofiles,
6363
quotas,
6464
controllerregistrations,
6565
resourcequotas,

backend/__fixtures__/namespacedCloudProfiles.cjs renamed to backend/__fixtures__/namespacedcloudpofiles.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ const namespacedCloudProfileList = [
124124
}),
125125
]
126126

127-
const namespacedCloudProfiles = {
127+
const namespacedcloudpofiles = {
128128
create (...args) {
129129
return getNamespacedCloudProfile(...args)
130130
},
@@ -141,4 +141,4 @@ const namespacedCloudProfiles = {
141141
reset () {},
142142
}
143143

144-
module.exports = namespacedCloudProfiles
144+
module.exports = namespacedcloudpofiles
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`api all namespaced cloudprofiles should verify authorization checks with snapshot 1`] = `
4+
[
5+
[
6+
{
7+
":authority": "kubernetes:6443",
8+
":method": "post",
9+
":path": "/apis/authorization.k8s.io/v1/selfsubjectaccessreviews",
10+
":scheme": "https",
11+
"authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImpvaG4uZG9lQGV4YW1wbGUub3JnIiwiaWF0IjoxNTc3ODM2ODAwLCJhdWQiOlsiZ2FyZGVuZXIiXSwiZXhwIjozMTU1NzE2ODAwLCJqdGkiOiJqdGkifQ.LkQ9PEN893UNTsZZn2Ux_CAYNOoQ2ISboWuHiAc5HHU",
12+
},
13+
{
14+
"apiVersion": "authorization.k8s.io/v1",
15+
"kind": "SelfSubjectAccessReview",
16+
"spec": {
17+
"nonResourceAttributes": undefined,
18+
"resourceAttributes": {
19+
"group": "core.gardener.cloud",
20+
"namespace": "garden-local",
21+
"resource": "namespacedcloudprofiles",
22+
"verb": "list",
23+
},
24+
},
25+
},
26+
],
27+
[
28+
{
29+
":authority": "kubernetes:6443",
30+
":method": "post",
31+
":path": "/apis/authorization.k8s.io/v1/selfsubjectaccessreviews",
32+
":scheme": "https",
33+
"authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImpvaG4uZG9lQGV4YW1wbGUub3JnIiwiaWF0IjoxNTc3ODM2ODAwLCJhdWQiOlsiZ2FyZGVuZXIiXSwiZXhwIjozMTU1NzE2ODAwLCJqdGkiOiJqdGkifQ.LkQ9PEN893UNTsZZn2Ux_CAYNOoQ2ISboWuHiAc5HHU",
34+
},
35+
{
36+
"apiVersion": "authorization.k8s.io/v1",
37+
"kind": "SelfSubjectAccessReview",
38+
"spec": {
39+
"nonResourceAttributes": undefined,
40+
"resourceAttributes": {
41+
"group": "core.gardener.cloud",
42+
"namespace": "garden-dev",
43+
"resource": "namespacedcloudprofiles",
44+
"verb": "list",
45+
},
46+
},
47+
},
48+
],
49+
]
50+
`;

backend/__tests__/acceptance/__snapshots__/api.namespacedCloudprofiles.spec.cjs.snap

Lines changed: 177 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,182 @@ exports[`api namespaced cloudprofiles should return all namespaced cloudprofiles
2828
`;
2929

3030
exports[`api namespaced cloudprofiles should return all namespaced cloudprofiles for a namespace 2`] = `
31-
{
32-
"code": 500,
33-
"details": {
34-
"name": "TypeError",
35-
"stack": "TypeError: Cannot read properties of undefined (reading 'list')
36-
at [object Object]
37-
at [object Object]
38-
at [object Object]
39-
at [object Object]",
31+
[
32+
{
33+
"metadata": {
34+
"name": "custom-cloudprofile-1",
35+
"namespace": "garden-local",
36+
"uid": 1001,
37+
},
38+
"spec": {
39+
"kubernetes": {
40+
"versions": [
41+
{
42+
"expirationDate": "2025-02-28T23:59:59Z",
43+
"version": "1.31.1",
44+
},
45+
],
46+
},
47+
"machineTypes": [
48+
{
49+
"cpu": "4",
50+
"gpu": "0",
51+
"memory": "16Gi",
52+
"name": "local-large",
53+
"usable": true,
54+
},
55+
],
56+
"parent": {
57+
"kind": "CloudProfile",
58+
"name": "local",
59+
},
60+
},
61+
"status": {
62+
"cloudProfileSpec": {
63+
"kubernetes": {
64+
"versions": [
65+
{
66+
"expirationDate": "2025-02-28T23:59:59Z",
67+
"version": "1.31.1",
68+
},
69+
{
70+
"version": "1.30.8",
71+
},
72+
{
73+
"version": "1.29.10",
74+
},
75+
],
76+
},
77+
"machineImages": [
78+
{
79+
"name": "gardenlinux",
80+
"versions": [
81+
{
82+
"version": "15.4.20220818",
83+
},
84+
],
85+
},
86+
],
87+
"machineTypes": [
88+
{
89+
"cpu": "4",
90+
"gpu": "0",
91+
"memory": "16Gi",
92+
"name": "local-large",
93+
"usable": true,
94+
},
95+
{
96+
"cpu": "2",
97+
"gpu": "0",
98+
"memory": "8Gi",
99+
"name": "local-medium",
100+
"usable": true,
101+
},
102+
],
103+
"regions": [
104+
{
105+
"name": "europe-central-1",
106+
"zones": [
107+
{
108+
"name": "europe-central-1a",
109+
},
110+
],
111+
},
112+
],
113+
"seedSelector": {},
114+
"type": "local",
115+
},
116+
},
117+
},
118+
{
119+
"metadata": {
120+
"name": "custom-cloudprofile-2",
121+
"namespace": "garden-local",
122+
"uid": 1002,
123+
},
124+
"spec": {
125+
"kubernetes": {
126+
"versions": [
127+
{
128+
"expirationDate": "2025-02-28T23:59:59Z",
129+
"version": "1.31.1",
130+
},
131+
],
132+
},
133+
"machineTypes": [
134+
{
135+
"cpu": "4",
136+
"gpu": "0",
137+
"memory": "16Gi",
138+
"name": "infra1-large",
139+
"usable": true,
140+
},
141+
],
142+
"parent": {
143+
"kind": "CloudProfile",
144+
"name": "infra1-profileName",
145+
},
146+
},
147+
"status": {
148+
"cloudProfileSpec": {
149+
"kubernetes": {
150+
"versions": [
151+
{
152+
"expirationDate": "2025-02-28T23:59:59Z",
153+
"version": "1.31.1",
154+
},
155+
{
156+
"version": "1.30.8",
157+
},
158+
{
159+
"version": "1.29.10",
160+
},
161+
],
162+
},
163+
"machineImages": [
164+
{
165+
"name": "gardenlinux",
166+
"versions": [
167+
{
168+
"version": "15.4.20220818",
169+
},
170+
],
171+
},
172+
],
173+
"machineTypes": [
174+
{
175+
"cpu": "4",
176+
"gpu": "0",
177+
"memory": "16Gi",
178+
"name": "infra1-large",
179+
"usable": true,
180+
},
181+
{
182+
"cpu": "2",
183+
"gpu": "0",
184+
"memory": "8Gi",
185+
"name": "infra1-medium",
186+
"usable": true,
187+
},
188+
],
189+
"regions": [
190+
{
191+
"name": "europe-central-1",
192+
"zones": [
193+
{
194+
"name": "europe-central-1a",
195+
},
196+
],
197+
},
198+
],
199+
"seedSelector": {
200+
"matchLabels": {
201+
"env": "dev",
202+
},
203+
},
204+
"type": "infra1",
205+
},
206+
},
40207
},
41-
"message": "Cannot read properties of undefined (reading 'list')",
42-
"reason": "Internal Server Error",
43-
"status": "Failure",
44-
}
208+
]
45209
`;
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//
2+
// SPDX-FileCopyrightText: 2026 SAP SE or an SAP affiliate company and Gardener contributors
3+
//
4+
// SPDX-License-Identifier: Apache-2.0
5+
//
6+
'use strict'
7+
const { mockRequest } = require('@gardener-dashboard/request')
8+
describe('api', function () {
9+
let agent
10+
beforeAll(() => {
11+
agent = createAgent()
12+
})
13+
afterAll(() => {
14+
return agent.close()
15+
})
16+
beforeEach(() => {
17+
mockRequest.mockReset()
18+
})
19+
describe('all namespaced cloudprofiles', function () {
20+
const user = fixtures.user.create({ id: 'john.doe@example.org' })
21+
it('should return all namespaced cloudprofiles from authorized namespaces', async function () {
22+
mockRequest
23+
.mockImplementationOnce(fixtures.auth.mocks.reviewSelfSubjectAccess({ allowed: true }))
24+
.mockImplementationOnce(fixtures.auth.mocks.reviewSelfSubjectAccess({ allowed: false }))
25+
const res = await agent
26+
.get('/api/namespacedcloudprofiles')
27+
.set('cookie', await user.cookie)
28+
.expect('content-type', /json/)
29+
.expect(200)
30+
expect(mockRequest).toHaveBeenCalledTimes(2)
31+
expect(res.body).toBeInstanceOf(Array)
32+
expect(res.body.length).toBe(2)
33+
expect(res.body.every(profile => profile.metadata.namespace === 'garden-local')).toBe(true)
34+
})
35+
it('should return all cloudprofiles when authorized for all namespaces', async function () {
36+
mockRequest
37+
.mockImplementationOnce(fixtures.auth.mocks.reviewSelfSubjectAccess({ allowed: true }))
38+
.mockImplementationOnce(fixtures.auth.mocks.reviewSelfSubjectAccess({ allowed: true }))
39+
const res = await agent
40+
.get('/api/namespacedcloudprofiles')
41+
.set('cookie', await user.cookie)
42+
.expect('content-type', /json/)
43+
.expect(200)
44+
expect(mockRequest).toHaveBeenCalledTimes(2)
45+
expect(res.body).toBeInstanceOf(Array)
46+
expect(res.body.length).toBe(3)
47+
})
48+
it('should return empty array when not authorized for any namespace', async function () {
49+
mockRequest
50+
.mockImplementationOnce(fixtures.auth.mocks.reviewSelfSubjectAccess({ allowed: false }))
51+
.mockImplementationOnce(fixtures.auth.mocks.reviewSelfSubjectAccess({ allowed: false }))
52+
const res = await agent
53+
.get('/api/namespacedcloudprofiles')
54+
.set('cookie', await user.cookie)
55+
.expect('content-type', /json/)
56+
.expect(200)
57+
expect(mockRequest).toHaveBeenCalledTimes(2)
58+
expect(res.body).toBeInstanceOf(Array)
59+
expect(res.body.length).toBe(0)
60+
})
61+
it('should verify authorization checks with snapshot', async function () {
62+
mockRequest
63+
.mockImplementationOnce(fixtures.auth.mocks.reviewSelfSubjectAccess({ allowed: true }))
64+
.mockImplementationOnce(fixtures.auth.mocks.reviewSelfSubjectAccess({ allowed: true }))
65+
await agent
66+
.get('/api/namespacedcloudprofiles')
67+
.set('cookie', await user.cookie)
68+
.expect(200)
69+
expect(mockRequest).toHaveBeenCalledTimes(2)
70+
expect(mockRequest.mock.calls).toMatchSnapshot()
71+
})
72+
})
73+
})

0 commit comments

Comments
 (0)