Skip to content

Commit

Permalink
fixed addTags to work with session that have no tags
Browse files Browse the repository at this point in the history
  • Loading branch information
awick committed Oct 20, 2015
1 parent 0b460f7 commit 415cfb2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -28,6 +28,7 @@
- db - Removed "index.codec.bloom.load=false"
- db - Added warning for ES below 1.6.2
- wise - use native hashtable, required for threatstream
- viewer - fixed addTags to work with session that have no tags

0.11.5 2015/06/02
- NOTICE: Only ES 1.[45].x is supported by this version.
Expand Down
16 changes: 15 additions & 1 deletion tests/api-tagging.t
@@ -1,4 +1,4 @@
use Test::More tests => 14;
use Test::More tests => 30;
use Cwd;
use URI::Escape;
use MolochTest;
Expand All @@ -11,6 +11,7 @@ my $pwd = getcwd() . "/pcap";
countTest(3, "date=-1&expression=" . uri_escape("file=$pwd/socks-http-example.pcap"));
countTest(0, "date=-1&expression=" . uri_escape("tags==TAGTEST1"));
countTest(0, "date=-1&expression=" . uri_escape("tags==TAGTEST2"));
countTest(3, "date=-1&expression=" . uri_escape("file=$pwd/socks-http-example.pcap && tags==domainwise"));

# adding/removing tags test expression
viewerPost("/addTags?date=-1&expression=file=$pwd/socks-http-example.pcap", "tags=TAGTEST1");
Expand All @@ -19,6 +20,7 @@ my $pwd = getcwd() . "/pcap";
viewerPost("/removeTags?date=-1&expression=file=$pwd/socks-http-example.pcap", "tags=TAGTEST1");
esGet("/_refresh");
countTest(0, "date=-1&expression=" . uri_escape("tags==TAGTEST1"));
countTest(3, "date=-1&expression=" . uri_escape("file=$pwd/socks-http-example.pcap && tags==domainwise"));

# adding/removing tags test ids
my $idQuery = viewerGet("/sessions.json?date=-1&expression=" . uri_escape("file=$pwd/socks-http-example.pcap"));
Expand All @@ -28,3 +30,15 @@ my $pwd = getcwd() . "/pcap";
viewerPost("/removeTags?date=-1", "tags=TAGTEST2&ids=" . $idQuery->{data}->[0]->{id});
esGet("/_refresh");
countTest(0, "date=-1&expression=" . uri_escape("tags==TAGTEST2"));
countTest(3, "date=-1&expression=" . uri_escape("file=$pwd/socks-http-example.pcap && tags==domainwise"));

# adding tag to no tag item
countTest(1, "date=-1&expression=" . uri_escape("file=$pwd/irc.pcap && tags!=EXISTS!"));
viewerPost("/addTags?date=-1&expression=file=$pwd/irc.pcap", "tags=TAGTEST3");
esGet("/_refresh");
countTest(1, "date=-1&expression=" . uri_escape("file=$pwd/irc.pcap && tags==TAGTEST3"));
countTest(0, "date=-1&expression=" . uri_escape("file=$pwd/irc.pcap && tags!=EXISTS!"));
viewerPost("/removeTags?date=-1&expression=file=$pwd/irc.pcap", "tags=TAGTEST3");
esGet("/_refresh");
countTest(0, "date=-1&expression=" . uri_escape("file=$pwd/irc.pcap && tags==TAGTEST3"));
countTest(1, "date=-1&expression=" . uri_escape("file=$pwd/irc.pcap && tags!=EXISTS!"));
8 changes: 6 additions & 2 deletions viewer/viewer.js
Expand Up @@ -3764,11 +3764,15 @@ function addTagsList(allTagIds, list, doneCb) {

var fields = session._source || session.fields;

if (!fields || !fields.ta) {
console.log("NO TA", session);
if (!fields) {
console.log("No Fields", session);
return nextCb(null);
}

if (!fields.ta) {
fields.ta = [];
}

// Find which tags need to be added to this session
for (var i = 0, ilen = allTagIds.length; i < ilen; i++) {
if (fields.ta.indexOf(allTagIds[i]) === -1) {
Expand Down

0 comments on commit 415cfb2

Please sign in to comment.