blob: 69be91871ed9e1a7245175927b89fc1863004d3a (
plain)
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
|
using FluentAssertions;
using Microsoft.AspNetCore.Mvc.Testing;
using System.Net;
using System.Threading.Tasks;
using TimelineApp.Tests.Helpers;
using Xunit;
namespace TimelineApp.Tests.IntegratedTests
{
public class AuthorizationTest : IntegratedTestBase
{
public AuthorizationTest(WebApplicationFactory<Startup> factory)
: base(factory)
{
}
private const string BaseUrl = "testing/auth/";
private const string AuthorizeUrl = BaseUrl + "Authorize";
private const string UserUrl = BaseUrl + "User";
private const string AdminUrl = BaseUrl + "Admin";
[Fact]
public async Task UnauthenticationTest()
{
using var client = await CreateDefaultClient();
var response = await client.GetAsync(AuthorizeUrl);
response.Should().HaveStatusCode(HttpStatusCode.Unauthorized);
}
[Fact]
public async Task AuthenticationTest()
{
using var client = await CreateClientAsUser();
var response = await client.GetAsync(AuthorizeUrl);
response.Should().HaveStatusCode(HttpStatusCode.OK);
}
[Fact]
public async Task UserAuthorizationTest()
{
using var client = await CreateClientAsUser();
var response1 = await client.GetAsync(UserUrl);
response1.Should().HaveStatusCode(HttpStatusCode.OK);
var response2 = await client.GetAsync(AdminUrl);
response2.Should().HaveStatusCode(HttpStatusCode.Forbidden);
}
[Fact]
public async Task AdminAuthorizationTest()
{
using var client = await CreateClientAsAdministrator();
var response1 = await client.GetAsync(UserUrl);
response1.Should().HaveStatusCode(HttpStatusCode.OK);
var response2 = await client.GetAsync(AdminUrl);
response2.Should().HaveStatusCode(HttpStatusCode.OK);
}
}
}
|