Search in sources :

Example 51 with DefaultFileSystem

use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonar-cloudformation-plugin by Hack23.

the class CfnNagProcessReportsTest method executeSimpleNagReportTest.

/**
 * Execute simple nag report test.
 *
 * @throws IOException Signals that an I/O exception has occurred.
 */
@Test
public void executeSimpleNagReportTest() throws IOException {
    final DefaultFileSystem fileSystem = new DefaultFileSystem(FileSystems.getDefault().getPath(".").toAbsolutePath());
    final DefaultInputFile inputFile = new TestInputFileBuilder("key", "src/test/resources/aws-cross-account-manager-master.yml").setLanguage("yaml").initMetadata(new String(Files.readAllBytes(FileSystems.getDefault().getPath("src/test/resources/aws-cross-account-manager-master.yml")))).setCharset(StandardCharsets.UTF_8).build();
    fileSystem.add(inputFile);
    final CfnNagProcessReports cloudformationSensor = new CfnNagProcessReports(fileSystem, new PathResolver());
    final SensorContextTester sensorContext = SensorContextTester.create(FileSystems.getDefault().getPath(".").toAbsolutePath());
    sensorContext.fileSystem().add(inputFile);
    cloudformationSensor.processCfnNagReport(sensorContext, Optional.of("src/test/resources/aws-cross-account-manager-master.yml.nag"));
    assertFalse(sensorContext.allIssues().isEmpty());
    assertEquals(44, sensorContext.allIssues().size());
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) PathResolver(org.sonar.api.scan.filesystem.PathResolver) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Test(org.junit.Test)

Example 52 with DefaultFileSystem

use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonar-cloudformation-plugin by Hack23.

the class CfnNagProcessReportsTest method executeSimpleNagScanReportTemplateMissingTest.

/**
 * Execute simple nag scan report template missing test.
 *
 * @throws IOException Signals that an I/O exception has occurred.
 */
@Test
public void executeSimpleNagScanReportTemplateMissingTest() throws IOException {
    final DefaultFileSystem fileSystem = new DefaultFileSystem(FileSystems.getDefault().getPath(".").toAbsolutePath());
    final CfnNagProcessReports cloudformationSensor = new CfnNagProcessReports(fileSystem, new PathResolver());
    final SensorContextTester sensorContext = SensorContextTester.create(FileSystems.getDefault().getPath(".").toAbsolutePath());
    cloudformationSensor.processCfnNagReport(sensorContext, Optional.of("src/test/resources/cfn-nag-scan.nagscan"));
    assertFalse(sensorContext.allIssues().isEmpty());
    assertEquals(6, sensorContext.allIssues().size());
}
Also used : SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) PathResolver(org.sonar.api.scan.filesystem.PathResolver) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Test(org.junit.Test)

Example 53 with DefaultFileSystem

use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonar-cloudformation-plugin by Hack23.

the class CfnNagProcessReportsTest method executeFileReportWithCustomRulesTest.

/**
 * Execute file report with custom rules test.
 *
 * @throws IOException Signals that an I/O exception has occurred.
 */
@Test
public void executeFileReportWithCustomRulesTest() throws IOException {
    final DefaultFileSystem fileSystem = new DefaultFileSystem(FileSystems.getDefault().getPath(".").toAbsolutePath());
    final DefaultInputFile inputFile = new TestInputFileBuilder("key", "src/test/resources/CloudTrailAllAccounts.yml").setLanguage("yaml").initMetadata(new String(Files.readAllBytes(FileSystems.getDefault().getPath("src/test/resources/CloudTrailAllAccounts.yml")))).setCharset(StandardCharsets.UTF_8).build();
    fileSystem.add(inputFile);
    final DefaultInputFile inputFile2 = new TestInputFileBuilder("key", "src/test/resources/aws-cross-account-manager-master.yml").setLanguage("yaml").initMetadata(new String(Files.readAllBytes(FileSystems.getDefault().getPath("src/test/resources/aws-cross-account-manager-master.yml")))).setCharset(StandardCharsets.UTF_8).build();
    fileSystem.add(inputFile2);
    final CfnNagProcessReports cloudformationSensor = new CfnNagProcessReports(fileSystem, new PathResolver());
    final SensorContextTester sensorContext = SensorContextTester.create(FileSystems.getDefault().getPath(".").toAbsolutePath());
    sensorContext.fileSystem().add(inputFile);
    sensorContext.fileSystem().add(inputFile2);
    cloudformationSensor.processCfnNagReport(sensorContext, Optional.of("src/test/resources/cfn-nag-scan-custom-rules.nagscan"));
    assertFalse(sensorContext.allIssues().isEmpty());
    assertEquals(14, sensorContext.allIssues().size());
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) PathResolver(org.sonar.api.scan.filesystem.PathResolver) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Test(org.junit.Test)

