Skip to content

Commit c771965

Browse files
authored
Merge pull request #8 from mulesoft-consulting/feature/domain
Added Mule 4 Domain Support
2 parents 5ebd50f + d428b5c commit c771965

File tree

6 files changed

+140
-2
lines changed

6 files changed

+140
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ Sonarqube plugin:
5454

5555
## Release Notes
5656

57+
#### 1.0.2
58+
##### Changes
59+
- Added Support for Mule 4 Domain Inspections
60+
5761
#### 1.0.1
5862
##### Changes
5963
- Refactor - One single project. mule-validation-xpath-core dependency is not longer needed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.mulesoft.services</groupId>
77
<artifactId>mule-validation-sonarqube-plugin</artifactId>
8-
<version>1.0.1</version>
8+
<version>1.0.2</version>
99
<packaging>jar</packaging>
1010

1111
<url>http://maven.apache.org</url>

src/main/resources/namespace-4.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ api-gateway=http://www.mulesoft.org/schema/mule/api-gateway
33
ee=http://www.mulesoft.org/schema/mule/ee/core
44
mule=http://www.mulesoft.org/schema/mule/core
55
munit=http://www.mulesoft.org/schema/mule/munit
6+
munit-tools=http://www.mulesoft.org/schema/mule/munit-tools
67
context=http://www.springframework.org/schema/context
78
secure-properties=http://www.mulesoft.org/schema/mule/secure-properties
89
http=http://www.mulesoft.org/schema/mule/http
910
scripting=http://www.mulesoft.org/schema/mule/scripting
1011
tls=http://www.mulesoft.org/schema/mule/tls
1112
doc=http://www.mulesoft.org/schema/mule/documentation
1213
validation=http://www.mulesoft.org/schema/mule/validation
14+
tls=http://www.mulesoft.org/schema/mule/tls
1315
java=http://www.mulesoft.org/schema/mule/java
14-
db=http://www.mulesoft.org/schema/mule/db
16+
db=http://www.mulesoft.org/schema/mule/db
17+
domain=http://www.mulesoft.org/schema/mule/ee/domain

src/test/java/com/mulesoft/services/tools/validation/Mule4Test.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,14 @@ public void testRuleDBProperties() throws JDOMException, IOException {
4848
boolean valid = xpathProcessor.processXPath(rule, rootElement, Boolean.class).booleanValue();
4949
assertTrue("DB CONFIG HOST MUST HAVE A PROP PLACEHOLDER", valid);
5050
}
51+
52+
@Test
53+
public void testDomain() throws JDOMException, IOException {
54+
String rule = "count(//domain:mule-domain/http:request-config[not(@responseTimeout) or not(matches(@responseTimeout,'^\\$\\{.*\\}$'))]) = 0";
55+
String fileName = testDirectory.concat(File.separator + "mule-domain-config.xml");
56+
Document document = saxBuilder.build(new File(fileName));
57+
Element rootElement = document.getRootElement();
58+
boolean valid = xpathProcessor.processXPath(rule, rootElement, Boolean.class).booleanValue();
59+
assertTrue("HTTP Requestor Configuration should have a configurable Response Timeout", valid);
60+
}
5161
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<domain:mule-domain
3+
xmlns:tls="http://www.mulesoft.org/schema/mule/tls"
4+
xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core"
5+
xmlns:domain="http://www.mulesoft.org/schema/mule/ee/domain"
6+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
7+
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
8+
xsi:schemaLocation="
9+
http://www.mulesoft.org/schema/mule/tls http://www.mulesoft.org/schema/mule/tls/current/mule-tls.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
10+
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
11+
http://www.mulesoft.org/schema/mule/ee/domain http://www.mulesoft.org/schema/mule/ee/domain/current/mule-domain-ee.xsd">
12+
13+
<!-- configure here resource to be shared within the domain -->
14+
<http:request-config name="HTTP_Request_configuration" doc:name="HTTP Request configuration" doc:id="0294ba59-72a5-4230-b29f-11a68e153790" responseTimeout="${http.timeout}">
15+
<http:request-connection protocol="HTTPS" host="api.exchangeratesapi.io" port="443">
16+
<reconnection >
17+
<reconnect frequency="${request.reconnection.freq}" count="${request.reconnection.count}" />
18+
</reconnection>
19+
</http:request-connection>
20+
<http:default-headers >
21+
<http:default-header key="whateverOne" value="something" />
22+
<http:default-header key="whateverTwo" value="somethingElse" />
23+
</http:default-headers>
24+
<http:default-query-params >
25+
<http:query-param key="parameter" value="value" />
26+
</http:default-query-params>
27+
</http:request-config>
28+
<http:listener-config name="test-api-with-examples-httpListenerConfig">
29+
<http:listener-connection host="0.0.0.0" port="${http.port}" protocol="HTTPS" tlsContext="${http.tls.config}"/>
30+
</http:listener-config>
31+
<tls:context name="TLS_Context" doc:name="TLS Context" doc:id="1da6ee2f-5864-4d8d-ada0-4298257a7962" >
32+
<tls:trust-store path="${}"/>
33+
<tls:key-store type="jks" path="${}" />
34+
</tls:context>
35+
</domain:mule-domain>

