mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2026-09-08 18:20:49 +00:00
Limits
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
using Esiur.Core;
|
||||
using Esiur.Data;
|
||||
using Esiur.Data.Types;
|
||||
using Esiur.Protocol;
|
||||
using Esiur.Resource;
|
||||
using Esiur.Security.Authority;
|
||||
using Esiur.Security.Permissions;
|
||||
|
||||
namespace Esiur.Tests.Unit.Integration;
|
||||
|
||||
@@ -36,10 +41,68 @@ public class AttachmentSecurityTests
|
||||
Assert.Equal(1, cluster.Connection.ResourceAttachRequestCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task PropertyNotifications_RespectPerPropertyReadPermission()
|
||||
{
|
||||
PropertyBroadcastResource? source = null;
|
||||
await using var cluster = await IntegrationCluster.StartAsync(async warehouse =>
|
||||
{
|
||||
var permissions = new PropertyBroadcastPermissions();
|
||||
warehouse.RegisterManager(permissions);
|
||||
source = await warehouse.Put("sys/property-broadcast", new PropertyBroadcastResource());
|
||||
source.Instance!.Managers.Add(permissions);
|
||||
}).WaitAsync(TimeSpan.FromSeconds(10));
|
||||
|
||||
var remote = (EpResource)await cluster.Connection.Get("sys/property-broadcast");
|
||||
var received = new List<string>();
|
||||
remote.Instance.PropertyModified += info => received.Add(info.PropertyDef.Name);
|
||||
|
||||
source!.Secret = 7;
|
||||
source.Visible = 9;
|
||||
|
||||
var deadline = DateTime.UtcNow + TimeSpan.FromSeconds(3);
|
||||
while (!received.Contains(nameof(PropertyBroadcastResource.Visible)) &&
|
||||
DateTime.UtcNow < deadline)
|
||||
await Task.Delay(20);
|
||||
|
||||
Assert.Contains(nameof(PropertyBroadcastResource.Visible), received);
|
||||
Assert.DoesNotContain(nameof(PropertyBroadcastResource.Secret), received);
|
||||
}
|
||||
|
||||
static Task<IntegrationCluster> StartCluster()
|
||||
=> IntegrationCluster.StartAsync(async warehouse =>
|
||||
{
|
||||
await warehouse.Put("sys/first", new RateLimitedResource());
|
||||
await warehouse.Put("sys/second", new RateLimitedResource());
|
||||
});
|
||||
|
||||
sealed class PropertyBroadcastPermissions : IPermissionsManager
|
||||
{
|
||||
public Map<string, object> Settings { get; } = new();
|
||||
|
||||
public Ruling Applicable(
|
||||
IResource resource,
|
||||
Session session,
|
||||
ActionType action,
|
||||
MemberDef member,
|
||||
object inquirer = null!)
|
||||
{
|
||||
if (action == ActionType.Attach)
|
||||
return Ruling.Allowed;
|
||||
if (action == ActionType.GetProperty)
|
||||
return member?.Name == nameof(PropertyBroadcastResource.Secret)
|
||||
? Ruling.Denied
|
||||
: Ruling.Allowed;
|
||||
return Ruling.DontCare;
|
||||
}
|
||||
|
||||
public bool Initialize(Map<string, object> settings, IResource resource) => true;
|
||||
}
|
||||
}
|
||||
|
||||
[Resource]
|
||||
public partial class PropertyBroadcastResource
|
||||
{
|
||||
[Export] int secret;
|
||||
[Export] int visible;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,46 @@ using System.Net;
|
||||
[Collection("Integration")]
|
||||
public class SessionHeadersIntegrationTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task Handshake_ExchangesParserAndEncryptedRecordBudgetsInBothDirections()
|
||||
{
|
||||
await using var cluster = await IntegrationCluster
|
||||
.StartAsync(
|
||||
warehouse =>
|
||||
{
|
||||
warehouse.Configuration.Parser.MaximumPacketSize = 7_100_001;
|
||||
warehouse.Configuration.Parser.MaximumAllocationSize = 3_100_002;
|
||||
warehouse.Configuration.Parser.MaximumCollectionItems = 51_003;
|
||||
warehouse.Configuration.Parser.MaximumTypeMetadataDepth = 54;
|
||||
warehouse.Configuration.Encryption.MaximumRecordSize = 7_101_004;
|
||||
return Task.CompletedTask;
|
||||
},
|
||||
populateClient: warehouse =>
|
||||
{
|
||||
warehouse.Configuration.Parser.MaximumPacketSize = 6_200_001;
|
||||
warehouse.Configuration.Parser.MaximumAllocationSize = 2_200_002;
|
||||
warehouse.Configuration.Parser.MaximumCollectionItems = 42_003;
|
||||
warehouse.Configuration.Parser.MaximumTypeMetadataDepth = 45;
|
||||
warehouse.Configuration.Encryption.MaximumRecordSize = 6_201_004;
|
||||
return Task.CompletedTask;
|
||||
})
|
||||
.WaitAsync(TimeSpan.FromSeconds(10));
|
||||
|
||||
var serverConnection = Assert.Single(cluster.Server.Connections);
|
||||
|
||||
Assert.Equal(7_100_001u, cluster.Connection.Session.RemoteMaximumPacketSize);
|
||||
Assert.Equal(3_100_002u, cluster.Connection.Session.RemoteMaximumAllocationSize);
|
||||
Assert.Equal(51_003, cluster.Connection.Session.RemoteMaximumCollectionItems);
|
||||
Assert.Equal(54, cluster.Connection.Session.RemoteMaximumTypeMetadataDepth);
|
||||
Assert.Equal(7_101_004u, cluster.Connection.Session.RemoteMaximumEncryptedRecordSize);
|
||||
|
||||
Assert.Equal(6_200_001u, serverConnection.Session.RemoteMaximumPacketSize);
|
||||
Assert.Equal(2_200_002u, serverConnection.Session.RemoteMaximumAllocationSize);
|
||||
Assert.Equal(42_003, serverConnection.Session.RemoteMaximumCollectionItems);
|
||||
Assert.Equal(45, serverConnection.Session.RemoteMaximumTypeMetadataDepth);
|
||||
Assert.Equal(6_201_004u, serverConnection.Session.RemoteMaximumEncryptedRecordSize);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AcceptedConnection_RaisesReadyAndDisconnectedLifecycleEvents()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user