コード例 #1
0
        public async Task Function_HttpAnalyze_FileWithPAT_Should_Return_SarifLog()
        {
            const string  patTextFile = "SEC101_102.AdoPat.txt";
            IActionResult result      = await HttpAnalyzeFunction.Analyze(
                request : TestHelper.MockAnalyzeFunctionRequest(patTextFile, TestHelper.GetTestResourceContent(patTextFile)),
                log : logger,
                context : TestHelper.ContextSetup());

            ValidateResult(string.Empty, result, runCount: 1, resultCount: 2, FailureLevel.Warning, ignoreRegionContent: true);
        }
コード例 #2
0
        public async Task Function_HttpAnalyze_WithEmptyFileName_Should_Return_OK()
        {
            IActionResult result = await HttpAnalyzeFunction.Analyze(
                request : TestHelper.MockAnalyzeFunctionRequest(string.Empty, TestHelper.SampleCode),
                log : logger,
                context : TestHelper.ContextSetup());

            var resultObject = (OkObjectResult)result;

            resultObject.Should().NotBeNull();
            resultObject.StatusCode.Should().Be((int)HttpStatusCode.OK);
        }
コード例 #3
0
        public async Task Function_HttpAnalyze_WithoutFileContent_Should_Return_BadRequest()
        {
            IActionResult result = await HttpAnalyzeFunction.Analyze(
                request : TestHelper.HttpRequestSetup(new Dictionary <string, StringValues> {
                { FunctionConstants.FileNamePropertyName, "ExtensionMethods.cs" }
            }),
                log : logger,
                context : TestHelper.ContextSetup());

            var resultObject = (BadRequestResult)result;

            resultObject.Should().NotBeNull();
            resultObject.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
        }
コード例 #4
0
        public async Task Function_HttpAnalyze_NormalFileContent_Should_Return_SarifLog()
        {
            IActionResult result = await HttpAnalyzeFunction.Analyze(
                request : TestHelper.MockAnalyzeFunctionRequest("abc.cs", TestHelper.SampleCode),
                log : logger,
                context : TestHelper.ContextSetup());

            var resultObject = (OkObjectResult)result;

            resultObject.Should().NotBeNull();
            resultObject.StatusCode.Should().Be((int)HttpStatusCode.OK);
            resultObject.Value.Should().NotBeNull();

            var sarifLog = resultObject.Value as SarifLog;

            sarifLog.Should().NotBeNull();
            sarifLog.Runs.Count.Should().Be(1);
        }
コード例 #5
0
        public async Task Function_HttpAnalyze_WithFileContent_Should_Return_DifferentResponses()
        {
            const string patTextFile = "SEC101_005.SlackTokens.py";
            string       content     = TestHelper.GetTestResourceContent(patTextFile);

            string[] lines = content.Split(Environment.NewLine);

            IActionResult result = await HttpAnalyzeFunction.Analyze(
                request : TestHelper.MockAnalyzeFunctionRequest(patTextFile, lines[0]),
                log : logger,
                context : TestHelper.ContextSetup());

            ValidateResult(lines[0], result, runCount: 1, resultCount: 1, FailureLevel.Warning);

            result = await HttpAnalyzeFunction.Analyze(
                request : TestHelper.MockAnalyzeFunctionRequest(patTextFile, lines[1]),
                log : logger,
                context : TestHelper.ContextSetup());

            ValidateResult(lines[1], result, runCount: 1, resultCount: 0);
        }