Skip to content
This repository was archived by the owner on Jul 26, 2022. It is now read-only.

Commit a7d8c6c

Browse files
fix: fixes naming convention permission check for data items with path attribute only. (#830)
* Fixes naming convention permission check for data items with path attribute only. * Apply suggestions from code review Co-authored-by: Markus Maga <[email protected]> * Updates permission check to independently verify key and path. Co-authored-by: Markus Maga <[email protected]>
1 parent 8e15151 commit a7d8c6c

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

lib/poller.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -281,16 +281,15 @@ class Poller {
281281
// Testing data property
282282
if (namingConvention && externalData) {
283283
externalData.forEach((secretProperty, index) => {
284-
if (secretProperty.path) {
285-
if (!reNaming.test(secretProperty.path)) {
286-
allowed = false
287-
reason = `path ${secretProperty.path} does not match naming convention ${namingConvention}`
288-
return {
289-
allowed, reason
290-
}
284+
if ('path' in secretProperty && !reNaming.test(secretProperty.path)) {
285+
allowed = false
286+
reason = `path ${secretProperty.path} does not match naming convention ${namingConvention}`
287+
return {
288+
allowed, reason
291289
}
292290
}
293-
if (!reNaming.test(secretProperty.key)) {
291+
292+
if ('key' in secretProperty && !reNaming.test(secretProperty.key)) {
294293
allowed = false
295294
reason = `key name ${secretProperty.key} does not match naming convention ${namingConvention}`
296295
return {

lib/poller.test.js

+37
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,43 @@ describe('Poller', () => {
982982
},
983983
permitted: false
984984
},
985+
{
986+
// test regex on path
987+
ns: { metadata: { annotations: { [namingPermittedAnnotation]: 'dev/team-a/.*' } } },
988+
descriptor: {
989+
data: [
990+
{ path: 'dev/team-a/secret' }
991+
]
992+
},
993+
permitted: true
994+
},
995+
{
996+
ns: { metadata: { annotations: { [namingPermittedAnnotation]: 'dev/team-a/.*' } } },
997+
descriptor: {
998+
data: [
999+
{ key: 'dev/team-a/secret', name: 'somethingelse', path: '' }
1000+
]
1001+
},
1002+
permitted: false
1003+
},
1004+
{
1005+
ns: { metadata: { annotations: { [namingPermittedAnnotation]: 'dev/team-a/.*' } } },
1006+
descriptor: {
1007+
data: [
1008+
{ key: 'this-should-fail', name: 'somethingelse', path: 'dev/team-a/such-path' }
1009+
]
1010+
},
1011+
permitted: false
1012+
},
1013+
{
1014+
ns: { metadata: { annotations: { [namingPermittedAnnotation]: 'dev/team-a/.*' } } },
1015+
descriptor: {
1016+
data: [
1017+
{ key: 'dev/team-a/such-key', name: 'somethingelse', path: 'this-should-fail' }
1018+
]
1019+
},
1020+
permitted: false
1021+
},
9851022
{
9861023
// test regex on path
9871024
ns: { metadata: { annotations: { [namingPermittedAnnotation]: 'dev/team-a/.*' } } },

0 commit comments

Comments
 (0)