Skip to content

Commit

Permalink
feat: adjust secrets error message
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed Aug 28, 2023
1 parent 78be5e0 commit 9e31249
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/utils/error-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ export function getErrorMessage(report, executionPlatform, executionPlatformVers
return getEventBasedGatewayTargetNotAllowedErrorMessage(report);
}

if (type === ERROR_TYPES.SECRET_EXPRESSION_INVALID) {
return getSecretExpressionInvalidErrorMessage(report);
}

return message;
}

Expand Down Expand Up @@ -619,4 +623,12 @@ function getPropertyValueNotAllowedErrorMessage(report, executionPlatform, execu
}

return message;
}

function getSecretExpressionInvalidErrorMessage(report) {
const { data } = report;

const { property } = data;

return `Property <${ property }> is not a valid secret`;
}
4 changes: 4 additions & 0 deletions lib/utils/properties-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ export function getErrorMessage(id, report) {
return 'Cannot be an expression.';
}

if (data.type === ERROR_TYPES.SECRET_EXPRESSION_INVALID) {
return 'Must be a valid secret.';
}

if (id === 'isExecutable') {
const { parentNode } = data;

Expand Down
94 changes: 94 additions & 0 deletions test/spec/utils/error-messages.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1715,6 +1715,100 @@ describe('utils/error-messages', function() {

});


describe('secret expression invalid', function() {

it('should adjust (correlation key)', async function() {

// given
const node = createElement('bpmn:IntermediateCatchEvent', {
eventDefinitions: [
createElement('bpmn:MessageEventDefinition', {
messageRef: createElement('bpmn:Message', {
name: 'foo',
extensionElements: createElement('bpmn:ExtensionElements', {
values: [
createElement('zeebe:Subscription', {
correlationKey: 'secrets.'
})
]
})
})
})
]
});

const { default: rule } = await import('bpmnlint-plugin-camunda-compat/rules/camunda-cloud/secrets');

const report = await getLintError(node, rule);

// when
const errorMessage = getErrorMessage(report);

// then
expect(errorMessage).to.equal('Property <correlationKey> is not a valid secret');
});


it('should adjust (input source)', async function() {

// given
const node = createElement('bpmn:ServiceTask', {
extensionElements: createElement('bpmn:ExtensionElements', {
values: [
createElement('zeebe:IoMapping', {
inputParameters: [
createElement('zeebe:Input', {
source: 'secrets.'
})
]
})
]
})
});

const { default: rule } = await import('bpmnlint-plugin-camunda-compat/rules/camunda-cloud/secrets');

const report = await getLintError(node, rule);

// when
const errorMessage = getErrorMessage(report);

// then
expect(errorMessage).to.equal('Property <source> is not a valid secret');
});


it('should adjust (property value)', async function() {

// given
const node = createElement('bpmn:ServiceTask', {
extensionElements: createElement('bpmn:ExtensionElements', {
values: [
createElement('zeebe:Properties', {
properties: [
createElement('zeebe:Property', {
value: 'secrets.'
})
]
})
]
})
});

const { default: rule } = await import('bpmnlint-plugin-camunda-compat/rules/camunda-cloud/secrets');

const report = await getLintError(node, rule);

// when
const errorMessage = getErrorMessage(report);

// then
expect(errorMessage).to.equal('Property <value> is not a valid secret');
});

});

});


Expand Down
97 changes: 97 additions & 0 deletions test/spec/utils/properties-panel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1562,6 +1562,103 @@ describe('utils/properties-panel', function() {
expectErrorMessage(entryIds[ 0 ], 'Not supported.', report);
});


describe('secret expression invalid', function() {

it('Subscription correlation key', async function() {

// given
const node = createElement('bpmn:ReceiveTask', {
messageRef: createElement('bpmn:Message', {
extensionElements: createElement('bpmn:ExtensionElements', {
values: [
createElement('zeebe:Subscription', {
correlationKey: 'secrets.'
})
]
})
})
});

const { default: rule } = await import('bpmnlint-plugin-camunda-compat/rules/camunda-cloud/secrets');

const report = await getLintError(node, rule);

// when
const entryIds = getEntryIds(report);

// then
expect(entryIds).to.eql([ 'messageSubscriptionCorrelationKey' ]);

expectErrorMessage(entryIds[ 0 ], 'Must be a valid secret.', report);
});


it('Input variable assignment value', async function() {

// given
const node = createElement('bpmn:ServiceTask', {
id: 'ServiceTask_1',
extensionElements: createElement('bpmn:ExtensionElements', {
values: [
createElement('zeebe:IoMapping', {
inputParameters: [
createElement('zeebe:Input', {
source: 'secrets.'
})
]
})
]
})
});

const { default: rule } = await import('bpmnlint-plugin-camunda-compat/rules/camunda-cloud/secrets');

const report = await getLintError(node, rule);

// when
const entryIds = getEntryIds(report);

// then
expect(entryIds).to.eql([ 'ServiceTask_1-input-0-source' ]);

expectErrorMessage(entryIds[ 0 ], 'Must be a valid secret.', report);
});


it('Extension property value', async function() {

// given
const node = createElement('bpmn:ServiceTask', {
id: 'ServiceTask_1',
extensionElements: createElement('bpmn:ExtensionElements', {
values: [
createElement('zeebe:Properties', {
properties: [
createElement('zeebe:Property', {
value: 'secrets.'
})
]
})
]
})
});

const { default: rule } = await import('bpmnlint-plugin-camunda-compat/rules/camunda-cloud/secrets');

const report = await getLintError(node, rule);

// when
const entryIds = getEntryIds(report);

// then
expect(entryIds).to.eql([ 'ServiceTask_1-extensionProperty-0-value' ]);

expectErrorMessage(entryIds[ 0 ], 'Must be a valid secret.', report);
});

});

});


Expand Down

0 comments on commit 9e31249

Please sign in to comment.