diff --git a/tests/config.test.ini b/tests/config.test.ini index 89d65f3f9c..b512beb4b5 100644 --- a/tests/config.test.ini +++ b/tests/config.test.ini @@ -17,7 +17,7 @@ viewPort=8123 [test] passwordSecret= -enableShutdown=true +regressionTests=true [headers-http-request] diff --git a/tests/tests.pl b/tests/tests.pl index ddb89ecb8b..b8b095f718 100755 --- a/tests/tests.pl +++ b/tests/tests.pl @@ -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"); @@ -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 @@ -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")); @@ -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") { diff --git a/viewer/db.js b/viewer/db.js index 88cfeca22f..f872bea0a0 100644 --- a/viewer/db.js +++ b/viewer/db.js @@ -30,6 +30,8 @@ var internals = {tagId2Name: {}, tagName2Id: {}, fileId2File: {}, fileName2File: {}, + molochNodeStatsCache: {}, + healthCache: {}, qInProgress: 0, apiVersion: "0.90", q: []}; @@ -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) { @@ -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); diff --git a/viewer/viewer.js b/viewer/viewer.js index cc4b5a40b2..1d0aa9fdd7 100644 --- a/viewer/viewer.js +++ b/viewer/viewer.js @@ -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(); }); } @@ -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(""); + }); } //////////////////////////////////////////////////////////////////////////////////