private static bool ExecuteJavaRunnerIgnoringAsserts(AnalysisConfig config, IEnumerable <string> userCmdLineArguments, ILogger logger, string exeFileName, string propertiesFileName, IProcessRunner runner)
 {
     using (new AssertIgnoreScope())
     {
         return(SonarScannerWrapper.ExecuteJavaRunner(config, userCmdLineArguments, logger, exeFileName, propertiesFileName, runner));
     }
 }
示例#2
0
        public void SonarScanner_SensitiveArgsPassedOnCommandLine()
        {
            // Check that sensitive arguments from the config are passed on the command line

            // Arrange
            var logger = new TestLogger();

            var testDir = TestUtils.CreateTestSpecificFolder(TestContext);

            var exePath            = CreateDummarySonarScannerBatchFile();
            var propertiesFilePath = CreateDummySonarScannerPropertiesFile();

            var userArgs = new string[] { "-Dxxx=yyy", "-Dsonar.password=cmdline.password" };

            // Create a config file containing sensitive arguments
            var fileSettings = new AnalysisProperties
            {
                new Property()
                {
                    Id = SonarProperties.DbPassword, Value = "file db pwd"
                },
                new Property()
                {
                    Id = SonarProperties.SonarPassword, Value = "file.password - should not be returned"
                },
                new Property()
                {
                    Id = "file.not.sensitive.key", Value = "not sensitive value"
                }
            };
            var settingsFilePath = Path.Combine(testDir, "fileSettings.txt");

            fileSettings.Save(settingsFilePath);

            var config = new AnalysisConfig()
            {
                SonarScannerWorkingDirectory = TestContext.DeploymentDirectory
            };

            config.SetSettingsFilePath(settingsFilePath);

            // Act
            var success = SonarScannerWrapper.ExecuteJavaRunner(config, userArgs, logger, exePath, propertiesFilePath);

            // Assert
            VerifyProcessRunOutcome(logger, TestContext.DeploymentDirectory, success, true);
            var actualCmdLineArgs = CheckStandardArgsPassed(logger, propertiesFilePath);

            // Non-sensitive values from the file should not be passed on the command line
            CheckArgDoesNotExist("file.not.sensitive.key", actualCmdLineArgs);

            var dbPwdIndex   = CheckArgExists("-Dsonar.jdbc.password=file db pwd", actualCmdLineArgs); // sensitive value from file
            var userPwdIndex = CheckArgExists("-Dsonar.password=cmdline.password", actualCmdLineArgs); // sensitive value from cmd line: overrides file value

            var propertiesFileIndex = CheckArgExists(SonarScannerWrapper.ProjectSettingsFileArgName, actualCmdLineArgs);

            Assert.IsTrue(dbPwdIndex < propertiesFileIndex, "User arguments should appear first");
            Assert.IsTrue(userPwdIndex < propertiesFileIndex, "User arguments should appear first");
        }
        public void Execute_WhenUserCmdLineArgumentsIsNull_Throws()
        {
            // Arrange
            var    testSubject = new SonarScannerWrapper(new TestLogger());
            Action act         = () => testSubject.Execute(new AnalysisConfig(), null);

            // Act & Assert
            act.Should().ThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("userCmdLineArguments");
        }
        public void Execute_WhenConfigIsNull_Throws()
        {
            // Arrange
            var    testSubject = new SonarScannerWrapper(new TestLogger());
            Action act         = () => testSubject.Execute(null, new string[] { });

            // Act & Assert
            act.Should().ThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("config");
        }
示例#5
0
        public void SonarScanner_StandardAdditionalArgumentsPassed()
        {
            // Arrange
            var logger             = new TestLogger();
            var exePath            = CreateDummarySonarScannerBatchFile();
            var propertiesFilePath = CreateDummySonarScannerPropertiesFile();
            var config             = new AnalysisConfig()
            {
                SonarScannerWorkingDirectory = TestContext.DeploymentDirectory
            };

            // Act
            var success = SonarScannerWrapper.ExecuteJavaRunner(config, Enumerable.Empty <string>(), logger, exePath, propertiesFilePath);

            // Assert
            VerifyProcessRunOutcome(logger, TestContext.DeploymentDirectory, success, true);
        }
示例#6
0
        private void TestWrapperErrorHandling(int?exitCode, bool addMessageToStdErr, bool expectedOutcome)
        {
            // Arrange
            var logger             = new TestLogger();
            var exePath            = CreateDummarySonarScannerBatchFile(addMessageToStdErr, exitCode);
            var propertiesFilePath = CreateDummySonarScannerPropertiesFile();
            var config             = new AnalysisConfig()
            {
                SonarScannerWorkingDirectory = TestContext.DeploymentDirectory
            };

            // Act
            var success = SonarScannerWrapper.ExecuteJavaRunner(config, Enumerable.Empty <string>(), logger, exePath, propertiesFilePath);

            // Assert
            VerifyProcessRunOutcome(logger, TestContext.DeploymentDirectory, success, expectedOutcome);
        }
示例#7
0
        public void SonarScannerrHome_MessageLoggedIfAlreadySet()
        {
            using (var scope = new EnvironmentVariableScope())
            {
                scope.SetVariable(SonarScannerWrapper.SonarScannerHomeVariableName, "some_path");

                // Arrange
                var testLogger         = new TestLogger();
                var exePath            = CreateDummarySonarScannerBatchFile();
                var propertiesFilePath = CreateDummySonarScannerPropertiesFile();
                var config             = new AnalysisConfig()
                {
                    SonarScannerWorkingDirectory = TestContext.DeploymentDirectory
                };

                // Act
                var success = SonarScannerWrapper.ExecuteJavaRunner(config, Enumerable.Empty <string>(), testLogger, exePath, propertiesFilePath);

                // Assert
                VerifyProcessRunOutcome(testLogger, TestContext.DeploymentDirectory, success, true);
            }
        }
