-
Notifications
You must be signed in to change notification settings - Fork 0
/
receive_event_certs.test
117 lines (95 loc) · 2.95 KB
/
receive_event_certs.test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# @TEST-PORT: BTEST_BROKER_WEB_SOCKET_PORT
# @TEST-EXEC: btest-bg-run sender "SSL_CAFILE=${FILES}/minica.pem SSL_CERTIFICATE=${FILES}/cert.pem SSL_KEYFILE=${FILES}/key.pem zeek ../test.zeek > send.out"
# @TEST-EXEC: SSL_CAFILE=${FILES}/minica.pem SSL_CERTIFICATE=${FILES}/cert.pem SSL_KEYFILE=${FILES}/key.pem go run test.go > receive.out
# @TEST-EXEC: btest-bg-wait -k 10
# @TEST-EXEC: btest-diff receive.out
# @TEST-EXEC: btest-diff sender/send.out
# @TEST-START-FILE test.zeek
redef exit_only_after_terminate = T;
redef Broker::ssl_cafile = getenv("SSL_CAFILE");
redef Broker::ssl_certificate = getenv("SSL_CERTIFICATE");
redef Broker::ssl_keyfile = getenv("SSL_KEYFILE");
global test_topic = "/topic/test";
export {
type color: enum { Red = 10, White = 20, Blue = 30 };
global test: event(a1: bool, a2: int, a3: count, a4: double, a5: time, a6: interval, a7: string, a8: port,
a9: addr, a10: subnet, a11: color, a12: table[count] of string, a13: set[port], a14: vector of string);
}
event zeek_init()
{
Broker::listen_websocket("127.0.0.1", to_port(getenv("BTEST_BROKER_WEB_SOCKET_PORT")));
}
event Broker::peer_added(endpoint: Broker::EndpointInfo, msg: string)
{
local e = Broker::make_event(test,
T,
-42,
42,
3.14159,
double_to_time(1683001909),
3.5 min,
"hi",
6667/tcp,
1.2.3.4,
1.2.3.0/24,
White,
table(
[11] = "eleven",
[5] = "five",
),
set(21/tcp, 23/tcp, 80/tcp, 443/tcp),
vector("one", "two", "three"),
);
print(e);
Broker::publish(test_topic, e);
}
event Broker::peer_lost(endpoint: Broker::EndpointInfo, msg: string)
{
terminate();
}
# @TEST-END-FILE
# @TEST-START-FILE test.go
package main
import (
"context"
"fmt"
"os"
"strings"
"net"
"github.com/corelight/go-zeek-broker-ws/pkg/client"
"github.com/corelight/go-zeek-broker-ws/pkg/encoding"
"github.com/corelight/go-zeek-broker-ws/pkg/securetls"
)
func main() {
topic := "/topic/test"
portString := os.Getenv("BTEST_BROKER_WEB_SOCKET_PORT")
if portString == "" {
panic("BTEST_BROKER_WEB_SOCKET_PORT not set")
}
portString = strings.TrimSuffix(portString, "/tcp")
hostPort := fmt.Sprintf("localhost:%s", portString)
ctx := context.Background()
dialFunc := securetls.MakeSecureDialer(os.Getenv("SSL_CAFILE"), os.Getenv("SSL_CERTIFICATE"), os.Getenv("SSL_KEYFILE"))
broker, err := client.NewClient(ctx, hostPort, true, dialFunc, []string{topic})
if err != nil {
panic(err)
}
defer func() {
_ = broker.Close()
}()
topic, event, err := broker.ReadEvent()
if err != nil {
panic(err)
}
fmt.Printf("topic=%s\nname=%s\n", topic, event.Name)
for i, arg := range event.Arguments {
switch arg.DataType {
case encoding.TypeSubnet:
subnet := arg.DataValue.(*net.IPNet)
fmt.Printf("a%d=encoding.Data{DataType:\"subnet\", DataValue:\"%s\"} // %s\n", i+1, subnet.String(), subnet.String())
default:
fmt.Printf("a%d=%#v // %v\n", i+1, arg, arg.DataValue)
}
}
}
# @TEST-END-FILE