mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-16 15:30:41 +09:00
Drop subscriptions when a user loses permission for them
The permission for a subscription was only checked when subscribing, so a control connection kept receiving events after the user's roles or role permissions changed to no longer allow it. Add SubscriptionController.unsubscribeUnpermitted which rechecks every subscription of a link and removes the ones the user is no longer permitted, and call it for the affected control connections from userPermissionsUpdated and rolesUpdated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ce6bfe282f
commit
beec2f523a
4 files changed
+103
No files matched your search
@@ -552,6 +552,57 @@ describe("lib/subscriptions", function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe(".unsubscribeUnpermitted()", function() {
|
||||
class DenyingUser {
|
||||
constructor(denied) {
|
||||
this.denied = denied;
|
||||
}
|
||||
|
||||
checkPermission(permission) {
|
||||
if (permission === this.denied) {
|
||||
throw new lib.PermissionError("Permission denied");
|
||||
}
|
||||
}
|
||||
}
|
||||
beforeEach(async function() {
|
||||
subscriptions.handle(StringPermissionEvent);
|
||||
subscriptions.handle(FunctionPermissionEvent);
|
||||
for (const connectorData of connectorSetupDate) {
|
||||
for (const Event of [StringPermissionEvent, FunctionPermissionEvent]) {
|
||||
const request = new lib.SubscriptionRequest(Event.name, "subscribe");
|
||||
await subscriptions.handleRequest(getLink(connectorData.id), request, connectorData.dst);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it("should remove subscriptions with a string permission the user lost", async function() {
|
||||
subscriptions.unsubscribeUnpermitted(getLink(0), new DenyingUser("StringPermission"));
|
||||
subscriptions.broadcast(new StringPermissionEvent());
|
||||
await onceConnectorSend(1);
|
||||
assertNoEvent(0);
|
||||
subscriptions.broadcast(new FunctionPermissionEvent());
|
||||
await onceConnectorSend(0);
|
||||
assertLastEvent(0, FunctionPermissionEvent);
|
||||
});
|
||||
|
||||
it("should remove subscriptions with a function permission the user lost", async function() {
|
||||
subscriptions.unsubscribeUnpermitted(getLink(0), new DenyingUser("FunctionPermission"));
|
||||
subscriptions.broadcast(new FunctionPermissionEvent());
|
||||
await onceConnectorSend(1);
|
||||
assertNoEvent(0);
|
||||
subscriptions.broadcast(new StringPermissionEvent());
|
||||
await onceConnectorSend(0);
|
||||
assertLastEvent(0, StringPermissionEvent);
|
||||
});
|
||||
|
||||
it("should keep subscriptions the user still has permission for", async function() {
|
||||
subscriptions.unsubscribeUnpermitted(getLink(0), new DenyingUser(null));
|
||||
subscriptions.broadcast(new StringPermissionEvent());
|
||||
await onceConnectorSend(0);
|
||||
assertLastEvent(0, StringPermissionEvent);
|
||||
});
|
||||
});
|
||||
|
||||
describe(".handleRequest()", function() {
|
||||
beforeEach(function() {
|
||||
subscriptions.handle(RegisteredEvent);
|
||||
|
||||
Reference in new issue
Block a user