示例#8
0
        public void SonarScannerHome_NoMessageIfNotAlreadySet()
        {
            // Arrange
            TestLogger testLogger         = new TestLogger();
            string     exePath            = CreateDummarySonarScannerBatchFile();
            string     propertiesFilePath = CreateDummySonarScannerPropertiesFile();

            using (EnvironmentVariableScope scope = new EnvironmentVariableScope())
            {
                scope.SetVariable(SonarScannerWrapper.SonarScannerHomeVariableName, null);
                AnalysisConfig config = new AnalysisConfig()
                {
                    SonarScannerWorkingDirectory = this.TestContext.DeploymentDirectory
                };

                // Act
                bool success = SonarScannerWrapper.ExecuteJavaRunner(config, Enumerable.Empty <string>(), testLogger, exePath, propertiesFilePath);

                // Assert
                VerifyProcessRunOutcome(testLogger, this.TestContext.DeploymentDirectory, success, true);
                testLogger.AssertMessageNotLogged(SonarScanner.Shim.Resources.MSG_SonarScannerHomeIsSet);
            }
        }
示例#9
0
        public void SonarScannerHome_NoMessageIfNotAlreadySet()
        {
            // Arrange
            var testLogger         = new TestLogger();
            var exePath            = CreateDummarySonarScannerBatchFile();
            var propertiesFilePath = CreateDummySonarScannerPropertiesFile();

            using (var scope = new EnvironmentVariableScope())
            {
                scope.SetVariable(SonarScannerWrapper.SonarScannerHomeVariableName, null);
                var config = new AnalysisConfig()
                {
                    SonarScannerWorkingDirectory = TestUtils.CreateTestSpecificFolder(TestContext)
                };

                // Act
                var success = SonarScannerWrapper.ExecuteJavaRunner(config, Enumerable.Empty <string>(), testLogger, exePath, propertiesFilePath);

                // Assert
                VerifyProcessRunOutcome(testLogger, TestUtils.CreateTestSpecificFolder(TestContext), success, true);
                testLogger.AssertMessageNotLogged(SonarScanner.MSBuild.Shim.Resources.MSG_SonarScannerHomeIsSet);
            }
        }
示例#10
0
        public void SonarScanner_CmdLineArgsOrdering()
        {
            // Check that user arguments are passed through to the wrapper and that they appear first

            // Arrange
            TestLogger logger = new TestLogger();

            string exePath            = CreateDummarySonarScannerBatchFile();
            string propertiesFilePath = CreateDummySonarScannerPropertiesFile();

            string[] userArgs = new string[] { "-Dsonar.login=me", "-Dsonar.password=my.pwd" };

            // Act
            bool success = SonarScannerWrapper.ExecuteJavaRunner(
                new AnalysisConfig()
            {
                SonarScannerWorkingDirectory = this.TestContext.DeploymentDirectory
            },
                userArgs,
                logger,
                exePath,
                propertiesFilePath);

            // Assert
            VerifyProcessRunOutcome(logger, this.TestContext.DeploymentDirectory, success, true);

            string actualCmdLineArgs = CheckStandardArgsPassed(logger, propertiesFilePath);

            int loginIndex = CheckArgExists("-Dsonar.login=me", actualCmdLineArgs);
            int pwdIndex   = CheckArgExists("-Dsonar.password=my.pwd", actualCmdLineArgs);

            int standardArgsIndex   = CheckArgExists(SonarScannerWrapper.StandardAdditionalScannerArguments, actualCmdLineArgs);
            int propertiesFileIndex = CheckArgExists(SonarScannerWrapper.ProjectSettingsFileArgName, actualCmdLineArgs);

            Assert.IsTrue(loginIndex < standardArgsIndex && loginIndex < propertiesFileIndex, "User arguments should appear first");
            Assert.IsTrue(pwdIndex < standardArgsIndex && pwdIndex < propertiesFileIndex, "User arguments should appear first");
        }
        public void SonarScanner_CmdLineArgsOrdering()
        {
            // Check that user arguments are passed through to the wrapper and that they appear first

            // Arrange
            var logger = new TestLogger();

            var exePath            = CreateDummarySonarScannerBatchFile();
            var propertiesFilePath = CreateDummySonarScannerPropertiesFile();

            var userArgs = new string[] { "-Dsonar.login=me", "-Dsonar.password=my.pwd" };

            // Act
            var success = SonarScannerWrapper.ExecuteJavaRunner(
                new AnalysisConfig()
            {
                SonarScannerWorkingDirectory = TestContext.DeploymentDirectory
            },
                userArgs,
                logger,
                exePath,
                propertiesFilePath);

            // Assert
            VerifyProcessRunOutcome(logger, TestContext.DeploymentDirectory, success, true);

            var actualCmdLineArgs = CheckStandardArgsPassed(logger, propertiesFilePath);

            var loginIndex = CheckArgExists("-Dsonar.login=me", actualCmdLineArgs);
            var pwdIndex   = CheckArgExists("-Dsonar.password=my.pwd", actualCmdLineArgs);

            var propertiesFileIndex = CheckArgExists(SonarScannerWrapper.ProjectSettingsFileArgName, actualCmdLineArgs);

            propertiesFileIndex.Should().BeGreaterThan(loginIndex, "User arguments should appear first");
            propertiesFileIndex.Should().BeGreaterThan(pwdIndex, "User arguments should appear first");
        }