public PostProcTestContext(TestContext testContext) { this.Config = new AnalysisConfig(); this.settings = TeamBuildSettings.CreateNonTeamBuildSettings(testContext.DeploymentDirectory); this.logger = new TestLogger(); this.codeCoverage = new MockCodeCoverageProcessor(); this.runner = new MockSonarRunner(); this.reportBuilder = new MockSummaryReportBuilder(); this.codeCoverage.InitialiseValueToReturn = true; this.codeCoverage.ProcessValueToReturn = true; }
public void AnalysisConfGen_FileProperties() { // File properties should not be copied to the file. // Instead, a pointer to the file should be created. // Arrange string analysisDir = TestUtils.CreateTestSpecificFolder(this.TestContext); TestLogger logger = new TestLogger(); // The set of file properties to supply AnalysisProperties fileProperties = new AnalysisProperties(); fileProperties.Add(new Property() { Id = SonarProperties.HostUrl, Value = "http://myserver" }); fileProperties.Add(new Property() { Id = "file.only", Value = "file value" }); string settingsFilePath = Path.Combine(analysisDir, "settings.txt"); fileProperties.Save(settingsFilePath); FilePropertyProvider fileProvider = FilePropertyProvider.Load(settingsFilePath); ProcessedArgs args = new ProcessedArgs("key", "name", "version", false, EmptyPropertyProvider.Instance, fileProvider); TeamBuildSettings settings = TeamBuildSettings.CreateNonTeamBuildSettings(analysisDir); Directory.CreateDirectory(settings.SonarConfigDirectory); // config directory needs to exist // Act AnalysisConfig actualConfig = AnalysisConfigGenerator.GenerateFile(args, settings, new Dictionary <string, string>(), logger); // Assert AssertConfigFileExists(actualConfig); logger.AssertErrorsLogged(0); logger.AssertWarningsLogged(0); string actualSettingsFilePath = actualConfig.GetSettingsFilePath(); Assert.AreEqual(settingsFilePath, actualSettingsFilePath, "Unexpected settings file path"); // Check the file setting value do not appear in the config file AssertFileDoesNotContainText(actualConfig.FileName, "file.only"); }
public void SummaryReport_ReportIsGenerated() { // Arrange string hostUrl = "http://mySonarQube:9000"; ProjectInfoAnalysisResult result = new ProjectInfoAnalysisResult(); AnalysisConfig config = new AnalysisConfig() { SonarProjectKey = "Foo", SonarQubeHostUrl = hostUrl }; TeamBuildSettings settings = TeamBuildSettings.CreateNonTeamBuildSettings(this.TestContext.DeploymentDirectory); config.SonarOutputDir = TestContext.TestDeploymentDir; // this will be cleaned up by VS when there are too many results string expectedReportPath = Path.Combine(TestContext.TestDeploymentDir, SummaryReportBuilder.SummaryMdFilename); // Act SummaryReportBuilder builder = new SummaryReportBuilder(); builder.GenerateReports(settings, config, result, new TestLogger()); // Assert Assert.IsTrue(File.Exists(expectedReportPath) && (new FileInfo(expectedReportPath)).Length > 0, "The report file cannot be found or is empty"); }
[WorkItem(127)] // Do not store the db and server credentials in the config files: http://jira.sonarsource.com/browse/SONARMSBRU-127 public void AnalysisConfGen_AnalysisConfigDoesNotContainSensitiveData() { // Arrange string analysisDir = TestUtils.CreateTestSpecificFolder(this.TestContext); TestLogger logger = new TestLogger(); ListPropertiesProvider cmdLineArgs = new ListPropertiesProvider(); // Public args - should be written to the config file cmdLineArgs.AddProperty("sonar.host.url", "http://host"); cmdLineArgs.AddProperty("public.key", "public value"); // Sensitive values - should not be written to the config file cmdLineArgs.AddProperty(SonarProperties.DbPassword, "secret db password"); cmdLineArgs.AddProperty(SonarProperties.DbUserName, "secret db user"); // Create a settings file with public and sensitive data AnalysisProperties fileSettings = new AnalysisProperties(); fileSettings.Add(new Property() { Id = "file.public.key", Value = "file public value" }); fileSettings.Add(new Property() { Id = SonarProperties.DbUserName, Value = "secret db user" }); fileSettings.Add(new Property() { Id = SonarProperties.DbPassword, Value = "secret db password" }); string fileSettingsPath = Path.Combine(analysisDir, "fileSettings.txt"); fileSettings.Save(fileSettingsPath); FilePropertyProvider fileProvider = FilePropertyProvider.Load(fileSettingsPath); ProcessedArgs args = new ProcessedArgs("key", "name", "1.0", false, cmdLineArgs, fileProvider); IDictionary <string, string> serverProperties = new Dictionary <string, string>(); // Public server settings serverProperties.Add("server.key.1", "server value 1"); // Sensitive server settings serverProperties.Add(SonarProperties.SonarUserName, "secret user"); serverProperties.Add(SonarProperties.SonarPassword, "secret pwd"); TeamBuildSettings settings = TeamBuildSettings.CreateNonTeamBuildSettings(analysisDir); Directory.CreateDirectory(settings.SonarConfigDirectory); // config directory needs to exist // Act AnalysisConfig config = AnalysisConfigGenerator.GenerateFile(args, settings, serverProperties, logger); // Assert AssertConfigFileExists(config); logger.AssertErrorsLogged(0); logger.AssertWarningsLogged(0); // Check the config // "Public" arguments should be in the file Assert.AreEqual("key", config.SonarProjectKey, "Unexpected project key"); Assert.AreEqual("name", config.SonarProjectName, "Unexpected project name"); Assert.AreEqual("1.0", config.SonarProjectVersion, "Unexpected project version"); AssertExpectedLocalSetting(SonarProperties.HostUrl, "http://host", config); AssertExpectedServerSetting("server.key.1", "server value 1", config); AssertFileDoesNotContainText(config.FileName, "file.public.key"); // file settings values should not be in the config // SONARMSBRU-136: TODO - uncomment the following code: //AssertFileDoesNotContainText(config.FileName, "secret"); // sensitive data should not be in config // SONARMSBRU-136: TODO - delete the following code: // v1.0.1 back-compat: check sensitive data is written to the config file AssertExpectedLocalSetting(SonarProperties.DbPassword, "secret db password", config); AssertExpectedLocalSetting(SonarProperties.DbUserName, "secret db user", config); AssertExpectedServerSetting(SonarProperties.SonarUserName, "secret user", config); AssertExpectedServerSetting(SonarProperties.SonarPassword, "secret pwd", config); }
private TeamBuildSettings CreateValidSettings() { return(TeamBuildSettings.CreateNonTeamBuildSettings(this.TestContext.DeploymentDirectory)); }