Example 54 with DefaultFileSystem

use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonar-cloudformation-plugin by Hack23.

the class CheckovProcessReportsTest method executeSimpleCheckovReportTest.

/**
 * Execute simple checkov report test.
 *
 * @throws IOException Signals that an I/O exception has occurred.
 */
@Test
public void executeSimpleCheckovReportTest() throws IOException {
    final DefaultFileSystem fileSystem = new DefaultFileSystem(FileSystems.getDefault().getPath(".").toAbsolutePath());
    final DefaultInputFile inputFile = new TestInputFileBuilder("key", "src/test/resources/checkov/cia-dist-cloudformation.json").setLanguage("json").initMetadata(new String(Files.readAllBytes(FileSystems.getDefault().getPath("src/test/resources/checkov/cia-dist-cloudformation.json")))).setCharset(StandardCharsets.UTF_8).build();
    fileSystem.add(inputFile);
    final CheckovProcessReports cloudformationSensor = new CheckovProcessReports(fileSystem, new PathResolver());
    final SensorContextTester sensorContext = SensorContextTester.create(FileSystems.getDefault().getPath(".").toAbsolutePath());
    sensorContext.fileSystem().add(inputFile);
    final ActiveRules activeRules = new DefaultActiveRules(Arrays.asList(new NewActiveRule.Builder().setRuleKey(RuleKey.of("cloudformation-plugin-cfn", "cloudformation-CKV_AWS_8")).build()));
    sensorContext.setActiveRules(activeRules);
    cloudformationSensor.processCheckovReport(sensorContext, Optional.of("src/test/resources/checkov/cia-dist-cloudformation.checkov-report"));
    assertFalse(sensorContext.allIssues().isEmpty());
    assertEquals(1, sensorContext.allIssues().size());
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultActiveRules(org.sonar.api.batch.rule.internal.DefaultActiveRules) SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultActiveRules(org.sonar.api.batch.rule.internal.DefaultActiveRules) ActiveRules(org.sonar.api.batch.rule.ActiveRules) PathResolver(org.sonar.api.scan.filesystem.PathResolver) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Test(org.junit.Test)

Example 55 with DefaultFileSystem

use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonar-cloudformation-plugin by Hack23.

the class CheckovProcessReportsTest method executeSimpleCheckovReportFoundNoTemplateTest.

/**
 * Execute simple checkov report found no template test.
 *
 * @throws IOException Signals that an I/O exception has occurred.
 */
@Test
public void executeSimpleCheckovReportFoundNoTemplateTest() throws IOException {
    final DefaultFileSystem fileSystem = new DefaultFileSystem(FileSystems.getDefault().getPath(".").toAbsolutePath());
    final CheckovProcessReports cloudformationSensor = new CheckovProcessReports(fileSystem, new PathResolver());
    final SensorContextTester sensorContext = SensorContextTester.create(FileSystems.getDefault().getPath(".").toAbsolutePath());
    final ActiveRules activeRules = new DefaultActiveRules(Arrays.asList(new NewActiveRule.Builder().setRuleKey(RuleKey.of("cfn-yaml", "cloudformation-CKV_AWS_111")).build()));
    sensorContext.setActiveRules(activeRules);
    cloudformationSensor.processCheckovReport(sensorContext, Optional.of("src/test/resources/checkov/cia-dist-cloudformation.checkov-report"));
    assertTrue(sensorContext.allIssues().isEmpty());
}
Also used : DefaultActiveRules(org.sonar.api.batch.rule.internal.DefaultActiveRules) SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultActiveRules(org.sonar.api.batch.rule.internal.DefaultActiveRules) ActiveRules(org.sonar.api.batch.rule.ActiveRules) PathResolver(org.sonar.api.scan.filesystem.PathResolver) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Test(org.junit.Test)

Aggregations

DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)112 File (java.io.File)69 InputFile (org.sonar.api.batch.fs.InputFile)58 Test (org.junit.Test)46 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)46 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)38 SensorContextTester (org.sonar.api.batch.sensor.internal.SensorContextTester)37 Test (org.junit.jupiter.api.Test)25 SonarComponents (org.sonar.java.SonarComponents)24 Before (org.junit.Before)22 MapSettings (org.sonar.api.config.internal.MapSettings)21 PathResolver (org.sonar.api.scan.filesystem.PathResolver)20 JavaCheck (org.sonar.plugins.java.api.JavaCheck)14 AnalyzerMessage (org.sonar.java.AnalyzerMessage)11 ClasspathForTest (org.sonar.java.classpath.ClasspathForTest)10 NoSonarFilter (org.sonar.api.issue.NoSonarFilter)8 Path (java.nio.file.Path)7 ClasspathForMain (org.sonar.java.classpath.ClasspathForMain)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6