From 9e312499b38d60dbacfc154c3a92d6801d468a09 Mon Sep 17 00:00:00 2001 From: Philipp Date: Mon, 28 Aug 2023 17:25:50 +0200 Subject: [PATCH] feat: adjust `secrets` error message --- lib/utils/error-messages.js | 12 +++ lib/utils/properties-panel.js | 4 + test/spec/utils/error-messages.spec.js | 94 +++++++++++++++++++++++ test/spec/utils/properties-panel.spec.js | 97 ++++++++++++++++++++++++ 4 files changed, 207 insertions(+) diff --git a/lib/utils/error-messages.js b/lib/utils/error-messages.js index 71ac574..f7e977c 100644 --- a/lib/utils/error-messages.js +++ b/lib/utils/error-messages.js @@ -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; } @@ -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`; } \ No newline at end of file diff --git a/lib/utils/properties-panel.js b/lib/utils/properties-panel.js index d8084ac..71c4980 100644 --- a/lib/utils/properties-panel.js +++ b/lib/utils/properties-panel.js @@ -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; diff --git a/test/spec/utils/error-messages.spec.js b/test/spec/utils/error-messages.spec.js index 0752773..cd899e2 100644 --- a/test/spec/utils/error-messages.spec.js +++ b/test/spec/utils/error-messages.spec.js @@ -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 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 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 is not a valid secret'); + }); + + }); + }); diff --git a/test/spec/utils/properties-panel.spec.js b/test/spec/utils/properties-panel.spec.js index 348ff89..5d6778e 100644 --- a/test/spec/utils/properties-panel.spec.js +++ b/test/spec/utils/properties-panel.spec.js @@ -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); + }); + + }); + });