From 2effd967054aca3af8d2c37b1a01179af62cda81 Mon Sep 17 00:00:00 2001 From: Shaopeng Li Date: Thu, 30 Nov 2023 20:40:28 -0800 Subject: [PATCH] Release History --- ReleaseHistory.md | 1 + .../CommandLineTests.cs | 37 ++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/ReleaseHistory.md b/ReleaseHistory.md index e48c5494..191d104d 100644 --- a/ReleaseHistory.md +++ b/ReleaseHistory.md @@ -16,6 +16,7 @@ - NEW => new feature ## UNRELEASED +* NEW: Add `--disable-telemetry` argument to disable telemetry collection. ## **v4.2.1** * FPS: `BA2004.EnableSecureSourceCodeHashing` now will no longer generate false positives on precompiled headers, they are always without hash. [#965](https://github.com/microsoft/binskim/pull/965) diff --git a/src/Test.FunctionalTests.BinSkim.Driver/CommandLineTests.cs b/src/Test.FunctionalTests.BinSkim.Driver/CommandLineTests.cs index c81084ea..370dbdd2 100644 --- a/src/Test.FunctionalTests.BinSkim.Driver/CommandLineTests.cs +++ b/src/Test.FunctionalTests.BinSkim.Driver/CommandLineTests.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -10,7 +11,6 @@ using FluentAssertions; using Microsoft.CodeAnalysis.IL; -using Microsoft.CodeAnalysis.Sarif.Driver; using Xunit; @@ -70,5 +70,40 @@ public void MostlyFunctionlessCommandlineTest() builder.Length.Should().Be(0, $"all test cases should pass, but the following test cases failed:\n{builder}"); } + + [Fact] + public void DisableTelemetryCommandlineTest() + { + var testCases = new List>() + { + new Tuple(@"analyze C:\Native.exe -o C:\result.sarif", null), + new Tuple(@"analyze C:\Native.exe -o C:\result.sarif --disable-telemetry true", true), + new Tuple(@"analyze C:\Native.exe -o C:\result.sarif --disable-telemetry false", false) + }; + + var builder = new StringBuilder(); + + foreach (Tuple testCase in testCases) + { + string[] args = testCase.Item1.Split(' '); + bool parser = new Parser(cfg => cfg.CaseInsensitiveEnumValues = true).ParseArguments(args) + .MapResult( + options => + { + if (options.DisableTelemetry != testCase.Item2) + { + builder.AppendLine($"\u2022 {testCase.Item1}"); + } + return true; + }, + err => + { + builder.AppendLine($"\u2022 {testCase.Item1}"); + return true; + }); + } + builder.Length.Should().Be(0, + $"all test cases should pass, but the following test cases failed:\n{builder}"); + } } }