mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Add more tests for previously-untested BIFs
This commit is contained in:
parent
15689ce005
commit
6869e1aadc
22 changed files with 228 additions and 0 deletions
15
testing/btest/Baseline/bifs.create_file/out
Normal file
15
testing/btest/Baseline/bifs.create_file/out
Normal file
|
@ -0,0 +1,15 @@
|
|||
T
|
||||
testfile
|
||||
F
|
||||
15.0
|
||||
T
|
||||
F
|
||||
28.0
|
||||
-1.0
|
||||
15.0
|
||||
0.0
|
||||
T
|
||||
15.0
|
||||
T
|
||||
testdir/testfile4
|
||||
F
|
2
testing/btest/Baseline/bifs.create_file/testfile
Normal file
2
testing/btest/Baseline/bifs.create_file/testfile
Normal file
|
@ -0,0 +1,2 @@
|
|||
This is a test
|
||||
another test
|
1
testing/btest/Baseline/bifs.create_file/testfile2
Normal file
1
testing/btest/Baseline/bifs.create_file/testfile2
Normal file
|
@ -0,0 +1 @@
|
|||
new text
|
2
testing/btest/Baseline/bifs.find_entropy/out
Normal file
2
testing/btest/Baseline/bifs.find_entropy/out
Normal file
|
@ -0,0 +1,2 @@
|
|||
[entropy=4.715374, chi_square=591.981818, mean=75.472727, monte_carlo_pi=4.0, serial_correlation=-0.11027]
|
||||
[entropy=2.083189, chi_square=3906.018182, mean=69.054545, monte_carlo_pi=4.0, serial_correlation=0.849402]
|
2
testing/btest/Baseline/bifs.fmt_ftp_port/out
Normal file
2
testing/btest/Baseline/bifs.fmt_ftp_port/out
Normal file
|
@ -0,0 +1,2 @@
|
|||
192,168,0,2,1,1
|
||||
|
3
testing/btest/Baseline/bifs.get_port_transport_proto/out
Normal file
3
testing/btest/Baseline/bifs.get_port_transport_proto/out
Normal file
|
@ -0,0 +1,3 @@
|
|||
tcp
|
||||
udp
|
||||
icmp
|
1
testing/btest/Baseline/bifs.global_ids/out
Normal file
1
testing/btest/Baseline/bifs.global_ids/out
Normal file
|
@ -0,0 +1 @@
|
|||
func
|
2
testing/btest/Baseline/bifs.is_ascii/out
Normal file
2
testing/btest/Baseline/bifs.is_ascii/out
Normal file
|
@ -0,0 +1,2 @@
|
|||
F
|
||||
T
|
3
testing/btest/Baseline/bifs.rotate_file/out
Normal file
3
testing/btest/Baseline/bifs.rotate_file/out
Normal file
|
@ -0,0 +1,3 @@
|
|||
file rotated
|
||||
15.0
|
||||
0.0
|
3
testing/btest/Baseline/bifs.rotate_file_by_name/out
Normal file
3
testing/btest/Baseline/bifs.rotate_file_by_name/out
Normal file
|
@ -0,0 +1,3 @@
|
|||
file rotated
|
||||
15.0
|
||||
0.0
|
3
testing/btest/Baseline/bifs.same_object/out
Normal file
3
testing/btest/Baseline/bifs.same_object/out
Normal file
|
@ -0,0 +1,3 @@
|
|||
T
|
||||
F
|
||||
F
|
2
testing/btest/Baseline/bifs.uuid_to_string/out
Normal file
2
testing/btest/Baseline/bifs.uuid_to_string/out
Normal file
|
@ -0,0 +1,2 @@
|
|||
626180fe-6463-6665-6730-313233343536
|
||||
<Invalid UUID>
|
65
testing/btest/bifs/create_file.bro
Normal file
65
testing/btest/bifs/create_file.bro
Normal file
|
@ -0,0 +1,65 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
# @TEST-EXEC: btest-diff testfile
|
||||
# @TEST-EXEC: btest-diff testfile2
|
||||
# @TEST-EXEC: test -f testdir/testfile4
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
# Test that creating a file works as expected
|
||||
local a = open("testfile");
|
||||
print active_file(a);
|
||||
print get_file_name(a);
|
||||
write_file(a, "This is a test\n");
|
||||
close(a);
|
||||
|
||||
print active_file(a);
|
||||
print file_size("testfile");
|
||||
|
||||
# Test that "open_for_append" doesn't overwrite an existing file
|
||||
a = open_for_append("testfile");
|
||||
print active_file(a);
|
||||
write_file(a, "another test\n");
|
||||
close(a);
|
||||
|
||||
print active_file(a);
|
||||
print file_size("testfile");
|
||||
|
||||
# This should fail
|
||||
print file_size("doesnotexist");
|
||||
|
||||
# Test that "open" overwrites existing file
|
||||
a = open("testfile2");
|
||||
write_file(a, "this will be overwritten\n");
|
||||
close(a);
|
||||
a = open("testfile2");
|
||||
write_file(a, "new text\n");
|
||||
close(a);
|
||||
|
||||
# Test that set_buf and flush_all work correctly
|
||||
a = open("testfile3");
|
||||
set_buf(a, F);
|
||||
write_file(a, "This is a test\n");
|
||||
print file_size("testfile3");
|
||||
close(a);
|
||||
a = open("testfile3");
|
||||
set_buf(a, T);
|
||||
write_file(a, "This is a test\n");
|
||||
print file_size("testfile3");
|
||||
print flush_all();
|
||||
print file_size("testfile3");
|
||||
close(a);
|
||||
|
||||
# Create a new directory
|
||||
print mkdir("testdir");
|
||||
|
||||
# Create a file in the new directory
|
||||
a = open("testdir/testfile4");
|
||||
print get_file_name(a);
|
||||
write_file(a, "This is a test\n");
|
||||
close(a);
|
||||
|
||||
# This should fail
|
||||
print mkdir("/thisdoesnotexist/dir");
|
||||
}
|
13
testing/btest/bifs/find_entropy.bro
Normal file
13
testing/btest/bifs/find_entropy.bro
Normal file
|
@ -0,0 +1,13 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = "dh3Hie02uh^s#Sdf9L3frd243h$d78r2G4cM6*Q05d(7rh46f!0|4-f";
|
||||
local b = "0011000aaabbbbcccc000011111000000000aaaabbbbcccc0000000";
|
||||
|
||||
print find_entropy(a);
|
||||
|
||||
print find_entropy(b);
|
||||
}
|
13
testing/btest/bifs/fmt_ftp_port.bro
Normal file
13
testing/btest/bifs/fmt_ftp_port.bro
Normal file
|
@ -0,0 +1,13 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = 192.168.0.2;
|
||||
local b = 257/tcp;
|
||||
print fmt_ftp_port(a, b);
|
||||
|
||||
a = [fe80::1234];
|
||||
print fmt_ftp_port(a, b);
|
||||
}
|
13
testing/btest/bifs/get_port_transport_proto.bro
Normal file
13
testing/btest/bifs/get_port_transport_proto.bro
Normal file
|
@ -0,0 +1,13 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = 123/tcp;
|
||||
local b = 123/udp;
|
||||
local c = 123/icmp;
|
||||
print get_port_transport_proto(a);
|
||||
print get_port_transport_proto(b);
|
||||
print get_port_transport_proto(c);
|
||||
}
|
16
testing/btest/bifs/global_ids.bro
Normal file
16
testing/btest/bifs/global_ids.bro
Normal file
|
@ -0,0 +1,16 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = global_ids();
|
||||
for ( i in a )
|
||||
{
|
||||
# the table is quite large, so just print one item we expect
|
||||
if ( i == "bro_init" )
|
||||
print a[i]$type_name;
|
||||
|
||||
}
|
||||
|
||||
}
|
12
testing/btest/bifs/is_ascii.bro
Normal file
12
testing/btest/bifs/is_ascii.bro
Normal file
|
@ -0,0 +1,12 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = "this is a test\xfe";
|
||||
local b = "this is a test\x7f";
|
||||
|
||||
print is_ascii(a);
|
||||
print is_ascii(b);
|
||||
}
|
15
testing/btest/bifs/rotate_file.bro
Normal file
15
testing/btest/bifs/rotate_file.bro
Normal file
|
@ -0,0 +1,15 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = open("testfile");
|
||||
write_file(a, "this is a test\n");
|
||||
|
||||
local b = rotate_file(a);
|
||||
if ( b$new_name != "testfile" )
|
||||
print "file rotated";
|
||||
print file_size(b$new_name);
|
||||
print file_size("testfile");
|
||||
}
|
16
testing/btest/bifs/rotate_file_by_name.bro
Normal file
16
testing/btest/bifs/rotate_file_by_name.bro
Normal file
|
@ -0,0 +1,16 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = open("testfile");
|
||||
write_file(a, "this is a test\n");
|
||||
close(a);
|
||||
|
||||
local b = rotate_file_by_name("testfile");
|
||||
if ( b$new_name != "testfile" )
|
||||
print "file rotated";
|
||||
print file_size(b$new_name);
|
||||
print file_size("testfile");
|
||||
}
|
16
testing/btest/bifs/same_object.bro
Normal file
16
testing/btest/bifs/same_object.bro
Normal file
|
@ -0,0 +1,16 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = "This is a test";
|
||||
local b: string;
|
||||
local c = "This is a test";
|
||||
b = a;
|
||||
print same_object(a, b);
|
||||
print same_object(a, c);
|
||||
|
||||
local d = vector(1, 2, 3);
|
||||
print same_object(a, d);
|
||||
}
|
10
testing/btest/bifs/uuid_to_string.bro
Normal file
10
testing/btest/bifs/uuid_to_string.bro
Normal file
|
@ -0,0 +1,10 @@
|
|||
#
|
||||
# @TEST-EXEC: bro %INPUT >out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
event bro_init()
|
||||
{
|
||||
local a = "\xfe\x80abcdefg0123456";
|
||||
print uuid_to_string(a);
|
||||
print uuid_to_string("");
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue