Skip to content

Commit

Permalink
Add C# 9 tests for S2092
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-epure-sonarsource committed Nov 4, 2020
1 parent 1b823c4 commit 79fe6b8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ public void CookiesShouldBeSecure_NetCore() =>
new CookieShouldBeSecure(AnalyzerConfiguration.AlwaysEnabled),
additionalReferences: GetAdditionalReferences_NetCore());

[TestMethod]
[TestCategory("Rule")]
public void CookiesShouldBeSecure_NetCore_CSharp9() =>
Verifier.VerifyAnalyzer(@"TestCases\CookieShouldBeSecure_NetCore.CSharp9.cs",
new CookieShouldBeSecure(AnalyzerConfiguration.AlwaysEnabled),
ParseOptionsHelper.FromCSharp9,
outputKind: OutputKind.ConsoleApplication,
additionalReferences: GetAdditionalReferences_NetCore());

private static IEnumerable<MetadataReference> GetAdditionalReferences_NetCore() =>
NuGetMetadataReference.MicrosoftAspNetCoreHttpFeatures(Constants.NuGetLatestVersion);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using Microsoft.AspNetCore.Http;

CookieOptions topLevelStatement1 = new(); // FN
CookieOptions topLevelStatement2 = new CookieOptions(); // Noncompliant

class Program
{
CookieOptions field1 = new(); // FN
CookieOptions field2;

CookieOptions Property0 { get; init; } = new CookieOptions(); // Noncompliant
CookieOptions Property1 { get; init; } = new (); // FN
CookieOptions Property2 { get; init; }

Program()
{
Property2.Secure = false; // Noncompliant
}

void InitializerSetsNotAllowedValue()
{
CookieOptions c0 = new () { Secure = false }; // FN
CookieOptions c1 = new () { HttpOnly = true }; // FN, as Secure is not set
}
}

// See https://github.com/dotnet/roslyn/issues/45510
namespace System.Runtime.CompilerServices
{
public class IsExternalInit { }
}

0 comments on commit 79fe6b8

Please sign in to comment.