public void FileGen_AdditionalProperties() { // 0. Arrange string analysisRootDir = TestUtils.CreateTestSpecificFolder(this.TestContext); TestLogger logger = new TestLogger(); CreateProjectWithFiles("project1", analysisRootDir); AnalysisConfig config = CreateValidConfig(analysisRootDir); // Add additional properties config.LocalSettings = new AnalysisProperties(); config.LocalSettings.Add(new Property() { Id = "key1", Value = "value1" }); config.LocalSettings.Add(new Property() { Id = "key.2", Value = "value two" }); config.LocalSettings.Add(new Property() { Id = "key.3", Value = " " }); // Sensitive data should not be written config.LocalSettings.Add(new Property() { Id = SonarProperties.DbPassword, Value ="secret db pwd" }); config.LocalSettings.Add(new Property() { Id = SonarProperties.SonarPassword, Value = "secret pwd" }); // Server properties should not be added config.ServerSettings = new AnalysisProperties(); config.ServerSettings.Add(new Property() { Id = "server.key", Value = "should not be added" }); // Act ProjectInfoAnalysisResult result = PropertiesFileGenerator.GenerateFile(config, logger); // Assert AssertExpectedProjectCount(1, result); // One valid project info file -> file created AssertPropertiesFilesCreated(result, logger); SQPropertiesFileReader provider = new SQPropertiesFileReader(result.FullPropertiesFilePath); provider.AssertSettingExists("key1", "value1"); provider.AssertSettingExists("key.2", "value two"); provider.AssertSettingExists("key.3", " "); provider.AssertSettingDoesNotExist("server.key"); provider.AssertSettingDoesNotExist(SonarProperties.DbPassword); provider.AssertSettingDoesNotExist(SonarProperties.SonarPassword); }
public void FileGen_BuildWrapperOutputDirIsMissing_PropertyNotWritten() { // Arrange TestLogger logger = new TestLogger(); Property buildWrapperProperty = new Property() { Id = PropertiesFileGenerator.BuildWrapperOutputDirectoryKey, Value = "non-existent directory" }; // Act ProjectInfoAnalysisResult result = ExecuteAndCheckSucceeds("buildwrapper_missingdir", logger, buildWrapperProperty); // Assert SQPropertiesFileReader provider = new SQPropertiesFileReader(result.FullPropertiesFilePath); provider.AssertSettingDoesNotExist(PropertiesFileGenerator.BuildWrapperOutputDirectoryKey); logger.AssertSingleDebugMessageExists(PropertiesFileGenerator.BuildWrapperOutputDirectoryKey, "non-existent directory"); logger.AssertWarningsLogged(0); logger.AssertErrorsLogged(0); }
public void FileGen_ValidFiles_WithUnfixableSarif() { // Arrange string testDir = TestUtils.CreateTestSpecificFolder(this.TestContext); // SARIF file path string testSarifPath = Path.Combine(testDir, "testSarif.json"); string escapedSarifPath = testSarifPath.Replace(@"\", @"\\"); // Create SARIF report path property and add it to the project info AnalysisProperties projectSettings = new AnalysisProperties(); projectSettings.Add(new Property() { Id = RoslynV1SarifFixer.ReportFilePropertyKey, Value = testSarifPath }); Guid projectGuid = Guid.NewGuid(); CreateProjectWithFiles("withFiles1", testDir, projectGuid, true, projectSettings); TestLogger logger = new TestLogger(); AnalysisConfig config = CreateValidConfig(testDir); // Mock SARIF fixer simulated unfixable/absent file MockRoslynV1SarifFixer mockSarifFixer = new MockRoslynV1SarifFixer(null); // Act ProjectInfoAnalysisResult result = PropertiesFileGenerator.GenerateFile(config, logger, mockSarifFixer); // Assert Assert.AreEqual(1, mockSarifFixer.CallCount); // One valid project info file -> file created AssertPropertiesFilesCreated(result, logger); // Unfixable SARIF -> cannot fix -> report file property removed SQPropertiesFileReader provider = new SQPropertiesFileReader(result.FullPropertiesFilePath); provider.AssertSettingDoesNotExist(projectGuid.ToString().ToUpper() + "." + RoslynV1SarifFixer.ReportFilePropertyKey); }
public void FileGen_BuildWrapperOutputDirIsEmpty_PropertyNotWritten() { // Arrange // Create empty folder with empty child folder string emptyFolderPath = TestUtils.CreateTestSpecificFolder(this.TestContext, "empty_bw_output"); TestUtils.CreateTestSpecificFolder(this.TestContext, "empty_bw_output\\childDir"); TestLogger logger = new TestLogger(); Property buildWrapperProperty = new Property() { Id = PropertiesFileGenerator.BuildWrapperOutputDirectoryKey, Value = emptyFolderPath }; // Act ProjectInfoAnalysisResult result = ExecuteAndCheckSucceeds("buildwrapper_emptydir", logger, buildWrapperProperty); // Assert SQPropertiesFileReader provider = new SQPropertiesFileReader(result.FullPropertiesFilePath); provider.AssertSettingDoesNotExist(PropertiesFileGenerator.BuildWrapperOutputDirectoryKey); logger.AssertSingleDebugMessageExists(PropertiesFileGenerator.BuildWrapperOutputDirectoryKey, emptyFolderPath); logger.AssertWarningsLogged(0); logger.AssertErrorsLogged(0); }