From d428b5c4baec76b658dac5f78de454800ab8e0ad Mon Sep 17 00:00:00 2001 From: Franco Perez Date: Thu, 23 Apr 2020 18:00:55 -0300 Subject: [PATCH] Added Mule 4 Domain Support --- README.md | 4 + pom.xml | 2 +- src/main/resources/namespace-4.properties | 5 +- .../services/tools/validation/Mule4Test.java | 10 +++ .../resources/mule4/mule-domain-config.xml | 35 ++++++++ src/test/resources/rules-4.xml | 86 +++++++++++++++++++ 6 files changed, 140 insertions(+), 2 deletions(-) create mode 100644 src/test/resources/mule4/mule-domain-config.xml diff --git a/README.md b/README.md index 48b6cc5..4947ffb 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,10 @@ Sonarqube plugin: ## Release Notes +#### 1.0.2 +##### Changes + - Added Support for Mule 4 Domain Inspections + #### 1.0.1 ##### Changes - Refactor - One single project. mule-validation-xpath-core dependency is not longer needed diff --git a/pom.xml b/pom.xml index c2ba44b..9f39e59 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.mulesoft.services mule-validation-sonarqube-plugin - 1.0.1 + 1.0.2 jar http://maven.apache.org diff --git a/src/main/resources/namespace-4.properties b/src/main/resources/namespace-4.properties index 51a6bfb..ed88754 100644 --- a/src/main/resources/namespace-4.properties +++ b/src/main/resources/namespace-4.properties @@ -3,6 +3,7 @@ api-gateway=http://www.mulesoft.org/schema/mule/api-gateway ee=http://www.mulesoft.org/schema/mule/ee/core mule=http://www.mulesoft.org/schema/mule/core munit=http://www.mulesoft.org/schema/mule/munit +munit-tools=http://www.mulesoft.org/schema/mule/munit-tools context=http://www.springframework.org/schema/context secure-properties=http://www.mulesoft.org/schema/mule/secure-properties http=http://www.mulesoft.org/schema/mule/http @@ -10,5 +11,7 @@ scripting=http://www.mulesoft.org/schema/mule/scripting tls=http://www.mulesoft.org/schema/mule/tls doc=http://www.mulesoft.org/schema/mule/documentation validation=http://www.mulesoft.org/schema/mule/validation +tls=http://www.mulesoft.org/schema/mule/tls java=http://www.mulesoft.org/schema/mule/java -db=http://www.mulesoft.org/schema/mule/db \ No newline at end of file +db=http://www.mulesoft.org/schema/mule/db +domain=http://www.mulesoft.org/schema/mule/ee/domain \ No newline at end of file diff --git a/src/test/java/com/mulesoft/services/tools/validation/Mule4Test.java b/src/test/java/com/mulesoft/services/tools/validation/Mule4Test.java index 11cfb81..8e03bf1 100644 --- a/src/test/java/com/mulesoft/services/tools/validation/Mule4Test.java +++ b/src/test/java/com/mulesoft/services/tools/validation/Mule4Test.java @@ -48,4 +48,14 @@ public void testRuleDBProperties() throws JDOMException, IOException { boolean valid = xpathProcessor.processXPath(rule, rootElement, Boolean.class).booleanValue(); assertTrue("DB CONFIG HOST MUST HAVE A PROP PLACEHOLDER", valid); } + + @Test + public void testDomain() throws JDOMException, IOException { + String rule = "count(//domain:mule-domain/http:request-config[not(@responseTimeout) or not(matches(@responseTimeout,'^\\$\\{.*\\}$'))]) = 0"; + String fileName = testDirectory.concat(File.separator + "mule-domain-config.xml"); + Document document = saxBuilder.build(new File(fileName)); + Element rootElement = document.getRootElement(); + boolean valid = xpathProcessor.processXPath(rule, rootElement, Boolean.class).booleanValue(); + assertTrue("HTTP Requestor Configuration should have a configurable Response Timeout", valid); + } } diff --git a/src/test/resources/mule4/mule-domain-config.xml b/src/test/resources/mule4/mule-domain-config.xml new file mode 100644 index 0000000..623b23e --- /dev/null +++ b/src/test/resources/mule4/mule-domain-config.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/rules-4.xml b/src/test/resources/rules-4.xml index 5d27da1..75bc092 100644 --- a/src/test/resources/rules-4.xml +++ b/src/test/resources/rules-4.xml @@ -129,6 +129,92 @@ matches(//mule:mule/db:config/db:mssql-connection/@host, '^\$\{.*\}$') + + count(//domain:mule-domain/http:request-config/http:request-connection) + = count( + //domain:mule-domain/http:request-config/http:request-connection/mule:reconnection/mule:reconnect[matches(@count,'^\$\{.*\}$')] + ) + + + count(//domain:mule-domain/http:request-config/http:request-connection) + = count( + //domain:mule-domain/http:request-config/http:request-connection/mule:reconnection/mule:reconnect[matches(@frequency,'^\$\{.*\}$')] + ) + + + count(//domain:mule-domain/secure-properties:config/secure-properties:encrypt[@algorithm!='AES' + or @mode!='CBC']) = 0 + + + count(//domain:mule-domain/http:listener-config)=0 + or + matches(//domain:mule-domain/http:listener-config/http:listener-connection/@port, + '^\$\{.*\}$') + + + count(//domain:mule-domain/http:request-config) = + count(//domain:mule-domain/http:request-config/http:request-connection[matches(@tlsContext,'^\$\{.*\}$')]) + + + count(//domain:mule-domain/tls:context/tls:trust-store) = + count(//domain:mule-domain/tls:context/tls:trust-store[matches(@path,'^\$\{.*\}$')]) + + + count(//domain:mule-domain/tls:context/tls:key-store) = + count(//domain:mule-domain/tls:context/tls:key-store[matches(@path,'^\$\{.*\}$')]) + + + count(//domain:mule-domain/tls:context/tls:trust-store) = + count(//domain:mule-domain/tls:context/tls:trust-store[not(@insecure)]) + + + count(//domain:mule-domain/http:listener-config/http:listener-connection[@protocol='HTTPS' + and not(@tlsContext)])=0 + + + count(//domain:mule-domain/http:request-config/http:default-headers/http:default-header[matches(@value,'^#\[.*\]$')]) + = 0 + and + count(//domain:mule-domain/http:request-config/http:default-query-params/http:query-param[matches(@value,'^#\[.*\]$')]) + = 0 + + + count(//domain:mule-domain/http:request-config[not(@responseTimeout) + or not(matches(@responseTimeout,'^\$\{.*\}$'))]) = 0 +