/
CspFixture.cs
49 lines (42 loc) · 1.73 KB
/
CspFixture.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using CspUtils;
using FluentAssertions;
using NUnit.Framework;
namespace CspUtil.Tests
{
public class CspFixture
{
// TODO: any edge cases around default-src?
// TODO: any edge cases around *?
[Test]
public void PoliciesCanBeMerged()
{
var octopusServerPolicy = new Csp(
new CspDirective("default-src", "'self'"),
new CspDirective("script-src", "'self'"),
new CspDirective("connect-src", "'self'"),
new CspDirective("font-src", "'none'")
);
var octopusDotComPolicy = new Csp(
new CspDirective("script-src", "octopus.com"),
new CspDirective("connect-src", "octopus.com"),
new CspDirective("img-src", "octopus.com")
);
var otherServicePolicy = new Csp(
new CspDirective("script-src", "otherservice.com"),
new CspDirective("connect-src", "otherservice.com"),
new CspDirective("font-src", "otherservice.com")
);
var actual = octopusServerPolicy
.Union(octopusDotComPolicy)
.Union(otherServicePolicy);
var expected = new Csp(
new CspDirective("default-src", "'self'"),
new CspDirective("script-src", "'self'", "octopus.com", "otherservice.com"),
new CspDirective("connect-src", "'self'", "octopus.com", "otherservice.com"),
new CspDirective("font-src", "otherservice.com"),
new CspDirective("img-src", "octopus.com")
);
actual.Should().Be(expected);
}
}
}