43 lines
1.7 KiB
C#
43 lines
1.7 KiB
C#
using System.Net.Http.Json;
|
|||
|
|
using System.Text.Json;
|
||
|
|
using Heimdall.IntegrationTests.Factories;
|
||
|
|
using Shouldly;
|
||
|
|
|
||
|
|
namespace Heimdall.IntegrationTests.Controllers;
|
||
|
|
|
||
|
|
public class PermissionsControllerTests : PostgresTestBase
|
||
|
|
{
|
||
|
|
public PermissionsControllerTests(PostgreSqlContainerFixture postgres) : base(postgres) { }
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public async Task List_WithoutAuth_ReturnsUnauthorized()
|
||
|
|
{
|
||
|
|
var client = Factory.CreateClient();
|
||
|
|
var response = await client.GetAsync("api/permissions");
|
||
|
|
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.Unauthorized);
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public async Task List_WithAdminAuth_ReturnsOk()
|
||
|
|
{
|
||
|
|
var client = await Factory.CreateAdminClientAsync();
|
||
|
|
var response = await client.GetAsync("api/permissions");
|
||
|
|
response.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
|
||
|
|
|
||
|
|
var content = await response.Content.ReadFromJsonAsync<JsonElement>();
|
||
|
|
content.GetProperty("permissions").GetArrayLength().ShouldBeGreaterThan(0);
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public async Task List_ContainsExpectedPermissions()
|
||
|
|
{
|
||
|
|
var client = await Factory.CreateAdminClientAsync();
|
||
|
|
var response = await client.GetAsync("api/permissions");
|
||
|
|
var content = await response.Content.ReadFromJsonAsync<JsonElement>();
|
||
|
|
var permissions = content.GetProperty("permissions").EnumerateArray().ToList();
|
||
|
|
|
||
|
|
permissions.Any(p => p.GetProperty("name").GetString() == "Site.Read").ShouldBeTrue();
|
||
|
|
permissions.Any(p => p.GetProperty("name").GetString() == "Camera.Read").ShouldBeTrue();
|
||
|
|
permissions.Any(p => p.GetProperty("name").GetString() == "Event.Read").ShouldBeTrue();
|
||
|
|
}
|
||
|
|
}
|