stryker-mutator / stryker-net

Mutation testing for .NET core and .NET framework!
https://stryker-mutator.io
Apache License 2.0
1.76k stars 175 forks source link

Passing an invalid query string for azure-fileshare-sas results in a NullReferenceException #2725

Closed BasdeBruynInfoSupport closed 1 month ago

BasdeBruynInfoSupport commented 10 months ago

Describe the bug When passing --azure-fileshare-sas to the stryker cli and the value doesn't contain any query paramaters, stryker throws a NullReferenceException. This happens because Stryker.Core.Options.Inputs.AzureFileStorageSasInput.Validate() parses the given SAS credential as a query string, then loops through all keys where it doesn't check if the keys are null.

var query = HttpUtility.ParseQueryString(SuppliedInput);

var hasImportantKey = query.AllKeys.Where(x => x.Equals("sv", System.StringComparison.InvariantCultureIgnoreCase) || x.Equals("sig", System.StringComparison.InvariantCultureIgnoreCase));

x in the Where statement can be null, so calling Equals on it can result in a NullReferenceException.

Logs

Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
    at Stryker.Core.Options.Inputs.AzureFileStorageSasInput.<>c.<Validate>b__4_0(String x) in .\stryker-net-fork\src\Stryker.Core\Stryker.Core\Options\Inputs\AzureFileStorageSasInput.cs:line 25  
    at System.Linq.Enumerable.WhereArrayIterator`1.GetCount(Boolean onlyIfCheap)
    at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source)
    at Stryker.Core.Options.Inputs.AzureFileStorageSasInput.Validate(BaselineProvider baselineProvider) in .\stryker-net-fork\src\Stryker.Core\Stryker.Core\Options\Inputs\AzureFileStorageSasInput.cs:line 27
    at Stryker.Core.Options.StrykerInputs.ValidateAll() in .\stryker-net-fork\src\Stryker.Core\Stryker.Core\Options\StrykerInputs.cs:line 120
    at Stryker.Core.StrykerRunner.RunMutationTest(IStrykerInputs inputs, ILoggerFactory loggerFactory, IProjectOrchestrator projectOrchestrator) in .\stryker-net-fork\src\Stryker.Core\Stryker.Core\StrykerRunner.cs:line 53
    at Stryker.CLI.StrykerCli.RunStryker(IStrykerInputs inputs) in .\stryker-net-fork\src\Stryker.CLI\Stryker.CLI\StrykerCLI.cs:line 93
    at Stryker.CLI.StrykerCli.<>c__DisplayClass10_0.<Run>b__0() in .\stryker-net-fork\src\Stryker.CLI\Stryker.CLI\StrykerCLI.cs:line 68
    at McMaster.Extensions.CommandLineUtils.CommandLineApplication.<>c__DisplayClass143_0.<OnExecute>b__0(CancellationToken _)
    at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync(String[] args, CancellationToken cancellationToken)
    at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
    at Stryker.CLI.StrykerCli.Run(String[] args) in .\stryker-net-fork\src\Stryker.CLI\Stryker.CLI\StrykerCLI.cs:line 74
    at Stryker.CLI.Program.Main(String[] args) in .\stryker-net-fork\src\Stryker.CLI\Stryker.CLI\Program.cs:line 14

Expected behavior Stryker should stop and inform you that your SAS credentials are invalid. Maybe even that it is incorrectly formatted.

Desktop (please complete the following information):

Additional context