Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
awick committed May 14, 2014
1 parent 50ed32c commit 7b9b6b4
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 17 deletions.
2 changes: 1 addition & 1 deletion tests/config.test.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ viewPort=8123

[test]
passwordSecret=
enableShutdown=true
regressionTests=true


[headers-http-request]
Expand Down
54 changes: 42 additions & 12 deletions tests/tests.pl
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,18 @@ sub countTest {
sub doViewer {
my ($cmd) = @_;

plan tests => 695;
plan tests => 720;

die "Must run in tests directory" if (! -f "../db/db.pl");

if ($cmd eq "--viewerfast") {
print "Skipping ES Init and PCAP load\n";
$main::userAgent->post("http://localhost:8123/flushCache");
system("/bin/cp socks-http-example.pcap copytest.pcap");
if ($main::debug) {
system("../capture/moloch-capture -c config.test.ini -n test -r copytest.pcap");
system("../capture/moloch-capture --debug -c config.test.ini -n test -r copytest.pcap --tag testisfun");
} else {
system("../capture/moloch-capture -c config.test.ini -n test -r copytest.pcap 2>&1 1>/dev/null");
system("../capture/moloch-capture -c config.test.ini -n test -r copytest.pcap --tag testisfun 2>&1 1>/dev/null");
}
} else {
print ("Initializing ES\n");
Expand Down Expand Up @@ -179,7 +180,9 @@ sub doViewer {
sleep 2;
}

$main::userAgent->get("http://localhost:9200/_flush");
$main::userAgent->get("http://localhost:9200/_refresh");
sleep 1;

my $pwd = getcwd();
# file tests
Expand Down Expand Up @@ -593,17 +596,22 @@ sub doViewer {
', "CSV Ids");

# scrub tags test ids
$main::userAgent->post("http://localhost:8123/scrub?date=-1", Content => "ids=" . $idQuery->{aaData}->[0]->{id});
$main::userAgent->get("http://localhost:9200/_refresh");
countTest(1, "date=-1&expression=" . uri_escape("file=$pwd/copytest.pcap&&scrubbed.by==anonymous"));
countTest(2, "date=-1&expression=" . uri_escape("file=$pwd/copytest.pcap&&scrubbed.by!=anonymous"));
countTest(1, "date=-1&expression=" . uri_escape("file=$pwd/copytest.pcap&&scrubbed.by==Anonymous"));
countTest(1, "date=-1&expression=" . uri_escape("file=$pwd/copytest.pcap&&scrubbed.by==[Anonymous]"));
countTest(2, "date=-1&expression=" . uri_escape("file=$pwd/copytest.pcap&&scrubbed.by!=[Anonymous]"));
countTest(1, "date=-1&expression=" . uri_escape("file=$pwd/copytest.pcap&&scrubbed.by==Anon*mous"));
countTest(1, "date=-1&expression=" . uri_escape("file=$pwd/copytest.pcap&&scrubbed.by==/Anon.*mous/"));
if (defined $idQuery->{aaData}->[0]->{id}) {
$main::userAgent->post("http://localhost:8123/scrub?date=-1", Content => "ids=" . $idQuery->{aaData}->[0]->{id});
$main::userAgent->get("http://localhost:9200/_refresh");
countTest(1, "date=-1&expression=" . uri_escape("file=$pwd/copytest.pcap&&scrubbed.by==anonymous"));
countTest(2, "date=-1&expression=" . uri_escape("file=$pwd/copytest.pcap&&scrubbed.by!=anonymous"));
countTest(1, "date=-1&expression=" . uri_escape("file=$pwd/copytest.pcap&&scrubbed.by==Anonymous"));
countTest(1, "date=-1&expression=" . uri_escape("file=$pwd/copytest.pcap&&scrubbed.by==[Anonymous]"));
countTest(2, "date=-1&expression=" . uri_escape("file=$pwd/copytest.pcap&&scrubbed.by!=[Anonymous]"));
countTest(1, "date=-1&expression=" . uri_escape("file=$pwd/copytest.pcap&&scrubbed.by==Anon*mous"));
countTest(1, "date=-1&expression=" . uri_escape("file=$pwd/copytest.pcap&&scrubbed.by==/Anon.*mous/"));
} else {
diag "No scrubid, so skipping scrub\n";
}

# delete tags test expression
countTest(3, "date=-1&expression=" . uri_escape("file=$pwd/copytest.pcap"));
$main::userAgent->post("http://localhost:8123/delete?date=-1&expression=file=$pwd/copytest.pcap");
$main::userAgent->get("http://localhost:9200/_refresh");
countTest(0, "date=-1&expression=" . uri_escape("file=$pwd/copytest.pcap"));
Expand All @@ -625,6 +633,28 @@ sub doViewer {
$users = from_json($main::userAgent->post("http://localhost:8123/users.json")->content);
is (@{$users->{aaData}}, 0, "Removed user");

# stats.json
my $stats = viewerGet("/stats.json");
is (@{$stats->{aaData}}, 1, "stats.json aaData set ");
is ($stats->{iTotalRecords}, 1, "stats.json iTotalRecords");
is ($stats->{aaData}->[0]->{id}, "test", "stats.json name");
foreach my $i ("diskQueue", "deltaDroppedPerSec") {
is ($stats->{aaData}->[0]->{$i}, 0, "stats.json $i 0");
}

foreach my $i ("monitoring", "diskQueue", "deltaDropped", "deltaDroppedPerSec") {
is ($stats->{aaData}->[0]->{$i}, 0, "stats.json $i == 0");
}

foreach my $i ("deltaMS", "totalPackets", "deltaSessions", "deltaPackets", "deltaBytes", "memory", "currentTime", "totalK", "totalSessions", "freeSpaceM", "deltaSessionsPerSec", "deltaBytesPerSec", "deltaPacketsPerSec") {
cmp_ok ($stats->{aaData}->[0]->{$i}, '>', 0, "stats.json $i > 0");
}

# dstats.json
my $dstats = viewerGet("/dstats.json?nodeName=test&start=1399680425&stop=1399680460&step=5&interval=5&name=deltaPackets");
is (@{$dstats}, 7, "dstats.json array size");

# Cleanup
unlink("copytest.pcap");

if ($cmd eq "--viewer") {
Expand Down
12 changes: 10 additions & 2 deletions viewer/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ var internals = {tagId2Name: {},
tagName2Id: {},
fileId2File: {},
fileName2File: {},
molochNodeStatsCache: {},
healthCache: {},
qInProgress: 0,
apiVersion: "0.90",
q: []};
Expand Down Expand Up @@ -196,7 +198,14 @@ exports.close = function () {
//////////////////////////////////////////////////////////////////////////////////
//// High level functions
//////////////////////////////////////////////////////////////////////////////////
internals.molochNodeStatsCache = {};
exports.flushCache = function () {
internals.tagId2Name = {};
internals.tagName2Id = {};
internals.fileId2File = {};
internals.fileName2File = {};
internals.molochNodeStatsCache = {};
internals.healthCache = {};
}

exports.molochNodeStats = function (name, cb) {
exports.get('stats', 'stat', name, function(err, stat) {
Expand Down Expand Up @@ -226,7 +235,6 @@ exports.molochNodeStatsCache = function (name, cb) {
};


internals.healthCache = {};
exports.healthCache = function (cb) {
if (internals.healthCache._timeStamp !== undefined && internals.healthCache._timeStamp > Date.now() - 10000) {
return cb(null, internals.healthCache);
Expand Down
8 changes: 6 additions & 2 deletions viewer/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ app.configure(function() {
/* Shared password isn't set, who cares about auth */
app.locals.alwaysShowESStatus = true;
app.use(function(req, res, next) {
req.user = {userId: "anonymous", enabled: true, createEnabled: Config.get("enableShutdown", false), webEnabled: true, headerAuthEnabled: false, emailSearch: true, removeEnabled: true, settings: {}};
req.user = {userId: "anonymous", enabled: true, createEnabled: Config.get("regressionTests", false), webEnabled: true, headerAuthEnabled: false, emailSearch: true, removeEnabled: true, settings: {}};
next();
});
}
Expand Down Expand Up @@ -4365,11 +4365,15 @@ app.post('/upload', function(req, res) {
});
});

if (Config.get("enableShutdown")) {
if (Config.get("regressionTests")) {
app.post('/shutdown', function(req, res) {
Db.close();
process.exit(0);
});
app.post('/flushCache', function(req, res) {
Db.flushCache();
res.send("");
});
}

//////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 7b9b6b4

Please sign in to comment.