src/test/resources/rules-4.xml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,92 @@
129129
matches(//mule:mule/db:config/db:mssql-connection/@host,
130130
'^\$\{.*\}$')
131131
</rule>
132+
<rule id="11"
133+
name="Domain - HTTP Requestor reconnection strategy should use a configurable count value"
134+
description="&lt;b&gt;Domain&lt;/b&gt; - HTTP Requestor reconnection strategy should use a configurable count value"
135+
severity="MAJOR" applies="file" type="bug">
136+
count(//domain:mule-domain/http:request-config/http:request-connection)
137+
= count(
138+
//domain:mule-domain/http:request-config/http:request-connection/mule:reconnection/mule:reconnect[matches(@count,'^\$\{.*\}$')]
139+
)
140+
</rule>
141+
<rule id="12"
142+
name="Domain - HTTP Requestor reconnection strategy should use configurable frequency"
143+
description="&lt;b&gt;Domain&lt;/b&gt; - HTTP Requestor reconnection strategy should use configurable frequency"
144+
severity="MAJOR" applies="file" type="bug">
145+
count(//domain:mule-domain/http:request-config/http:request-connection)
146+
= count(
147+
//domain:mule-domain/http:request-config/http:request-connection/mule:reconnection/mule:reconnect[matches(@frequency,'^\$\{.*\}$')]
148+
)
149+
</rule>
150+
<rule id="13"
151+
name="Domain - Mule Secure Properties should use AES-CBC algorithm"
152+
description="&lt;b&gt;Domain&lt;/b&gt; - Mule Secure Properties should use AES-CBC algorithm"
153+
severity="MAJOR" applies="file" type="vulnerability">
154+
count(//domain:mule-domain/secure-properties:config/secure-properties:encrypt[@algorithm!='AES'
155+
or @mode!='CBC']) = 0
156+
</rule>
157+
<rule id="14"
158+
name="Domain - HTTP Listener should not use a hardcoded port value"
159+
description="&lt;b&gt;Domain&lt;/b&gt; - HTTP Listener should not use a hardcoded port value"
160+
severity="MAJOR" applies="file" type="code_smell">
161+
count(//domain:mule-domain/http:listener-config)=0
162+
or
163+
matches(//domain:mule-domain/http:listener-config/http:listener-connection/@port,
164+
'^\$\{.*\}$')
165+
</rule>
166+
<rule id="15"
167+
name="Domain - HTTP Requestor Configuration should reference a TLS Configuration"
168+
description="&lt;b&gt;Domain&lt;/b&gt; - HTTP Requestor should reference a TLS Configuration"
169+
severity="MINOR" applies="file" type="bug">
170+
count(//domain:mule-domain/http:request-config) =
171+
count(//domain:mule-domain/http:request-config/http:request-connection[matches(@tlsContext,'^\$\{.*\}$')])
172+
</rule>
173+
<rule id="16"
174+
name="Domain - Trust Store Configuration should use a configurable path"
175+
description="&lt;b&gt;Domain&lt;/b&gt; - Trust Store Configuration should use a configurable path"
176+
severity="MINOR" applies="file" type="vulnerability">
177+
count(//domain:mule-domain/tls:context/tls:trust-store) =
178+
count(//domain:mule-domain/tls:context/tls:trust-store[matches(@path,'^\$\{.*\}$')])
179+
</rule>
180+
<rule id="17"
181+
name="Domain - Key Store Configuration should use a configurable path"
182+
description="&lt;b&gt;Domain&lt;/b&gt; - Key Store Configuration should use a configurable path"
183+
severity="MINOR" applies="file" type="vulnerability">
184+
count(//domain:mule-domain/tls:context/tls:key-store) =
185+
count(//domain:mule-domain/tls:context/tls:key-store[matches(@path,'^\$\{.*\}$')])
186+
</rule>
187+
<rule id="18"
188+
name="Domain - Trust Store Configuration should not have the insecure attribute"
189+
description="&lt;b&gt;Domain&lt;/b&gt; - Trust Store Configuration should not have the insecure attribute"
190+
severity="CRITICAL" applies="file" type="vulnerability">
191+
count(//domain:mule-domain/tls:context/tls:trust-store) =
192+
count(//domain:mule-domain/tls:context/tls:trust-store[not(@insecure)])
193+
</rule>
194+
<rule id="19"
195+
name="Domain - HTTPS Listener should have a TLS Configuration"
196+
description="&lt;b&gt;Domain&lt;/b&gt; - HTTPS Listener should have a TLS Configuration"
197+
severity="MAJOR" applies="file" type="vulnerability">
198+
count(//domain:mule-domain/http:listener-config/http:listener-connection[@protocol='HTTPS'
199+
and not(@tlsContext)])=0
200+
</rule>
201+
<rule id="20"
202+
name="Domain - HTTP Requestor Configuration should not use dynamic default headers or query params"
203+
description="&lt;b&gt;Domain&lt;/b&gt; - HTTP Requestor Configuration should not use dynamic default headers or query params"
204+
severity="CRITICAL" applies="file" type="code_smell">
205+
count(//domain:mule-domain/http:request-config/http:default-headers/http:default-header[matches(@value,'^#\[.*\]$')])
206+
= 0
207+
and
208+
count(//domain:mule-domain/http:request-config/http:default-query-params/http:query-param[matches(@value,'^#\[.*\]$')])
209+
= 0
210+
</rule>
211+
<rule id="21"
212+
name="Domain - HTTP Requestor Configuration should have a configurable Response Timeout"
213+
description="&lt;b&gt;Domain&lt;/b&gt; - HTTP Requestor Configuration should have a configurable Response Timeout"
214+
severity="CRITICAL" applies="file" type="bug">
215+
count(//domain:mule-domain/http:request-config[not(@responseTimeout)
216+
or not(matches(@responseTimeout,'^\$\{.*\}$'))]) = 0
217+
</rule>
132218
</ruleset>
133219
</rulestore>
134220

0 commit comments

Comments
 (0)