Skip to content
This repository was archived by the owner on Oct 14, 2020. It is now read-only.

Commit 73ff85a

Browse files
committed
#33 Throw explicit error when unkown operator was specified
1 parent e476530 commit 73ff85a

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

hooks/declarative-subsequent-scans/kubernetes-label-selector.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,19 @@ test("should generate selectors with both expression and labelMatching", () => {
131131
"critical=true,environment notin (production),team in (search,payment),foobar,!barfoo"
132132
);
133133
});
134+
135+
test("should throw a exception when passed a unknown operator", () => {
136+
expect(() =>
137+
generateLabelSelectorString({
138+
matchExpression: [
139+
{
140+
key: "environment",
141+
operator: "FooBar",
142+
values: ["production"]
143+
}
144+
]
145+
})
146+
).toThrowErrorMatchingInlineSnapshot(
147+
`"Unknown LabelSelector Operator \\"FooBar\\". Supported are (In, NotIn, Exists, DoesNotExist). If this is an official label selector operator in kubernetes please open up a issue in the secureCodeBox Repo."`
148+
);
149+
});

hooks/declarative-subsequent-scans/kubernetes-label-selector.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ export function generateLabelSelectorString({
4343
if (operator === LabelSelectorRequirementOperator.DoesNotExist) {
4444
return `!${key}`;
4545
}
46+
47+
const supportedOperators = Object.values(
48+
LabelSelectorRequirementOperator
49+
).join(", ");
50+
51+
throw new Error(
52+
`Unknown LabelSelector Operator "${operator}". Supported are (${supportedOperators}). If this is an official label selector operator in kubernetes please open up a issue in the secureCodeBox Repo.`
53+
);
4654
}
4755
);
4856

0 commit comments

Comments
 (0)