pepr 0.38.0 → 0.38.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +13 -13
- package/dist/controller.js +1 -1
- package/package.json +5 -3
- package/src/lib/assets/pods.ts +6 -6
- package/src/lib/assets/yaml.ts +6 -6
- package/dist/cli/init/utils.test.d.ts +0 -2
- package/dist/cli/init/utils.test.d.ts.map +0 -1
- package/dist/cli/init/walkthrough.test.d.ts +0 -2
- package/dist/cli/init/walkthrough.test.d.ts.map +0 -1
- package/dist/lib/adjudicators.test.d.ts +0 -2
- package/dist/lib/adjudicators.test.d.ts.map +0 -1
- package/dist/lib/assets/helm.test.d.ts +0 -2
- package/dist/lib/assets/helm.test.d.ts.map +0 -1
- package/dist/lib/assets/pods.test.d.ts +0 -2
- package/dist/lib/assets/pods.test.d.ts.map +0 -1
- package/dist/lib/capability.test.d.ts +0 -2
- package/dist/lib/capability.test.d.ts.map +0 -1
- package/dist/lib/controller/store.test.d.ts +0 -2
- package/dist/lib/controller/store.test.d.ts.map +0 -1
- package/dist/lib/errors.test.d.ts +0 -2
- package/dist/lib/errors.test.d.ts.map +0 -1
- package/dist/lib/filter.test.d.ts +0 -3
- package/dist/lib/filter.test.d.ts.map +0 -1
- package/dist/lib/finalizer.test.d.ts +0 -2
- package/dist/lib/finalizer.test.d.ts.map +0 -1
- package/dist/lib/helpers.test.d.ts +0 -2
- package/dist/lib/helpers.test.d.ts.map +0 -1
- package/dist/lib/included-files.test.d.ts +0 -2
- package/dist/lib/included-files.test.d.ts.map +0 -1
- package/dist/lib/logger.test.d.ts +0 -2
- package/dist/lib/logger.test.d.ts.map +0 -1
- package/dist/lib/metrics.test.d.ts +0 -2
- package/dist/lib/metrics.test.d.ts.map +0 -1
- package/dist/lib/module.test.d.ts +0 -2
- package/dist/lib/module.test.d.ts.map +0 -1
- package/dist/lib/mutate-request.test.d.ts +0 -2
- package/dist/lib/mutate-request.test.d.ts.map +0 -1
- package/dist/lib/queue.test.d.ts +0 -2
- package/dist/lib/queue.test.d.ts.map +0 -1
- package/dist/lib/schedule.test.d.ts +0 -15
- package/dist/lib/schedule.test.d.ts.map +0 -1
- package/dist/lib/storage.test.d.ts +0 -2
- package/dist/lib/storage.test.d.ts.map +0 -1
- package/dist/lib/tls.test.d.ts +0 -2
- package/dist/lib/tls.test.d.ts.map +0 -1
- package/dist/lib/utils.test.d.ts +0 -2
- package/dist/lib/utils.test.d.ts.map +0 -1
- package/dist/lib/validate-request.test.d.ts +0 -2
- package/dist/lib/validate-request.test.d.ts.map +0 -1
- package/dist/lib/watch-processor.test.d.ts +0 -2
- package/dist/lib/watch-processor.test.d.ts.map +0 -1
- package/dist/sdk/sdk.test.d.ts +0 -2
- package/dist/sdk/sdk.test.d.ts.map +0 -1
- package/src/cli/init/utils.test.ts +0 -19
- package/src/cli/init/walkthrough.test.ts +0 -102
- package/src/lib/adjudicators.test.ts +0 -1236
- package/src/lib/assets/helm.test.ts +0 -64
- package/src/lib/assets/pods.test.ts +0 -553
- package/src/lib/capability.test.ts +0 -655
- package/src/lib/controller/store.test.ts +0 -131
- package/src/lib/errors.test.ts +0 -85
- package/src/lib/filter.test.ts +0 -691
- package/src/lib/finalizer.test.ts +0 -236
- package/src/lib/helpers.test.ts +0 -1486
- package/src/lib/included-files.test.ts +0 -22
- package/src/lib/logger.test.ts +0 -18
- package/src/lib/metrics.test.ts +0 -132
- package/src/lib/module.test.ts +0 -126
- package/src/lib/mutate-request.test.ts +0 -187
- package/src/lib/queue.test.ts +0 -152
- package/src/lib/schedule.test.ts +0 -217
- package/src/lib/storage.test.ts +0 -216
- package/src/lib/tls.test.ts +0 -18
- package/src/lib/utils.test.ts +0 -69
- package/src/lib/validate-request.test.ts +0 -121
- package/src/lib/watch-processor.test.ts +0 -417
- package/src/sdk/sdk.test.ts +0 -276
package/src/lib/filter.test.ts
DELETED
|
@@ -1,691 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
|
|
3
|
-
|
|
4
|
-
import { expect, test, describe } from "@jest/globals";
|
|
5
|
-
import { kind, modelToGroupVersionKind } from "kubernetes-fluent-client";
|
|
6
|
-
import * as fc from "fast-check";
|
|
7
|
-
import { CreatePod, DeletePod } from "../fixtures/loader";
|
|
8
|
-
import { shouldSkipRequest } from "./filter";
|
|
9
|
-
import { AdmissionRequest, Binding, Event } from "./types";
|
|
10
|
-
|
|
11
|
-
export const callback = () => undefined;
|
|
12
|
-
|
|
13
|
-
export const podKind = modelToGroupVersionKind(kind.Pod.name);
|
|
14
|
-
|
|
15
|
-
describe("Fuzzing shouldSkipRequest", () => {
|
|
16
|
-
test("should handle random inputs without crashing", () => {
|
|
17
|
-
fc.assert(
|
|
18
|
-
fc.property(
|
|
19
|
-
fc.record({
|
|
20
|
-
event: fc.constantFrom("CREATE", "UPDATE", "DELETE", "ANY"),
|
|
21
|
-
kind: fc.record({
|
|
22
|
-
group: fc.string(),
|
|
23
|
-
version: fc.string(),
|
|
24
|
-
kind: fc.string(),
|
|
25
|
-
}),
|
|
26
|
-
filters: fc.record({
|
|
27
|
-
name: fc.string(),
|
|
28
|
-
namespaces: fc.array(fc.string()),
|
|
29
|
-
labels: fc.dictionary(fc.string(), fc.string()),
|
|
30
|
-
annotations: fc.dictionary(fc.string(), fc.string()),
|
|
31
|
-
deletionTimestamp: fc.boolean(),
|
|
32
|
-
}),
|
|
33
|
-
}),
|
|
34
|
-
fc.record({
|
|
35
|
-
operation: fc.string(),
|
|
36
|
-
uid: fc.string(),
|
|
37
|
-
name: fc.string(),
|
|
38
|
-
namespace: fc.string(),
|
|
39
|
-
kind: fc.record({
|
|
40
|
-
group: fc.string(),
|
|
41
|
-
version: fc.string(),
|
|
42
|
-
kind: fc.string(),
|
|
43
|
-
}),
|
|
44
|
-
object: fc.record({
|
|
45
|
-
metadata: fc.record({
|
|
46
|
-
deletionTimestamp: fc.option(fc.date()),
|
|
47
|
-
}),
|
|
48
|
-
}),
|
|
49
|
-
}),
|
|
50
|
-
fc.array(fc.string()),
|
|
51
|
-
(binding, req, capabilityNamespaces) => {
|
|
52
|
-
expect(() =>
|
|
53
|
-
shouldSkipRequest(binding as Binding, req as AdmissionRequest, capabilityNamespaces),
|
|
54
|
-
).not.toThrow();
|
|
55
|
-
},
|
|
56
|
-
),
|
|
57
|
-
{ numRuns: 100 },
|
|
58
|
-
);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
describe("Property-Based Testing shouldSkipRequest", () => {
|
|
63
|
-
test("should only skip requests that do not match the binding criteria", () => {
|
|
64
|
-
fc.assert(
|
|
65
|
-
fc.property(
|
|
66
|
-
fc.record({
|
|
67
|
-
event: fc.constantFrom("CREATE", "UPDATE", "DELETE", "ANY"),
|
|
68
|
-
kind: fc.record({
|
|
69
|
-
group: fc.string(),
|
|
70
|
-
version: fc.string(),
|
|
71
|
-
kind: fc.string(),
|
|
72
|
-
}),
|
|
73
|
-
filters: fc.record({
|
|
74
|
-
name: fc.string(),
|
|
75
|
-
namespaces: fc.array(fc.string()),
|
|
76
|
-
labels: fc.dictionary(fc.string(), fc.string()),
|
|
77
|
-
annotations: fc.dictionary(fc.string(), fc.string()),
|
|
78
|
-
deletionTimestamp: fc.boolean(),
|
|
79
|
-
}),
|
|
80
|
-
}),
|
|
81
|
-
fc.record({
|
|
82
|
-
operation: fc.string(),
|
|
83
|
-
uid: fc.string(),
|
|
84
|
-
name: fc.string(),
|
|
85
|
-
namespace: fc.string(),
|
|
86
|
-
kind: fc.record({
|
|
87
|
-
group: fc.string(),
|
|
88
|
-
version: fc.string(),
|
|
89
|
-
kind: fc.string(),
|
|
90
|
-
}),
|
|
91
|
-
object: fc.record({
|
|
92
|
-
metadata: fc.record({
|
|
93
|
-
deletionTimestamp: fc.option(fc.date()),
|
|
94
|
-
}),
|
|
95
|
-
}),
|
|
96
|
-
}),
|
|
97
|
-
fc.array(fc.string()),
|
|
98
|
-
(binding, req, capabilityNamespaces) => {
|
|
99
|
-
const shouldSkip = shouldSkipRequest(binding as Binding, req as AdmissionRequest, capabilityNamespaces);
|
|
100
|
-
expect(typeof shouldSkip).toBe("string");
|
|
101
|
-
},
|
|
102
|
-
),
|
|
103
|
-
{ numRuns: 100 },
|
|
104
|
-
);
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
test("create: should reject when regex name does not match", () => {
|
|
109
|
-
const binding = {
|
|
110
|
-
model: kind.Pod,
|
|
111
|
-
event: Event.Any,
|
|
112
|
-
kind: podKind,
|
|
113
|
-
filters: {
|
|
114
|
-
name: "",
|
|
115
|
-
namespaces: [],
|
|
116
|
-
regexNamespaces: [],
|
|
117
|
-
regexName: "^default$",
|
|
118
|
-
labels: {},
|
|
119
|
-
annotations: {},
|
|
120
|
-
deletionTimestamp: false,
|
|
121
|
-
},
|
|
122
|
-
callback,
|
|
123
|
-
};
|
|
124
|
-
const pod = CreatePod();
|
|
125
|
-
expect(shouldSkipRequest(binding, pod, [])).toMatch(
|
|
126
|
-
/Ignoring Admission Callback: Binding defines name regex '.*' but Object carries '.*'./,
|
|
127
|
-
);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
test("create: should not reject when regex name does match", () => {
|
|
131
|
-
const binding = {
|
|
132
|
-
model: kind.Pod,
|
|
133
|
-
event: Event.Any,
|
|
134
|
-
kind: podKind,
|
|
135
|
-
filters: {
|
|
136
|
-
name: "",
|
|
137
|
-
namespaces: [],
|
|
138
|
-
regexNamespaces: [],
|
|
139
|
-
regexName: "^cool",
|
|
140
|
-
labels: {},
|
|
141
|
-
annotations: {},
|
|
142
|
-
deletionTimestamp: false,
|
|
143
|
-
},
|
|
144
|
-
callback,
|
|
145
|
-
};
|
|
146
|
-
const pod = CreatePod();
|
|
147
|
-
expect(shouldSkipRequest(binding, pod, [])).toBe("");
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
test("delete: should reject when regex name does not match", () => {
|
|
151
|
-
const binding = {
|
|
152
|
-
model: kind.Pod,
|
|
153
|
-
event: Event.Any,
|
|
154
|
-
kind: podKind,
|
|
155
|
-
filters: {
|
|
156
|
-
name: "",
|
|
157
|
-
namespaces: [],
|
|
158
|
-
regexNamespaces: [],
|
|
159
|
-
regexName: "^default$",
|
|
160
|
-
labels: {},
|
|
161
|
-
annotations: {},
|
|
162
|
-
deletionTimestamp: false,
|
|
163
|
-
},
|
|
164
|
-
callback,
|
|
165
|
-
};
|
|
166
|
-
const pod = DeletePod();
|
|
167
|
-
expect(shouldSkipRequest(binding, pod, [])).toMatch(
|
|
168
|
-
/Ignoring Admission Callback: Binding defines name regex '.*' but Object carries '.*'./,
|
|
169
|
-
);
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
test("delete: should not reject when regex name does match", () => {
|
|
173
|
-
const binding = {
|
|
174
|
-
model: kind.Pod,
|
|
175
|
-
event: Event.Any,
|
|
176
|
-
kind: podKind,
|
|
177
|
-
filters: {
|
|
178
|
-
name: "",
|
|
179
|
-
namespaces: [],
|
|
180
|
-
regexNamespaces: [],
|
|
181
|
-
regexName: "^cool",
|
|
182
|
-
labels: {},
|
|
183
|
-
annotations: {},
|
|
184
|
-
deletionTimestamp: false,
|
|
185
|
-
},
|
|
186
|
-
callback,
|
|
187
|
-
};
|
|
188
|
-
const pod = DeletePod();
|
|
189
|
-
expect(shouldSkipRequest(binding, pod, [])).toBe("");
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
test("create: should not reject when regex namespace does match", () => {
|
|
193
|
-
const binding = {
|
|
194
|
-
model: kind.Pod,
|
|
195
|
-
event: Event.Any,
|
|
196
|
-
kind: podKind,
|
|
197
|
-
filters: {
|
|
198
|
-
name: "",
|
|
199
|
-
namespaces: [],
|
|
200
|
-
regexNamespaces: ["^helm"],
|
|
201
|
-
regexName: "",
|
|
202
|
-
labels: {},
|
|
203
|
-
annotations: {},
|
|
204
|
-
deletionTimestamp: false,
|
|
205
|
-
},
|
|
206
|
-
callback,
|
|
207
|
-
};
|
|
208
|
-
const pod = CreatePod();
|
|
209
|
-
expect(shouldSkipRequest(binding, pod, [])).toBe("");
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
test("create: should reject when regex namespace does not match", () => {
|
|
213
|
-
const binding = {
|
|
214
|
-
model: kind.Pod,
|
|
215
|
-
event: Event.Any,
|
|
216
|
-
kind: podKind,
|
|
217
|
-
filters: {
|
|
218
|
-
name: "",
|
|
219
|
-
namespaces: [],
|
|
220
|
-
regexNamespaces: ["^argo"],
|
|
221
|
-
regexName: "",
|
|
222
|
-
labels: {},
|
|
223
|
-
annotations: {},
|
|
224
|
-
deletionTimestamp: false,
|
|
225
|
-
},
|
|
226
|
-
callback,
|
|
227
|
-
};
|
|
228
|
-
const pod = CreatePod();
|
|
229
|
-
expect(shouldSkipRequest(binding, pod, [])).toMatch(
|
|
230
|
-
/Ignoring Admission Callback: Binding defines namespace regexes '.*' but Object carries '.*'./,
|
|
231
|
-
);
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
test("delete: should reject when regex namespace does not match", () => {
|
|
235
|
-
const binding = {
|
|
236
|
-
model: kind.Pod,
|
|
237
|
-
event: Event.Any,
|
|
238
|
-
kind: podKind,
|
|
239
|
-
filters: {
|
|
240
|
-
name: "",
|
|
241
|
-
namespaces: [],
|
|
242
|
-
regexNamespaces: ["^argo"],
|
|
243
|
-
regexName: "",
|
|
244
|
-
labels: {},
|
|
245
|
-
annotations: {},
|
|
246
|
-
deletionTimestamp: false,
|
|
247
|
-
},
|
|
248
|
-
callback,
|
|
249
|
-
};
|
|
250
|
-
const pod = DeletePod();
|
|
251
|
-
expect(shouldSkipRequest(binding, pod, [])).toMatch(
|
|
252
|
-
/Ignoring Admission Callback: Binding defines namespace regexes '.*' but Object carries '.*'./,
|
|
253
|
-
);
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
test("delete: should not reject when regex namespace does match", () => {
|
|
257
|
-
const binding = {
|
|
258
|
-
model: kind.Pod,
|
|
259
|
-
event: Event.Any,
|
|
260
|
-
kind: podKind,
|
|
261
|
-
filters: {
|
|
262
|
-
name: "",
|
|
263
|
-
namespaces: [],
|
|
264
|
-
regexNamespaces: ["^helm"],
|
|
265
|
-
regexName: "",
|
|
266
|
-
labels: {},
|
|
267
|
-
annotations: {},
|
|
268
|
-
deletionTimestamp: false,
|
|
269
|
-
},
|
|
270
|
-
callback,
|
|
271
|
-
};
|
|
272
|
-
const pod = DeletePod();
|
|
273
|
-
expect(shouldSkipRequest(binding, pod, [])).toBe("");
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
test("delete: should reject when name does not match", () => {
|
|
277
|
-
const binding = {
|
|
278
|
-
model: kind.Pod,
|
|
279
|
-
event: Event.Any,
|
|
280
|
-
kind: podKind,
|
|
281
|
-
filters: {
|
|
282
|
-
name: "bleh",
|
|
283
|
-
namespaces: [],
|
|
284
|
-
regexNamespaces: [],
|
|
285
|
-
regexName: "^not-cool",
|
|
286
|
-
labels: {},
|
|
287
|
-
annotations: {},
|
|
288
|
-
deletionTimestamp: false,
|
|
289
|
-
},
|
|
290
|
-
callback,
|
|
291
|
-
};
|
|
292
|
-
const pod = DeletePod();
|
|
293
|
-
expect(shouldSkipRequest(binding, pod, [])).toMatch(
|
|
294
|
-
/Ignoring Admission Callback: Binding defines name '.*' but Object carries '.*'./,
|
|
295
|
-
);
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
test("should reject when kind does not match", () => {
|
|
299
|
-
const binding = {
|
|
300
|
-
model: kind.Pod,
|
|
301
|
-
event: Event.Any,
|
|
302
|
-
kind: {
|
|
303
|
-
group: "",
|
|
304
|
-
version: "v1",
|
|
305
|
-
kind: "Nope",
|
|
306
|
-
},
|
|
307
|
-
filters: {
|
|
308
|
-
name: "",
|
|
309
|
-
namespaces: [],
|
|
310
|
-
regexNamespaces: [],
|
|
311
|
-
regexName: "",
|
|
312
|
-
labels: {},
|
|
313
|
-
annotations: {},
|
|
314
|
-
deletionTimestamp: false,
|
|
315
|
-
},
|
|
316
|
-
callback,
|
|
317
|
-
};
|
|
318
|
-
const pod = CreatePod();
|
|
319
|
-
|
|
320
|
-
expect(shouldSkipRequest(binding, pod, [])).toMatch(
|
|
321
|
-
/Ignoring Admission Callback: Binding defines kind '.*' but Request declares '.*'./,
|
|
322
|
-
);
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
test("should reject when group does not match", () => {
|
|
326
|
-
const binding = {
|
|
327
|
-
model: kind.Pod,
|
|
328
|
-
event: Event.Any,
|
|
329
|
-
kind: {
|
|
330
|
-
group: "Nope",
|
|
331
|
-
version: "v1",
|
|
332
|
-
kind: "Pod",
|
|
333
|
-
},
|
|
334
|
-
filters: {
|
|
335
|
-
name: "",
|
|
336
|
-
namespaces: [],
|
|
337
|
-
labels: {},
|
|
338
|
-
annotations: {},
|
|
339
|
-
deletionTimestamp: false,
|
|
340
|
-
regexNamespaces: [],
|
|
341
|
-
regexName: "",
|
|
342
|
-
},
|
|
343
|
-
callback,
|
|
344
|
-
};
|
|
345
|
-
const pod = CreatePod();
|
|
346
|
-
|
|
347
|
-
expect(shouldSkipRequest(binding, pod, [])).toMatch(
|
|
348
|
-
/Ignoring Admission Callback: Binding defines group '.*' but Request declares '.*'./,
|
|
349
|
-
);
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
test("should reject when version does not match", () => {
|
|
353
|
-
const binding = {
|
|
354
|
-
model: kind.Pod,
|
|
355
|
-
event: Event.Any,
|
|
356
|
-
kind: {
|
|
357
|
-
group: "",
|
|
358
|
-
version: "Nope",
|
|
359
|
-
kind: "Pod",
|
|
360
|
-
},
|
|
361
|
-
filters: {
|
|
362
|
-
name: "",
|
|
363
|
-
namespaces: [],
|
|
364
|
-
labels: {},
|
|
365
|
-
annotations: {},
|
|
366
|
-
deletionTimestamp: false,
|
|
367
|
-
regexNamespaces: [],
|
|
368
|
-
regexName: "",
|
|
369
|
-
},
|
|
370
|
-
callback,
|
|
371
|
-
};
|
|
372
|
-
const pod = CreatePod();
|
|
373
|
-
|
|
374
|
-
expect(shouldSkipRequest(binding, pod, [])).toMatch(
|
|
375
|
-
/Ignoring Admission Callback: Binding defines version '.*' but Request declares '.*'./,
|
|
376
|
-
);
|
|
377
|
-
});
|
|
378
|
-
|
|
379
|
-
test("should allow when group, version, and kind match", () => {
|
|
380
|
-
const binding = {
|
|
381
|
-
model: kind.Pod,
|
|
382
|
-
event: Event.Any,
|
|
383
|
-
kind: podKind,
|
|
384
|
-
filters: {
|
|
385
|
-
name: "",
|
|
386
|
-
namespaces: [],
|
|
387
|
-
labels: {},
|
|
388
|
-
annotations: {},
|
|
389
|
-
deletionTimestamp: false,
|
|
390
|
-
regexNamespaces: [],
|
|
391
|
-
regexName: "",
|
|
392
|
-
},
|
|
393
|
-
callback,
|
|
394
|
-
};
|
|
395
|
-
const pod = CreatePod();
|
|
396
|
-
|
|
397
|
-
expect(shouldSkipRequest(binding, pod, [])).toBe("");
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
test("should allow when kind match and others are empty", () => {
|
|
401
|
-
const binding = {
|
|
402
|
-
model: kind.Pod,
|
|
403
|
-
event: Event.Any,
|
|
404
|
-
kind: {
|
|
405
|
-
group: "",
|
|
406
|
-
version: "",
|
|
407
|
-
kind: "Pod",
|
|
408
|
-
},
|
|
409
|
-
filters: {
|
|
410
|
-
name: "",
|
|
411
|
-
namespaces: [],
|
|
412
|
-
labels: {},
|
|
413
|
-
annotations: {},
|
|
414
|
-
deletionTimestamp: false,
|
|
415
|
-
regexNamespaces: [],
|
|
416
|
-
regexName: "",
|
|
417
|
-
},
|
|
418
|
-
callback,
|
|
419
|
-
};
|
|
420
|
-
const pod = CreatePod();
|
|
421
|
-
|
|
422
|
-
expect(shouldSkipRequest(binding, pod, [])).toBe("");
|
|
423
|
-
});
|
|
424
|
-
|
|
425
|
-
test("should reject when the capability namespace does not match", () => {
|
|
426
|
-
const binding = {
|
|
427
|
-
model: kind.Pod,
|
|
428
|
-
event: Event.Any,
|
|
429
|
-
kind: podKind,
|
|
430
|
-
filters: {
|
|
431
|
-
name: "",
|
|
432
|
-
namespaces: [],
|
|
433
|
-
labels: {},
|
|
434
|
-
annotations: {},
|
|
435
|
-
deletionTimestamp: false,
|
|
436
|
-
regexNamespaces: [],
|
|
437
|
-
regexName: "",
|
|
438
|
-
},
|
|
439
|
-
callback,
|
|
440
|
-
};
|
|
441
|
-
const pod = CreatePod();
|
|
442
|
-
|
|
443
|
-
expect(shouldSkipRequest(binding, pod, ["bleh", "bleh2"])).toMatch(
|
|
444
|
-
/Ignoring Admission Callback: Object carries namespace '.*' but namespaces allowed by Capability are '.*'./,
|
|
445
|
-
);
|
|
446
|
-
});
|
|
447
|
-
|
|
448
|
-
test("should reject when namespace does not match", () => {
|
|
449
|
-
const binding = {
|
|
450
|
-
model: kind.Pod,
|
|
451
|
-
event: Event.Any,
|
|
452
|
-
kind: podKind,
|
|
453
|
-
filters: {
|
|
454
|
-
name: "",
|
|
455
|
-
namespaces: ["bleh"],
|
|
456
|
-
labels: {},
|
|
457
|
-
annotations: {},
|
|
458
|
-
deletionTimestamp: false,
|
|
459
|
-
regexNamespaces: [],
|
|
460
|
-
regexName: "",
|
|
461
|
-
},
|
|
462
|
-
callback,
|
|
463
|
-
};
|
|
464
|
-
const pod = CreatePod();
|
|
465
|
-
|
|
466
|
-
expect(shouldSkipRequest(binding, pod, [])).toMatch(
|
|
467
|
-
/Ignoring Admission Callback: Binding defines namespaces '.*' but Object carries '.*'./,
|
|
468
|
-
);
|
|
469
|
-
});
|
|
470
|
-
|
|
471
|
-
test("should allow when namespace is match", () => {
|
|
472
|
-
const binding = {
|
|
473
|
-
model: kind.Pod,
|
|
474
|
-
event: Event.Any,
|
|
475
|
-
kind: podKind,
|
|
476
|
-
filters: {
|
|
477
|
-
name: "",
|
|
478
|
-
namespaces: ["helm-releasename", "unicorn", "things"],
|
|
479
|
-
labels: {},
|
|
480
|
-
annotations: {},
|
|
481
|
-
deletionTimestamp: false,
|
|
482
|
-
regexNamespaces: [],
|
|
483
|
-
regexName: "",
|
|
484
|
-
},
|
|
485
|
-
callback,
|
|
486
|
-
};
|
|
487
|
-
const pod = CreatePod();
|
|
488
|
-
|
|
489
|
-
expect(shouldSkipRequest(binding, pod, [])).toBe("");
|
|
490
|
-
});
|
|
491
|
-
|
|
492
|
-
test("should reject when label does not match", () => {
|
|
493
|
-
const binding = {
|
|
494
|
-
model: kind.Pod,
|
|
495
|
-
event: Event.Any,
|
|
496
|
-
kind: podKind,
|
|
497
|
-
filters: {
|
|
498
|
-
name: "",
|
|
499
|
-
namespaces: [],
|
|
500
|
-
labels: {
|
|
501
|
-
foo: "bar",
|
|
502
|
-
},
|
|
503
|
-
annotations: {},
|
|
504
|
-
deletionTimestamp: false,
|
|
505
|
-
regexNamespaces: [],
|
|
506
|
-
regexName: "",
|
|
507
|
-
},
|
|
508
|
-
callback,
|
|
509
|
-
};
|
|
510
|
-
const pod = CreatePod();
|
|
511
|
-
|
|
512
|
-
expect(shouldSkipRequest(binding, pod, [])).toMatch(
|
|
513
|
-
/Ignoring Admission Callback: Binding defines labels '.*' but Object carries '.*'./,
|
|
514
|
-
);
|
|
515
|
-
});
|
|
516
|
-
|
|
517
|
-
test("should allow when label is match", () => {
|
|
518
|
-
const binding = {
|
|
519
|
-
model: kind.Pod,
|
|
520
|
-
event: Event.Any,
|
|
521
|
-
kind: podKind,
|
|
522
|
-
filters: {
|
|
523
|
-
name: "",
|
|
524
|
-
deletionTimestamp: false,
|
|
525
|
-
namespaces: [],
|
|
526
|
-
regexNamespaces: [],
|
|
527
|
-
regexName: "",
|
|
528
|
-
labels: {
|
|
529
|
-
foo: "bar",
|
|
530
|
-
test: "test1",
|
|
531
|
-
},
|
|
532
|
-
annotations: {},
|
|
533
|
-
},
|
|
534
|
-
callback,
|
|
535
|
-
};
|
|
536
|
-
|
|
537
|
-
const pod = CreatePod();
|
|
538
|
-
pod.object.metadata = pod.object.metadata || {};
|
|
539
|
-
pod.object.metadata.labels = {
|
|
540
|
-
foo: "bar",
|
|
541
|
-
test: "test1",
|
|
542
|
-
test2: "test2",
|
|
543
|
-
};
|
|
544
|
-
|
|
545
|
-
expect(shouldSkipRequest(binding, pod, [])).toBe("");
|
|
546
|
-
});
|
|
547
|
-
|
|
548
|
-
test("should reject when annotation does not match", () => {
|
|
549
|
-
const binding = {
|
|
550
|
-
model: kind.Pod,
|
|
551
|
-
event: Event.Any,
|
|
552
|
-
kind: podKind,
|
|
553
|
-
filters: {
|
|
554
|
-
name: "",
|
|
555
|
-
namespaces: [],
|
|
556
|
-
labels: {},
|
|
557
|
-
annotations: {
|
|
558
|
-
foo: "bar",
|
|
559
|
-
},
|
|
560
|
-
deletionTimestamp: false,
|
|
561
|
-
regexNamespaces: [],
|
|
562
|
-
regexName: "",
|
|
563
|
-
},
|
|
564
|
-
callback,
|
|
565
|
-
};
|
|
566
|
-
const pod = CreatePod();
|
|
567
|
-
|
|
568
|
-
expect(shouldSkipRequest(binding, pod, [])).toMatch(
|
|
569
|
-
/Ignoring Admission Callback: Binding defines annotations '.*' but Object carries '.*'./,
|
|
570
|
-
);
|
|
571
|
-
});
|
|
572
|
-
|
|
573
|
-
test("should allow when annotation is match", () => {
|
|
574
|
-
const binding = {
|
|
575
|
-
model: kind.Pod,
|
|
576
|
-
event: Event.Any,
|
|
577
|
-
kind: podKind,
|
|
578
|
-
filters: {
|
|
579
|
-
name: "",
|
|
580
|
-
namespaces: [],
|
|
581
|
-
labels: {},
|
|
582
|
-
annotations: {
|
|
583
|
-
foo: "bar",
|
|
584
|
-
test: "test1",
|
|
585
|
-
},
|
|
586
|
-
deletionTimestamp: false,
|
|
587
|
-
regexNamespaces: [],
|
|
588
|
-
regexName: "",
|
|
589
|
-
},
|
|
590
|
-
callback,
|
|
591
|
-
};
|
|
592
|
-
|
|
593
|
-
const pod = CreatePod();
|
|
594
|
-
pod.object.metadata = pod.object.metadata || {};
|
|
595
|
-
pod.object.metadata.annotations = {
|
|
596
|
-
foo: "bar",
|
|
597
|
-
test: "test1",
|
|
598
|
-
test2: "test2",
|
|
599
|
-
};
|
|
600
|
-
|
|
601
|
-
expect(shouldSkipRequest(binding, pod, [])).toBe("");
|
|
602
|
-
});
|
|
603
|
-
|
|
604
|
-
test("should use `oldObject` when the operation is `DELETE`", () => {
|
|
605
|
-
const binding = {
|
|
606
|
-
model: kind.Pod,
|
|
607
|
-
event: Event.Delete,
|
|
608
|
-
kind: podKind,
|
|
609
|
-
filters: {
|
|
610
|
-
name: "",
|
|
611
|
-
namespaces: [],
|
|
612
|
-
regexNamespaces: [],
|
|
613
|
-
regexName: "",
|
|
614
|
-
deletionTimestamp: false,
|
|
615
|
-
labels: {
|
|
616
|
-
"test-op": "delete",
|
|
617
|
-
},
|
|
618
|
-
annotations: {},
|
|
619
|
-
},
|
|
620
|
-
callback,
|
|
621
|
-
};
|
|
622
|
-
|
|
623
|
-
const pod = DeletePod();
|
|
624
|
-
|
|
625
|
-
expect(shouldSkipRequest(binding, pod, [])).toBe("");
|
|
626
|
-
});
|
|
627
|
-
|
|
628
|
-
test("should allow when deletionTimestamp is present on pod", () => {
|
|
629
|
-
const binding = {
|
|
630
|
-
model: kind.Pod,
|
|
631
|
-
event: Event.Any,
|
|
632
|
-
kind: podKind,
|
|
633
|
-
filters: {
|
|
634
|
-
name: "",
|
|
635
|
-
namespaces: [],
|
|
636
|
-
labels: {},
|
|
637
|
-
regexNamespaces: [],
|
|
638
|
-
regexName: "",
|
|
639
|
-
annotations: {
|
|
640
|
-
foo: "bar",
|
|
641
|
-
test: "test1",
|
|
642
|
-
},
|
|
643
|
-
deletionTimestamp: true,
|
|
644
|
-
},
|
|
645
|
-
callback,
|
|
646
|
-
};
|
|
647
|
-
|
|
648
|
-
const pod = CreatePod();
|
|
649
|
-
pod.object.metadata = pod.object.metadata || {};
|
|
650
|
-
pod.object.metadata!.deletionTimestamp = new Date("2021-09-01T00:00:00Z");
|
|
651
|
-
pod.object.metadata.annotations = {
|
|
652
|
-
foo: "bar",
|
|
653
|
-
test: "test1",
|
|
654
|
-
test2: "test2",
|
|
655
|
-
};
|
|
656
|
-
|
|
657
|
-
expect(shouldSkipRequest(binding, pod, [])).toBe("");
|
|
658
|
-
});
|
|
659
|
-
|
|
660
|
-
test("should reject when deletionTimestamp is not present on pod", () => {
|
|
661
|
-
const binding = {
|
|
662
|
-
model: kind.Pod,
|
|
663
|
-
event: Event.Any,
|
|
664
|
-
kind: podKind,
|
|
665
|
-
filters: {
|
|
666
|
-
name: "",
|
|
667
|
-
namespaces: [],
|
|
668
|
-
labels: {},
|
|
669
|
-
regexNamespaces: [],
|
|
670
|
-
regexName: "",
|
|
671
|
-
annotations: {
|
|
672
|
-
foo: "bar",
|
|
673
|
-
test: "test1",
|
|
674
|
-
},
|
|
675
|
-
deletionTimestamp: true,
|
|
676
|
-
},
|
|
677
|
-
callback,
|
|
678
|
-
};
|
|
679
|
-
|
|
680
|
-
const pod = CreatePod();
|
|
681
|
-
pod.object.metadata = pod.object.metadata || {};
|
|
682
|
-
pod.object.metadata.annotations = {
|
|
683
|
-
foo: "bar",
|
|
684
|
-
test: "test1",
|
|
685
|
-
test2: "test2",
|
|
686
|
-
};
|
|
687
|
-
|
|
688
|
-
expect(shouldSkipRequest(binding, pod, [])).toMatch(
|
|
689
|
-
/Ignoring Admission Callback: Binding defines deletionTimestamp but Object does not carry it./,
|
|
690
|
-
);
|
|
691
|
-
});
|