mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Merge remote-tracking branch 'origin/topic/awelzel/4571-reject-cluster-event-broker-publish'
* origin/topic/awelzel/4571-reject-cluster-event-broker-publish: broker: Handle Broker::publish() with non Broker::Event
This commit is contained in:
commit
b0a26eddaa
6 changed files with 74 additions and 7 deletions
4
CHANGES
4
CHANGES
|
@ -1,3 +1,7 @@
|
|||
8.0.0-dev.445 | 2025-06-22 15:48:21 +0200
|
||||
|
||||
* GH-4571: broker: Handle Broker::publish() with non Broker::Event (Arne Welzel, Corelight)
|
||||
|
||||
8.0.0-dev.443 | 2025-06-18 13:27:06 +0100
|
||||
|
||||
* Change x509 not_before/not_after to not be based on local timezone (Johanna Amann, Corelight)
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
8.0.0-dev.443
|
||||
8.0.0-dev.445
|
||||
|
|
|
@ -66,15 +66,22 @@ static bool publish_event_args(ArgsSpan args, const zeek::String* topic,
|
|||
"Did you mean to use Cluster::publish() instead of Broker::publish()?");
|
||||
|
||||
if ( args[0]->GetType()->Tag() == zeek::TYPE_RECORD )
|
||||
rval = zeek::broker_mgr->PublishEvent(topic->CheckString(),
|
||||
args[0]->AsRecordVal());
|
||||
else
|
||||
{
|
||||
auto ev = zeek::broker_mgr->MakeEvent(args, frame);
|
||||
rval = zeek::broker_mgr->PublishEvent(topic->CheckString(), ev->AsRecordVal());
|
||||
auto* rv = args[0]->AsRecordVal();
|
||||
|
||||
// same_type() should be fast if it's the type pointers are the same.
|
||||
if ( ! zeek::same_type(rv->GetType(), zeek::BifType::Record::Broker::Event) )
|
||||
{
|
||||
zeek::emit_builtin_error(zeek::util::fmt("expected Broker::Event, got %s",
|
||||
zeek::obj_desc_short(rv->GetType()).c_str()));
|
||||
return false;
|
||||
}
|
||||
|
||||
return rval;
|
||||
return zeek::broker_mgr->PublishEvent(topic->CheckString(), rv);
|
||||
}
|
||||
|
||||
auto ev = zeek::broker_mgr->MakeEvent(args, frame);
|
||||
return zeek::broker_mgr->PublishEvent(topic->CheckString(), ev->AsRecordVal());
|
||||
}
|
||||
|
||||
static bool is_cluster_pool(zeek::Val* pool)
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
error in ../send.zeek, line 18: expected Broker::Event, got Cluster::Event (Broker::publish(/test/topic, <internal>::evt.18))
|
|
@ -0,0 +1,2 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
error in ../send.zeek, line 18: expected Broker::Event, got Cluster::Event (Broker::publish(/test/topic, evt))
|
52
testing/btest/broker/publish-errors.zeek
Normal file
52
testing/btest/broker/publish-errors.zeek
Normal file
|
@ -0,0 +1,52 @@
|
|||
# @TEST-DOC: Test that calling Broker::publish() with a Cluster::Event instance fails. Regression test for #4571.
|
||||
#
|
||||
# @TEST-GROUP: broker
|
||||
#
|
||||
# @TEST-PORT: BROKER_PORT
|
||||
#
|
||||
# @TEST-EXEC: btest-bg-run recv "zeek -b ../recv.zeek"
|
||||
# @TEST-EXEC: btest-bg-run send "zeek -b ../send.zeek"
|
||||
#
|
||||
# @TEST-EXEC: btest-bg-wait 30
|
||||
#
|
||||
# @TEST-EXEC: btest-diff send/.stderr
|
||||
|
||||
# @TEST-START-FILE send.zeek
|
||||
redef exit_only_after_terminate = T;
|
||||
|
||||
event my_event(i: count)
|
||||
{
|
||||
# Not supposed to be invoked!
|
||||
exit(1);
|
||||
}
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
Broker::peer("127.0.0.1", to_port(getenv("BROKER_PORT")));
|
||||
}
|
||||
|
||||
event Broker::peer_added(endpoint: Broker::EndpointInfo, msg: string)
|
||||
{
|
||||
print "peer added", msg;
|
||||
local evt = Cluster::make_event(my_event, 42);
|
||||
local r = Broker::publish("/test/topic", evt);
|
||||
assert ! r; # Supposed to fail.
|
||||
exit(0);
|
||||
}
|
||||
# @TEST-END-FILE
|
||||
|
||||
|
||||
# @TEST-START-FILE recv.zeek
|
||||
|
||||
redef exit_only_after_terminate = T;
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
Broker::listen("127.0.0.1", to_port(getenv("BROKER_PORT")));
|
||||
}
|
||||
|
||||
event Broker::peer_lost(endpoint: Broker::EndpointInfo, msg: string)
|
||||
{
|
||||
terminate();
|
||||
}
|
||||
# @TEST-END-FILE
|
Loading…
Add table
Add a link
Reference in a new issue