Skip to content

Commit

Permalink
facet tests, --viewerstart option which doesn't load PCAP but starts …
Browse files Browse the repository at this point in the history
…processes
  • Loading branch information
awick committed Dec 9, 2014
1 parent ee25d61 commit 4b59ebd
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 8 deletions.
12 changes: 7 additions & 5 deletions tests/MolochTest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use LWP::UserAgent;
use HTTP::Request::Common;
use JSON;
use URI::Escape;
use Data::Dumper;

$MolochTest::userAgent = LWP::UserAgent->new(timeout => 120);
$MolochTest::host = "127.0.0.1";
Expand Down Expand Up @@ -52,10 +53,10 @@ my ($url, $content) = @_;
}
################################################################################
sub mesGet {
my ($url) = @_;
my ($url, $debug) = @_;

my $response = $MolochTest::userAgent->get("http://$MolochTest::host:8200$url");
#print $url, " response:", $response->content;
diag $url, " response:", $response->content if ($debug);
my $json = from_json($response->content);
return ($json);
}
Expand Down Expand Up @@ -123,28 +124,29 @@ sub esCopy

esPost("/_bulk", $out);
}
esGet("/_flush");
}
################################################################################
sub countTest {
my ($count, $test, $debug) = @_;
my $json = viewerGet("/sessions.json?$test");
print Dumper($json) if ($debug);
diag Dumper($json) if ($debug);
is ($json->{iTotalDisplayRecords}, $count, uri_unescape($test) . " iTotalDisplayRecords");
is (scalar @{$json->{aaData}}, $count, uri_unescape($test) . " aaData count");
}
################################################################################
sub countTest2 {
my ($count, $test, $debug) = @_;
my $json = viewerGet2("/sessions.json?$test");
print Dumper($json) if ($debug);
diag Dumper($json) if ($debug);
is ($json->{iTotalDisplayRecords}, $count, uri_unescape($test) . " iTotalDisplayRecords");
is (scalar @{$json->{aaData}}, $count, uri_unescape($test) . " aaData count");
}
################################################################################
sub errTest {
my ($test, $debug) = @_;
my $json = viewerGet("/sessions.json?$test");
print Dumper($json) if ($debug);
diag Dumper($json) if ($debug);
ok (exists $json->{bsqErr}, uri_unescape($test) . " bsqErr exists");
}
################################################################################
Expand Down
1 change: 1 addition & 0 deletions tests/api-fresh.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use strict;

# Clear out node2
system("../db/db.pl --prefix tests2 localhost:9200 initnoprompt 2>&1 1>/dev/null");
esCopy("tests_fields", "tests2_fields", "field");


# Make sure no items
Expand Down
36 changes: 35 additions & 1 deletion tests/api-sessions.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Test::More tests => 4;
use Test::More tests => 26;
use Cwd;
use URI::Escape;
use MolochTest;
Expand All @@ -15,6 +15,40 @@ my $pwd = getcwd() . "/pcap";
my $response = $MolochTest::userAgent->get("http://$MolochTest::host:8123/test/raw/" . $json->{aaData}->[0]->{id} . "?type=src");
is (unpack("H*", $response->content), "4fa11b290002538d08090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f30313233343536374fa11b2d0008129108090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f3031323334353637", "Correct bigendian tcpdump data");

# Check facets short
$json = viewerGet("/sessions.json?startTime=1386004308&stopTime=1386004400&facets=1&expression=" . uri_escape("file=$pwd/bigendian.pcap|file=$pwd/socks-http-example.pcap|file=$pwd/bt-tcp.pcap"));

eq_or_diff($json->{map}, from_json('{"USA": 6}'), "map short");
eq_or_diff($json->{graph}->{lpHisto}, from_json('[["1386004309000", 1], ["1386004312000", 1], [1386004317000, 1]]'), "lpHisto short");
eq_or_diff($json->{graph}->{paHisto}, from_json('[["1386004309000", 14], ["1386004312000", 15], [1386004317000, 17]]'), "paHisto short");
eq_or_diff($json->{graph}->{dbHisto}, from_json('[["1386004309000", 1754], ["1386004312000", 1770], [1386004317000, 1763]]'), "dbHisto short");
is ($json->{iTotalDisplayRecords}, 3, "records short");
is ($json->{graph}->{interval}, 1, "correct interval short");
is ($json->{graph}->{xmax}, 1386004400000, "correct xmax short");
is ($json->{graph}->{xmin}, 1386004308000, "correct xmin short");

# Check facets medium
$json = viewerGet("/sessions.json?startTime=1386004308&stopTime=1386349908&facets=1&expression=" . uri_escape("file=$pwd/bigendian.pcap|file=$pwd/socks-http-example.pcap|file=$pwd/bt-tcp.pcap"));

eq_or_diff($json->{map}, from_json('{"USA": 6}'), "map medium");
eq_or_diff($json->{graph}->{lpHisto}, from_json('[["1386004260000", 3]]'), "lpHisto medium");
eq_or_diff($json->{graph}->{paHisto}, from_json('[["1386004260000", 46]]'), "paHisto medium");
eq_or_diff($json->{graph}->{dbHisto}, from_json('[["1386004260000", 5287]]'), "dbHisto medium");
is ($json->{iTotalDisplayRecords}, 3, "records medium");
is ($json->{graph}->{interval}, 60, "correct interval medium");
is ($json->{graph}->{xmax}, 1386349908000, "correct xmax medium");
is ($json->{graph}->{xmin}, 1386004308000, "correct xmin medium");

