Skip to content

Commit

Permalink
Check localhost usage in config and code (#996)
Browse files Browse the repository at this point in the history
* Add new runtime springboot and add JPA as supported

* 1) Add Spring App and War
2) Add label for Springboot

* Update the test jar file

* use simple test data

* Add more spring framework to runtime springboot
change spring boot war to spring war

* Divided 'Spring Boot Application' into 3 relevant technologies

* Fixed 'technology-tag's cases

* Changed consistently labels definitions

* Changed 'SpringBootApplication' annotation technologies' placement

* Rule '3rd-party-spring-03001': removed useless 'or' condition

* Added new technologies to README

* Check the localhost

---------

Co-authored-by: PhilipCattanach <31246010+PhilipCattanach@users.noreply.github.com>
Co-authored-by: mrizzi <mrizzi@redhat.com>
  • Loading branch information
3 people authored Jun 30, 2023
1 parent 0d8e05f commit 91e8302
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
52 changes: 52 additions & 0 deletions rules/rules-reviewed/cloud-readiness/localhost.windup.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0"?>
<ruleset id="localhost" xmlns="http://windup.jboss.org/schema/jboss-ruleset" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://windup.jboss.org/schema/jboss-ruleset http://windup.jboss.org/schema/jboss-ruleset/windup-jboss-ruleset.xsd">
<metadata>
<description>
This is a ruleset for check if localhost used in app
</description>
<dependencies>
<addon id="org.jboss.windup.rules,windup-rules-javaee,2.4.0.Final" />
<addon id="org.jboss.windup.rules,windup-rules-java,2.4.0.Final" />
</dependencies>
<!-- version ranges applied to from and to technologies -->
<targetTechnology id="cloud-readiness" />
<tag>localhost</tag>
</metadata>
<rules>
<rule id="localhost-http-00001">
<when>
<filecontent filename="{*}.{extensions}" pattern="{pattern}" />
</when>
<perform>
<hint title="Local HTTP Calls" effort="7" category-id="mandatory">
<message>The app is trying to access local resource by HTTP, please try to migrate the resource to cloud</message>
<tag>localhost</tag>
</hint>
</perform>
<where param="extensions">
<matches pattern="(java|properties|jsp|jspf|tag|xml|txt|yaml)" />
</where>
<where param="pattern">
<matches pattern="http(s)?://((localhost)|(127\.0\.0\.1))+(:[0-9]+)?(/.*)?" />
</where>
</rule>
<rule id="localhost-http-00001">
<when>
<filecontent filename="{*}.{extensions}" pattern="{pattern}" />
</when>
<perform>
<hint title="Local JDBC Calls" effort="7" category-id="mandatory">
<message>The app is trying to access local resource by JDBC, please try to migrate the resource to cloud</message>
<tag>localhost</tag>
</hint>
</perform>
<where param="extensions">
<matches pattern="(java|properties|jsp|jspf|tag|xml|txt|yaml)" />
</where>
<where param="pattern">
<matches pattern="jdbc:([a-z0-9-]+)://(localhost|127\.0\.0\.1)(:[0-9]+)?" />
</where>
</rule>
</rules>
</ruleset>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mysql=jdbc:sqlserver://127.0.0.1:3306/asdf
sqlserver=jdbc:sqlserver://localhost;encrypt=true;user=MyUserName;password=*****
http=http://localhost:8080
https=https://127.0.0.1:8080/ddd
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0"?>
<ruletest id="localhost-code-test" xmlns="http://windup.jboss.org/schema/jboss-ruleset" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://windup.jboss.org/schema/jboss-ruleset http://windup.jboss.org/schema/jboss-ruleset/windup-jboss-ruleset.xsd">
<testDataPath>data</testDataPath>
<rulePath>../localhost.windup.xml</rulePath>
<ruleset>
<rules>
<rule id="localhost-http-test-00001">
<when>
<not>
<iterable-filter size="2">
<hint-exists message="The app is trying to access local resource by HTTP" />
</iterable-filter>
</not>
</when>
<perform>
<fail message="localhost http usage was not found" />
</perform>
</rule>
<rule id="localhost-jdbc-test-00002">
<when>
<not>
<iterable-filter size="2">
<hint-exists message="The app is trying to access local resource by JDBC" />
</iterable-filter>
</not>
</when>
<perform>
<fail message="localhost jdbc usage was not found" />
</perform>
</rule>
</rules>
</ruleset>
</ruletest>

0 comments on commit 91e8302

Please sign in to comment.