Search in sources :

Example 56 with SensorContextTester

use of org.sonar.api.batch.sensor.internal.SensorContextTester 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 57 with SensorContextTester

use of org.sonar.api.batch.sensor.internal.SensorContextTester 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 58 with SensorContextTester

use of org.sonar.api.batch.sensor.internal.SensorContextTester 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 59 with SensorContextTester

use of org.sonar.api.batch.sensor.internal.SensorContextTester 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 60 with SensorContextTester

use of org.sonar.api.batch.sensor.internal.SensorContextTester 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

SensorContextTester (org.sonar.api.batch.sensor.internal.SensorContextTester)199 Test (org.junit.jupiter.api.Test)81 File (java.io.File)77 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)59 InputFile (org.sonar.api.batch.fs.InputFile)58 Test (org.junit.Test)51 MapSettings (org.sonar.api.config.internal.MapSettings)47 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)43 Test (org.testng.annotations.Test)42 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)38 OpenEdgePluginTest (org.sonar.plugins.openedge.OpenEdgePluginTest)37 Path (java.nio.file.Path)33 OpenEdgeSettings (org.sonar.plugins.openedge.foundation.OpenEdgeSettings)30 SonarComponents (org.sonar.java.SonarComponents)19 ClasspathForTest (org.sonar.java.classpath.ClasspathForTest)18 ExternalIssue (org.sonar.api.batch.sensor.issue.ExternalIssue)15 ArrayList (java.util.ArrayList)14 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)14 GeneratedFile (org.sonar.java.model.GeneratedFile)14 PathResolver (org.sonar.api.scan.filesystem.PathResolver)13