# Check facets ALL
$json = viewerGet("/sessions.json?date=-1&facets=1&expression=" . uri_escape("file=$pwd/bigendian.pcap|file=$pwd/socks-http-example.pcap|file=$pwd/bt-tcp.pcap"));

eq_or_diff($json->{map}, from_json('{"RUS": 1, "USA": 6, "CAN": 1}'), "map ALL");
eq_or_diff($json->{graph}->{lpHisto}, from_json('[["1335956400000", 1], ["1386003600000", 3], [1387742400000, 1]]'), "lpHisto ALL");
eq_or_diff($json->{graph}->{paHisto}, from_json('[["1335956400000", 2], ["1386003600000", 46], [1387742400000, 4]]'), "paHisto ALL");
eq_or_diff($json->{graph}->{dbHisto}, from_json('[["1335956400000", 0], ["1386003600000", 5287], [1387742400000, 68]]'), "dbHisto ALL");
is ($json->{iTotalDisplayRecords}, 5, "records ALL");
is ($json->{graph}->{interval}, 3600, "correct interval ALL");

# csv
my $csv = $MolochTest::userAgent->get("http://$MolochTest::host:8123/sessions.csv?date=-1&expression=" . uri_escape("file=$pwd/socks-http-example.pcap"))->content;
$csv =~ s/\r//g;
Expand Down
1 change: 1 addition & 0 deletions tests/config.test.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ spiDataMaxIndices=-1
parseQSValue=true
passwordSecret=password
viewPort=8123
viewerPlugins=wise.js

[test]
prefix=tests
Expand Down
1 change: 1 addition & 0 deletions tests/ip.wise
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
10.0.0.3;tags=wisebyip1;irc.channel=wisebyip1channel;email.x-priority=999
192.168.177.160;tags=wisebyip2;mysql.ver=wisebyip2mysqlversion;test.ip=21.21.21.21
128.128.128.0/24;tags=wisebyip2;mysql.ver=wisebyip2mysqlversion;test.ip=21.21.21.21
21 changes: 19 additions & 2 deletions tests/tests.pl
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,23 @@ sub doViewer {
if ($cmd eq "--viewerfast") {
print "Skipping ES Init and PCAP load\n";
$main::userAgent->post("http://localhost:8123/flushCache");
} elsif ($cmd eq "--viewerstart") {
print "Skipping ES Init and PCAP load\n";
$main::userAgent->post("http://localhost:8123/flushCache");
print ("Starting viewer\n");
if ($main::debug) {
system("cd ../capture/plugins/wiseService ; node wiseService.js -c ../../../tests/config.test.ini > /tmp/moloch.wise &");
system("cd ../viewer ; node multies.js -c ../tests/config.test.ini -n all > /tmp/multies.all &");
system("cd ../viewer ; node viewer.js -c ../tests/config.test.ini -n test > /tmp/moloch.test &");
system("cd ../viewer ; node viewer.js -c ../tests/config.test.ini -n test2 > /tmp/moloch.test2 &");
system("cd ../viewer ; node viewer.js -c ../tests/config.test.ini -n all > /tmp/moloch.all &");
} else {
system("cd ../capture/plugins/wiseService ; node wiseService.js -c ../../../tests/config.test.ini > /dev/null &");
system("cd ../viewer ; node multies.js -c ../tests/config.test.ini -n all > /dev/null &");
system("cd ../viewer ; node viewer.js -c ../tests/config.test.ini -n test > /dev/null &");
system("cd ../viewer ; node viewer.js -c ../tests/config.test.ini -n test2 > /dev/null &");
system("cd ../viewer ; node viewer.js -c ../tests/config.test.ini -n all > /dev/null &");
}
} else {
print ("Initializing ES\n");
if ($main::debug) {
Expand Down Expand Up @@ -214,7 +231,7 @@ sub doViewer {


# Cleanup
if ($cmd eq "--viewer") {
if ($cmd ne "--viewerfast") {
$main::userAgent->post("http://localhost:8123/shutdown");
$main::userAgent->post("http://localhost:8124/shutdown");
$main::userAgent->post("http://localhost:8125/shutdown");
Expand All @@ -234,7 +251,7 @@ sub doViewer {
} elsif ($ARGV[0] eq "--valgrind") {
$main::valgrind = 1;
shift @ARGV;
} elsif ($ARGV[0] =~ /^--(viewer|fix|make|capture|viewerfast|help)$/) {
} elsif ($ARGV[0] =~ /^--(viewer|fix|make|capture|viewerfast|viewerstart|help)$/) {
$main::cmd = $ARGV[0];
shift @ARGV;
} elsif ($ARGV[0] =~ /^-/) {
Expand Down
6 changes: 6 additions & 0 deletions tests/wise.t
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ eq_or_diff($wise, '{key: "10.0.0.3", ops:
{field: "mysql.ver", len: 22, value: "wisebyip2mysqlversion"},
{field: "test.ip", len: 12, value: "21.21.21.21"}]
},
{key: "128.128.128.0/24", ops:
[{field: "tags", len: 7, value: "ipwise"},
{field: "tags", len: 10, value: "wisebyip2"},
{field: "mysql.ver", len: 22, value: "wisebyip2mysqlversion"},
{field: "test.ip", len: 12, value: "21.21.21.21"}]
},
', "file:ip dump");

$wise = $MolochTest::userAgent->get("http://$MolochTest::host:8081/dump/file:ipcsv")->content;
Expand Down

0 comments on commit 4b59ebd

Please sign in to comment.