diff --git a/src/LondonTravel.Site/Controllers/ManageController.cs b/src/LondonTravel.Site/Controllers/ManageController.cs index 73f266d55..9512dfe22 100644 --- a/src/LondonTravel.Site/Controllers/ManageController.cs +++ b/src/LondonTravel.Site/Controllers/ManageController.cs @@ -10,6 +10,8 @@ using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; +#pragma warning disable SA1010 + namespace MartinCostello.LondonTravel.Site.Controllers; [Authorize] @@ -368,22 +370,22 @@ private async Task UpdateClaimsAsync(LondonTravelUser user, Exte if (user.RoleClaims == null) { - user.RoleClaims = new List(); + user.RoleClaims = []; commitUpdate = true; } foreach (var claim in info.Principal.Claims) { - bool hasClaim = user?.RoleClaims + bool hasClaim = user.RoleClaims .Where((p) => p.ClaimType == claim.Type) .Where((p) => p.Issuer == claim.Issuer) .Where((p) => p.Value == claim.Value) .Where((p) => p.ValueType == claim.ValueType) - .Any() == true; + .Any(); if (!hasClaim) { - user!.RoleClaims.Add(LondonTravelRole.FromClaim(claim)); + user.RoleClaims.Add(LondonTravelRole.FromClaim(claim)); commitUpdate = true; } } diff --git a/src/LondonTravel.Site/Middleware/CustomHttpHeadersMiddleware.cs b/src/LondonTravel.Site/Middleware/CustomHttpHeadersMiddleware.cs index f8208db15..1d6f20a1a 100644 --- a/src/LondonTravel.Site/Middleware/CustomHttpHeadersMiddleware.cs +++ b/src/LondonTravel.Site/Middleware/CustomHttpHeadersMiddleware.cs @@ -212,33 +212,33 @@ private string BuildContentSecurityPolicy(string? nonce, bool allowInlineStyles, var options = _options.CurrentValue; string? cdn = GetCdnOriginForContentSecurityPolicy(options); - var scriptDirectives = new List() - { + List scriptDirectives = + [ Csp.Self, - }; + ]; - var styleDirectives = new List() - { + List styleDirectives = + [ Csp.Self, - }; + ]; var policies = new Dictionary>() { - ["default-src"] = new[] { Csp.Self, Csp.Data }, + ["default-src"] = [Csp.Self, Csp.Data], ["script-src"] = scriptDirectives, ["style-src"] = styleDirectives, - ["img-src"] = new[] { Csp.Self, Csp.Data, cdn }, - ["font-src"] = new[] { Csp.Self }, - ["connect-src"] = new[] { Csp.Self }, - ["media-src"] = new[] { Csp.None }, - ["object-src"] = new[] { Csp.None }, - ["child-src"] = new[] { Csp.Self }, - ["frame-ancestors"] = new[] { Csp.None }, - ["form-action"] = new[] { Csp.Self }, - ["block-all-mixed-content"] = Array.Empty(), - ["base-uri"] = new[] { Csp.Self }, - ["manifest-src"] = new[] { Csp.Self }, - ["worker-src"] = new[] { Csp.Self }, + ["img-src"] = [Csp.Self, Csp.Data, cdn], + ["font-src"] = [Csp.Self], + ["connect-src"] = [Csp.Self], + ["media-src"] = [Csp.None], + ["object-src"] = [Csp.None], + ["child-src"] = [Csp.Self], + ["frame-ancestors"] = [Csp.None], + ["form-action"] = [Csp.Self], + ["block-all-mixed-content"] = [], + ["base-uri"] = [Csp.Self], + ["manifest-src"] = [Csp.Self], + ["worker-src"] = [Csp.Self], }; if (allowInlineStyles) diff --git a/tests/LondonTravel.Site.Tests/BrowserTest.cs b/tests/LondonTravel.Site.Tests/BrowserTest.cs index 8255ddcca..70467b327 100644 --- a/tests/LondonTravel.Site.Tests/BrowserTest.cs +++ b/tests/LondonTravel.Site.Tests/BrowserTest.cs @@ -167,7 +167,7 @@ protected virtual void Dispose(bool disposing) private static void InstallPlaywright() { - int exitCode = Microsoft.Playwright.Program.Main(new[] { "install" }); + int exitCode = Microsoft.Playwright.Program.Main(["install"]); if (exitCode != 0) { diff --git a/tests/LondonTravel.Site.Tests/BrowsersTestData.cs b/tests/LondonTravel.Site.Tests/BrowsersTestData.cs index edd321920..ef1908e88 100644 --- a/tests/LondonTravel.Site.Tests/BrowsersTestData.cs +++ b/tests/LondonTravel.Site.Tests/BrowsersTestData.cs @@ -10,19 +10,19 @@ public sealed class BrowsersTestData : IEnumerable { public IEnumerator GetEnumerator() { - yield return new[] { BrowserType.Chromium, null }; - yield return new[] { BrowserType.Chromium, "chrome" }; + yield return [BrowserType.Chromium, null]; + yield return [BrowserType.Chromium, "chrome"]; if (!OperatingSystem.IsLinux()) { - yield return new[] { BrowserType.Chromium, "msedge" }; + yield return [BrowserType.Chromium, "msedge"]; } - yield return new[] { BrowserType.Firefox, null }; + yield return [BrowserType.Firefox, null]; if (OperatingSystem.IsMacOS()) { - yield return new[] { BrowserType.Webkit, null }; + yield return [BrowserType.Webkit, null]; } } diff --git a/tests/LondonTravel.Site.Tests/Extensions/ClaimsPrincipalExtensionsTests.cs b/tests/LondonTravel.Site.Tests/Extensions/ClaimsPrincipalExtensionsTests.cs index 470bced72..1c379b735 100644 --- a/tests/LondonTravel.Site.Tests/Extensions/ClaimsPrincipalExtensionsTests.cs +++ b/tests/LondonTravel.Site.Tests/Extensions/ClaimsPrincipalExtensionsTests.cs @@ -38,7 +38,7 @@ public static void GetAvatarUrl_Returns_Correct_Url_If_No_Email_Claim() public static void GetAvatarUrl_Returns_Correct_Url(string email, string expected) { // Arrange - var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Email, email) }); + var identity = new ClaimsIdentity([new Claim(ClaimTypes.Email, email)]); var principal = new ClaimsPrincipal(identity); // Act @@ -52,7 +52,7 @@ public static void GetAvatarUrl_Returns_Correct_Url(string email, string expecte public static void GetAvatarUrl_Returns_Correct_Url_With_Explicit_Size() { // Arrange - var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Email, "MyEmailAddress@example.com") }); + var identity = new ClaimsIdentity([new Claim(ClaimTypes.Email, "MyEmailAddress@example.com")]); var principal = new ClaimsPrincipal(identity); // Act @@ -87,7 +87,7 @@ public static void GetDisplayName_Returns_Correct_Value_If_No_GivenName_Or_Name( public static void GetDisplayName_Returns_Correct_Value_If_No_GivenName_But_Name(string name, string expected) { // Arrange - var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, name) }); + var identity = new ClaimsIdentity([new Claim(ClaimTypes.Name, name)]); var principal = new ClaimsPrincipal(identity); // Act @@ -103,7 +103,7 @@ public static void GetDisplayName_Returns_Correct_Value_If_No_GivenName_But_Name public static void GetDisplayName_Returns_Correct_Value_If_Blank_GivenName_But_Name(string name, string expected) { // Arrange - var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, name), new Claim(ClaimTypes.GivenName, string.Empty) }); + var identity = new ClaimsIdentity([new Claim(ClaimTypes.Name, name), new Claim(ClaimTypes.GivenName, string.Empty)]); var principal = new ClaimsPrincipal(identity); // Act @@ -119,7 +119,7 @@ public static void GetDisplayName_Returns_Correct_Value_If_Blank_GivenName_But_N public static void GetDisplayName_Returns_Correct_Value_If_GivenName(string givenName, string expected) { // Arrange - var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.GivenName, givenName) }); + var identity = new ClaimsIdentity([new Claim(ClaimTypes.GivenName, givenName)]); var principal = new ClaimsPrincipal(identity); // Act diff --git a/tests/LondonTravel.Site.Tests/Services/Tfl/TflServiceTests.cs b/tests/LondonTravel.Site.Tests/Services/Tfl/TflServiceTests.cs index 5d3708fce..57c03cafd 100644 --- a/tests/LondonTravel.Site.Tests/Services/Tfl/TflServiceTests.cs +++ b/tests/LondonTravel.Site.Tests/Services/Tfl/TflServiceTests.cs @@ -202,7 +202,7 @@ private static TflOptions CreateOptions() AppId = "My-App-Id", AppKey = "My-App-Key", BaseUri = new Uri("https://api.tfl.gov.uk/"), - SupportedModes = new[] { "dlr", "elizabeth-line", "overground", "tube" }, + SupportedModes = ["dlr", "elizabeth-line", "overground", "tube"], }; } }