-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started implementing CSP Nonce (#30)
* Started implementing CSP Nonce * Removed nonce definition * Removed Helpers * Changed to update header to include nonce only if called by the TagHelper * Reworked with service * Removed as unrequired * Changed to check context * Fixed incorrect key * Reversed check * Added ability to output data-attribute nonce * Removed unused class * Removed unused interface * Corrected check * Updated readme * Moved to constant * Updated more places to use constants * Branch update and some code changes * Code changes reordered CSP directives * code clean up and testing fix * Build fixes * Build pipeline permissions * Test reporter doesnt support external PRS so need to split into two actions * fix yaml formatting * Fix test run report uploading * Fix report yaml * Fixing reporting * Fixing reporting * Update step versions --------- Co-authored-by: Matthew Wise <6782865+Matthew-Wise@users.noreply.github.com>
- Loading branch information
1 parent
d67bea2
commit d293004
Showing
20 changed files
with
435 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: 'Test Report' | ||
on: | ||
workflow_run: | ||
workflows: [Build] # runs after Build workflow | ||
types: | ||
- completed | ||
permissions: | ||
contents: read | ||
actions: read | ||
checks: write | ||
jobs: | ||
report: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: dorny/test-reporter@v1 | ||
with: | ||
artifact: test-results # artifact name | ||
name: .NET Tests # Name of the check run which will be created | ||
path: "**/test-results.trx" # Path to test results (inside artifact .zip) | ||
reporter: dotnet-trx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
58 changes: 58 additions & 0 deletions
58
src/Umbraco.Community.CSPManager.Tests/Middleware/MiddlewareTestCases.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
namespace Umbraco.Community.CSPManager.Tests.Middleware; | ||
|
||
using System.Collections.Generic; | ||
using Umbraco.Cms.Core; | ||
using Umbraco.Community.CSPManager.Models; | ||
|
||
internal static class MiddlewareTestCases | ||
{ | ||
public static IEnumerable<TestCaseData> CspMiddlewareReturnsExpectedCspWhenEnabledCases | ||
{ | ||
get | ||
{ | ||
yield return new TestCaseData("/umbraco", | ||
new CspDefinition | ||
{ | ||
Id = CspConstants.DefaultBackofficeId, | ||
Enabled = true, | ||
IsBackOffice = true, | ||
Sources = CspConstants.DefaultBackOfficeCsp | ||
}) | ||
{ TestName = "Backoffice enabled" }; | ||
|
||
yield return new TestCaseData("/umbraco", | ||
new CspDefinition | ||
{ | ||
Id = CspConstants.DefaultBackofficeId, | ||
Enabled = true, | ||
IsBackOffice = true, | ||
ReportOnly = true, | ||
Sources = CspConstants.DefaultBackOfficeCsp | ||
}) | ||
{ TestName = "Backoffice Report Only" }; | ||
|
||
yield return new TestCaseData("/umbraco", | ||
new CspDefinition | ||
{ | ||
Id = CspConstants.DefaultBackofficeId, | ||
Enabled = false, | ||
IsBackOffice = true, | ||
Sources = CspConstants.DefaultBackOfficeCsp | ||
}) | ||
{ TestName = "Backoffice disabled" }; | ||
} | ||
} | ||
|
||
public static IEnumerable<TestCaseData> CspMiddlewareOnlyRunsWithRuntimeRunCases | ||
{ | ||
get | ||
{ | ||
yield return new TestCaseData(RuntimeLevel.Run, Times.Once()); | ||
yield return new TestCaseData(RuntimeLevel.Install, Times.Never()); | ||
yield return new TestCaseData(RuntimeLevel.Upgrade, Times.Never()); | ||
yield return new TestCaseData(RuntimeLevel.Boot, Times.Never()); | ||
yield return new TestCaseData(RuntimeLevel.BootFailed, Times.Never()); | ||
yield return new TestCaseData(RuntimeLevel.Unknown, Times.Never()); | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/Umbraco.Community.CSPManager.Tests/Services/CspServiceTestCases.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
namespace Umbraco.Community.CSPManager.Tests.Services; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Umbraco.Community.CSPManager.Models; | ||
|
||
internal class CspServiceTestCases | ||
{ | ||
public static IEnumerable<TestCaseData> SaveCspDefinitionSource | ||
{ | ||
get | ||
{ | ||
var oneLessSource = new CspDefinition | ||
{ | ||
Id = CspConstants.DefaultBackofficeId, | ||
Enabled = true, | ||
IsBackOffice = true, | ||
Sources = CspConstants.DefaultBackOfficeCsp.GetRange(0, CspConstants.DefaultBackOfficeCsp.Count - 1) | ||
}; | ||
|
||
yield return new TestCaseData(oneLessSource) { TestName = "Remove a CSP Source from a Definition" }; | ||
|
||
var additionalSource = CspConstants.DefaultBackOfficeCsp.ToList(); | ||
additionalSource.Add(new CspDefinitionSource | ||
{ | ||
DefinitionId = CspConstants.DefaultBackofficeId, | ||
Directives = new() { CspConstants.Directives.BaseUri }, | ||
Source = "test" | ||
}); | ||
|
||
yield return new TestCaseData(new CspDefinition | ||
{ | ||
Id = CspConstants.DefaultBackofficeId, | ||
Enabled = true, | ||
IsBackOffice = true, | ||
Sources = additionalSource | ||
}) | ||
{ TestName = "Add a CSP Source to a Definition" }; | ||
|
||
|
||
var longSource = CspConstants.DefaultBackOfficeCsp.ToList(); | ||
longSource.Add(new CspDefinitionSource | ||
{ | ||
DefinitionId = CspConstants.DefaultBackofficeId, | ||
Directives = new() { CspConstants.Directives.BaseUri }, | ||
Source = new string('a', 300) | ||
}); | ||
|
||
|
||
yield return new TestCaseData(new CspDefinition | ||
{ | ||
Id = CspConstants.DefaultBackofficeId, | ||
Enabled = true, | ||
IsBackOffice = true, | ||
Sources = additionalSource | ||
}) | ||
{ TestName = "Add a CSP Long Source to a Definition" }; | ||
} | ||
} | ||
} |
Oops, something went wrong.