This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Tiku.Application.Security;
|
||||
using Tiku.Domain.Common;
|
||||
using Tiku.Domain.Identity;
|
||||
using Tiku.Domain.Operations;
|
||||
using Tiku.Domain.Tenancy;
|
||||
using Tiku.Infrastructure.Persistence;
|
||||
|
||||
namespace Tiku.IntegrationTests.Api;
|
||||
|
||||
@@ -144,9 +147,25 @@ public sealed class BackofficeUiBootstrapTests
|
||||
commandRecorder.Reset();
|
||||
using var response = await client.GetAsync("/api/platform/access/ui-bootstrap");
|
||||
using var bootstrap = JsonDocument.Parse(await response.Content.ReadAsStringAsync());
|
||||
var commands = commandRecorder.Snapshot();
|
||||
var firstRequestCommands = commandRecorder.Snapshot();
|
||||
commandRecorder.Reset();
|
||||
using var repeatedResponse = await client.GetAsync("/api/platform/access/ui-bootstrap");
|
||||
var repeatedRequestCommands = commandRecorder.Snapshot();
|
||||
|
||||
using (var scope = factory.CreateSystemScope("Revoke cached platform UI permission"))
|
||||
{
|
||||
var dbContext = scope.ServiceProvider.GetRequiredService<TikuDbContext>();
|
||||
var permission = await dbContext.PlatformBackendRolePermissions.SingleAsync(item =>
|
||||
item.RoleId == roleId && item.PermissionCode == BackendPermissions.PlatformDashboardView);
|
||||
dbContext.Remove(permission);
|
||||
await dbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
using var revokedResponse = await client.GetAsync("/api/platform/access/ui-bootstrap");
|
||||
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.OK, repeatedResponse.StatusCode);
|
||||
Assert.Equal(HttpStatusCode.Unauthorized, revokedResponse.StatusCode);
|
||||
Assert.Equal(
|
||||
[BackendPermissions.PlatformDashboardView],
|
||||
bootstrap.RootElement.GetProperty("permissionCodes").EnumerateArray().Select(item => item.GetString()));
|
||||
@@ -154,8 +173,11 @@ public sealed class BackofficeUiBootstrapTests
|
||||
["platform.dashboard"],
|
||||
bootstrap.RootElement.GetProperty("menus").EnumerateArray()
|
||||
.Select(item => item.GetProperty("code").GetString()));
|
||||
Assert.InRange(commands.Count, 1, 10);
|
||||
AssertNoPerCodeCatalogExistenceQueries(commands);
|
||||
Assert.InRange(firstRequestCommands.Count, 1, 10);
|
||||
Assert.Contains(firstRequestCommands, IsPlatformPermissionQuery);
|
||||
Assert.DoesNotContain(repeatedRequestCommands, IsPlatformPermissionQuery);
|
||||
AssertNoPerCodeCatalogExistenceQueries(firstRequestCommands);
|
||||
AssertNoPerCodeCatalogExistenceQueries(repeatedRequestCommands);
|
||||
}
|
||||
|
||||
private static void AssertNoPerCodeCatalogExistenceQueries(IEnumerable<string> commands)
|
||||
@@ -165,4 +187,10 @@ public sealed class BackofficeUiBootstrapTests
|
||||
command.TrimStart().StartsWith("SELECT EXISTS", StringComparison.OrdinalIgnoreCase) &&
|
||||
catalogTables.Any(table => command.Contains(table, StringComparison.OrdinalIgnoreCase)));
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsPlatformPermissionQuery(string command)
|
||||
{
|
||||
return command.Contains("platform_backend_role_permissions", StringComparison.OrdinalIgnoreCase) &&
|
||||
command.Contains("SELECT DISTINCT", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user