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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations