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

Fixes naming convention permission check for data items with path attribute only. #830

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions lib/poller.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,16 +281,15 @@ class Poller {
// Testing data property
if (namingConvention && externalData) {
externalData.forEach((secretProperty, index) => {
if (secretProperty.path) {
if (!reNaming.test(secretProperty.path)) {
allowed = false
reason = `path ${secretProperty.path} does not match naming convention ${namingConvention}`
return {
allowed, reason
}
if ('path' in secretProperty && !reNaming.test(secretProperty.path)) {
allowed = false
reason = `path ${secretProperty.path} does not match naming convention ${namingConvention}`
return {
allowed, reason
}
}
if (!reNaming.test(secretProperty.key)) {

if ('key' in secretProperty && !reNaming.test(secretProperty.key)) {
allowed = false
reason = `key name ${secretProperty.key} does not match naming convention ${namingConvention}`
return {
Expand Down
37 changes: 37 additions & 0 deletions lib/poller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,43 @@ describe('Poller', () => {
},
permitted: false
},
{
// test regex on path
ns: { metadata: { annotations: { [namingPermittedAnnotation]: 'dev/team-a/.*' } } },
descriptor: {
data: [
{ path: 'dev/team-a/secret' }
]
},
permitted: true
},
vladlosev marked this conversation as resolved.
Show resolved Hide resolved
{
ns: { metadata: { annotations: { [namingPermittedAnnotation]: 'dev/team-a/.*' } } },
descriptor: {
data: [
{ key: 'dev/team-a/secret', name: 'somethingelse', path: '' }
]
},
permitted: false
},
{
ns: { metadata: { annotations: { [namingPermittedAnnotation]: 'dev/team-a/.*' } } },
descriptor: {
data: [
{ key: 'this-should-fail', name: 'somethingelse', path: 'dev/team-a/such-path' }
]
},
permitted: false
},
{
ns: { metadata: { annotations: { [namingPermittedAnnotation]: 'dev/team-a/.*' } } },
descriptor: {
data: [
{ key: 'dev/team-a/such-key', name: 'somethingelse', path: 'this-should-fail' }
]
},
permitted: false
},
{
// test regex on path
ns: { metadata: { annotations: { [namingPermittedAnnotation]: 'dev/team-a/.*' } } },
Expand Down