mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-16 23:30:41 +09:00
Filter plugin messages forwarded to links
Drop events forwarded to a slave or instance that does not have the plugin the event is defined in. Reject requests for the same reason.
This commit is contained in:
1 parent
ca2839594e
commit
a194508f52
8 files changed
+108
-37
No files matched your search
+11
-5
@@ -96,19 +96,25 @@ describe("lib/plugin", function() {
|
||||
|
||||
describe("attachPluginMessages()", function() {
|
||||
let mockLink = new link.Link('source', 'target', new mock.MockConnector());
|
||||
let mockEvent = new link.Event({ type: 'test', links: ['target-source'] });
|
||||
let mockEvent = new link.Event({ type: "test:test", links: ["target-source"] });
|
||||
it("should accept pluginInfo without messages", function() {
|
||||
plugin.attachPluginMessages(mockLink, {}, null);
|
||||
});
|
||||
it("should attach handler for the given message", function() {
|
||||
let mockEventEventHandler = function() {};
|
||||
plugin.attachPluginMessages(mockLink, { messages: { mockEvent }}, { mockEventEventHandler });
|
||||
assert(mockLink._handlers.get('test_event'), "handler was not registered");
|
||||
plugin.attachPluginMessages(mockLink, { name: "test", messages: { mockEvent }}, { mockEventEventHandler });
|
||||
assert(mockLink._handlers.get("test:test_event"), "handler was not registered");
|
||||
});
|
||||
it("should throw if missing handler for the given message", function() {
|
||||
assert.throws(
|
||||
() => plugin.attachPluginMessages(mockLink, { messages: { mockEvent }}, {}),
|
||||
new Error("Missing handler for test_event on source-target link")
|
||||
() => plugin.attachPluginMessages(mockLink, { name: "test", messages: { mockEvent }}, {}),
|
||||
new Error("Missing handler for test:test_event on source-target link")
|
||||
);
|
||||
});
|
||||
it("should throw if message starts with the wrong prefix", function() {
|
||||
assert.throws(
|
||||
() => plugin.attachPluginMessages(mockLink, { name: "foo", messages: { mockEvent }}, {}),
|
||||
new Error('Type of mockEvent message must start with "foo:"')
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user