-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppTests.cs
76 lines (62 loc) · 1.98 KB
/
AppTests.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
namespace App.SecurityTests;
public class AppTests : IClassFixture<AppFixture>, IAsyncLifetime
{
private readonly AppFixture _fixture;
private SecRunner _runner;
public AppTests(AppFixture fixture)
{
_fixture = fixture;
}
public async Task InitializeAsync()
{
// Loading environment variables from .env file using https://github.com/tonerdo/dotnet-env
Env.NoClobber().TraversePath().Load();
var hostname = Environment.GetEnvironmentVariable("BRIGHT_HOSTNAME")!;
var config = new Configuration(hostname);
_runner = await SecRunner.Create(config);
await _runner.Init();
}
public async Task DisposeAsync()
{
await _runner.DisposeAsync();
GC.SuppressFinalize(this);
}
[Fact]
public async Task Post_Users_ShouldNotHaveXss()
{
var content = JsonContent.Create(new { Name = "Test" },
options: new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
var target = new Target($"{_fixture.Url}/Users")
.WithMethod(HttpMethod.Post)
.WithBody(content);
var builder = new ScanSettingsBuilder()
.WithName(nameof(Post_Users_ShouldNotHaveXss))
.WithAttackParamLocations(new List<AttackParamLocation>
{
AttackParamLocation.Body
})
.WithTests(new List<TestType> { TestType.Xss });
await _runner
.CreateScan(builder)
.Threshold(Severity.Medium)
.Run(target);
}
[Fact]
public async Task Get_Users_ShouldNotHaveSqli()
{
var target = new Target($"{_fixture.Url}/Users")
.WithMethod(HttpMethod.Get)
.WithQuery(new Dictionary<string, string> { { "name", "Test" } });
var builder = new ScanSettingsBuilder()
.WithName(nameof(Get_Users_ShouldNotHaveSqli))
.WithAttackParamLocations(new List<AttackParamLocation>
{
AttackParamLocation.Query
})
.WithTests(new List<TestType> { TestType.Sqli });
await _runner
.CreateScan(builder)
.Threshold(Severity.Medium)
.Run(target);
}
}