mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
parent
a22837536d
commit
07e9870f34
4 changed files with 69 additions and 6 deletions
|
@ -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()?");
|
"Did you mean to use Cluster::publish() instead of Broker::publish()?");
|
||||||
|
|
||||||
if ( args[0]->GetType()->Tag() == zeek::TYPE_RECORD )
|
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);
|
auto* rv = args[0]->AsRecordVal();
|
||||||
rval = zeek::broker_mgr->PublishEvent(topic->CheckString(), ev->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 zeek::broker_mgr->PublishEvent(topic->CheckString(), rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rval;
|
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)
|
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