-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added "Sonar Security" quality profile
- Loading branch information
Pierre-Loup TRISTANT
committed
Oct 16, 2018
1 parent
43e8979
commit 0d0356f
Showing
7 changed files
with
313 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/fr/niji/sonarphp/DrupalSecurityProfileDefinition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package fr.niji.sonarphp; | ||
|
||
import org.sonar.api.profiles.ProfileDefinition; | ||
import org.sonar.api.profiles.RulesProfile; | ||
import org.sonar.api.profiles.XMLProfileParser; | ||
import org.sonar.api.utils.ValidationMessages; | ||
|
||
public class DrupalSecurityProfileDefinition extends ProfileDefinition { | ||
|
||
private final XMLProfileParser xmlProfileParser; | ||
|
||
public DrupalSecurityProfileDefinition(XMLProfileParser xmlProfileParser) { | ||
this.xmlProfileParser = xmlProfileParser; | ||
} | ||
|
||
@Override | ||
public RulesProfile createProfile(ValidationMessages validation) { | ||
return xmlProfileParser.parseResource(getClass().getClassLoader(), "fr/niji/sonarphp/profile/drupal-security-profile.xml", validation); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
192 changes: 192 additions & 0 deletions
192
src/main/resources/fr/niji/sonarphp/profile/drupal-security-profile.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<profile> | ||
<name>Drupal Security</name> | ||
<language>php</language> | ||
<rules> | ||
<rule> | ||
<repositoryKey>niji-php-rules</repositoryKey> | ||
<key>S10</key> | ||
<priority>MAJOR</priority> | ||
<parameters/> | ||
</rule> | ||
<rule> | ||
<repositoryKey>niji-php-rules</repositoryKey> | ||
<key>S2</key> | ||
<priority>MAJOR</priority> | ||
<parameters/> | ||
</rule> | ||
<rule> | ||
<repositoryKey>niji-php-rules</repositoryKey> | ||
<key>S3</key> | ||
<priority>MAJOR</priority> | ||
<parameters/> | ||
</rule> | ||
<rule> | ||
<repositoryKey>niji-php-rules</repositoryKey> | ||
<key>S4</key> | ||
<priority>MINOR</priority> | ||
<parameters/> | ||
</rule> | ||
<rule> | ||
<repositoryKey>niji-php-rules</repositoryKey> | ||
<key>S5</key> | ||
<priority>CRITICAL</priority> | ||
<parameters/> | ||
</rule> | ||
<rule> | ||
<repositoryKey>niji-php-rules</repositoryKey> | ||
<key>S6</key> | ||
<priority>CRITICAL</priority> | ||
<parameters/> | ||
</rule> | ||
<rule> | ||
<repositoryKey>niji-php-rules</repositoryKey> | ||
<key>S8</key> | ||
<priority>MAJOR</priority> | ||
<parameters/> | ||
</rule> | ||
<rule> | ||
<repositoryKey>php</repositoryKey> | ||
<key>S1313</key> | ||
<priority>MINOR</priority> | ||
<parameters/> | ||
</rule> | ||
<rule> | ||
<repositoryKey>php</repositoryKey> | ||
<key>S1523</key> | ||
<priority>CRITICAL</priority> | ||
<parameters/> | ||
</rule> | ||
<rule> | ||
<repositoryKey>php</repositoryKey> | ||
<key>S1600</key> | ||
<priority>MAJOR</priority> | ||
<parameters/> | ||
</rule> | ||
<rule> | ||
<repositoryKey>php</repositoryKey> | ||
<key>S1799</key> | ||
<priority>BLOCKER</priority> | ||
<parameters/> | ||
</rule> | ||
<rule> | ||
<repositoryKey>php</repositoryKey> | ||
<key>S2000</key> | ||
<priority>MINOR</priority> | ||
<parameters/> | ||
</rule> | ||
<rule> | ||
<repositoryKey>php</repositoryKey> | ||
<key>S2001</key> | ||
<priority>MAJOR</priority> | ||
<parameters/> | ||
</rule> | ||
<rule> | ||
<repositoryKey>php</repositoryKey> | ||
<key>S2002</key> | ||
<priority>MINOR</priority> | ||
<parameters/> | ||
</rule> | ||
<rule> | ||
<repositoryKey>php</repositoryKey> | ||
<key>S2043</key> | ||
<priority>MINOR</priority> | ||
<parameters/> | ||
</rule> | ||
<rule> | ||
<repositoryKey>php</repositoryKey> | ||
<key>S2053</key> | ||
<priority>CRITICAL</priority> | ||
<parameters/> | ||
</rule> | ||
<rule> | ||
<repositoryKey>php</repositoryKey> | ||
<key>S2068</key> | ||
<priority>BLOCKER</priority> | ||
<parameters> | ||
<parameter> | ||
<key>credentialWords</key> | ||
<value>password,passwd,pwd</value> | ||
</parameter> | ||
</parameters> | ||
</rule> | ||
<rule> | ||
<repositoryKey>php</repositoryKey> | ||
<key>S2070</key> | ||
<priority>CRITICAL</priority> | ||
<parameters/> | ||
</rule> | ||
<rule> | ||
<repositoryKey>php</repositoryKey> | ||
<key>S2092</key> | ||
<priority>MINOR</priority> | ||
<parameters/> | ||
</rule> | ||
<rule> | ||
<repositoryKey>php</repositoryKey> | ||
<key>S2245</key> | ||
<priority>CRITICAL</priority> | ||
<parameters/> | ||
</rule> | ||
<rule> | ||
<repositoryKey>php</repositoryKey> | ||
<key>S2255</key> | ||
<priority>MINOR</priority> | ||
<parameters/> | ||
</rule> | ||
<rule> | ||
<repositoryKey>php</repositoryKey> | ||
<key>S2277</key> | ||
<priority>CRITICAL</priority> | ||
<parameters/> | ||
</rule> | ||
<rule> | ||
<repositoryKey>php</repositoryKey> | ||
<key>S2278</key> | ||
<priority>BLOCKER</priority> | ||
<parameters/> | ||
</rule> | ||
<rule> | ||
<repositoryKey>php</repositoryKey> | ||
<key>S2964</key> | ||
<priority>MINOR</priority> | ||
<parameters/> | ||
</rule> | ||
<rule> | ||
<repositoryKey>php</repositoryKey> | ||
<key>S3330</key> | ||
<priority>CRITICAL</priority> | ||
<parameters/> | ||
</rule> | ||
<rule> | ||
<repositoryKey>php</repositoryKey> | ||
<key>S3331</key> | ||
<priority>CRITICAL</priority> | ||
<parameters/> | ||
</rule> | ||
<rule> | ||
<repositoryKey>php</repositoryKey> | ||
<key>S4423</key> | ||
<priority>MAJOR</priority> | ||
<parameters/> | ||
</rule> | ||
<rule> | ||
<repositoryKey>php</repositoryKey> | ||
<key>S4426</key> | ||
<priority>BLOCKER</priority> | ||
<parameters/> | ||
</rule> | ||
<rule> | ||
<repositoryKey>php</repositoryKey> | ||
<key>S4508</key> | ||
<priority>CRITICAL</priority> | ||
<parameters/> | ||
</rule> | ||
<rule> | ||
<repositoryKey>php</repositoryKey> | ||
<key>S4721</key> | ||
<priority>CRITICAL</priority> | ||
<parameters/> | ||
</rule> | ||
</rules> | ||
</profile> |
27 changes: 27 additions & 0 deletions
27
src/test/java/fr/niji/sonarphp/DrupalSecurityProfileDefinitionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package fr.niji.sonarphp; | ||
|
||
import org.junit.Test; | ||
import org.sonar.api.profiles.RulesProfile; | ||
import org.sonar.api.utils.ValidationMessages; | ||
import org.sonar.php.checks.CheckList; | ||
import org.sonar.plugins.php.api.Php; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class DrupalSecurityProfileDefinitionTest { | ||
|
||
@Test | ||
public void profile_creation() { | ||
ValidationMessages validation = ValidationMessages.create(); | ||
|
||
DrupalSecurityProfileDefinition definition = new DrupalSecurityProfileDefinition(new FakeProfileParser()); | ||
RulesProfile profile = definition.createProfile(validation); | ||
|
||
assertThat(profile.getLanguage()).isEqualTo(Php.KEY); | ||
assertThat(profile.getName()).isEqualTo("Drupal Security"); | ||
assertThat(profile.getActiveRulesByRepository(CheckList.REPOSITORY_KEY)).hasSize(23); | ||
assertThat(profile.getActiveRulesByRepository(PHPRuleDefinitions.REPOSITORY_KEY)).hasSize(7); | ||
assertThat(validation.hasErrors()).isFalse(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package fr.niji.sonarphp; | ||
|
||
import org.mockito.invocation.InvocationOnMock; | ||
import org.mockito.stubbing.Answer; | ||
import org.sonar.api.profiles.XMLProfileParser; | ||
import org.sonar.api.rules.Rule; | ||
import org.sonar.api.rules.RuleFinder; | ||
|
||
import static org.mockito.Matchers.anyString; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class FakeProfileParser extends XMLProfileParser { | ||
|
||
public FakeProfileParser() { | ||
super(ruleFinder()); | ||
} | ||
|
||
private static RuleFinder ruleFinder() { | ||
return when(mock(RuleFinder.class).findByKey(anyString(), anyString())).thenAnswer(new Answer<Rule>() { | ||
public Rule answer(InvocationOnMock invocation) { | ||
Object[] arguments = invocation.getArguments(); | ||
return Rule.create((String) arguments[0], (String) arguments[1], (String) arguments[1]); | ||
} | ||
}).getMock(); | ||
} | ||
|
||
} |