From f82c7c801d3c926095b651330678bdeb006cf76b Mon Sep 17 00:00:00 2001 From: Tim Pavlik Date: Wed, 14 Apr 2021 13:13:50 -0700 Subject: [PATCH 001/178] Replace deprecated node util.print command --- client/splunk.test.js | 4 ++-- examples/node/search.js | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/client/splunk.test.js b/client/splunk.test.js index e84d7f864..56a84fa20 100644 --- a/client/splunk.test.js +++ b/client/splunk.test.js @@ -25344,7 +25344,7 @@ require.define("/examples/node/search.js", function (require, module, exports, _ scanned + " scanned | " + matched + " matched | " + results + " results"; - print("\r" + stats + " "); + sprintf("%s", "\r" + stats + " "); } Async.sleep(1000, iterationDone); @@ -25353,7 +25353,7 @@ require.define("/examples/node/search.js", function (require, module, exports, _ }, function(err) { if (isVerbose) { - print("\r"); + sprintf("%s", "\r"); } done(err, job); } diff --git a/examples/node/search.js b/examples/node/search.js index fc900b5a7..973a654f7 100644 --- a/examples/node/search.js +++ b/examples/node/search.js @@ -19,7 +19,6 @@ var utils = splunkjs.Utils; var Async = splunkjs.Async; var options = require('./cmdline'); - var print = require('util').print; var FLAGS_CREATE = [ "search", "earliest_time", "latest_time", "now", "time_format", @@ -81,7 +80,7 @@ scanned + " scanned | " + matched + " matched | " + results + " results"; - print("\r" + stats + " "); + console.log("\r" + stats + " "); } Async.sleep(1000, iterationDone); @@ -90,7 +89,7 @@ }, function(err) { if (isVerbose) { - print("\r"); + console.log("\r"); } done(err, job); } From faab35d73148207597a00979e208eb79fc5b9c8b Mon Sep 17 00:00:00 2001 From: Tim Pavlik Date: Wed, 14 Apr 2021 14:13:09 -0700 Subject: [PATCH 002/178] Fix some browser tests missing http. --- client/splunk.test.js | 44 +++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/client/splunk.test.js b/client/splunk.test.js index 56a84fa20..a45746b87 100644 --- a/client/splunk.test.js +++ b/client/splunk.test.js @@ -14833,7 +14833,7 @@ exports.setup = function(svc) { }, "Callback#get autologin - success": function(test) { - var service = new splunkjs.Service( + var service = new splunkjs.Service(svc.http, { scheme: this.service.scheme, host: this.service.host, @@ -14854,7 +14854,7 @@ exports.setup = function(svc) { }, "Callback#get autologin - error": function(test) { - var service = new splunkjs.Service( + var service = new splunkjs.Service(svc.http, { scheme: this.service.scheme, host: this.service.host, @@ -14874,7 +14874,7 @@ exports.setup = function(svc) { "Callback#get autologin - disabled": function(test) { - var service = new splunkjs.Service( + var service = new splunkjs.Service(svc.http, { scheme: this.service.scheme, host: this.service.host, @@ -14894,7 +14894,7 @@ exports.setup = function(svc) { }, "Callback#get relogin - success": function(test) { - var service = new splunkjs.Service( + var service = new splunkjs.Service(svc.http, { scheme: this.service.scheme, host: this.service.host, @@ -14917,7 +14917,7 @@ exports.setup = function(svc) { }, "Callback#get relogin - error": function(test) { - var service = new splunkjs.Service( + var service = new splunkjs.Service(svc.http, { scheme: this.service.scheme, host: this.service.host, @@ -14960,7 +14960,7 @@ exports.setup = function(svc) { }, "Callback#post autologin - success": function(test) { - var service = new splunkjs.Service( + var service = new splunkjs.Service(svc.http, { scheme: this.service.scheme, host: this.service.host, @@ -14985,7 +14985,7 @@ exports.setup = function(svc) { }, "Callback#post autologin - error": function(test) { - var service = new splunkjs.Service( + var service = new splunkjs.Service(svc.http, { scheme: this.service.scheme, host: this.service.host, @@ -15004,7 +15004,7 @@ exports.setup = function(svc) { }, "Callback#post autologin - disabled": function(test) { - var service = new splunkjs.Service( + var service = new splunkjs.Service(svc.http, { scheme: this.service.scheme, host: this.service.host, @@ -15024,7 +15024,7 @@ exports.setup = function(svc) { }, "Callback#post relogin - success": function(test) { - var service = new splunkjs.Service( + var service = new splunkjs.Service(svc.http, { scheme: this.service.scheme, host: this.service.host, @@ -15050,7 +15050,7 @@ exports.setup = function(svc) { }, "Callback#post relogin - error": function(test) { - var service = new splunkjs.Service( + var service = new splunkjs.Service(svc.http, { scheme: this.service.scheme, host: this.service.host, @@ -15091,7 +15091,7 @@ exports.setup = function(svc) { }, "Callback#delete autologin - success": function(test) { - var service = new splunkjs.Service( + var service = new splunkjs.Service(svc.http, { scheme: this.service.scheme, host: this.service.host, @@ -15115,7 +15115,7 @@ exports.setup = function(svc) { }, "Callback#delete autologin - error": function(test) { - var service = new splunkjs.Service( + var service = new splunkjs.Service(svc.http, { scheme: this.service.scheme, host: this.service.host, @@ -15134,7 +15134,7 @@ exports.setup = function(svc) { }, "Callback#delete autologin - disabled": function(test) { - var service = new splunkjs.Service( + var service = new splunkjs.Service(svc.http, { scheme: this.service.scheme, host: this.service.host, @@ -15154,7 +15154,7 @@ exports.setup = function(svc) { }, "Callback#delete relogin - success": function(test) { - var service = new splunkjs.Service( + var service = new splunkjs.Service(svc.http, { scheme: this.service.scheme, host: this.service.host, @@ -15179,7 +15179,7 @@ exports.setup = function(svc) { }, "Callback#delete relogin - error": function(test) { - var service = new splunkjs.Service( + var service = new splunkjs.Service(svc.http, { scheme: this.service.scheme, host: this.service.host, @@ -15247,7 +15247,7 @@ exports.setup = function(svc) { }, "Callback#request autologin - success": function(test) { - var service = new splunkjs.Service( + var service = new splunkjs.Service(svc.http, { scheme: this.service.scheme, host: this.service.host, @@ -15276,7 +15276,7 @@ exports.setup = function(svc) { }, "Callback#request autologin - error": function(test) { - var service = new splunkjs.Service( + var service = new splunkjs.Service(svc.http, { scheme: this.service.scheme, host: this.service.host, @@ -15298,7 +15298,7 @@ exports.setup = function(svc) { }, "Callback#request autologin - disabled": function(test) { - var service = new splunkjs.Service( + var service = new splunkjs.Service(svc.http, { scheme: this.service.scheme, host: this.service.host, @@ -15321,7 +15321,7 @@ exports.setup = function(svc) { }, "Callback#request relogin - success": function(test) { - var service = new splunkjs.Service( + var service = new splunkjs.Service(svc.http, { scheme: this.service.scheme, host: this.service.host, @@ -15351,7 +15351,7 @@ exports.setup = function(svc) { }, "Callback#request relogin - error": function(test) { - var service = new splunkjs.Service( + var service = new splunkjs.Service(svc.http, { scheme: this.service.scheme, host: this.service.host, @@ -15405,7 +15405,7 @@ exports.setup = function(svc) { }, "Callback#timeout timed test": function(test){ - var service = new splunkjs.Service( + var service = new splunkjs.Service(svc.http, { scheme: this.service.scheme, host: this.service.host, @@ -15426,7 +15426,7 @@ exports.setup = function(svc) { // This test is not stable, commenting it out until we figure it out // "Callback#timeout fail -- FAILS INTERMITTENTLY": function(test){ - // var service = new splunkjs.Service( + // var service = new splunkjs.Service(svc.http, // { // scheme: this.service.scheme, // host: this.service.host, From 001e327a8432902e19055dcea01677919010bc5b Mon Sep 17 00:00:00 2001 From: vmalaviya Date: Fri, 11 Jun 2021 11:11:01 +0530 Subject: [PATCH 003/178] [DVPL-9508] : Made changes for Needle library and disabled tests for Splunk 8.2 --- bin/cli.js | 29 ++- client/splunk.test.js | 244 +++++++++---------- docker-compose.yml | 2 +- lib/platform/node/node_http.js | 27 ++- tests/service_tests/job.js | 302 ++++++++++++------------ tests/service_tests/storagepasswords.js | 139 +++++------ 6 files changed, 395 insertions(+), 348 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 81cbadea3..29234a91e 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -26,6 +26,7 @@ var http = require('http'); var url = require('url'); var request = require('request'); + var needle = require('needle'); /** * Constants @@ -101,29 +102,45 @@ method: req.method, headers: { "Content-Length": req.headers["content-length"] || 0, - "Content-Type": req.headers["content-type"], - "Authorization": req.headers["authorization"] + "Content-Type": req.headers["content-type"] || '', + "Authorization": req.headers["authorization"] || '' }, followAllRedirects: true, - body: body, + body: body || '', jar: false, - strictSSL: false + strictSSL: false, + rejectUnauthorized : false }; try { - request(options, function(err, response, data) { + needle.request(options.method, options.url, options.body, options, function(err, response, body) + { try { var statusCode = (response ? response.statusCode : 500) || 500; var headers = (response ? response.headers : {}) || {}; res.writeHead(statusCode, headers); - res.write(data || JSON.stringify(err)); + res.write(JSON.stringify(body) || JSON.stringify(err)); res.end(); } catch (ex) { writeError(); } }); + + // request(options, function(err, response, data) { + // try { + // var statusCode = (response ? response.statusCode : 500) || 500; + // var headers = (response ? response.headers : {}) || {}; + + // res.writeHead(statusCode, headers); + // res.write(data || JSON.stringify(err)); + // res.end(); + // } + // catch (ex) { + // writeError(); + // } + // }); } catch (ex) { writeError(); diff --git a/client/splunk.test.js b/client/splunk.test.js index a45746b87..812906052 100644 --- a/client/splunk.test.js +++ b/client/splunk.test.js @@ -2373,128 +2373,128 @@ module.exports = {} }); require.define("/node_modules/cookie/index.js", function (require, module, exports, __dirname, __filename) { -/*! - * cookie - * Copyright(c) 2012-2014 Roman Shtylman - * MIT Licensed - */ - -/** - * Module exports. - * @public - */ - -exports.parse = parse; -exports.serialize = serialize; - -/** - * Module variables. - * @private - */ - -var decode = decodeURIComponent; -var encode = encodeURIComponent; -var pairSplitRegExp = /; */; - -/** - * Parse a cookie header. - * - * Parse the given cookie header string into an object - * The object has the various cookies as keys(names) => values - * - * @param {string} str - * @param {object} [options] - * @return {object} - * @public - */ - -function parse(str, options) { - if (typeof str !== 'string') { - throw new TypeError('argument str must be a string'); - } - - var obj = {} - var opt = options || {}; - var pairs = str.split(pairSplitRegExp); - var dec = opt.decode || decode; - - pairs.forEach(function(pair) { - var eq_idx = pair.indexOf('=') - - // skip things that don't look like key=value - if (eq_idx < 0) { - return; - } - - var key = pair.substr(0, eq_idx).trim() - var val = pair.substr(++eq_idx, pair.length).trim(); - - // quoted values - if ('"' == val[0]) { - val = val.slice(1, -1); - } - - // only assign once - if (undefined == obj[key]) { - obj[key] = tryDecode(val, dec); - } - }); - - return obj; -} - -/** - * Serialize data into a cookie header. - * - * Serialize the a name value pair into a cookie string suitable for - * http headers. An optional options object specified cookie parameters. - * - * serialize('foo', 'bar', { httpOnly: true }) - * => "foo=bar; httpOnly" - * - * @param {string} name - * @param {string} val - * @param {object} [options] - * @return {string} - * @public - */ - -function serialize(name, val, options) { - var opt = options || {}; - var enc = opt.encode || encode; - var pairs = [name + '=' + enc(val)]; - - if (null != opt.maxAge) { - var maxAge = opt.maxAge - 0; - if (isNaN(maxAge)) throw new Error('maxAge should be a Number'); - pairs.push('Max-Age=' + maxAge); - } - - if (opt.domain) pairs.push('Domain=' + opt.domain); - if (opt.path) pairs.push('Path=' + opt.path); - if (opt.expires) pairs.push('Expires=' + opt.expires.toUTCString()); - if (opt.httpOnly) pairs.push('HttpOnly'); - if (opt.secure) pairs.push('Secure'); - if (opt.firstPartyOnly) pairs.push('First-Party-Only'); - - return pairs.join('; '); -} - -/** - * Try decoding a string using a decoding function. - * - * @param {string} str - * @param {function} decode - * @private - */ - -function tryDecode(str, decode) { - try { - return decode(str); - } catch (e) { - return str; - } -} +/*! + * cookie + * Copyright(c) 2012-2014 Roman Shtylman + * MIT Licensed + */ + +/** + * Module exports. + * @public + */ + +exports.parse = parse; +exports.serialize = serialize; + +/** + * Module variables. + * @private + */ + +var decode = decodeURIComponent; +var encode = encodeURIComponent; +var pairSplitRegExp = /; */; + +/** + * Parse a cookie header. + * + * Parse the given cookie header string into an object + * The object has the various cookies as keys(names) => values + * + * @param {string} str + * @param {object} [options] + * @return {object} + * @public + */ + +function parse(str, options) { + if (typeof str !== 'string') { + throw new TypeError('argument str must be a string'); + } + + var obj = {} + var opt = options || {}; + var pairs = str.split(pairSplitRegExp); + var dec = opt.decode || decode; + + pairs.forEach(function(pair) { + var eq_idx = pair.indexOf('=') + + // skip things that don't look like key=value + if (eq_idx < 0) { + return; + } + + var key = pair.substr(0, eq_idx).trim() + var val = pair.substr(++eq_idx, pair.length).trim(); + + // quoted values + if ('"' == val[0]) { + val = val.slice(1, -1); + } + + // only assign once + if (undefined == obj[key]) { + obj[key] = tryDecode(val, dec); + } + }); + + return obj; +} + +/** + * Serialize data into a cookie header. + * + * Serialize the a name value pair into a cookie string suitable for + * http headers. An optional options object specified cookie parameters. + * + * serialize('foo', 'bar', { httpOnly: true }) + * => "foo=bar; httpOnly" + * + * @param {string} name + * @param {string} val + * @param {object} [options] + * @return {string} + * @public + */ + +function serialize(name, val, options) { + var opt = options || {}; + var enc = opt.encode || encode; + var pairs = [name + '=' + enc(val)]; + + if (null != opt.maxAge) { + var maxAge = opt.maxAge - 0; + if (isNaN(maxAge)) throw new Error('maxAge should be a Number'); + pairs.push('Max-Age=' + maxAge); + } + + if (opt.domain) pairs.push('Domain=' + opt.domain); + if (opt.path) pairs.push('Path=' + opt.path); + if (opt.expires) pairs.push('Expires=' + opt.expires.toUTCString()); + if (opt.httpOnly) pairs.push('HttpOnly'); + if (opt.secure) pairs.push('Secure'); + if (opt.firstPartyOnly) pairs.push('First-Party-Only'); + + return pairs.join('; '); +} + +/** + * Try decoding a string using a decoding function. + * + * @param {string} str + * @param {function} decode + * @private + */ + +function tryDecode(str, decode) { + try { + return decode(str); + } catch (e) { + return str; + } +} }); diff --git a/docker-compose.yml b/docker-compose.yml index c4107d5dc..b1a26ade7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: '3.6' services: splunk: - image: "splunk/splunk:${SPLUNK_VERSION}" + image: "splunk/splunk:8.0" container_name: splunk environment: - SPLUNK_START_ARGS=--accept-license diff --git a/lib/platform/node/node_http.js b/lib/platform/node/node_http.js index 8191d0165..292246fb8 100644 --- a/lib/platform/node/node_http.js +++ b/lib/platform/node/node_http.js @@ -14,7 +14,8 @@ // under the License. (function() { - var request = require('request'); + // var request = require('request'); + var needle = require('needle'); var Http = require('../../http'); var utils = require('../../utils'); @@ -34,14 +35,17 @@ timeout: message.timeout || 0, jar: false, followAllRedirects: true, - strictSSL: false + strictSSL: false, + rejectUnauthorized : false }; // Get the byte-length of the content, which adjusts for multi-byte characters request_options.headers["Content-Length"] = Buffer.byteLength(request_options.body, "utf8"); var that = this; - var req = request(request_options, function (error, res, data) { + var req = needle.request(request_options.method, request_options.url, request_options.body, request_options, + function (error, res, data) + { // If we already aborted this request, then do nothing if (req.wasAborted) { return; @@ -52,11 +56,11 @@ statusCode: res ? res.statusCode : 600 }; - var complete_response = that._buildResponse(error, response, data); + var complete_response = that._buildResponse(error, response, JSON.stringify(data)); callback(complete_response); }); - req.on("abort", function() { + req.abort = function () { var res = { headers: {}, statusCode: "abort" }; var data = "{}"; var complete_response = that._buildResponse("abort", res, data); @@ -65,7 +69,18 @@ // Note that we were aborted req.wasAborted = true; - }); + } + + // req.on("abort", function() { + // var res = { headers: {}, statusCode: "abort" }; + // var data = "{}"; + // var complete_response = that._buildResponse("abort", res, data); + + // callback(complete_response); + + // // Note that we were aborted + // req.wasAborted = true; + // }); return req; }, diff --git a/tests/service_tests/job.js b/tests/service_tests/job.js index bd1d19f29..b676e4b30 100644 --- a/tests/service_tests/job.js +++ b/tests/service_tests/job.js @@ -15,36 +15,38 @@ module.exports = function(svc) { done(); }, - "Callback#Create+abort job": function(test) { - var service = this.service; - Async.chain([ - function(done){ - var app_name = path.join(process.env.SPLUNK_HOME, ('/etc/apps/sdk-app-collection/build/sleep_command.tar')); - // Fix path on Windows if $SPLUNK_HOME contains a space (ex: C:/Program%20Files/Splunk) - app_name = app_name.replace("%20", " "); - service.post("apps/appinstall", {update:1, name:app_name}, done); - }, - function(done){ - var sid = getNextId(); - var options = {id: sid}; - var jobs = service.jobs({app: "sdk-app-collection"}); - var req = jobs.oneshotSearch('search index=_internal | head 1 | sleep 10', options, function(err, job) { - test.ok(err); - test.ok(!job); - test.strictEqual(err.error, "abort"); - test.done(); - }); - - Async.sleep(1000, function(){ - req.abort(); - }); - } - ], - function(err){ - test.ok(!err); - test.done(); - }); - }, + // Disabling this test because apps/appinstall endpoint is deprecated in Splunk 8.2. + // + // "Callback#Create+abort job": function(test) { + // var service = this.service; + // Async.chain([ + // function(done){ + // var app_name = path.join(process.env.SPLUNK_HOME, ('/etc/apps/sdk-app-collection/build/sleep_command.tar')); + // // Fix path on Windows if $SPLUNK_HOME contains a space (ex: C:/Program%20Files/Splunk) + // app_name = app_name.replace("%20", " "); + // service.post("apps/appinstall", {update:1, name:app_name}, done); + // }, + // function(done){ + // var sid = getNextId(); + // var options = {id: sid}; + // var jobs = service.jobs({app: "sdk-app-collection"}); + // var req = jobs.oneshotSearch('search index=_internal | head 1 | sleep 10', options, function(err, job) { + // test.ok(err); + // test.ok(!job); + // test.strictEqual(err.error, "abort"); + // test.done(); + // }); + + // Async.sleep(1000, function(){ + // req.abort(); + // }); + // } + // ], + // function(err){ + // test.ok(!err); + // test.done(); + // }); + // }, "Callback#Create+cancel job": function(test) { var sid = getNextId(); @@ -268,85 +270,92 @@ module.exports = function(svc) { ); }, - "Callback#Enable + disable preview": function(test) { - var that = this; - var sid = getNextId(); - - var service = this.service.specialize("nobody", "sdk-app-collection"); - - Async.chain([ - function(done) { - service.jobs().search('search index=_internal | head 1 | sleep 60', {id: sid}, done); - }, - function(job, done) { - job.enablePreview(done); - - }, - function(job, done) { - job.disablePreview(done); - }, - function(job, done) { - job.cancel(done); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Pause + unpause + finalize preview": function(test) { - var that = this; - var sid = getNextId(); - - var service = this.service.specialize("nobody", "sdk-app-collection"); - - Async.chain([ - function(done) { - service.jobs().search('search index=_internal | head 1 | sleep 5', {id: sid}, done); - }, - function(job, done) { - job.pause(done); - }, - function(job, done) { - tutils.pollUntil( - job, - function(j) { - return j.properties()["isPaused"]; - }, - 10, - done - ); - }, - function(job, done) { - test.ok(job.properties()["isPaused"]); - job.unpause(done); - }, - function(job, done) { - tutils.pollUntil( - job, - function(j) { - return !j.properties()["isPaused"]; - }, - 10, - done - ); - }, - function(job, done) { - test.ok(!job.properties()["isPaused"]); - job.finalize(done); - }, - function(job, done) { - job.cancel(done); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, + // Disabling this test because apps/appinstall endpoint is deprecated in Splunk 8.2. + // + // + // "Callback#Enable + disable preview": function(test) { + // var that = this; + // var sid = getNextId(); + + // var service = this.service.specialize("nobody", "sdk-app-collection"); + + // Async.chain([ + // function(done) { + // service.jobs().search('search index=_internal | head 1 | sleep 60', {id: sid}, done); + // }, + // function(job, done) { + // job.enablePreview(done); + + // }, + // function(job, done) { + // job.disablePreview(done); + // }, + // function(job, done) { + // job.cancel(done); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + + // Disabling this test because apps/appinstall endpoint is deprecated in Splunk 8.2. + // + // + // "Callback#Pause + unpause + finalize preview": function(test) { + // var that = this; + // var sid = getNextId(); + + // var service = this.service.specialize("nobody", "sdk-app-collection"); + + // Async.chain([ + // function(done) { + // service.jobs().search('search index=_internal | head 1 | sleep 5', {id: sid}, done); + // }, + // function(job, done) { + // job.pause(done); + // }, + // function(job, done) { + // tutils.pollUntil( + // job, + // function(j) { + // return j.properties()["isPaused"]; + // }, + // 10, + // done + // ); + // }, + // function(job, done) { + // test.ok(job.properties()["isPaused"]); + // job.unpause(done); + // }, + // function(job, done) { + // tutils.pollUntil( + // job, + // function(j) { + // return !j.properties()["isPaused"]; + // }, + // 10, + // done + // ); + // }, + // function(job, done) { + // test.ok(!job.properties()["isPaused"]); + // job.finalize(done); + // }, + // function(job, done) { + // job.cancel(done); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, "Callback#Set TTL": function(test) { var sid = getNextId(); @@ -383,42 +392,45 @@ module.exports = function(svc) { ); }, - "Callback#Set priority": function(test) { - var sid = getNextId(); - var originalPriority = 0; - var that = this; - - var service = this.service.specialize("nobody", "sdk-app-collection"); - - Async.chain([ - function(done) { - service.jobs().search('search index=_internal | head 1 | sleep 5', {id: sid}, done); - }, - function(job, done) { - job.track({}, { - ready: function(job) { - done(null, job); - } - }); - }, - function(job, done) { - var priority = job.properties()["priority"]; - test.ok(priority, 5); - job.setPriority(priority + 1, done); - }, - function(job, done) { - job.fetch(done); - }, - function(job, done) { - job.cancel(done); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, + // Disabling this test because apps/appinstall endpoint is deprecated in Splunk 8.2. + // + // + // "Callback#Set priority": function(test) { + // var sid = getNextId(); + // var originalPriority = 0; + // var that = this; + + // var service = this.service.specialize("nobody", "sdk-app-collection"); + + // Async.chain([ + // function(done) { + // service.jobs().search('search index=_internal | head 1 | sleep 5', {id: sid}, done); + // }, + // function(job, done) { + // job.track({}, { + // ready: function(job) { + // done(null, job); + // } + // }); + // }, + // function(job, done) { + // var priority = job.properties()["priority"]; + // test.ok(priority, 5); + // job.setPriority(priority + 1, done); + // }, + // function(job, done) { + // job.fetch(done); + // }, + // function(job, done) { + // job.cancel(done); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, "Callback#Search log": function(test) { var sid = getNextId(); diff --git a/tests/service_tests/storagepasswords.js b/tests/service_tests/storagepasswords.js index 551d7bfee..c53e806fe 100644 --- a/tests/service_tests/storagepasswords.js +++ b/tests/service_tests/storagepasswords.js @@ -456,76 +456,79 @@ module.exports = function(svc) { ); }, - "Callback#Update": function(test) { - var startcount = -1; - var name = "delete-me-" + getNextId(); - var realm = "delete-me-" + getNextId(); - var that = this; - Async.chain([ - function(done) { - that.service.storagePasswords().fetch(done); - }, - function(storagePasswords, done) { - startcount = storagePasswords.list().length; - storagePasswords.create({name: name, realm: realm, password: "changeme"}, done); - }, - function(storagePassword, done) { - test.strictEqual(name, storagePassword.properties().username); - test.strictEqual(realm + ":" + name + ":", storagePassword.name); - test.strictEqual("changeme", storagePassword.properties().clear_password); - test.strictEqual(realm, storagePassword.properties().realm); - that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); - }, - function(storagePasswords, storagePassword, done) { - test.strictEqual(startcount + 1, storagePasswords.list().length); - storagePassword.update({password: "changed"}, done); - }, - function(storagePassword, done) { - test.strictEqual(name, storagePassword.properties().username); - test.strictEqual(realm + ":" + name + ":", storagePassword.name); - test.strictEqual("changed", storagePassword.properties().clear_password); - test.strictEqual(realm, storagePassword.properties().realm); - that.service.storagePasswords().fetch(done); - }, - function(storagePasswords, done) { - var list = storagePasswords.list(); - var found = false; - var index = -1; + // Disabling this test because clear_password field has been removed in Splunk 8.2 + // + // + // "Callback#Update": function(test) { + // var startcount = -1; + // var name = "delete-me-" + getNextId(); + // var realm = "delete-me-" + getNextId(); + // var that = this; + // Async.chain([ + // function(done) { + // that.service.storagePasswords().fetch(done); + // }, + // function(storagePasswords, done) { + // startcount = storagePasswords.list().length; + // storagePasswords.create({name: name, realm: realm, password: "changeme"}, done); + // }, + // function(storagePassword, done) { + // test.strictEqual(name, storagePassword.properties().username); + // test.strictEqual(realm + ":" + name + ":", storagePassword.name); + // test.strictEqual("changeme", storagePassword.properties().clear_password); + // test.strictEqual(realm, storagePassword.properties().realm); + // that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); + // }, + // function(storagePasswords, storagePassword, done) { + // test.strictEqual(startcount + 1, storagePasswords.list().length); + // storagePassword.update({password: "changed"}, done); + // }, + // function(storagePassword, done) { + // test.strictEqual(name, storagePassword.properties().username); + // test.strictEqual(realm + ":" + name + ":", storagePassword.name); + // test.strictEqual("changed", storagePassword.properties().clear_password); + // test.strictEqual(realm, storagePassword.properties().realm); + // that.service.storagePasswords().fetch(done); + // }, + // function(storagePasswords, done) { + // var list = storagePasswords.list(); + // var found = false; + // var index = -1; - test.strictEqual(startcount + 1, list.length); - for (var i = 0; i < list.length; i ++) { - if (realm + ":" + name + ":" === list[i].name) { - found = true; - index = i; - test.strictEqual(name, list[i].properties().username); - test.strictEqual(realm + ":" + name + ":", list[i].name); - test.strictEqual("changed", list[i].properties().clear_password); - test.strictEqual(realm, list[i].properties().realm); - } - } - test.ok(found); + // test.strictEqual(startcount + 1, list.length); + // for (var i = 0; i < list.length; i ++) { + // if (realm + ":" + name + ":" === list[i].name) { + // found = true; + // index = i; + // test.strictEqual(name, list[i].properties().username); + // test.strictEqual(realm + ":" + name + ":", list[i].name); + // test.strictEqual("changed", list[i].properties().clear_password); + // test.strictEqual(realm, list[i].properties().realm); + // } + // } + // test.ok(found); - if (!found) { - done(new Error("Didn't find the created password")); - } - else { - list[index].remove(done); - } - }, - function(done) { - that.service.storagePasswords().fetch(done); - }, - function(storagePasswords, done) { - test.strictEqual(startcount, storagePasswords.list().length); - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, + // if (!found) { + // done(new Error("Didn't find the created password")); + // } + // else { + // list[index].remove(done); + // } + // }, + // function(done) { + // that.service.storagePasswords().fetch(done); + // }, + // function(storagePasswords, done) { + // test.strictEqual(startcount, storagePasswords.list().length); + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, "Callback#Delete": function(test) { var startcount = -1; From ff1fc0026a1668bbfe84b9bdb6d2ef8db8900f26 Mon Sep 17 00:00:00 2001 From: vmalaviya Date: Fri, 11 Jun 2021 11:19:52 +0530 Subject: [PATCH 004/178] Update package.json --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index e24522ab9..e6d3eadc3 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,8 @@ "dependencies": { "cookie": "0.2.0", "elementtree": "0.1.6", - "request": "^2.x.x" + "request": "^2.x.x", + "needle": "2.6.0" }, "devDependencies": { "browserify": "^16.2.3", From 339a005d08383c5214e301ac1be711c4bb7079ac Mon Sep 17 00:00:00 2001 From: akaila-splunk Date: Tue, 15 Jun 2021 14:05:44 +0530 Subject: [PATCH 005/178] Modified code for testing --- .env | 1 + bin/cli.js | 3 + client/splunk.test.js | 12948 ++++++++-------- client/splunk.test.min.js | 2 +- docker-compose.yml | 2 +- examples/browser/helloworld/index.html | 6 +- examples/browser/minisplunk/index.html | 2 +- examples/browser/minisplunk/views.js | 2 +- examples/browser/ui/index.html | 6 +- examples/browser/viz/index.html | 6 +- examples/node/helloworld/apps.js | 2 +- examples/node/helloworld/apps_async.js | 2 +- .../node/helloworld/endpoint_instantiation.js | 2 +- examples/node/helloworld/firedalerts.js | 2 +- examples/node/helloworld/firedalerts_async.js | 2 +- .../node/helloworld/firedalerts_create.js | 2 +- .../node/helloworld/firedalerts_delete.js | 2 +- examples/node/helloworld/get_job.js | 2 +- examples/node/helloworld/log.js | 2 +- examples/node/helloworld/pivot_async.js | 2 +- examples/node/helloworld/savedsearches.js | 2 +- .../node/helloworld/savedsearches_async.js | 2 +- .../node/helloworld/savedsearches_create.js | 2 +- .../node/helloworld/savedsearches_delete.js | 2 +- examples/node/helloworld/search_blocking.js | 2 +- examples/node/helloworld/search_normal.js | 2 +- examples/node/helloworld/search_oneshot.js | 2 +- examples/node/helloworld/search_realtime.js | 2 +- index.js | 1 + package-lock.json | 41 +- package.json | 5 +- tests/service_tests/storagepasswords.js | 46 +- tests/tests.browser.html | 10 +- 33 files changed, 6580 insertions(+), 6537 deletions(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 000000000..c80803e8e --- /dev/null +++ b/.env @@ -0,0 +1 @@ +SPLUNK_HOME="/opt/splunk" \ No newline at end of file diff --git a/bin/cli.js b/bin/cli.js index 29234a91e..e644182f5 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -124,6 +124,7 @@ res.end(); } catch (ex) { + console.log("Ex - ", ex); writeError(); } }); @@ -143,12 +144,14 @@ // }); } catch (ex) { + console.log("Ex - ", ex); writeError(); } }); } catch (ex) { + console.log("Ex - ", ex); writeError(); } }; diff --git a/client/splunk.test.js b/client/splunk.test.js index 812906052..fc077ae18 100644 --- a/client/splunk.test.js +++ b/client/splunk.test.js @@ -16027,6212 +16027,6212 @@ exports.setup = function(svc, loggedOutSvc) { }; var suite = { - "Namespace Tests": { - setUp: function(finished) { - this.service = svc; - var that = this; - - var appName1 = "jssdk_testapp_" + getNextId(); - var appName2 = "jssdk_testapp_" + getNextId(); - - var userName1 = "jssdk_testuser_" + getNextId(); - var userName2 = "jssdk_testuser_" + getNextId(); - - var apps = this.service.apps(); - var users = this.service.users(); - - this.namespace11 = {owner: userName1, app: appName1}; - this.namespace12 = {owner: userName1, app: appName2}; - this.namespace21 = {owner: userName2, app: appName1}; - this.namespace22 = {owner: userName2, app: appName2}; - - Async.chain([ - function(done) { - apps.create({name: appName1}, done); - }, - function(app1, done) { - that.app1 = app1; - that.appName1 = appName1; - apps.create({name: appName2}, done); - }, - function(app2, done) { - that.app2 = app2; - that.appName2 = appName2; - users.create({name: userName1, password: "abc", roles: ["user"]}, done); - }, - function(user1, done) { - that.user1 = user1; - that.userName1 = userName1; - users.create({name: userName2, password: "abc", roles: ["user"]}, done); - }, - function(user2, done) { - that.user2 = user2; - that.userName2 = userName2; - - done(); - } - ], - function(err) { - finished(); - } - ); - }, - - "Callback#Namespace protection": function(test) { - var searchName = "jssdk_search_" + getNextId(); - var search = "search *"; - var service = this.service; - - var savedSearches11 = service.savedSearches(this.namespace11); - var savedSearches21 = service.savedSearches(this.namespace21); - - var that = this; - Async.chain([ - function(done) { - // Create the saved search only in the 11 namespace - savedSearches11.create({name: searchName, search: search}, done); - }, - function(savedSearch, done) { - // Refresh the 11 saved searches - savedSearches11.fetch(done); - }, - function(savedSearches, done) { - // Refresh the 21 saved searches - savedSearches21.fetch(done); - }, - function(savedSearches, done) { - var entity11 = savedSearches11.item(searchName); - var entity21 = savedSearches21.item(searchName); - - // Make sure the saved search exists in the 11 namespace - test.ok(entity11); - test.strictEqual(entity11.name, searchName); - test.strictEqual(entity11.properties().search, search); - - // Make sure the saved search doesn't exist in the 11 namespace - test.ok(!entity21); - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Namespace item": function(test) { - var searchName = "jssdk_search_" + getNextId(); - var search = "search *"; - var service = this.service; - - var namespace_1 = {owner: "-", app: this.appName1}; - var namespace_nobody1 = {owner: "nobody", app: this.appName1}; - - var savedSearches11 = service.savedSearches(this.namespace11); - var savedSearches21 = service.savedSearches(this.namespace21); - var savedSearches_1 = service.savedSearches(namespace_1); - var savedSearches_nobody1 = service.savedSearches(namespace_nobody1); - - var that = this; - Async.chain([ - function(done) { - // Create a saved search in the 11 namespace - savedSearches11.create({name: searchName, search: search}, done); - }, - function(savedSearch, done) { - // Create a saved search in the 21 namespace - savedSearches21.create({name: searchName, search: search}, done); - }, - function(savedSearch, done) { - // Refresh the -/1 namespace - savedSearches_1.fetch(done); - }, - function(savedSearches, done) { - // Refresh the 1/1 namespace - savedSearches11.fetch(done); - }, - function(savedSearches, done) { - // Refresh the 2/1 namespace - savedSearches21.fetch(done); - }, - function(savedSearches, done) { - var entity11 = savedSearches11.item(searchName, that.namespace11); - var entity21 = savedSearches21.item(searchName, that.namespace21); - - // Ensure that the saved search exists in the 11 namespace - test.ok(entity11); - test.strictEqual(entity11.name, searchName); - test.strictEqual(entity11.properties().search, search); - test.strictEqual(entity11.namespace.owner, that.namespace11.owner); - test.strictEqual(entity11.namespace.app, that.namespace11.app); - - // Ensure that the saved search exists in the 21 namespace - test.ok(entity21); - test.strictEqual(entity21.name, searchName); - test.strictEqual(entity21.properties().search, search); - test.strictEqual(entity21.namespace.owner, that.namespace21.owner); - test.strictEqual(entity21.namespace.app, that.namespace21.app); - - done(); - }, - function(done) { - // Create a saved search in the nobody/1 namespace - savedSearches_nobody1.create({name: searchName, search: search}, done); - }, - function(savedSearch, done) { - // Refresh the 1/1 namespace - savedSearches11.fetch(done); - }, - function(savedSearches, done) { - // Refresh the 2/1 namespace - savedSearches21.fetch(done); - }, - function(savedSearches, done) { - // Ensure that we can't get the item from the generic - // namespace without specifying a namespace - try { - savedSearches_1.item(searchName); - test.ok(false); - } - catch(err) { - test.ok(err); - } - - // Ensure that we can't get the item using wildcard namespaces. - try{ - savedSearches_1.item(searchName, {owner:'-'}); - test.ok(false); - } - catch(err){ - test.ok(err); - } - - try{ - savedSearches_1.item(searchName, {app:'-'}); - test.ok(false); - } - catch(err){ - test.ok(err); - } - - try{ - savedSearches_1.item(searchName, {app:'-', owner:'-'}); - test.ok(false); - } - catch(err){ - test.ok(err); - } - - // Ensure we get the right entities from the -/1 namespace when we - // specify it. - var entity11 = savedSearches_1.item(searchName, that.namespace11); - var entity21 = savedSearches_1.item(searchName, that.namespace21); - - test.ok(entity11); - test.strictEqual(entity11.name, searchName); - test.strictEqual(entity11.properties().search, search); - test.strictEqual(entity11.namespace.owner, that.namespace11.owner); - test.strictEqual(entity11.namespace.app, that.namespace11.app); - - test.ok(entity21); - test.strictEqual(entity21.name, searchName); - test.strictEqual(entity21.properties().search, search); - test.strictEqual(entity21.namespace.owner, that.namespace21.owner); - test.strictEqual(entity21.namespace.app, that.namespace21.app); - - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#delete test applications": function(test) { - var apps = this.service.apps(); - apps.fetch(function(err, apps) { - test.ok(!err); - test.ok(apps); - var appList = apps.list(); - - Async.parallelEach( - appList, - function(app, idx, callback) { - if (utils.startsWith(app.name, "jssdk_")) { - app.remove(callback); - } - else { - callback(); - } - }, function(err) { - test.ok(!err); - test.done(); - } - ); - }); - }, - - "Callback#delete test users": function(test) { - var users = this.service.users(); - users.fetch(function(err, users) { - var userList = users.list(); - - Async.parallelEach( - userList, - function(user, idx, callback) { - if (utils.startsWith(user.name, "jssdk_")) { - user.remove(callback); - } - else { - callback(); - } - }, function(err) { - test.ok(!err); - test.done(); - } - ); - }); - } - }, - - "Job Tests": { - setUp: function(done) { - this.service = svc; - done(); - }, - - "Callback#Create+abort job": function(test) { - var service = this.service; - Async.chain([ - function(done){ - var app_name = path.join(process.env.SPLUNK_HOME, ('/etc/apps/sdk-app-collection/build/sleep_command.tar')); - // Fix path on Windows if $SPLUNK_HOME contains a space (ex: C:/Program%20Files/Splunk) - app_name = app_name.replace("%20", " "); - service.post("apps/appinstall", {update:1, name:app_name}, done); - }, - function(done){ - var sid = getNextId(); - var options = {id: sid}; - var jobs = service.jobs({app: "sdk-app-collection"}); - var req = jobs.oneshotSearch('search index=_internal | head 1 | sleep 10', options, function(err, job) { - test.ok(err); - test.ok(!job); - test.strictEqual(err.error, "abort"); - test.done(); - }); - - Async.sleep(1000, function(){ - req.abort(); - }); - } - ], - function(err){ - test.ok(!err); - test.done(); - }); - }, - - "Callback#Create+cancel job": function(test) { - var sid = getNextId(); - this.service.jobs().search('search index=_internal | head 1', {id: sid}, function(err, job) { - test.ok(job); - test.strictEqual(job.sid, sid); - - job.cancel(function() { - test.done(); - }); - }); - }, - - "Callback#Create job error": function(test) { - var sid = getNextId(); - this.service.jobs().search({search: 'index=_internal | head 1', id: sid}, function(err) { - test.ok(!!err); - test.done(); - }); - }, - - "Callback#List jobs": function(test) { - this.service.jobs().fetch(function(err, jobs) { - test.ok(!err); - test.ok(jobs); - - var jobsList = jobs.list(); - test.ok(jobsList.length > 0); - - for(var i = 0; i < jobsList.length; i++) { - test.ok(jobsList[i]); - } - - test.done(); - }); - }, - - "Callback#Contains job": function(test) { - var that = this; - var sid = getNextId(); - var jobs = this.service.jobs(); - - jobs.search('search index=_internal | head 1', {id: sid}, function(err, job) { - test.ok(!err); - test.ok(job); - test.strictEqual(job.sid, sid); - - jobs.fetch(function(err, jobs) { - test.ok(!err); - var job = jobs.item(sid); - test.ok(job); - - job.cancel(function() { - test.done(); - }); - }); - }); - }, - - "Callback#job results": function(test) { - var sid = getNextId(); - var service = this.service; - var that = this; - - Async.chain([ - function(done) { - that.service.jobs().search('search index=_internal | head 1 | stats count', {id: sid}, done); - }, - function(job, done) { - test.strictEqual(job.sid, sid); - tutils.pollUntil( - job, - function(j) { - return job.properties()["isDone"]; - }, - 10, - done - ); - }, - function(job, done) { - job.results({}, done); - }, - function(results, job, done) { - test.strictEqual(results.rows.length, 1); - test.strictEqual(results.fields.length, 1); - test.strictEqual(results.fields[0], "count"); - test.strictEqual(results.rows[0][0], "1"); - job.cancel(done); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#job events": function(test) { - var sid = getNextId(); - var service = this.service; - var that = this; - - Async.chain([ - function(done) { - that.service.jobs().search('search index=_internal | head 1', {id: sid}, done); - }, - function(job, done) { - test.strictEqual(job.sid, sid); - tutils.pollUntil( - job, - function(j) { - return job.properties()["isDone"]; - }, - 10, - done - ); - }, - function(job, done) { - job.events({}, done); - }, - function(results, job, done) { - test.strictEqual(results.rows.length, 1); - test.strictEqual(results.fields.length, results.rows[0].length); - job.cancel(done); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#job results preview": function(test) { - var sid = getNextId(); - var service = this.service; - var that = this; - - Async.chain([ - function(done) { - that.service.jobs().search('search index=_internal | head 1 | stats count', {id: sid}, done); - }, - function(job, done) { - test.strictEqual(job.sid, sid); - tutils.pollUntil( - job, - function(j) { - return job.properties()["isDone"]; - }, - 10, - done - ); - }, - function(job, done) { - job.preview({}, done); - }, - function(results, job, done) { - test.strictEqual(results.rows.length, 1); - test.strictEqual(results.fields.length, 1); - test.strictEqual(results.fields[0], "count"); - test.strictEqual(results.rows[0][0], "1"); - job.cancel(done); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#job results iterator": function(test) { - var that = this; - - Async.chain([ - function(done) { - that.service.jobs().search('search index=_internal | head 10', {}, done); - }, - function(job, done) { - tutils.pollUntil( - job, - function(j) { - return job.properties()["isDone"]; - }, - 10, - done - ); - }, - function(job, done) { - var iterator = job.iterator("results", { pagesize: 4 }); - var hasMore = true; - var numElements = 0; - var pageSizes = []; - Async.whilst( - function() { return hasMore; }, - function(nextIteration) { - iterator.next(function(err, results, _hasMore) { - if (err) { - nextIteration(err); - return; - } - - hasMore = _hasMore; - if (hasMore) { - pageSizes.push(results.rows.length); - } - nextIteration(); - }); - }, - function(err) { - test.deepEqual(pageSizes, [4,4,2]); - done(err); - } - ); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Enable + disable preview": function(test) { - var that = this; - var sid = getNextId(); - - var service = this.service.specialize("nobody", "sdk-app-collection"); - - Async.chain([ - function(done) { - service.jobs().search('search index=_internal | head 1 | sleep 60', {id: sid}, done); - }, - function(job, done) { - job.enablePreview(done); - - }, - function(job, done) { - job.disablePreview(done); - }, - function(job, done) { - job.cancel(done); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Pause + unpause + finalize preview": function(test) { - var that = this; - var sid = getNextId(); - - var service = this.service.specialize("nobody", "sdk-app-collection"); - - Async.chain([ - function(done) { - service.jobs().search('search index=_internal | head 1 | sleep 5', {id: sid}, done); - }, - function(job, done) { - job.pause(done); - }, - function(job, done) { - tutils.pollUntil( - job, - function(j) { - return j.properties()["isPaused"]; - }, - 10, - done - ); - }, - function(job, done) { - test.ok(job.properties()["isPaused"]); - job.unpause(done); - }, - function(job, done) { - tutils.pollUntil( - job, - function(j) { - return !j.properties()["isPaused"]; - }, - 10, - done - ); - }, - function(job, done) { - test.ok(!job.properties()["isPaused"]); - job.finalize(done); - }, - function(job, done) { - job.cancel(done); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Set TTL": function(test) { - var sid = getNextId(); - var originalTTL = 0; - var that = this; - - Async.chain([ - function(done) { - that.service.jobs().search('search index=_internal | head 1', {id: sid}, done); - }, - function(job, done) { - job.fetch(done); - }, - function(job, done) { - var ttl = job.properties()["ttl"]; - originalTTL = ttl; - - job.setTTL(ttl*2, done); - }, - function(job, done) { - job.fetch(done); - }, - function(job, done) { - var ttl = job.properties()["ttl"]; - test.ok(ttl > originalTTL); - test.ok(ttl <= (originalTTL*2)); - job.cancel(done); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Set priority": function(test) { - var sid = getNextId(); - var originalPriority = 0; - var that = this; - - var service = this.service.specialize("nobody", "sdk-app-collection"); - - Async.chain([ - function(done) { - service.jobs().search('search index=_internal | head 1 | sleep 5', {id: sid}, done); - }, - function(job, done) { - job.track({}, { - ready: function(job) { - done(null, job); - } - }); - }, - function(job, done) { - var priority = job.properties()["priority"]; - test.ok(priority, 5); - job.setPriority(priority + 1, done); - }, - function(job, done) { - job.fetch(done); - }, - function(job, done) { - job.cancel(done); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Search log": function(test) { - var sid = getNextId(); - var that = this; - - Async.chain([ - function(done) { - that.service.jobs().search('search index=_internal | head 1', {id: sid, exec_mode: "blocking"}, done); - }, - function(job, done) { - job.searchlog(done); - }, - function(log, job, done) { - test.ok(job); - test.ok(log); - test.ok(log.length > 0); - test.ok(log.split("\r\n").length > 0); - job.cancel(done); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Search summary": function(test) { - var sid = getNextId(); - var that = this; - - Async.chain([ - function(done) { - that.service.jobs().search( - 'search index=_internal | head 1 | eval foo="bar" | fields foo', - { - id: sid, - status_buckets: 300, - rf: ["foo"] - }, - done); - }, - function(job, done) { - // Let's sleep for 2 second so - // we let the server catch up - Async.sleep(2000, function() { - job.summary({}, done); - }); - }, - function(summary, job, done) { - test.ok(job); - test.ok(summary); - test.strictEqual(summary.event_count, 1); - test.strictEqual(summary.fields.foo.count, 1); - test.strictEqual(summary.fields.foo.distinct_count, 1); - test.ok(summary.fields.foo.is_exact, 1); - test.strictEqual(summary.fields.foo.modes.length, 1); - test.strictEqual(summary.fields.foo.modes[0].count, 1); - test.strictEqual(summary.fields.foo.modes[0].value, "bar"); - test.ok(summary.fields.foo.modes[0].is_exact); - job.cancel(done); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Search timeline": function(test) { - var sid = getNextId(); - var that = this; - - Async.chain([ - function(done) { - that.service.jobs().search( - 'search index=_internal | head 1 | eval foo="bar" | fields foo', - { - id: sid, - status_buckets: 300, - rf: ["foo"], - exec_mode: "blocking" - }, - done); - }, - function(job, done) { - job.timeline({}, done); - }, - function(timeline, job, done) { - test.ok(job); - test.ok(timeline); - test.strictEqual(timeline.buckets.length, 1); - test.strictEqual(timeline.event_count, 1); - test.strictEqual(timeline.buckets[0].available_count, 1); - test.strictEqual(timeline.buckets[0].duration, 0.001); - test.strictEqual(timeline.buckets[0].earliest_time_offset, timeline.buckets[0].latest_time_offset); - test.strictEqual(timeline.buckets[0].total_count, 1); - test.ok(timeline.buckets[0].is_finalized); - job.cancel(done); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Touch": function(test) { - var sid = getNextId(); - var that = this; - var originalTime = ""; - - Async.chain([ - function(done) { - that.service.jobs().search('search index=_internal | head 1', {id: sid}, done); - }, - function(job, done) { - job.fetch(done); - }, - function(job, done) { - test.ok(job); - originalTime = job.properties().updated; - Async.sleep(1200, function() { job.touch(done); }); - }, - function(job, done) { - job.fetch(done); - }, - function(job, done) { - test.ok(originalTime !== job.updated()); - job.cancel(done); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Create failure": function(test) { - var name = "jssdk_savedsearch_" + getNextId(); - var originalSearch = "search index=_internal | head 1"; - - var jobs = this.service.jobs(); - test.throws(function() {jobs.create({search: originalSearch, name: name, exec_mode: "oneshot"}, function() {});}); - test.done(); - }, - - "Callback#Create fails with no search string": function(test) { - var jobs = this.service.jobs(); - jobs.create( - "", {}, - function(err) { - test.ok(err); - test.done(); - } - ); - }, - - "Callback#Oneshot search": function(test) { - var sid = getNextId(); - var that = this; - var originalTime = ""; - - Async.chain([ - function(done) { - that.service.jobs().oneshotSearch('search index=_internal | head 1 | stats count', {id: sid}, done); - }, - function(results, done) { - test.ok(results); - test.ok(results.fields); - test.strictEqual(results.fields.length, 1); - test.strictEqual(results.fields[0], "count"); - test.ok(results.rows); - test.strictEqual(results.rows.length, 1); - test.strictEqual(results.rows[0].length, 1); - test.strictEqual(results.rows[0][0], "1"); - - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Oneshot search with no results": function(test) { - var sid = getNextId(); - var that = this; - var originalTime = ""; - - Async.chain([ - function(done) { - var query = 'search index=history MUST_NOT_EXISTABCDEF'; - that.service.jobs().oneshotSearch(query, {id: sid}, done); - }, - function(results, done) { - test.ok(results); - test.strictEqual(results.fields.length, 0); - test.strictEqual(results.rows.length, 0); - test.ok(!results.preview); - - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Service oneshot search": function(test) { - var sid = getNextId(); - var that = this; - var namespace = {owner: "admin", app: "search"}; - var splunkVersion = 6.1; // Default to pre-6.2 version - var originalLoggerLevel = "DEBUG"; - - Async.chain([ - function(done) { - // If running on Splunk 6.2+, first set the search logger level to DEBUG - Async.chain([ - function(done1) { - that.service.serverInfo(done1); - }, - function(info, done1) { - splunkVersion = parseFloat(info.properties().version); - if (splunkVersion < 6.2) { - done(); // Exit the inner Async.chain - } - else { - done1(); - } - }, - function(done1) { - that.service.configurations({owner: "admin", app: "search"}).fetch(done1); - }, - function(confs, done1) { - try { - confs.item("limits").fetch(done1); - } - catch(e) { - done1(e); - } - }, - function(conf, done1) { - var searchInfo = conf.item("search_info"); - // Save this so it can be restored later - originalLoggerLevel = searchInfo.properties()["infocsv_log_level"]; - searchInfo.update({"infocsv_log_level": "DEBUG"}, done1); - }, - function(conf, done1) { - test.strictEqual("DEBUG", conf.properties()["infocsv_log_level"]); - done1(); - } - ], - function(err) { - test.ok(!err); - done(); - } - ); - }, - function(done) { - that.service.oneshotSearch('search index=_internal | head 1 | stats count', {id: sid}, namespace, done); - }, - function(results, done) { - test.ok(results); - test.ok(results.fields); - test.strictEqual(results.fields.length, 1); - test.strictEqual(results.fields[0], "count"); - test.ok(results.rows); - test.strictEqual(results.rows.length, 1); - test.strictEqual(results.rows[0].length, 1); - test.strictEqual(results.rows[0][0], "1"); - test.ok(results.messages[1].text.indexOf('owner="admin"')); - test.ok(results.messages[1].text.indexOf('app="search"')); - - done(); - }, - function(done) { - Async.chain([ - function(done1) { - if (splunkVersion < 6.2) { - done(); // Exit the inner Async.chain - } - else { - done1(); - } - }, - function(done1) { - that.service.configurations({owner: "admin", app: "search"}).fetch(done1); - }, - function(confs, done1) { - try { - confs.item("limits").fetch(done1); - } - catch(e) { - done1(e); - } - }, - function(conf, done1) { - var searchInfo = conf.item("search_info"); - // Restore the logger level from before - searchInfo.update({"infocsv_log_level": originalLoggerLevel}, done1); - }, - function(conf, done1) { - test.strictEqual(originalLoggerLevel, conf.properties()["infocsv_log_level"]); - done1(); - } - ], - function(err) { - test.ok(!err); - done(); - } - ); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Service search": function(test) { - var sid = getNextId(); - var service = this.service; - var that = this; - var namespace = {owner: "admin", app: "search"}; - - Async.chain([ - function(done) { - that.service.search('search index=_internal | head 1 | stats count', {id: sid}, namespace, done); - }, - function(job, done) { - test.strictEqual(job.sid, sid); - test.strictEqual(job.namespace, namespace); - tutils.pollUntil( - job, - function(j) { - return job.properties()["isDone"]; - }, - 10, - done - ); - }, - function(job, done) { - job.results({}, done); - }, - function(results, job, done) { - test.strictEqual(results.rows.length, 1); - test.strictEqual(results.fields.length, 1); - test.strictEqual(results.fields[0], "count"); - test.strictEqual(results.rows[0][0], "1"); - job.cancel(done); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Wait until job done": function(test) { - this.service.search('search index=_internal | head 1000', {}, function(err, job) { - test.ok(!err); - - var numReadyEvents = 0; - var numProgressEvents = 0; - job.track({ period: 200 }, { - ready: function(job) { - test.ok(job); - - numReadyEvents++; - }, - progress: function(job) { - test.ok(job); - - numProgressEvents++; - }, - done: function(job) { - test.ok(job); - - test.ok(numReadyEvents === 1); // all done jobs must have become ready - test.ok(numProgressEvents >= 1); // a job that becomes ready has progress - test.done(); - }, - failed: function(job) { - test.ok(job); - - test.ok(false, "Job failed unexpectedly."); - test.done(); - }, - error: function(err) { - test.ok(err); - - test.ok(false, "Error while tracking job."); - test.done(); - } - }); - }); - }, - - "Callback#Wait until job failed": function(test) { - this.service.search('search index=_internal | head bogusarg', {}, function(err, job) { - if (err) { - test.ok(!err); - test.done(); - return; - } - - var numReadyEvents = 0; - var numProgressEvents = 0; - job.track({ period: 200 }, { - ready: function(job) { - test.ok(job); - - numReadyEvents++; - }, - progress: function(job) { - test.ok(job); - - numProgressEvents++; - }, - done: function(job) { - test.ok(job); - - test.ok(false, "Job became done unexpectedly."); - test.done(); - }, - failed: function(job) { - test.ok(job); - - test.ok(numReadyEvents === 1); // even failed jobs become ready - test.ok(numProgressEvents >= 1); // a job that becomes ready has progress - test.done(); - }, - error: function(err) { - test.ok(err); - - test.ok(false, "Error while tracking job."); - test.done(); - } - }); - }); - }, - - "Callback#track() with default params and one function": function(test) { - this.service.search('search index=_internal | head 1', {}, function(err, job) { - if (err) { - test.ok(!err); - test.done(); - return; - } - - job.track({}, function(job) { - test.ok(job); - test.done(); - }); - }); - }, - - "Callback#track() should stop polling if only the ready callback is specified": function(test) { - this.service.search('search index=_internal | head 1', {}, function(err, job) { - if (err) { - test.ok(!err); - test.done(); - return; - } - - job.track({}, { - ready: function(job) { - test.ok(job); - }, - - _stoppedAfterReady: function(job) { - test.done(); - } - }); - }); - }, - - "Callback#track() a job that is not immediately ready": function(test) { - /*jshint loopfunc:true */ - var numJobs = 20; - var numJobsLeft = numJobs; - var gotJobNotImmediatelyReady = false; - for (var i = 0; i < numJobs; i++) { - this.service.search('search index=_internal | head 10000', {}, function(err, job) { - if (err) { - test.ok(!err); - test.done(); - return; - } - - job.track({}, { - _preready: function(job) { - gotJobNotImmediatelyReady = true; - }, - - ready: function(job) { - numJobsLeft--; - - if (numJobsLeft === 0) { - if (!gotJobNotImmediatelyReady) { - splunkjs.Logger.error("", "WARNING: Couldn't test code path in track() where job wasn't ready immediately."); - } - test.done(); - } - } - }); - }); - } - }, - - "Callback#Service.getJob() works": function(test) { - var that = this; - var sidsMatch = false; - this.service.search('search index=_internal | head 1', {}, function(err, job){ - if (err) { - test.ok(!err); - test.done(); - return; - } - var sid = job.sid; - return Async.chain([ - function(done) { - that.service.getJob(sid, done); - }, - function(innerJob, done) { - test.strictEqual(sid, innerJob.sid); - sidsMatch = sid === innerJob.sid; - done(); - } - ], - function(err) { - test.ok(!err); - test.ok(sidsMatch); - test.done(); - } - ); - }); - } - }, - - "Data Model tests": { - setUp: function(done) { - this.service = svc; - this.dataModels = svc.dataModels(); - this.skip = false; - var that = this; - this.service.serverInfo(function(err, info) { - if (parseInt(info.properties().version.split(".")[0], 10) < 6) { - that.skip = true; - splunkjs.Logger.log("Skipping data model tests..."); - } - done(err); - }); - }, - - "Callback#DataModels - fetch a built-in data model": function(test) { - if (this.skip) { - test.done(); - return; - } - var that = this; - Async.chain([ - function(done) { - that.dataModels.fetch(done); - }, - function(dataModels, done) { - var dm = dataModels.item("internal_audit_logs"); - // Check for the 3 objects we expect - test.ok(dm.objectByName("Audit")); - test.ok(dm.objectByName("searches")); - test.ok(dm.objectByName("modify")); - - // Check for an object that shouldn't exist - test.strictEqual(null, dm.objectByName(getNextId())); - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#DataModels - create & delete an empty data model": function(test) { - if (this.skip) { - test.done(); - return; - } - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/empty_data_model.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var name = "delete-me-" + getNextId(); - - var initialSize; - var that = this; - Async.chain([ - function(done) { - that.dataModels.fetch(done); - }, - function(dataModels, done) { - initialSize = dataModels.list().length; - dataModels.create(name, args, done); - }, - function(dataModel, done) { - that.dataModels.fetch(done); - }, - function(dataModels, done) { - // Make sure we have 1 more data model than we started with - test.strictEqual(initialSize + 1, dataModels.list().length); - // Delete the data model we just created, by name. - dataModels.item(name).remove(done); - }, - function(done) { - that.dataModels.fetch(done); - }, - function(dataModels, done) { - // Make sure we have as many data models as we started with - test.strictEqual(initialSize, dataModels.list().length); - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#DataModels - create a data model with spaces in the name, which are swapped for -'s": function(test) { - if (this.skip) { - test.done(); - return; - } - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/empty_data_model.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var name = "delete-me- " + getNextId(); - - var that = this; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - test.strictEqual(name.replace(" ", "_"), dataModel.name); - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#DataModels - create a data model with 0 objects": function(test) { - if (this.skip) { - test.done(); - return; - } - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/empty_data_model.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var name = "delete-me-" + getNextId(); - - var that = this; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - // Check for 0 objects before fetch - test.strictEqual(0, dataModel.objects.length); - that.dataModels.fetch(done); - }, - function(dataModels, done) { - // Check for 0 objects after fetch - test.strictEqual(0, dataModels.item(name).objects.length); - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#DataModels - create a data model with 1 search object": function(test) { - if (this.skip) { - test.done(); - return; - } - var dataModels = this.service.dataModels(); - - - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/object_with_one_search.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var name = "delete-me-" + getNextId(); - - var that = this; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - // Check for 1 object before fetch - test.strictEqual(1, dataModel.objects.length); - that.dataModels.fetch(done); - }, - function(dataModels, done) { - // Check for 1 object after fetch - test.strictEqual(1, dataModels.item(name).objects.length); - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#DataModels - create a data model with 2 search objects": function(test) { - if (this.skip) { - test.done(); - return; - } - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/object_with_two_searches.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var name = "delete-me-" + getNextId(); - - var that = this; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - // Check for 2 objects before fetch - test.strictEqual(2, dataModel.objects.length); - that.dataModels.fetch(done); - }, - function(dataModels, done) { - // Check for 2 objects after fetch - test.strictEqual(2, dataModels.item(name).objects.length); - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#DataModels - data model objects are created correctly": function(test) { - if (this.skip) { - test.done(); - return; - } - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/object_with_two_searches.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var name = "delete-me-" + getNextId(); - - var that = this; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - test.ok(dataModel.hasObject("search1")); - test.ok(dataModel.hasObject("search2")); - - var search1 = dataModel.objectByName("search1"); - test.ok(search1); - test.strictEqual("‡Øµ‡Ø±‡Ø∞‡ØØ - search 1", search1.displayName); - - var search2 = dataModel.objectByName("search2"); - test.ok(search2); - test.strictEqual("‡Øµ‡Ø±‡Ø∞‡ØØ - search 2", search2.displayName); - - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#DataModels - data model handles unicode characters": function(test) { - if (this.skip) { - test.done(); - return; - } - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/model_with_unicode_headers.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var name = "delete-me-" + getNextId(); - - var that = this; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - test.strictEqual(name, dataModel.name); - test.strictEqual("·Ä©·öô‡Øµ", dataModel.displayName); - test.strictEqual("‡Øµ‡Ø±‡Ø∞‡ØØ", dataModel.description); - - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#DataModels - create data model with empty headers": function(test) { - if (this.skip) { - test.done(); - return; - } - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/model_with_empty_headers.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var name = "delete-me-" + getNextId(); - - var that = this; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - test.strictEqual(name, dataModel.name); - test.strictEqual("", dataModel.displayName); - test.strictEqual("", dataModel.description); - - // Make sure we're not getting a summary of the data model - test.strictEqual("0", dataModel.concise); - - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#DataModels - test acceleration settings": function(test) { - if (this.skip) { - test.done(); - return; - } - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/data_model_with_test_objects.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var name = "delete-me-" + getNextId(); - - var that = this; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - dataModel.acceleration.enabled = true; - dataModel.acceleration.earliestTime = "-2mon"; - dataModel.acceleration.cronSchedule = "5/* * * * *"; - - test.strictEqual(true, dataModel.isAccelerated()); - test.strictEqual(true, dataModel.acceleration.enabled); - test.strictEqual("-2mon", dataModel.acceleration.earliestTime); - test.strictEqual("5/* * * * *", dataModel.acceleration.cronSchedule); - - dataModel.acceleration.enabled = false; - dataModel.acceleration.earliestTime = "-1mon"; - dataModel.acceleration.cronSchedule = "* * * * *"; - - test.strictEqual(false, dataModel.isAccelerated()); - test.strictEqual(false, dataModel.acceleration.enabled); - test.strictEqual("-1mon", dataModel.acceleration.earliestTime); - test.strictEqual("* * * * *", dataModel.acceleration.cronSchedule); - - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#DataModels - test data model object metadata": function(test) { - if (this.skip) { - test.done(); - return; - } - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/data_model_with_test_objects.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var name = "delete-me-" + getNextId(); - - var that = this; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - var obj = dataModel.objectByName("event1"); - test.ok(obj); - - test.strictEqual("event1 ·Ä©·öô", obj.displayName); - test.strictEqual("event1", obj.name); - test.same(dataModel, obj.dataModel); - - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#DataModels - test data model object parent": function(test) { - if (this.skip) { - test.done(); - return; - } - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/data_model_with_test_objects.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var name = "delete-me-" + getNextId(); - - var that = this; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - var obj = dataModel.objectByName("event1"); - test.ok(obj); - test.ok(!obj.parent()); - - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#DataModels - test data model object lineage": function(test) { - if (this.skip) { - test.done(); - return; - } - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/inheritance_test_data.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var name = "delete-me-" + getNextId(); - - var that = this; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - var obj = dataModel.objectByName("level_0"); - test.ok(obj); - test.strictEqual(1, obj.lineage.length); - test.strictEqual("level_0", obj.lineage[0]); - test.strictEqual("BaseEvent", obj.parentName); - - obj = dataModel.objectByName("level_1"); - test.ok(obj); - test.strictEqual(2, obj.lineage.length); - test.same(["level_0", "level_1"], obj.lineage); - test.strictEqual("level_0", obj.parentName); - - obj = dataModel.objectByName("level_2"); - test.ok(obj); - test.strictEqual(3, obj.lineage.length); - test.same(["level_0", "level_1", "level_2"], obj.lineage); - test.strictEqual("level_1", obj.parentName); - - // Make sure there's no extra children - test.ok(!dataModel.objectByName("level_3")); - - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#DataModels - test data model object fields": function(test) { - if (this.skip) { - test.done(); - return; - } - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/inheritance_test_data.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var name = "delete-me-" + getNextId(); - - var that = this; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - var obj = dataModel.objectByName("level_2"); - test.ok(obj); - - var timeField = obj.fieldByName("_time"); - test.ok(timeField); - test.strictEqual("timestamp", timeField.type); - test.ok(timeField.isTimestamp()); - test.ok(!timeField.isNumber()); - test.ok(!timeField.isString()); - test.ok(!timeField.isObjectcount()); - test.ok(!timeField.isChildcount()); - test.ok(!timeField.isIPv4()); - test.same(["BaseEvent"], timeField.lineage); - test.strictEqual("_time", timeField.name); - test.strictEqual(false, timeField.required); - test.strictEqual(false, timeField.multivalued); - test.strictEqual(false, timeField.hidden); - test.strictEqual(false, timeField.editable); - test.strictEqual(null, timeField.comment); - - var lvl2 = obj.fieldByName("level_2"); - test.strictEqual("level_2", lvl2.owner); - test.same(["level_0", "level_1", "level_2"], lvl2.lineage); - test.strictEqual("objectCount", lvl2.type); - test.ok(!lvl2.isTimestamp()); - test.ok(!lvl2.isNumber()); - test.ok(!lvl2.isString()); - test.ok(lvl2.isObjectcount()); - test.ok(!lvl2.isChildcount()); - test.ok(!lvl2.isIPv4()); - test.strictEqual("level_2", lvl2.name); - test.strictEqual("level 2", lvl2.displayName); - test.strictEqual(false, lvl2.required); - test.strictEqual(false, lvl2.multivalued); - test.strictEqual(false, lvl2.hidden); - test.strictEqual(false, lvl2.editable); - test.strictEqual(null, lvl2.comment); - - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#DataModels - test data model object properties": function(test) { - if (this.skip) { - test.done(); - return; - } - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var name = "delete-me-" + getNextId(); - - var that = this; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - var obj = dataModel.objectByName("test_data"); - test.ok(obj); - test.strictEqual(5, obj.fieldNames().length); - test.strictEqual(10, obj.allFieldNames().length); - test.ok(obj.fieldByName("has_boris")); - test.ok(obj.hasField("has_boris")); - test.ok(obj.fieldByName("_time")); - test.ok(obj.hasField("_time")); - - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#DataModels - create local acceleration job": function(test) { - if (this.skip) { - test.done(); - return; - } - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/inheritance_test_data.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var name = "delete-me-" + getNextId(); - - var obj; - var that = this; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - obj = dataModel.objectByName("level_2"); - test.ok(obj); - - obj.createLocalAccelerationJob(null, done); - }, - function(job, done) { - test.ok(job); - - tutils.pollUntil( - job, - function(j) { - return job.properties()["isDone"]; - }, - 10, - done - ); - }, - function(job, done) { - test.strictEqual("| datamodel \"" + name + "\" level_2 search | tscollect", job.properties().request.search); - job.cancel(done); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#DataModels - create local acceleration job with earliest time": function(test) { - if (this.skip) { - test.done(); - return; - } - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/inheritance_test_data.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var name = "delete-me-" + getNextId(); - - var obj; - var oldNow = Date.now(); - var that = this; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - obj = dataModel.objectByName("level_2"); - test.ok(obj); - obj.createLocalAccelerationJob("-1d", done); - }, - function(job, done) { - test.ok(job); - tutils.pollUntil( - job, - function(j) { - return job.properties()["isDone"]; - }, - 10, - done - ); - }, - function(job, done) { - test.strictEqual("| datamodel \"" + name + "\" level_2 search | tscollect", job.properties().request.search); - - // Make sure the earliest time is 1 day behind - var yesterday = new Date(Date.now() - (1000 * 60 * 60 * 24)); - var month = (yesterday.getMonth() + 1); - if (month <= 9) { - month = "0" + month; - } - var date = yesterday.getDate(); - if (date <= 9) { - date = "0" + date; - } - var expectedDate = yesterday.getFullYear() + "-" + month + "-" + date; - test.ok(utils.startsWith(job._state.content.earliestTime, expectedDate)); - - job.cancel(done); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#DataModels - test data model constraints": function(test) { - if (this.skip) { - test.done(); - return; - } - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/data_model_with_test_objects.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var name = "delete-me-" + getNextId(); - - var obj; - var that = this; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - obj = dataModel.objectByName("event1"); - test.ok(obj); - var constraints = obj.constraints; - test.ok(constraints); - var onlyOne = true; - - for (var i = 0; i < constraints.length; i++) { - var constraint = constraints[i]; - test.ok(!!onlyOne); - - test.strictEqual("event1", constraint.owner); - test.strictEqual("uri=\"*.php\" OR uri=\"*.py\"\nNOT (referer=null OR referer=\"-\")", constraint.query); - } - - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#DataModels - test data model calculations, and the different types": function(test) { - if (this.skip) { - test.done(); - return; - } - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/data_model_with_test_objects.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var name = "delete-me-" + getNextId(); - - var obj; - var that = this; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - obj = dataModel.objectByName("event1"); - test.ok(obj); - - var calculations = obj.calculations; - test.strictEqual(4, Object.keys(calculations).length); - test.strictEqual(4, obj.calculationIDs().length); - - var evalCalculation = calculations["93fzsv03wa7"]; - test.ok(evalCalculation); - test.strictEqual("event1", evalCalculation.owner); - test.same(["event1"], evalCalculation.lineage); - test.strictEqual("Eval", evalCalculation.type); - test.ok(evalCalculation.isEval()); - test.ok(!evalCalculation.isLookup()); - test.ok(!evalCalculation.isGeoIP()); - test.ok(!evalCalculation.isRex()); - test.strictEqual(null, evalCalculation.comment); - test.strictEqual(true, evalCalculation.isEditable()); - test.strictEqual("if(cidrmatch(\"192.0.0.0/16\", clientip), \"local\", \"other\")", evalCalculation.expression); - - test.strictEqual(1, Object.keys(evalCalculation.outputFields).length); - test.strictEqual(1, evalCalculation.outputFieldNames().length); - - var field = evalCalculation.outputFields["new_field"]; - test.ok(field); - test.strictEqual("My New Field", field.displayName); - - var lookupCalculation = calculations["sr3mc8o3mjr"]; - test.ok(lookupCalculation); - test.strictEqual("event1", lookupCalculation.owner); - test.same(["event1"], lookupCalculation.lineage); - test.strictEqual("Lookup", lookupCalculation.type); - test.ok(lookupCalculation.isLookup()); - test.ok(!lookupCalculation.isEval()); - test.ok(!lookupCalculation.isGeoIP()); - test.ok(!lookupCalculation.isRex()); - test.strictEqual(null, lookupCalculation.comment); - test.strictEqual(true, lookupCalculation.isEditable()); - test.same({lookupField: "a_lookup_field", inputField: "host"}, lookupCalculation.inputFieldMappings); - test.strictEqual(2, Object.keys(lookupCalculation.inputFieldMappings).length); - test.strictEqual("a_lookup_field", lookupCalculation.inputFieldMappings.lookupField); - test.strictEqual("host", lookupCalculation.inputFieldMappings.inputField); - test.strictEqual("dnslookup", lookupCalculation.lookupName); - - var regexpCalculation = calculations["a5v1k82ymic"]; - test.ok(regexpCalculation); - test.strictEqual("event1", regexpCalculation.owner); - test.same(["event1"], regexpCalculation.lineage); - test.strictEqual("Rex", regexpCalculation.type); - test.ok(regexpCalculation.isRex()); - test.ok(!regexpCalculation.isLookup()); - test.ok(!regexpCalculation.isEval()); - test.ok(!regexpCalculation.isGeoIP()); - test.strictEqual(2, regexpCalculation.outputFieldNames().length); - test.strictEqual("_raw", regexpCalculation.inputField); - test.strictEqual(" From: (?.*) To: (?.*) ", regexpCalculation.expression); - - var geoIPCalculation = calculations["pbe9bd0rp4"]; - test.ok(geoIPCalculation); - test.strictEqual("event1", geoIPCalculation.owner); - test.same(["event1"], geoIPCalculation.lineage); - test.strictEqual("GeoIP", geoIPCalculation.type); - test.ok(geoIPCalculation.isGeoIP()); - test.ok(!geoIPCalculation.isLookup()); - test.ok(!geoIPCalculation.isEval()); - test.ok(!geoIPCalculation.isRex()); - test.strictEqual("·Ä©·öô‡Øµ comment of pbe9bd0rp4", geoIPCalculation.comment); - test.strictEqual(5, geoIPCalculation.outputFieldNames().length); - test.strictEqual("output_from_reverse_hostname", geoIPCalculation.inputField); - - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#DataModels - run queries": function(test) { - if (this.skip) { - test.done(); - return; - } - var obj; - var that = this; - Async.chain([ - function(done) { - that.dataModels.fetch(done); - }, - function(dataModels, done) { - var dm = dataModels.item("internal_audit_logs"); - obj = dm.objectByName("searches"); - obj.startSearch({}, "", done); - }, - function(job, done) { - tutils.pollUntil( - job, - function(j) { - return job.properties()["isDone"]; - }, - 10, - done - ); - }, - function(job, done) { - test.strictEqual("| datamodel internal_audit_logs searches search", job.properties().request.search); - job.cancel(done); - }, - function(response, done) { - obj.startSearch({status_buckets: 5, enable_lookups: false}, "| head 3", done); - }, - function(job, done) { - tutils.pollUntil( - job, - function(j) { - return job.properties()["isDone"]; - }, - 10, - done - ); - }, - function(job, done) { - test.strictEqual("| datamodel internal_audit_logs searches search | head 3", job.properties().request.search); - job.cancel(done); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#DataModels - baseSearch is parsed correctly": function(test) { - if (this.skip) { - test.done(); - return; - } - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/model_with_multiple_types.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var name = "delete-me-" + getNextId(); - - var obj; - var that = this; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - obj = dataModel.objectByName("search1"); - test.ok(obj); - test.ok(obj instanceof splunkjs.Service.DataModelObject); - test.strictEqual("BaseSearch", obj.parentName); - test.ok(obj.isBaseSearch()); - test.ok(!obj.isBaseTransaction()); - test.strictEqual("search index=_internal | head 10", obj.baseSearch); - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#DataModels - baseTransaction is parsed correctly": function(test) { - if (this.skip) { - test.done(); - return; - } - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/model_with_multiple_types.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var name = "delete-me-" + getNextId(); - - var obj; - var that = this; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - obj = dataModel.objectByName("transaction1"); - test.ok(obj); - test.ok(obj instanceof splunkjs.Service.DataModelObject); - test.strictEqual("BaseTransaction", obj.parentName); - test.ok(obj.isBaseTransaction()); - test.ok(!obj.isBaseSearch()); - test.same(["event1"], obj.objectsToGroup); - test.same(["host", "from"], obj.groupByFields); - test.strictEqual("25s", obj.maxPause); - test.strictEqual("100m", obj.maxSpan); - - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - } - }, - - "Pivot tests": { - setUp: function(done) { - this.service = svc; - this.dataModels = svc.dataModels({owner: "nobody", app: "search"}); - this.skip = false; - var that = this; - this.service.serverInfo(function(err, info) { - if (parseInt(info.properties().version.split(".")[0], 10) < 6) { - that.skip = true; - splunkjs.Logger.log("Skipping pivot tests..."); - } - done(err); - }); - }, - - "Callback#Pivot - test constructor args": function(test) { - if (this.skip) { - test.done(); - return; - } - var name = "delete-me-" + getNextId(); - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var that = this; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - test.ok(dataModel.objectByName("test_data")); - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Pivot - test acceleration, then pivot": function(test) { - if (this.skip) { - test.done(); - return; - } - var name = "delete-me-" + getNextId(); - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var that = this; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - dataModel.objectByName("test_data"); - test.ok(dataModel); - - dataModel.acceleration.enabled = true; - dataModel.acceleration.earliestTime = "-2mon"; - dataModel.acceleration.cronSchedule = "0 */12 * * *"; - dataModel.update(done); - }, - function(dataModel, done) { - var props = dataModel.properties(); - - test.strictEqual(true, dataModel.isAccelerated()); - test.strictEqual(true, !!dataModel.acceleration.enabled); - test.strictEqual("-2mon", dataModel.acceleration.earliest_time); - test.strictEqual("0 */12 * * *", dataModel.acceleration.cron_schedule); - - var dataModelObject = dataModel.objectByName("test_data"); - var pivotSpecification = dataModelObject.createPivotSpecification(); - - test.strictEqual(dataModelObject.dataModel.name, pivotSpecification.accelerationNamespace); - - var name1 = "delete-me-" + getNextId(); - pivotSpecification.setAccelerationJob(name1); - test.strictEqual("sid=" + name1, pivotSpecification.accelerationNamespace); - - var namespaceTemp = "delete-me-" + getNextId(); - pivotSpecification.accelerationNamespace = namespaceTemp; - test.strictEqual(namespaceTemp, pivotSpecification.accelerationNamespace); - - pivotSpecification - .addCellValue("test_data", "Source Value", "count") - .run(done); - }, - function(job, pivot, done) { - test.ok(job); - test.ok(pivot); - test.notStrictEqual("FAILED", job.properties().dispatchState); - - job.track({}, function(job) { - test.ok(pivot.tstatsSearch); - test.strictEqual(0, job.properties().request.search.indexOf("| tstats")); - test.strictEqual("| tstats", job.properties().request.search.match("^\\| tstats")[0]); - test.strictEqual(1, job.properties().request.search.match("^\\| tstats").length); - - test.strictEqual(pivot.tstatsSearch, job.properties().request.search); - done(null, job); - }); - }, - function(job, done) { - test.ok(job); - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Pivot - test illegal filtering (all types)": function(test) { - if (this.skip) { - test.done(); - return; - } - var name = "delete-me-" + getNextId(); - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var that = this; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - var obj = dataModel.objectByName("test_data"); - test.ok(obj); - - var pivotSpecification = obj.createPivotSpecification(); - - // Boolean comparisons - try { - pivotSpecification.addFilter(getNextId(), "boolean", "=", true); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Cannot add filter on a nonexistent field."); - } - try { - pivotSpecification.addFilter("_time", "boolean", "=", true); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Cannot add boolean filter on _time because it is of type timestamp"); - } - - // String comparisons - try { - pivotSpecification.addFilter("has_boris", "string", "contains", "abc"); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Cannot add string filter on has_boris because it is of type boolean"); - } - try { - pivotSpecification.addFilter(getNextId(), "string", "contains", "abc"); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Cannot add filter on a nonexistent field."); - } - - // IPv4 comparisons - try { - pivotSpecification.addFilter("has_boris", "ipv4", "startsWith", "192.168"); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Cannot add ipv4 filter on has_boris because it is of type boolean"); - } - try { - pivotSpecification.addFilter(getNextId(), "ipv4", "startsWith", "192.168"); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Cannot add filter on a nonexistent field."); - } - - // Number comparisons - try { - pivotSpecification.addFilter("has_boris", "number", "atLeast", 2.3); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Cannot add number filter on has_boris because it is of type boolean"); - } - try { - pivotSpecification.addFilter(getNextId(), "number", "atLeast", 2.3); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Cannot add filter on a nonexistent field."); - } - - // Limit filter - try { - pivotSpecification.addLimitFilter("has_boris", "host", "DEFAULT", 50, "count"); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Cannot add limit filter on has_boris because it is of type boolean"); - } - try { - pivotSpecification.addLimitFilter(getNextId(), "host", "DEFAULT", 50, "count"); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Cannot add limit filter on a nonexistent field."); - } - try { - pivotSpecification.addLimitFilter("source", "host", "DEFAULT", 50, "sum"); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, - "Stats function for fields of type string must be COUNT or DISTINCT_COUNT; found sum"); - } - try { - pivotSpecification.addLimitFilter("epsilon", "host", "DEFAULT", 50, "duration"); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, - "Stats function for fields of type number must be one of COUNT, DISTINCT_COUNT, SUM, or AVERAGE; found duration"); - } - try { - pivotSpecification.addLimitFilter("test_data", "host", "DEFAULT", 50, "list"); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, - "Stats function for fields of type object count must be COUNT; found list"); - } - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Pivot - test boolean filtering": function(test) { - if (this.skip) { - test.done(); - return; - } - var name = "delete-me-" + getNextId(); - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var that = this; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - var obj = dataModel.objectByName("test_data"); - test.ok(obj); - - var pivotSpecification = obj.createPivotSpecification(); - try { - pivotSpecification.addFilter("has_boris", "boolean", "=", true); - test.strictEqual(1, pivotSpecification.filters.length); - - //Test the individual parts of the filter - var filter = pivotSpecification.filters[0]; - - test.ok(filter.hasOwnProperty("fieldName")); - test.ok(filter.hasOwnProperty("type")); - test.ok(filter.hasOwnProperty("rule")); - test.ok(filter.hasOwnProperty("owner")); - - test.strictEqual("has_boris", filter.fieldName); - test.strictEqual("boolean", filter.type); - test.strictEqual("=", filter.rule.comparator); - test.strictEqual(true, filter.rule.compareTo); - test.strictEqual("test_data", filter.owner); - } - catch (e) { - test.ok(false); - } - - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Pivot - test string filtering": function(test) { - if (this.skip) { - test.done(); - return; - } - var name = "delete-me-" + getNextId(); - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var that = this; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - var obj = dataModel.objectByName("test_data"); - test.ok(obj); - - var pivotSpecification = obj.createPivotSpecification(); - try { - pivotSpecification.addFilter("host", "string", "contains", "abc"); - test.strictEqual(1, pivotSpecification.filters.length); - - //Test the individual parts of the filter - var filter = pivotSpecification.filters[0]; - - test.ok(filter.hasOwnProperty("fieldName")); - test.ok(filter.hasOwnProperty("type")); - test.ok(filter.hasOwnProperty("rule")); - test.ok(filter.hasOwnProperty("owner")); - - test.strictEqual("host", filter.fieldName); - test.strictEqual("string", filter.type); - test.strictEqual("contains", filter.rule.comparator); - test.strictEqual("abc", filter.rule.compareTo); - test.strictEqual("BaseEvent", filter.owner); - } - catch (e) { - test.ok(false); - } - - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Pivot - test IPv4 filtering": function(test) { - if (this.skip) { - test.done(); - return; - } - var name = "delete-me-" + getNextId(); - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var that = this; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - var obj = dataModel.objectByName("test_data"); - test.ok(obj); - - var pivotSpecification = obj.createPivotSpecification(); - try { - pivotSpecification.addFilter("hostip", "ipv4", "startsWith", "192.168"); - test.strictEqual(1, pivotSpecification.filters.length); - - //Test the individual parts of the filter - var filter = pivotSpecification.filters[0]; - - test.ok(filter.hasOwnProperty("fieldName")); - test.ok(filter.hasOwnProperty("type")); - test.ok(filter.hasOwnProperty("rule")); - test.ok(filter.hasOwnProperty("owner")); - - test.strictEqual("hostip", filter.fieldName); - test.strictEqual("ipv4", filter.type); - test.strictEqual("startsWith", filter.rule.comparator); - test.strictEqual("192.168", filter.rule.compareTo); - test.strictEqual("test_data", filter.owner); - } - catch (e) { - test.ok(false); - } - - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Pivot - test number filtering": function(test) { - if (this.skip) { - test.done(); - return; - } - var name = "delete-me-" + getNextId(); - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var that = this; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - var obj = dataModel.objectByName("test_data"); - test.ok(obj); - - var pivotSpecification = obj.createPivotSpecification(); - try { - pivotSpecification.addFilter("epsilon", "number", ">=", 2.3); - test.strictEqual(1, pivotSpecification.filters.length); - - //Test the individual parts of the filter - var filter = pivotSpecification.filters[0]; - - test.ok(filter.hasOwnProperty("fieldName")); - test.ok(filter.hasOwnProperty("type")); - test.ok(filter.hasOwnProperty("rule")); - test.ok(filter.hasOwnProperty("owner")); - - test.strictEqual("epsilon", filter.fieldName); - test.strictEqual("number", filter.type); - test.strictEqual(">=", filter.rule.comparator); - test.strictEqual(2.3, filter.rule.compareTo); - test.strictEqual("test_data", filter.owner); - } - catch (e) { - test.ok(false); - } - - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - "Callback#Pivot - test limit filtering": function(test) { - if (this.skip) { - test.done(); - return; - } - var name = "delete-me-" + getNextId(); - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var that = this; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - var obj = dataModel.objectByName("test_data"); - test.ok(obj); - - var pivotSpecification = obj.createPivotSpecification(); - try { - pivotSpecification.addLimitFilter("epsilon", "host", "ASCENDING", 500, "average"); - test.strictEqual(1, pivotSpecification.filters.length); - - //Test the individual parts of the filter - var filter = pivotSpecification.filters[0]; - - test.ok(filter.hasOwnProperty("fieldName")); - test.ok(filter.hasOwnProperty("type")); - test.ok(filter.hasOwnProperty("owner")); - test.ok(filter.hasOwnProperty("attributeName")); - test.ok(filter.hasOwnProperty("attributeOwner")); - test.ok(filter.hasOwnProperty("limitType")); - test.ok(filter.hasOwnProperty("limitAmount")); - test.ok(filter.hasOwnProperty("statsFn")); - - test.strictEqual("epsilon", filter.fieldName); - test.strictEqual("number", filter.type); - test.strictEqual("test_data", filter.owner); - test.strictEqual("host", filter.attributeName); - test.strictEqual("BaseEvent", filter.attributeOwner); - test.strictEqual("lowest", filter.limitType); - test.strictEqual(500, filter.limitAmount); - test.strictEqual("average", filter.statsFn); - } - catch (e) { - test.ok(false); - } - - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - "Callback#Pivot - test row split": function(test) { - if (this.skip) { - test.done(); - return; - } - var name = "delete-me-" + getNextId(); - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var that = this; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - var obj = dataModel.objectByName("test_data"); - test.ok(obj); - - var pivotSpecification = obj.createPivotSpecification(); - - // Test error handling for row split - try { - pivotSpecification.addRowSplit("has_boris", "Wrong type here"); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Field was of type " + obj.fieldByName("has_boris").type + ", expected number or string."); - } - var field = getNextId(); - try { - - pivotSpecification.addRowSplit(field, "Break Me!"); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Did not find field " + field); - } - - // Test row split, number - pivotSpecification.addRowSplit("epsilon", "My Label"); - test.strictEqual(1, pivotSpecification.rows.length); - - var row = pivotSpecification.rows[0]; - test.ok(row.hasOwnProperty("fieldName")); - test.ok(row.hasOwnProperty("owner")); - test.ok(row.hasOwnProperty("type")); - test.ok(row.hasOwnProperty("label")); - test.ok(row.hasOwnProperty("display")); - - test.strictEqual("epsilon", row.fieldName); - test.strictEqual("test_data", row.owner); - test.strictEqual("number", row.type); - test.strictEqual("My Label", row.label); - test.strictEqual("all", row.display); - test.same({ - fieldName: "epsilon", - owner: "test_data", - type: "number", - label: "My Label", - display: "all" - }, - row); - - // Test row split, string - pivotSpecification.addRowSplit("host", "My Label"); - test.strictEqual(2, pivotSpecification.rows.length); - - row = pivotSpecification.rows[pivotSpecification.rows.length - 1]; - test.ok(row.hasOwnProperty("fieldName")); - test.ok(row.hasOwnProperty("owner")); - test.ok(row.hasOwnProperty("type")); - test.ok(row.hasOwnProperty("label")); - test.ok(!row.hasOwnProperty("display")); - - test.strictEqual("host", row.fieldName); - test.strictEqual("BaseEvent", row.owner); - test.strictEqual("string", row.type); - test.strictEqual("My Label", row.label); - test.same({ - fieldName: "host", - owner: "BaseEvent", - type: "string", - label: "My Label" - }, - row); - - // Test error handling on range row split - try { - pivotSpecification.addRangeRowSplit("has_boris", "Wrong type here", {start: 0, end: 100, step:20, limit:5}); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Field was of type " + obj.fieldByName("has_boris").type + ", expected number."); - } - try { - pivotSpecification.addRangeRowSplit(field, "Break Me!", {start: 0, end: 100, step:20, limit:5}); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Did not find field " + field); - } - - // Test range row split - pivotSpecification.addRangeRowSplit("epsilon", "My Label", {start: 0, end: 100, step:20, limit:5}); - test.strictEqual(3, pivotSpecification.rows.length); - - row = pivotSpecification.rows[pivotSpecification.rows.length - 1]; - test.ok(row.hasOwnProperty("fieldName")); - test.ok(row.hasOwnProperty("owner")); - test.ok(row.hasOwnProperty("type")); - test.ok(row.hasOwnProperty("label")); - test.ok(row.hasOwnProperty("display")); - test.ok(row.hasOwnProperty("ranges")); - - test.strictEqual("epsilon", row.fieldName); - test.strictEqual("test_data", row.owner); - test.strictEqual("number", row.type); - test.strictEqual("My Label", row.label); - test.strictEqual("ranges", row.display); - - var ranges = { - start: 0, - end: 100, - size: 20, - maxNumberOf: 5 - }; - test.same(ranges, row.ranges); - test.same({ - fieldName: "epsilon", - owner: "test_data", - type: "number", - label: "My Label", - display: "ranges", - ranges: ranges - }, - row); - - // Test error handling on boolean row split - try { - pivotSpecification.addBooleanRowSplit("epsilon", "Wrong type here", "t", "f"); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Field was of type " + obj.fieldByName("epsilon").type + ", expected boolean."); - } - try { - pivotSpecification.addBooleanRowSplit(field, "Break Me!", "t", "f"); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Did not find field " + field); - } - - // Test boolean row split - pivotSpecification.addBooleanRowSplit("has_boris", "My Label", "is_true", "is_false"); - test.strictEqual(4, pivotSpecification.rows.length); - - row = pivotSpecification.rows[pivotSpecification.rows.length - 1]; - test.ok(row.hasOwnProperty("fieldName")); - test.ok(row.hasOwnProperty("owner")); - test.ok(row.hasOwnProperty("type")); - test.ok(row.hasOwnProperty("label")); - test.ok(row.hasOwnProperty("trueLabel")); - test.ok(row.hasOwnProperty("falseLabel")); - - test.strictEqual("has_boris", row.fieldName); - test.strictEqual("My Label", row.label); - test.strictEqual("test_data", row.owner); - test.strictEqual("boolean", row.type); - test.strictEqual("is_true", row.trueLabel); - test.strictEqual("is_false", row.falseLabel); - test.same({ - fieldName: "has_boris", - label: "My Label", - owner: "test_data", - type: "boolean", - trueLabel: "is_true", - falseLabel: "is_false" - }, - row); - - // Test error handling on timestamp row split - try { - pivotSpecification.addTimestampRowSplit("epsilon", "Wrong type here", "some binning"); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Field was of type " + obj.fieldByName("epsilon").type + ", expected timestamp."); - } - try { - pivotSpecification.addTimestampRowSplit(field, "Break Me!", "some binning"); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Did not find field " + field); - } - try { - pivotSpecification.addTimestampRowSplit("_time", "some label", "Bogus binning value"); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Invalid binning Bogus binning value found. Valid values are: " + pivotSpecification._binning.join(", ")); - } - - // Test timestamp row split - pivotSpecification.addTimestampRowSplit("_time", "My Label", "day"); - test.strictEqual(5, pivotSpecification.rows.length); - - row = pivotSpecification.rows[pivotSpecification.rows.length - 1]; - test.ok(row.hasOwnProperty("fieldName")); - test.ok(row.hasOwnProperty("owner")); - test.ok(row.hasOwnProperty("type")); - test.ok(row.hasOwnProperty("label")); - test.ok(row.hasOwnProperty("period")); - - test.strictEqual("_time", row.fieldName); - test.strictEqual("My Label", row.label); - test.strictEqual("BaseEvent", row.owner); - test.strictEqual("timestamp", row.type); - test.strictEqual("day", row.period); - test.same({ - fieldName: "_time", - label: "My Label", - owner: "BaseEvent", - type: "timestamp", - period: "day" - }, - row); - - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - "Callback#Pivot - test column split": function(test) { - if (this.skip) { - test.done(); - return; - } - var name = "delete-me-" + getNextId(); - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var that = this; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - var obj = dataModel.objectByName("test_data"); - test.ok(obj); - - var pivotSpecification = obj.createPivotSpecification(); - - // Test error handling for column split - try { - pivotSpecification.addColumnSplit("has_boris", "Wrong type here"); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Field was of type " + obj.fieldByName("has_boris").type + ", expected number or string."); - } - var field = getNextId(); - try { - - pivotSpecification.addColumnSplit(field, "Break Me!"); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Did not find field " + field); - } - - // Test column split, number - pivotSpecification.addColumnSplit("epsilon"); - test.strictEqual(1, pivotSpecification.columns.length); - - var col = pivotSpecification.columns[pivotSpecification.columns.length - 1]; - test.ok(col.hasOwnProperty("fieldName")); - test.ok(col.hasOwnProperty("owner")); - test.ok(col.hasOwnProperty("type")); - test.ok(col.hasOwnProperty("display")); - - test.strictEqual("epsilon", col.fieldName); - test.strictEqual("test_data", col.owner); - test.strictEqual("number", col.type); - test.strictEqual("all", col.display); - test.same({ - fieldName: "epsilon", - owner: "test_data", - type: "number", - display: "all" - }, - col); - - // Test column split, string - pivotSpecification.addColumnSplit("host"); - test.strictEqual(2, pivotSpecification.columns.length); - - col = pivotSpecification.columns[pivotSpecification.columns.length - 1]; - test.ok(col.hasOwnProperty("fieldName")); - test.ok(col.hasOwnProperty("owner")); - test.ok(col.hasOwnProperty("type")); - test.ok(!col.hasOwnProperty("display")); - - test.strictEqual("host", col.fieldName); - test.strictEqual("BaseEvent", col.owner); - test.strictEqual("string", col.type); - test.same({ - fieldName: "host", - owner: "BaseEvent", - type: "string" - }, - col); - - done(); - - // Test error handling for range column split - try { - pivotSpecification.addRangeColumnSplit("has_boris", "Wrong type here", {start: 0, end: 100, step:20, limit:5}); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Field was of type " + obj.fieldByName("has_boris").type + ", expected number."); - } - try { - pivotSpecification.addRangeColumnSplit(field, {start: 0, end: 100, step:20, limit:5}); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Did not find field " + field); - } - - // Test range column split - pivotSpecification.addRangeColumnSplit("epsilon", {start: 0, end: 100, step:20, limit:5}); - test.strictEqual(3, pivotSpecification.columns.length); - - col = pivotSpecification.columns[pivotSpecification.columns.length - 1]; - test.ok(col.hasOwnProperty("fieldName")); - test.ok(col.hasOwnProperty("owner")); - test.ok(col.hasOwnProperty("type")); - test.ok(col.hasOwnProperty("display")); - test.ok(col.hasOwnProperty("ranges")); - - test.strictEqual("epsilon", col.fieldName); - test.strictEqual("test_data", col.owner); - test.strictEqual("number", col.type); - test.strictEqual("ranges", col.display); - var ranges = { - start: "0", - end: "100", - size: "20", - maxNumberOf: "5" - }; - test.same(ranges, col.ranges); - test.same({ - fieldName: "epsilon", - owner: "test_data", - type: "number", - display: "ranges", - ranges: ranges - }, - col); - - // Test error handling on boolean column split - try { - pivotSpecification.addBooleanColumnSplit("epsilon", "t", "f"); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Field was of type " + obj.fieldByName("epsilon").type + ", expected boolean."); - } - try { - pivotSpecification.addBooleanColumnSplit(field, "t", "f"); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Did not find field " + field); - } - - // Test boolean column split - pivotSpecification.addBooleanColumnSplit("has_boris", "is_true", "is_false"); - test.strictEqual(4, pivotSpecification.columns.length); - - col = pivotSpecification.columns[pivotSpecification.columns.length - 1]; - test.ok(col.hasOwnProperty("fieldName")); - test.ok(col.hasOwnProperty("owner")); - test.ok(col.hasOwnProperty("type")); - test.ok(!col.hasOwnProperty("label")); - test.ok(col.hasOwnProperty("trueLabel")); - test.ok(col.hasOwnProperty("falseLabel")); - - test.strictEqual("has_boris", col.fieldName); - test.strictEqual("test_data", col.owner); - test.strictEqual("boolean", col.type); - test.strictEqual("is_true", col.trueLabel); - test.strictEqual("is_false", col.falseLabel); - test.same({ - fieldName: "has_boris", - owner: "test_data", - type: "boolean", - trueLabel: "is_true", - falseLabel: "is_false" - }, - col); - - // Test error handling on timestamp column split - try { - pivotSpecification.addTimestampColumnSplit("epsilon", "Wrong type here"); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Field was of type " + obj.fieldByName("epsilon").type + ", expected timestamp."); - } - try { - pivotSpecification.addTimestampColumnSplit(field, "Break Me!"); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Did not find field " + field); - } - try { - pivotSpecification.addTimestampColumnSplit("_time", "Bogus binning value"); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Invalid binning Bogus binning value found. Valid values are: " + pivotSpecification._binning.join(", ")); - } - - // Test timestamp column split - pivotSpecification.addTimestampColumnSplit("_time", "day"); - test.strictEqual(5, pivotSpecification.columns.length); - - col = pivotSpecification.columns[pivotSpecification.columns.length - 1]; - test.ok(col.hasOwnProperty("fieldName")); - test.ok(col.hasOwnProperty("owner")); - test.ok(col.hasOwnProperty("type")); - test.ok(!col.hasOwnProperty("label")); - test.ok(col.hasOwnProperty("period")); - - test.strictEqual("_time", col.fieldName); - test.strictEqual("BaseEvent", col.owner); - test.strictEqual("timestamp", col.type); - test.strictEqual("day", col.period); - test.same({ - fieldName: "_time", - owner: "BaseEvent", - type: "timestamp", - period: "day" - }, - col); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - "Callback#Pivot - test cell value": function(test) { - if (this.skip) { - test.done(); - return; - } - var name = "delete-me-" + getNextId(); - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var that = this; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - var obj = dataModel.objectByName("test_data"); - test.ok(obj); - - var pivotSpecification = obj.createPivotSpecification(); - - // Test error handling for cell value, string - try { - pivotSpecification.addCellValue("iDontExist", "Break Me!", "explosion"); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Did not find field iDontExist"); - } - try { - pivotSpecification.addCellValue("source", "Wrong Stats Function", "stdev"); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Stats function on string and IPv4 fields must be one of:" + - " list, distinct_values, first, last, count, or distinct_count; found stdev"); - } - - // Add cell value, string - pivotSpecification.addCellValue("source", "Source Value", "dc"); - test.strictEqual(1, pivotSpecification.cells.length); - - var cell = pivotSpecification.cells[pivotSpecification.cells.length - 1]; - test.ok(cell.hasOwnProperty("fieldName")); - test.ok(cell.hasOwnProperty("owner")); - test.ok(cell.hasOwnProperty("type")); - test.ok(cell.hasOwnProperty("label")); - test.ok(cell.hasOwnProperty("value")); - test.ok(cell.hasOwnProperty("sparkline")); - - test.strictEqual("source", cell.fieldName); - test.strictEqual("BaseEvent", cell.owner); - test.strictEqual("string", cell.type); - test.strictEqual("Source Value", cell.label); - test.strictEqual("dc", cell.value); - test.strictEqual(false, cell.sparkline); - test.same({ - fieldName: "source", - owner: "BaseEvent", - type: "string", - label: "Source Value", - value: "dc", - sparkline: false - }, cell); - - // Test error handling for cell value, IPv4 - try { - pivotSpecification.addCellValue("hostip", "Wrong Stats Function", "stdev"); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Stats function on string and IPv4 fields must be one of:" + - " list, distinct_values, first, last, count, or distinct_count; found stdev"); - } - - // Add cell value, IPv4 - pivotSpecification.addCellValue("hostip", "Source Value", "dc"); - test.strictEqual(2, pivotSpecification.cells.length); - - cell = pivotSpecification.cells[pivotSpecification.cells.length - 1]; - test.ok(cell.hasOwnProperty("fieldName")); - test.ok(cell.hasOwnProperty("owner")); - test.ok(cell.hasOwnProperty("type")); - test.ok(cell.hasOwnProperty("label")); - test.ok(cell.hasOwnProperty("value")); - test.ok(cell.hasOwnProperty("sparkline")); - - test.strictEqual("hostip", cell.fieldName); - test.strictEqual("test_data", cell.owner); - test.strictEqual("ipv4", cell.type); - test.strictEqual("Source Value", cell.label); - test.strictEqual("dc", cell.value); - test.strictEqual(false, cell.sparkline); - test.same({ - fieldName: "hostip", - owner: "test_data", - type: "ipv4", - label: "Source Value", - value: "dc", - sparkline: false - }, cell); - - // Test error handling for cell value, boolean - try { - pivotSpecification.addCellValue("has_boris", "Booleans not allowed", "sum"); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Cannot use boolean valued fields as cell values."); - } - - // Test error handling for cell value, number - try { - pivotSpecification.addCellValue("epsilon", "Wrong Stats Function", "latest"); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Stats function on number field must be must be one of:" + - " sum, count, average, max, min, stdev, list, or distinct_values; found latest"); - } - - // Add cell value, number - pivotSpecification.addCellValue("epsilon", "Source Value", "average"); - test.strictEqual(3, pivotSpecification.cells.length); - - cell = pivotSpecification.cells[pivotSpecification.cells.length - 1]; - test.ok(cell.hasOwnProperty("fieldName")); - test.ok(cell.hasOwnProperty("owner")); - test.ok(cell.hasOwnProperty("type")); - test.ok(cell.hasOwnProperty("label")); - test.ok(cell.hasOwnProperty("value")); - test.ok(cell.hasOwnProperty("sparkline")); - - test.strictEqual("epsilon", cell.fieldName); - test.strictEqual("test_data", cell.owner); - test.strictEqual("number", cell.type); - test.strictEqual("Source Value", cell.label); - test.strictEqual("average", cell.value); - test.strictEqual(false, cell.sparkline); - test.same({ - fieldName: "epsilon", - owner: "test_data", - type: "number", - label: "Source Value", - value: "average", - sparkline: false - }, cell); - - // Test error handling for cell value, timestamp - try { - pivotSpecification.addCellValue("_time", "Wrong Stats Function", "max"); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Stats function on timestamp field must be one of:" + - " duration, earliest, latest, list, or distinct values; found max"); - } - - // Add cell value, timestamp - pivotSpecification.addCellValue("_time", "Source Value", "earliest"); - test.strictEqual(4, pivotSpecification.cells.length); - - cell = pivotSpecification.cells[pivotSpecification.cells.length - 1]; - test.ok(cell.hasOwnProperty("fieldName")); - test.ok(cell.hasOwnProperty("owner")); - test.ok(cell.hasOwnProperty("type")); - test.ok(cell.hasOwnProperty("label")); - test.ok(cell.hasOwnProperty("value")); - test.ok(cell.hasOwnProperty("sparkline")); - - test.strictEqual("_time", cell.fieldName); - test.strictEqual("BaseEvent", cell.owner); - test.strictEqual("timestamp", cell.type); - test.strictEqual("Source Value", cell.label); - test.strictEqual("earliest", cell.value); - test.strictEqual(false, cell.sparkline); - test.same({ - fieldName: "_time", - owner: "BaseEvent", - type: "timestamp", - label: "Source Value", - value: "earliest", - sparkline: false - }, cell); - - // Test error handling for cell value, count - try { - pivotSpecification.addCellValue("test_data", "Wrong Stats Function", "min"); - test.ok(false); - } - catch (e) { - test.ok(e); - test.strictEqual(e.message, "Stats function on childcount and objectcount fields " + - "must be count; found " + "min"); - } - - // Add cell value, count - pivotSpecification.addCellValue("test_data", "Source Value", "count"); - test.strictEqual(5, pivotSpecification.cells.length); - - cell = pivotSpecification.cells[pivotSpecification.cells.length - 1]; - test.ok(cell.hasOwnProperty("fieldName")); - test.ok(cell.hasOwnProperty("owner")); - test.ok(cell.hasOwnProperty("type")); - test.ok(cell.hasOwnProperty("label")); - test.ok(cell.hasOwnProperty("value")); - test.ok(cell.hasOwnProperty("sparkline")); - - test.strictEqual("test_data", cell.fieldName); - test.strictEqual("test_data", cell.owner); - test.strictEqual("objectCount", cell.type); - test.strictEqual("Source Value", cell.label); - test.strictEqual("count", cell.value); - test.strictEqual(false, cell.sparkline); - test.same({ - fieldName: "test_data", - owner: "test_data", - type: "objectCount", - label: "Source Value", - value: "count", - sparkline: false - }, cell); - - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - "Callback#Pivot - test pivot throws HTTP exception": function(test) { - if (this.skip) { - test.done(); - return; - } - var name = "delete-me-" + getNextId(); - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var that = this; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - var obj = dataModel.objectByName("test_data"); - test.ok(obj); - - obj.createPivotSpecification().pivot(done); - }, - function(pivot, done) { - test.ok(false); - } - ], - function(err) { - test.ok(err); - var expectedErr = "In handler 'datamodelpivot': Error in 'PivotReport': Must have non-empty cells or non-empty rows."; - test.ok(utils.endsWith(err.message, expectedErr)); - test.done(); - } - ); - }, - "Callback#Pivot - test pivot with simple namespace": function(test) { - if (this.skip) { - test.done(); - return; - } - var name = "delete-me-" + getNextId(); - var args; - try { - args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); - } - catch(err) { - // Fail if we can't read the file, likely to occur in the browser - test.ok(!err); - test.done(); - } - var that = this; - var obj; - var pivotSpecification; - var adhocjob; - Async.chain([ - function(done) { - that.dataModels.create(name, args, done); - }, - function(dataModel, done) { - obj = dataModel.objectByName("test_data"); - test.ok(obj); - obj.createLocalAccelerationJob(null, done); - }, - function(job, done) { - adhocjob = job; - test.ok(job); - pivotSpecification = obj.createPivotSpecification(); - - pivotSpecification.addBooleanRowSplit("has_boris", "Has Boris", "meep", "hilda"); - pivotSpecification.addCellValue("hostip", "Distinct IPs", "count"); - - // Test setting a job - pivotSpecification.setAccelerationJob(job); - test.strictEqual("string", typeof pivotSpecification.accelerationNamespace); - test.strictEqual("sid=" + job.sid, pivotSpecification.accelerationNamespace); - - // Test setting a job's SID - pivotSpecification.setAccelerationJob(job.sid); - test.strictEqual("string", typeof pivotSpecification.accelerationNamespace); - test.strictEqual("sid=" + job.sid, pivotSpecification.accelerationNamespace); - - pivotSpecification.pivot(done); - }, - function(pivot, done) { - test.ok(pivot.tstatsSearch); - test.ok(pivot.tstatsSearch.length > 0); - test.strictEqual(0, pivot.tstatsSearch.indexOf("| tstats")); - // This test won't work with utils.startsWith due to the regex escaping - test.strictEqual("| tstats", pivot.tstatsSearch.match("^\\| tstats")[0]); - test.strictEqual(1, pivot.tstatsSearch.match("^\\| tstats").length); - - pivot.run(done); - }, - function(job, done) { - tutils.pollUntil( - job, - function(j) { - return job.properties().isDone; - }, - 10, - done - ); - }, - function(job, done) { - test.ok("FAILED" !== job.properties().dispatchState); - - test.strictEqual(0, job.properties().request.search.indexOf("| tstats")); - // This test won't work with utils.startsWith due to the regex escaping - test.strictEqual("| tstats", job.properties().request.search.match("^\\| tstats")[0]); - test.strictEqual(1, job.properties().request.search.match("^\\| tstats").length); - - adhocjob.cancel(done); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - "Callback#Pivot - test pivot column range split": function(test) { - // This test is here because we had a problem with fields that were supposed to be - // numbers being expected as strings in Splunk 6.0. This was fixed in Splunk 6.1, and accepts - // either strings or numbers. - - if (this.skip) { - test.done(); - return; - } - var that = this; - var search; - Async.chain([ - function(done) { - that.dataModels.fetch(done); - }, - function(dataModels, done) { - var dm = dataModels.item("internal_audit_logs"); - var obj = dm.objectByName("searches"); - var pivotSpecification = obj.createPivotSpecification(); - - pivotSpecification.addRowSplit("user", "Executing user"); - pivotSpecification.addRangeColumnSplit("exec_time", {start: 0, end: 12, step: 5, limit: 4}); - pivotSpecification.addCellValue("search", "Search Query", "values"); - pivotSpecification.pivot(done); - }, - function(pivot, done) { - // If tstats is undefined, use pivotSearch - search = pivot.tstatsSearch || pivot.pivotSearch; - pivot.run(done); - }, - function(job, done) { - tutils.pollUntil( - job, - function(j) { - return job.properties().isDone; - }, - 10, - done - ); - }, - function(job, done) { - test.notStrictEqual("FAILED", job.properties().dispatchState); - // Make sure the job is run with the correct search query - test.strictEqual(search, job.properties().request.search); - job.cancel(done); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - "Callback#Pivot - test pivot with PivotSpecification.run and Job.track": function(test) { - if (this.skip) { - test.done(); - return; - } - var that = this; - Async.chain([ - function(done) { - that.dataModels.fetch(done); - }, - function(dataModels, done) { - var dm = dataModels.item("internal_audit_logs"); - var obj = dm.objectByName("searches"); - var pivotSpecification = obj.createPivotSpecification(); - - pivotSpecification.addRowSplit("user", "Executing user"); - pivotSpecification.addRangeColumnSplit("exec_time", {start: 0, end: 12, step: 5, limit: 4}); - pivotSpecification.addCellValue("search", "Search Query", "values"); - - pivotSpecification.run({}, done); - }, - function(job, pivot, done) { - job.track({}, function(job) { - test.strictEqual(pivot.tstatsSearch || pivot.pivotSearch, job.properties().request.search); - done(null, job); - }); - }, - function(job, done) { - test.notStrictEqual("FAILED", job.properties().dispatchState); - job.cancel(done); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - "Callback#DataModels - delete any remaining data models created by the SDK tests": function(test) { - if (this.skip) { - test.done(); - return; - } - svc.dataModels().fetch(function(err, dataModels) { - if (err) { - test.ok(!err); - } - - var dms = dataModels.list(); - Async.seriesEach( - dms, - function(datamodel, i, done) { - // Delete any test data models that we created - if (utils.startsWith(datamodel.name, "delete-me")) { - datamodel.remove(done); - } - else { - done(); - } - }, - function(err) { - test.ok(!err); - test.done(); - } - ); - }); - } - }, - - "App Tests": { - setUp: function(done) { - this.service = svc; - done(); - }, - - "Callback#list applications": function(test) { - var apps = this.service.apps(); - apps.fetch(function(err, apps) { - var appList = apps.list(); - test.ok(appList.length > 0); - test.done(); - }); - }, - - "Callback#contains applications": function(test) { - var apps = this.service.apps(); - apps.fetch(function(err, apps) { - var app = apps.item("search"); - test.ok(app); - test.done(); - }); - }, - - "Callback#create + contains app": function(test) { - var name = "jssdk_testapp_" + getNextId(); - var apps = this.service.apps(); - - apps.create({name: name}, function(err, app) { - var appName = app.name; - apps.fetch(function(err, apps) { - var entity = apps.item(appName); - test.ok(entity); - app.remove(function() { - test.done(); - }); - }); - }); - }, - - "Callback#create + modify app": function(test) { - var DESCRIPTION = "TEST DESCRIPTION"; - var VERSION = "1.1.0"; - - var name = "jssdk_testapp_" + getNextId(); - var apps = this.service.apps(); - - Async.chain([ - function(callback) { - apps.create({name: name}, callback); - }, - function(app, callback) { - test.ok(app); - test.strictEqual(app.name, name); - var versionMatches = app.properties().version === "1.0" || - app.properties().version == "1.0.0"; - test.ok(versionMatches); - - app.update({ - description: DESCRIPTION, - version: VERSION - }, callback); - }, - function(app, callback) { - test.ok(app); - var properties = app.properties(); - - test.strictEqual(properties.description, DESCRIPTION); - test.strictEqual(properties.version, VERSION); - - app.remove(callback); - } - ], function(err) { - test.ok(!err); - test.done(); - }); - }, - - "Callback#delete test applications": function(test) { - var apps = this.service.apps(); - apps.fetch(function(err, apps) { - var appList = apps.list(); - - Async.parallelEach( - appList, - function(app, idx, callback) { - if (utils.startsWith(app.name, "jssdk_")) { - app.remove(callback); - } - else { - callback(); - } - }, function(err) { - test.ok(!err); - test.done(); - } - ); - }); - }, - - "list applications with cookies as authentication": function(test) { - this.service.serverInfo(function (err, info) { - // Cookie authentication was added in splunk 6.2 - var majorVersion = parseInt(info.properties().version.split(".")[0], 10); - var minorVersion = parseInt(info.properties().version.split(".")[1], 10); - // Skip cookie test if Splunk older than 6.2 - if(majorVersion < 6 || (majorVersion === 6 && minorVersion < 2)) { - splunkjs.Logger.log("Skipping cookie test..."); - test.done(); - return; - } - - var service = new splunkjs.Service( - { - scheme: svc.scheme, - host: svc.host, - port: svc.port, - username: svc.username, - password: svc.password, - version: svc.version - }); - - var service2 = new splunkjs.Service( - { - scheme: svc.scheme, - host: svc.host, - port: svc.port, - version: svc.version - }); - - Async.chain([ - function (done) { - service.login(done); - }, - function (job, done) { - // Save the cookie store - var cookieStore = service.http._cookieStore; - // Test that there are cookies - test.ok(!utils.isEmpty(cookieStore)); - - // Add the cookies to a service with no other authenitcation information - service2.http._cookieStore = cookieStore; - - var apps = service2.apps(); - apps.fetch(done); - }, - function (apps, done) { - var appList = apps.list(); - test.ok(appList.length > 0); - test.ok(!utils.isEmpty(service2.http._cookieStore)); - done(); - } - ], - function(err) { - // Test that no errors were returned - test.ok(!err); - test.done(); - }); - }); - } - }, - - "Saved Search Tests": { - setUp: function(done) { - this.service = svc; - this.loggedOutService = loggedOutSvc; - done(); - }, - - "Callback#list": function(test) { - var searches = this.service.savedSearches(); - searches.fetch(function(err, searches) { - var savedSearches = searches.list(); - test.ok(savedSearches.length > 0); - - for(var i = 0; i < savedSearches.length; i++) { - test.ok(savedSearches[i]); - } - - test.done(); - }); - }, - - "Callback#contains": function(test) { - var searches = this.service.savedSearches(); - searches.fetch(function(err, searches) { - var search = searches.item("Errors in the last hour"); - test.ok(search); - - test.done(); - }); - }, - - "Callback#suppress": function(test) { - var searches = this.service.savedSearches(); - searches.fetch(function(err, searches) { - var search = searches.item("Errors in the last hour"); - test.ok(search); - - search.suppressInfo(function(err, info, search) { - test.ok(!err); - test.done(); - }); - }); - }, - - "Callback#list limit count": function(test) { - var searches = this.service.savedSearches(); - searches.fetch({count: 2}, function(err, searches) { - var savedSearches = searches.list(); - test.strictEqual(savedSearches.length, 2); - - for(var i = 0; i < savedSearches.length; i++) { - test.ok(savedSearches[i]); - } - - test.done(); - }); - }, - - "Callback#list filter": function(test) { - var searches = this.service.savedSearches(); - searches.fetch({search: "Error"}, function(err, searches) { - var savedSearches = searches.list(); - test.ok(savedSearches.length > 0); - - for(var i = 0; i < savedSearches.length; i++) { - test.ok(savedSearches[i]); - } - - test.done(); - }); - }, - - "Callback#list offset": function(test) { - var searches = this.service.savedSearches(); - searches.fetch({offset: 2, count: 1}, function(err, searches) { - var savedSearches = searches.list(); - test.strictEqual(searches.paging().offset, 2); - test.strictEqual(searches.paging().perPage, 1); - test.strictEqual(savedSearches.length, 1); - - for(var i = 0; i < savedSearches.length; i++) { - test.ok(savedSearches[i]); - } - - test.done(); - }); - }, - - "Callback#create + modify + delete saved search": function(test) { - var name = "jssdk_savedsearch"; - var originalSearch = "search * | head 1"; - var updatedSearch = "search * | head 10"; - var updatedDescription = "description"; - - var searches = this.service.savedSearches({owner: this.service.username, app: "sdk-app-collection"}); - - Async.chain([ - function(done) { - searches.create({search: originalSearch, name: name}, done); - }, - function(search, done) { - test.ok(search); - - test.strictEqual(search.name, name); - test.strictEqual(search.properties().search, originalSearch); - test.ok(!search.properties().description); - - search.update({search: updatedSearch}, done); - }, - function(search, done) { - test.ok(search); - test.ok(search); - - test.strictEqual(search.name, name); - test.strictEqual(search.properties().search, updatedSearch); - test.ok(!search.properties().description); - - search.update({description: updatedDescription}, done); - }, - function(search, done) { - test.ok(search); - test.ok(search); - - test.strictEqual(search.name, name); - test.strictEqual(search.properties().search, updatedSearch); - test.strictEqual(search.properties().description, updatedDescription); - - search.fetch(done); - }, - function(search, done) { - // Verify that we have the required fields - test.ok(search.fields().optional.length > 1); - test.ok(utils.indexOf(search.fields().optional, "disabled") > -1); - - search.remove(done); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#dispatch error": function(test) { - var name = "jssdk_savedsearch_" + getNextId(); - var originalSearch = "search index=_internal | head 1"; - var search = new splunkjs.Service.SavedSearch( - this.loggedOutService, - name, - {owner: "nobody", app: "search"} - ); - search.dispatch(function(err) { - test.ok(err); - test.done(); - }); - }, - - "Callback#dispatch omitting optional arguments": function(test) { - var name = "jssdk_savedsearch_" + getNextId(); - var originalSearch = "search index=_internal | head 1"; - - var searches = this.service.savedSearches({owner: this.service.username, app: "sdk-app-collection"}); - - Async.chain( - [function(done) { - searches.create({search: originalSearch, name: name}, done); - }, - function(search, done) { - test.ok(search); - - test.strictEqual(search.name, name); - test.strictEqual(search.properties().search, originalSearch); - test.ok(!search.properties().description); - - search.dispatch(done); - }, - function(job, search, done) { - test.ok(job); - test.ok(search); - test.done(); - }] - ); - }, - - "Callback#history error": function(test) { - var name = "jssdk_savedsearch_" + getNextId(); - var originalSearch = "search index=_internal | head 1"; - var search = new splunkjs.Service.SavedSearch( - this.loggedOutService, - name, - {owner: "nobody", app: "search", sharing: "system"} - ); - search.history(function(err) { - test.ok(err); - test.done(); - }); - }, - - "Callback#Update error": function(test) { - var name = "jssdk_savedsearch_" + getNextId(); - var originalSearch = "search index=_internal | head 1"; - var search = new splunkjs.Service.SavedSearch( - this.loggedOutService, - name, - {owner: "nobody", app: "search", sharing: "system"} - ); - search.update( - {}, - function(err) { - test.ok(err); - test.done(); - }); - }, - - "Callback#oneshot requires search string": function(test) { - test.throws(function() { this.service.oneshotSearch({name: "jssdk_oneshot_" + getNextId()}, function(err) {});}); - test.done(); - }, - - "Callback#Create + dispatch + history": function(test) { - var name = "jssdk_savedsearch_" + getNextId(); - var originalSearch = "search index=_internal | head 1"; - - var searches = this.service.savedSearches({owner: this.service.username, app: "sdk-app-collection"}); - - Async.chain( - function(done) { - searches.create({search: originalSearch, name: name}, done); - }, - function(search, done) { - test.ok(search); - - test.strictEqual(search.name, name); - test.strictEqual(search.properties().search, originalSearch); - test.ok(!search.properties().description); - - search.dispatch({force_dispatch: false, "dispatch.buckets": 295}, done); - }, - function(job, search, done) { - test.ok(job); - test.ok(search); - - tutils.pollUntil( - job, - function(j) { - return job.properties()["isDone"]; - }, - 10, - Async.augment(done, search) - ); - }, - function(job, search, done) { - test.strictEqual(job.properties().statusBuckets, 295); - search.history(Async.augment(done, job)); - }, - function(jobs, search, originalJob, done) { - test.ok(jobs); - test.ok(jobs.length > 0); - test.ok(search); - test.ok(originalJob); - - var cancel = function(job) { - return function(cb) { - job.cancel(cb); - }; - }; - - var found = false; - var cancellations = []; - for(var i = 0; i < jobs.length; i++) { - cancellations.push(cancel(jobs[i])); - found = found || (jobs[i].sid === originalJob.sid); - } - - test.ok(found); - - search.remove(function(err) { - if (err) { - done(err); - } - else { - Async.parallel(cancellations, done); - } - }); - }, - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#job events fails": function(test) { - var job = new splunkjs.Service.Job(this.loggedOutService, "abc", {}); - job.events({}, function (err) { - test.ok(err); - test.done(); - }); - }, - - "Callback#job preview fails": function(test) { - var job = new splunkjs.Service.Job(this.loggedOutService, "abc", {}); - job.preview({}, function(err) { - test.ok(err); - test.done(); - }); - }, - - "Callback#job results fails": function(test) { - var job = new splunkjs.Service.Job(this.loggedOutService, "abc", {}); - job.results({}, function(err) { - test.ok(err); - test.done(); - }); - }, - - "Callback#job searchlog fails": function(test) { - var job = new splunkjs.Service.Job(this.loggedOutService, "abc", {}); - job.searchlog(function(err) { - test.ok(err); - test.done(); - }); - }, - - "Callback#job summary fails": function(test) { - var job = new splunkjs.Service.Job(this.loggedOutService, "abc", {}); - job.summary({}, function(err) { - test.ok(err); - test.done(); - }); - }, - - "Callback#job timeline fails": function(test) { - var job = new splunkjs.Service.Job(this.loggedOutService, "abc", {}); - job.timeline({}, function(err) { - test.ok(err); - test.done(); - }); - }, - - "Callback#delete test saved searches": function(test) { - var searches = this.service.savedSearches({owner: this.service.username, app: "sdk-app-collection"}); - searches.fetch(function(err, searches) { - var searchList = searches.list(); - Async.parallelEach( - searchList, - function(search, idx, callback) { - if (utils.startsWith(search.name, "jssdk_")) { - search.remove(callback); - } - else { - callback(); - } - }, function(err) { - test.ok(!err); - test.done(); - } - ); - }); - }, - - "Callback#setupInfo fails": function(test) { - var searches = new splunkjs.Service.Application(this.loggedOutService, "search"); - searches.setupInfo(function(err, content, that) { - test.ok(err); - test.done(); - }); - }, - - "Callback#setupInfo succeeds": function(test) { - var app = new splunkjs.Service.Application(this.service, "sdk-app-collection"); - app.setupInfo(function(err, content, app) { - // This error message was removed in modern versions of Splunk - if (err) { - test.ok(err.data.messages[0].text.match("Setup configuration file does not")); - splunkjs.Logger.log("ERR ---", err.data.messages[0].text); - } - else { - test.ok(app); - } - test.done(); - }); - }, - - "Callback#updateInfo": function(test) { - var app = new splunkjs.Service.Application(this.service, "search"); - app.updateInfo(function(err, info, app) { - test.ok(!err); - test.ok(app); - test.strictEqual(app.name, 'search'); - test.done(); - }); - }, - - "Callback#updateInfo failure": function(test) { - var app = new splunkjs.Service.Application(this.loggedOutService, "sdk-app-collection"); - app.updateInfo(function(err, info, app) { - test.ok(err); - test.done(); - }); - } - }, - - "Fired Alerts Tests": { - setUp: function(done) { - this.service = svc; - this.loggedOutService = loggedOutSvc; - - var indexes = this.service.indexes(); - done(); - }, - - "Callback#create + verify emptiness + delete new alert group": function(test) { - var searches = this.service.savedSearches({owner: this.service.username}); - - var name = "jssdk_savedsearch_alert_" + getNextId(); - var searchConfig = { - "name": name, - "search": "index=_internal | head 1", - "alert_type": "always", - "alert.severity": "2", - "alert.suppress": "0", - "alert.track": "1", - "dispatch.earliest_time": "-1h", - "dispatch.latest_time": "now", - "is_scheduled": "1", - "cron_schedule": "* * * * *" - }; - - Async.chain([ - function(done) { - searches.create(searchConfig, done); - }, - function(search, done) { - test.ok(search); - test.strictEqual(search.alertCount(), 0); - search.history(done); - }, - function(jobs, search, done) { - test.strictEqual(jobs.length, 0); - test.strictEqual(search.firedAlertGroup().count(), 0); - searches.service.firedAlertGroups().fetch( Async.augment(done, search) ); - }, - function(firedAlertGroups, originalSearch, done) { - test.strictEqual(firedAlertGroups.list().indexOf(originalSearch.name), -1); - done(null, originalSearch); - }, - function(originalSearch, done) { - originalSearch.remove(done); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - // This test is not stable, commenting it out until we figure it out - // "Callback#alert is triggered + test firedAlert entity -- FAILS INTERMITTENTLY": function(test) { - // var searches = this.service.savedSearches({owner: this.service.username}); - // var indexName = "sdk-tests-alerts"; - // var name = "jssdk_savedsearch_alert_" + getNextId(); - - // // Real-time search config - // var searchConfig = { - // "name": name, - // "search": "index="+indexName+" sourcetype=sdk-tests-alerts | head 1", - // "alert_type": "always", - // "alert.severity": "2", - // "alert.suppress": "0", - // "alert.track": "1", - // "dispatch.earliest_time": "rt-1s", - // "dispatch.latest_time": "rt", - // "is_scheduled": "1", - // "cron_schedule": "* * * * *" - // }; - - // Async.chain([ - // function(done) { - // searches.create(searchConfig, done); - // }, - // function(search, done) { - // test.ok(search); - // test.strictEqual(search.alertCount(), 0); - // test.strictEqual(search.firedAlertGroup().count(), 0); - - // var indexes = search.service.indexes(); - // indexes.create(indexName, {}, function(err, index) { - // if (err && err.status !== 409) { - // done(new Error("Index creation failed for an unknown reason")); - // } - // done(null, search); - // }); - // }, - // function(originalSearch, done) { - // var indexes = originalSearch.service.indexes(); - // indexes.fetch(function(err, indexes) { - // if (err) { - // done(err); - // } - // else { - // var index = indexes.item(indexName); - // test.ok(index); - // index.enable(Async.augment(done, originalSearch)); - // } - // }); - // }, - // function(index, originalSearch, done) { - // //Is the index enabled? - // test.ok(!index.properties().disabled); - // //refresh the index - // index.fetch(Async.augment(done, originalSearch)); - // }, - // function(index, originalSearch, done) { - // //Store the current event count for a later comparison - // var eventCount = index.properties().totalEventCount; - - // test.strictEqual(index.properties().sync, 0); - // test.ok(!index.properties().disabled); - - // index.fetch(Async.augment(done, originalSearch, eventCount)); - // }, - // function(index, originalSearch, eventCount, done) { - // // submit an event - // index.submitEvent( - // "JS SDK: testing alerts", - // { - // sourcetype: "sdk-tests-alerts" - // }, - // Async.augment(done, originalSearch, eventCount) - // ); - // }, - // function(result, index, originalSearch, eventCount, done) { - // Async.sleep(1000, function(){ - // //refresh the search - // index.fetch(Async.augment(done, originalSearch, eventCount)); - // }); - // }, - // function(index, originalSearch, eventCount, done) { - // // Did the event get submitted - // test.strictEqual(index.properties().totalEventCount, eventCount+1); - // // Refresh the search - // originalSearch.fetch(Async.augment(done, index)); - // }, - // function(originalSearch, index, done) { - // splunkjs.Logger.log("\tAlert count pre-fetch", originalSearch.alertCount()); - // var attemptNum = 1; - // var maxAttempts = 20; - // Async.whilst( - // function() { - // // When this returns false, it hits the final function in the chain - // splunkjs.Logger.log("\tFetch attempt", attemptNum, "of", maxAttempts, "alertCount", originalSearch.alertCount()); - // if (originalSearch.alertCount() !== 0) { - // return false; - // } - // else { - // attemptNum++; - // return attemptNum < maxAttempts; - // } - // }, - // function(callback) { - // Async.sleep(500, function() { - // originalSearch.fetch(callback); - // }); - // }, - // function(err) { - // splunkjs.Logger.log("Attempted fetching", attemptNum, "of", maxAttempts, "result is", originalSearch.alertCount() !== 0); - // originalSearch.fetch(Async.augment(done, index)); - // } - // ); - // }, - // function(originalSearch, index, done) { - // splunkjs.Logger.log("about to fetch"); - // splunkjs.Logger.log("SavedSearch name was: " + originalSearch.name); - // svc.firedAlertGroups({username: svc.username}).fetch(Async.augment(done, index, originalSearch)); - // }, - // function(firedAlertGroups, index, originalSearch, done) { - // Async.seriesEach( - // firedAlertGroups.list(), - // function(firedAlertGroup, innerIndex, seriescallback) { - // Async.chain([ - // function(insideChainCallback) { - // firedAlertGroup.list(insideChainCallback); - // }, - // function(firedAlerts, firedAlertGroup, insideChainCallback) { - // for(var i = 0; i < firedAlerts.length; i++) { - // var firedAlert = firedAlerts[i]; - // firedAlert.actions(); - // firedAlert.alertType(); - // firedAlert.isDigestMode(); - // firedAlert.expirationTime(); - // firedAlert.savedSearchName(); - // firedAlert.severity(); - // firedAlert.sid(); - // firedAlert.triggerTime(); - // firedAlert.triggerTimeRendered(); - // firedAlert.triggeredAlertCount(); - // } - // insideChainCallback(null); - // } - // ], - // function(err) { - // if (err) { - // seriescallback(err); - // } - // seriescallback(null); - // } - // ); - // }, - // function(err) { - // if (err) { - // done(err, originalSearch, index); - // } - // done(null, originalSearch, index); - // } - // ); - // }, - // function(originalSearch, index, done) { - // // Make sure the event count has incremented, as expected - // test.strictEqual(originalSearch.alertCount(), 1); - // // Remove the search, especially because it's a real-time search - // originalSearch.remove(Async.augment(done, index)); - // }, - // function(index, done) { - // Async.sleep(500, function() { - // index.remove(done); - // }); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, - - "Callback#delete all alerts": function(test) { - var namePrefix = "jssdk_savedsearch_alert_"; - var alertList = this.service.savedSearches().list(); - - Async.parallelEach( - alertList, - function(alert, idx, callback) { - if (utils.startsWith(alert.name, namePrefix)) { - splunkjs.Logger.log("ALERT ---", alert.name); - alert.remove(callback); - } - else { - callback(); - } - }, function(err) { - test.ok(!err); - test.done(); - } - ); - } - }, - - "Properties Tests": { - setUp: function(done) { - this.service = svc; - done(); - }, - - "Callback#list": function(test) { - var that = this; - var namespace = {owner: "admin", app: "search"}; - - Async.chain([ - function(done) { - that.service.configurations(namespace).fetch(done); - }, - function(props, done) { - var files = props.list(); - test.ok(files.length > 0); - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - }); - }, - - "Callback#item": function(test) { - var that = this; - var namespace = {owner: "admin", app: "search"}; - - Async.chain([ - function(done) { that.service.configurations(namespace).fetch(done); }, - function(props, done) { - var file = props.item("web"); - test.ok(file); - file.fetch(done); - }, - function(file, done) { - test.strictEqual(file.name, "web"); - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - }); - }, - - "Callback#contains stanza": function(test) { - var that = this; - var namespace = {owner: "admin", app: "search"}; - - Async.chain([ - function(done) { that.service.configurations(namespace).fetch(done); }, - function(props, done) { - var file = props.item("web"); - test.ok(file); - file.fetch(done); - }, - function(file, done) { - test.strictEqual(file.name, "web"); - var stanza = file.item("settings"); - test.ok(stanza); - stanza.fetch(done); - }, - function(stanza, done) { - test.ok(stanza.properties().hasOwnProperty("httpport")); - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - }); - }, - - "Callback#create file + create stanza + update stanza": function(test) { - var that = this; - var fileName = "jssdk_file_" + getNextId(); - var value = "barfoo_" + getNextId(); - var namespace = {owner: "admin", app: "search"}; - - Async.chain([ - function(done) { - var properties = that.service.configurations(namespace); - properties.fetch(done); - }, - function(properties, done) { - properties.create(fileName, done); - }, - function(file, done) { - file.create("stanza", done); - }, - function(stanza, done) { - stanza.update({"jssdk_foobar": value}, done); - }, - function(stanza, done) { - test.strictEqual(stanza.properties()["jssdk_foobar"], value); - done(); - }, - function(done) { - var file = new splunkjs.Service.ConfigurationFile(svc, fileName); - file.fetch(done); - }, - function(file, done) { - var stanza = file.item("stanza"); - test.ok(stanza); - stanza.remove(done); - } - ], - function(err) { - test.ok(!err); - test.done(); - }); - } - }, - - "Configuration Tests": { - setUp: function(done) { - this.service = svc; - done(); - }, - - "Callback#list": function(test) { - var that = this; - var namespace = {owner: "admin", app: "search"}; - - Async.chain([ - function(done) { that.service.configurations(namespace).fetch(done); }, - function(props, done) { - var files = props.list(); - test.ok(files.length > 0); - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - }); - }, - - "Callback#contains": function(test) { - var that = this; - var namespace = {owner: "admin", app: "search"}; - - Async.chain([ - function(done) { that.service.configurations(namespace).fetch(done); }, - function(props, done) { - var file = props.item("web"); - test.ok(file); - file.fetch(done); - }, - function(file, done) { - test.strictEqual(file.name, "web"); - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - }); - }, - - "Callback#contains stanza": function(test) { - var that = this; - var namespace = {owner: "admin", app: "search"}; - - Async.chain([ - function(done) { that.service.configurations(namespace).fetch(done); }, - function(props, done) { - var file = props.item("web"); - test.ok(file); - file.fetch(done); - }, - function(file, done) { - test.strictEqual(file.name, "web"); - - var stanza = file.item("settings"); - test.ok(stanza); - stanza.fetch(done); - }, - function(stanza, done) { - test.ok(stanza.properties().hasOwnProperty("httpport")); - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - }); - }, - - "Callback#configurations init": function(test) { - test.throws(function() { - var confs = new splunkjs.Service.Configurations( - this.service, - {owner: "-", app: "-", sharing: "system"} - ); - }); - test.done(); - }, - - "Callback#create file + create stanza + update stanza": function(test) { - var that = this; - var namespace = {owner: "nobody", app: "system"}; - var fileName = "jssdk_file_" + getNextId(); - var value = "barfoo_" + getNextId(); - - Async.chain([ - function(done) { - var configs = svc.configurations(namespace); - configs.fetch(done); - }, - function(configs, done) { - configs.create({__conf: fileName}, done); - }, - function(file, done) { - if (file.item("stanza")) { - file.item("stanza").remove(); - } - file.create("stanza", done); - }, - function(stanza, done) { - stanza.update({"jssdk_foobar": value}, done); - }, - function(stanza, done) { - test.strictEqual(stanza.properties()["jssdk_foobar"], value); - done(); - }, - function(done) { - var file = new splunkjs.Service.ConfigurationFile(svc, fileName); - file.fetch(done); - }, - function(file, done) { - var stanza = file.item("stanza"); - test.ok(stanza); - stanza.remove(done); - } - ], - function(err) { - test.ok(!err); - test.done(); - }); - }, - - "Callback#can get default stanza": function(test) { - var that = this; - var namespace = {owner: "admin", app: "search"}; - - Async.chain([ - function(done) { that.service.configurations(namespace).fetch(done); }, - function(props, done) { - var file = props.item("savedsearches"); - test.strictEqual(namespace, file.namespace); - test.ok(file); - file.fetch(done); - }, - function(file, done) { - test.strictEqual(namespace, file.namespace); - file.getDefaultStanza().fetch(done); - }, - function(stanza, done) { - test.strictEqual(stanza.name, "default"); - test.strictEqual(namespace, stanza.namespace); - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - }); - }, - - "Callback#updating default stanza is noop": function(test) { - var that = this; - var namespace = {owner: "admin", app: "search"}; - var backup = null; - var invalid = "this won't work"; - - Async.chain([ - function(done) { that.service.configurations(namespace).fetch(done); }, - function(props, done) { - var file = props.item("savedsearches"); - test.strictEqual(namespace, file.namespace); - test.ok(file); - file.fetch(done); - }, - function(file, done) { - test.strictEqual(namespace, file.namespace); - file.getDefaultStanza().fetch(done); - }, - function(stanza, done) { - test.ok(stanza._properties.hasOwnProperty("max_concurrent")); - test.strictEqual(namespace, stanza.namespace); - backup = stanza._properties.max_concurrent; - stanza.update({"max_concurrent": invalid}, done); - }, - function(stanza, done) { - test.ok(stanza.properties().hasOwnProperty("max_concurrent")); - test.strictEqual(stanza.properties()["max_concurrent"], backup); - test.notStrictEqual(stanza.properties()["max_concurrent"], invalid); - stanza.fetch(done); - }, - function(stanza, done) { - test.ok(stanza.properties().hasOwnProperty("max_concurrent")); - test.strictEqual(stanza.properties()["max_concurrent"], backup); - test.notStrictEqual(stanza.properties()["max_concurrent"], invalid); - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - }); - } - }, - - "Storage Passwords Tests": { - setUp: function(done) { - this.service = svc; - done(); - }, - - "Callback#Create": function(test) { - var startcount = -1; - var name = "delete-me-" + getNextId(); - var realm = "delete-me-" + getNextId(); - var that = this; - Async.chain([ - function(done) { - that.service.storagePasswords().fetch(done); - }, - function(storagePasswords, done) { - startcount = storagePasswords.list().length; - storagePasswords.create({name: name, realm: realm, password: "changeme"}, done); - }, - function(storagePassword, done) { - test.strictEqual(name, storagePassword.properties().username); - test.strictEqual(realm + ":" + name + ":", storagePassword.name); - test.strictEqual("changeme", storagePassword.properties().clear_password); - test.strictEqual(realm, storagePassword.properties().realm); - that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); - }, - function(storagePasswords, storagePassword, done) { - test.strictEqual(startcount + 1, storagePasswords.list().length); - storagePassword.remove(done); - }, - function(done) { - that.service.storagePasswords().fetch(done); - }, - function(storagePasswords, done) { - test.strictEqual(startcount, storagePasswords.list().length); - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Create with backslashes": function(test) { - var startcount = -1; - var name = "\\delete-me-" + getNextId(); - var realm = "\\delete-me-" + getNextId(); - var that = this; - Async.chain([ - function(done) { - that.service.storagePasswords().fetch(done); - }, - function(storagePasswords, done) { - startcount = storagePasswords.list().length; - storagePasswords.create({name: name, realm: realm, password: "changeme"}, done); - }, - function(storagePassword, done) { - test.strictEqual(name, storagePassword.properties().username); - test.strictEqual("\\" + realm + ":\\" + name + ":", storagePassword.name); - test.strictEqual("changeme", storagePassword.properties().clear_password); - test.strictEqual(realm, storagePassword.properties().realm); - that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); - }, - function(storagePasswords, storagePassword, done) { - test.strictEqual(startcount + 1, storagePasswords.list().length); - storagePassword.remove(done); - }, - function(done) { - that.service.storagePasswords().fetch(done); - }, - function(storagePasswords, done) { - test.strictEqual(startcount, storagePasswords.list().length); - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Create with slashes": function(test) { - var startcount = -1; - var name = "/delete-me-" + getNextId(); - var realm = "/delete-me-" + getNextId(); - var that = this; - Async.chain([ - function(done) { - that.service.storagePasswords().fetch(done); - }, - function(storagePasswords, done) { - startcount = storagePasswords.list().length; - storagePasswords.create({name: name, realm: realm, password: "changeme"}, done); - }, - function(storagePassword, done) { - test.strictEqual(name, storagePassword.properties().username); - test.strictEqual(realm + ":" + name + ":", storagePassword.name); - test.strictEqual("changeme", storagePassword.properties().clear_password); - test.strictEqual(realm, storagePassword.properties().realm); - that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); - }, - function(storagePasswords, storagePassword, done) { - test.strictEqual(startcount + 1, storagePasswords.list().length); - storagePassword.remove(done); - }, - function(done) { - that.service.storagePasswords().fetch(done); - }, - function(storagePasswords, done) { - test.strictEqual(startcount, storagePasswords.list().length); - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Create without realm": function(test) { - var startcount = -1; - var name = "delete-me-" + getNextId(); - var that = this; - Async.chain([ - function(done) { - that.service.storagePasswords().fetch(done); - }, - function(storagePasswords, done) { - startcount = storagePasswords.list().length; - storagePasswords.create({name: name, password: "changeme"}, done); - }, - function(storagePassword, done) { - test.strictEqual(name, storagePassword.properties().username); - test.strictEqual(":" + name + ":", storagePassword.name); - test.strictEqual("changeme", storagePassword.properties().clear_password); - test.strictEqual("", storagePassword.properties().realm); - that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); - }, - function(storagePasswords, storagePassword, done) { - test.strictEqual(startcount + 1, storagePasswords.list().length); - storagePassword.remove(done); - }, - function(done) { - that.service.storagePasswords().fetch(done); - }, - function(storagePasswords, done) { - test.strictEqual(startcount, storagePasswords.list().length); - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Create should fail without user, or realm": function(test) { - var that = this; - Async.chain([ - function(done) { - that.service.storagePasswords().fetch(done); - }, - function(storagePasswords, done) { - storagePasswords.create({name: null, password: "changeme"}, done); - } - ], - function(err) { - test.ok(err); - test.done(); - } - ); - }, - - "Callback#Create should fail without password": function(test) { - var that = this; - Async.chain([ - function(done) { - that.service.storagePasswords().fetch(done); - }, - function(storagePasswords, done) { - storagePasswords.create({name: "something", password: null}, done); - } - ], - function(err) { - test.ok(err); - test.done(); - } - ); - }, - - "Callback#Create should fail without user, realm, or password": function(test) { - var that = this; - Async.chain([ - function(done) { - that.service.storagePasswords().fetch(done); - }, - function(storagePasswords, done) { - storagePasswords.create({name: null, password: null}, done); - } - ], - function(err) { - test.ok(err); - test.done(); - } - ); - }, - - "Callback#Create with colons": function(test) { - var startcount = -1; - var name = ":delete-me-" + getNextId(); - var realm = ":delete-me-" + getNextId(); - var that = this; - Async.chain([ - function(done) { - that.service.storagePasswords().fetch(done); - }, - function(storagePasswords, done) { - startcount = storagePasswords.list().length; - storagePasswords.create({name: name, realm: realm, password: "changeme"}, done); - }, - function(storagePassword, done) { - test.strictEqual(name, storagePassword.properties().username); - test.strictEqual("\\" + realm + ":\\" + name + ":", storagePassword.name); - test.strictEqual("changeme", storagePassword.properties().clear_password); - test.strictEqual(realm, storagePassword.properties().realm); - that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); - }, - function(storagePasswords, storagePassword, done) { - test.strictEqual(startcount + 1, storagePasswords.list().length); - storagePassword.remove(done); - }, - function(done) { - that.service.storagePasswords().fetch(done); - }, - function(storagePasswords, done) { - test.strictEqual(startcount, storagePasswords.list().length); - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Create crazy": function(test) { - var startcount = -1; - var name = "delete-me-" + getNextId(); - var realm = "delete-me-" + getNextId(); - var that = this; - Async.chain([ - function(done) { - that.service.storagePasswords().fetch(done); - }, - function(storagePasswords, done) { - startcount = storagePasswords.list().length; - storagePasswords.create({ - name: name + ":end!@#$%^&*()_+{}:|<>?", - realm: ":start::!@#$%^&*()_+{}:|<>?" + realm, - password: "changeme"}, - done); - }, - function(storagePassword, done) { - test.strictEqual(name + ":end!@#$%^&*()_+{}:|<>?", storagePassword.properties().username); - test.strictEqual("\\:start\\:\\:!@#$%^&*()_+{}\\:|<>?" + realm + ":" + name + "\\:end!@#$%^&*()_+{}\\:|<>?:", storagePassword.name); - test.strictEqual("changeme", storagePassword.properties().clear_password); - test.strictEqual(":start::!@#$%^&*()_+{}:|<>?" + realm, storagePassword.properties().realm); - that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); - }, - function(storagePasswords, storagePassword, done) { - test.strictEqual(startcount + 1, storagePasswords.list().length); - storagePassword.remove(done); - }, - function(done) { - that.service.storagePasswords().fetch(done); - }, - function(storagePasswords, done) { - test.strictEqual(startcount, storagePasswords.list().length); - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Create with unicode chars": function(test) { - var startcount = -1; - var name = "delete-me-" + getNextId(); - var realm = "delete-me-" + getNextId(); - var that = this; - Async.chain([ - function(done) { - that.service.storagePasswords().fetch(done); - }, - function(storagePasswords, done) { - startcount = storagePasswords.list().length; - storagePasswords.create({ - name: name + ":end!@#$%^&*()_+{}:|<>?쎼 and 쎶 and <&> für", - realm: ":start::!@#$%^&*()_+{}:|<>?" + encodeURIComponent("쎼 and 쎶 and <&> für") + realm, - password: decodeURIComponent(encodeURIComponent("쎼 and 쎶 and <&> für"))}, - done); - }, - function(storagePassword, done) { - test.strictEqual(name + ":end!@#$%^&*()_+{}:|<>?쎼 and 쎶 and <&> für", storagePassword.properties().username); - test.strictEqual("\\:start\\:\\:!@#$%^&*()_+{}\\:|<>?" + encodeURIComponent("쎼 and 쎶 and <&> für") + realm + ":" + name + "\\:end!@#$%^&*()_+{}\\:|<>?쎼 and 쎶 and <&> für:", storagePassword.name); - test.strictEqual(decodeURIComponent(encodeURIComponent("쎼 and 쎶 and <&> für")), storagePassword.properties().clear_password); - test.strictEqual(":start::!@#$%^&*()_+{}:|<>?" + encodeURIComponent("쎼 and 쎶 and <&> für") + realm, storagePassword.properties().realm); - that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); - }, - function(storagePasswords, storagePassword, done) { - test.strictEqual(startcount + 1, storagePasswords.list().length); - storagePassword.remove(done); - }, - function(done) { - that.service.storagePasswords().fetch(done); - }, - function(storagePasswords, done) { - test.strictEqual(startcount, storagePasswords.list().length); - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Read": function(test) { - var startcount = -1; - var name = "delete-me-" + getNextId(); - var realm = "delete-me-" + getNextId(); - var that = this; - Async.chain([ - function(done) { - that.service.storagePasswords().fetch(done); - }, - function(storagePasswords, done) { - startcount = storagePasswords.list().length; - storagePasswords.create({name: name, realm: realm, password: "changeme"}, done); - }, - function(storagePassword, done) { - test.strictEqual(name, storagePassword.properties().username); - test.strictEqual(realm + ":" + name + ":", storagePassword.name); - test.strictEqual("changeme", storagePassword.properties().clear_password); - test.strictEqual(realm, storagePassword.properties().realm); - that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); - }, - function(storagePasswords, storagePassword, done) { - try { - test.ok(!!storagePasswords.item(realm + ":" + name + ":")); - } - catch (e) { - test.ok(false); - } - - var list = storagePasswords.list(); - var found = false; - - test.strictEqual(startcount + 1, list.length); - for (var i = 0; i < list.length; i ++) { - if (realm + ":" + name + ":" === list[i].name) { - found = true; - } - } - test.ok(found); - - storagePassword.remove(done); - }, - function(done) { - that.service.storagePasswords().fetch(done); - }, - function(storagePasswords, done) { - test.strictEqual(startcount, storagePasswords.list().length); - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Read with slashes": function(test) { - var startcount = -1; - var name = "/delete-me-" + getNextId(); - var realm = "/delete-me-" + getNextId(); - var that = this; - Async.chain([ - function(done) { - that.service.storagePasswords().fetch(done); - }, - function(storagePasswords, done) { - startcount = storagePasswords.list().length; - storagePasswords.create({name: name, realm: realm, password: "changeme"}, done); - }, - function(storagePassword, done) { - test.strictEqual(name, storagePassword.properties().username); - test.strictEqual(realm + ":" + name + ":", storagePassword.name); - test.strictEqual("changeme", storagePassword.properties().clear_password); - test.strictEqual(realm, storagePassword.properties().realm); - that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); - }, - function(storagePasswords, storagePassword, done) { - try { - test.ok(!!storagePasswords.item(realm + ":" + name + ":")); - } - catch (e) { - test.ok(false); - } - - var list = storagePasswords.list(); - var found = false; - - test.strictEqual(startcount + 1, list.length); - for (var i = 0; i < list.length; i ++) { - if (realm + ":" + name + ":" === list[i].name) { - found = true; - } - } - test.ok(found); - - storagePassword.remove(done); - }, - function(done) { - that.service.storagePasswords().fetch(done); - }, - function(storagePasswords, done) { - test.strictEqual(startcount, storagePasswords.list().length); - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Update": function(test) { - var startcount = -1; - var name = "delete-me-" + getNextId(); - var realm = "delete-me-" + getNextId(); - var that = this; - Async.chain([ - function(done) { - that.service.storagePasswords().fetch(done); - }, - function(storagePasswords, done) { - startcount = storagePasswords.list().length; - storagePasswords.create({name: name, realm: realm, password: "changeme"}, done); - }, - function(storagePassword, done) { - test.strictEqual(name, storagePassword.properties().username); - test.strictEqual(realm + ":" + name + ":", storagePassword.name); - test.strictEqual("changeme", storagePassword.properties().clear_password); - test.strictEqual(realm, storagePassword.properties().realm); - that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); - }, - function(storagePasswords, storagePassword, done) { - test.strictEqual(startcount + 1, storagePasswords.list().length); - storagePassword.update({password: "changed"}, done); - }, - function(storagePassword, done) { - test.strictEqual(name, storagePassword.properties().username); - test.strictEqual(realm + ":" + name + ":", storagePassword.name); - test.strictEqual("changed", storagePassword.properties().clear_password); - test.strictEqual(realm, storagePassword.properties().realm); - that.service.storagePasswords().fetch(done); - }, - function(storagePasswords, done) { - var list = storagePasswords.list(); - var found = false; - var index = -1; - - test.strictEqual(startcount + 1, list.length); - for (var i = 0; i < list.length; i ++) { - if (realm + ":" + name + ":" === list[i].name) { - found = true; - index = i; - test.strictEqual(name, list[i].properties().username); - test.strictEqual(realm + ":" + name + ":", list[i].name); - test.strictEqual("changed", list[i].properties().clear_password); - test.strictEqual(realm, list[i].properties().realm); - } - } - test.ok(found); - - if (!found) { - done(new Error("Didn't find the created password")); - } - else { - list[index].remove(done); - } - }, - function(done) { - that.service.storagePasswords().fetch(done); - }, - function(storagePasswords, done) { - test.strictEqual(startcount, storagePasswords.list().length); - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Delete": function(test) { - var startcount = -1; - var name = "delete-me-" + getNextId(); - var realm = "delete-me-" + getNextId(); - var that = this; - Async.chain([ - function(done) { - that.service.storagePasswords().fetch(done); - }, - function(storagePasswords, done) { - startcount = storagePasswords.list().length; - storagePasswords.create({name: name, realm: realm, password: "changeme"}, done); - }, - function(storagePassword, done) { - test.strictEqual(name, storagePassword.properties().username); - test.strictEqual(realm + ":" + name + ":", storagePassword.name); - test.strictEqual("changeme", storagePassword.properties().clear_password); - test.strictEqual(realm, storagePassword.properties().realm); - that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); - }, - function(storagePasswords, storagePassword, done) { - test.strictEqual(startcount + 1, storagePasswords.list().length); - storagePassword.remove(done); - }, - function(done) { - that.service.storagePasswords().fetch(done); - }, - function(storagePasswords, done) { - test.strictEqual(startcount, storagePasswords.list().length); - storagePasswords.create({name: name, realm: realm, password: "changeme"}, done); - }, - function(storagePassword, done) { - test.strictEqual(name, storagePassword.properties().username); - that.service.storagePasswords().fetch(done); - }, - function(storagePasswords, done) { - test.strictEqual(startcount + 1, storagePasswords.list().length); - var list = storagePasswords.list(); - var found = false; - var index = -1; - - test.strictEqual(startcount + 1, list.length); - for (var i = 0; i < list.length; i ++) { - if (realm + ":" + name + ":" === list[i].name) { - found = true; - index = i; - test.strictEqual(name, list[i].properties().username); - test.strictEqual(realm + ":" + name + ":", list[i].name); - test.strictEqual("changeme", list[i].properties().clear_password); - test.strictEqual(realm, list[i].properties().realm); - } - } - test.ok(found); - - if (!found) { - done(new Error("Didn't find the created password")); - } - else { - list[index].remove(done); - } - }, - function(done) { - that.service.storagePasswords().fetch(done); - }, - function(storagePasswords, done) { - test.strictEqual(startcount, storagePasswords.list().length); - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - } - }, - - "Index Tests": { - setUp: function(done) { - this.service = svc; - this.loggedOutService = loggedOutSvc; - - // Create the index for everyone to use - var name = this.indexName = "sdk-tests"; - var indexes = this.service.indexes(); - indexes.create(name, {}, function(err, index) { - if (err && err.status !== 409) { - throw new Error("Index creation failed for an unknown reason"); - } - - done(); - }); - }, - - "Callback#remove index fails on Splunk 4.x": function(test) { - var original_version = this.service.version; - this.service.version = "4.0"; - - var index = this.service.indexes().item(this.indexName); - test.throws(function() { index.remove(function(err) {}); }); - - this.service.version = original_version; - test.done(); - }, - - "Callback#remove index": function(test) { - var indexes = this.service.indexes(); - - // Must generate a private index because an index cannot - // be recreated with the same name as a deleted index - // for a certain period of time after the deletion. - var salt = Math.floor(Math.random() * 65536); - var myIndexName = this.indexName + '-' + salt; - - if (this.service.versionCompare("5.0") < 0) { - splunkjs.Logger.info("", "Must be running Splunk 5.0+ for this test to work."); - test.done(); - return; - } - - Async.chain([ - function(callback) { - indexes.create(myIndexName, {}, callback); - }, - function(index, callback) { - index.remove(callback); - }, - function(callback) { - var numTriesLeft = 50; - var delayPerTry = 100; // ms - - Async.whilst( - function() { return indexes.item(myIndexName) && ((numTriesLeft--) > 0); }, - function(iterDone) { - Async.sleep(delayPerTry, function() { indexes.fetch(iterDone); }); - }, - function(err) { - if (err) { - callback(err); - } - else { - callback(numTriesLeft <= 0 ? "Timed out" : null); - } - } - ); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#list indexes": function(test) { - var indexes = this.service.indexes(); - indexes.fetch(function(err, indexes) { - var indexList = indexes.list(); - test.ok(indexList.length > 0); - test.done(); - }); - }, - - "Callback#contains index": function(test) { - var indexes = this.service.indexes(); - var indexName = this.indexName; - - indexes.fetch(function(err, indexes) { - var index = indexes.item(indexName); - test.ok(index); - test.done(); - }); - }, - - "Callback#modify index": function(test) { - - var name = this.indexName; - var indexes = this.service.indexes(); - var originalSyncMeta = false; - - Async.chain([ - function(callback) { - indexes.fetch(callback); - }, - function(indexes, callback) { - var index = indexes.item(name); - test.ok(index); - - originalSyncMeta = index.properties().syncMeta; - index.update({ - syncMeta: !originalSyncMeta - }, callback); - }, - function(index, callback) { - test.ok(index); - var properties = index.properties(); - - test.strictEqual(!originalSyncMeta, properties.syncMeta); - - index.update({ - syncMeta: !properties.syncMeta - }, callback); - }, - function(index, callback) { - test.ok(index); - var properties = index.properties(); - - test.strictEqual(originalSyncMeta, properties.syncMeta); - callback(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Enable+disable index": function(test) { - - var name = this.indexName; - var indexes = this.service.indexes(); - - Async.chain([ - function(callback) { - indexes.fetch(callback); - }, - function(indexes, callback) { - var index = indexes.item(name); - test.ok(index); - - index.disable(callback); - }, - function(index, callback) { - test.ok(index); - index.fetch(callback); - }, - function(index, callback) { - test.ok(index); - test.ok(index.properties().disabled); - - index.enable(callback); - }, - function(index, callback) { - test.ok(index); - index.fetch(callback); - }, - function(index, callback) { - test.ok(index); - test.ok(!index.properties().disabled); - - callback(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Service submit event": function(test) { - var message = "Hello World -- " + getNextId(); - var sourcetype = "sdk-tests"; - - var service = this.service; - var indexName = this.indexName; - Async.chain( - function(done) { - service.log(message, {sourcetype: sourcetype, index: indexName}, done); - }, - function(eventInfo, done) { - test.ok(eventInfo); - test.strictEqual(eventInfo.sourcetype, sourcetype); - test.strictEqual(eventInfo.bytes, message.length); - test.strictEqual(eventInfo.index, indexName); - - // We could poll to make sure the index has eaten up the event, - // but unfortunately this can take an unbounded amount of time. - // As such, since we got a good response, we'll just be done with it. - done(); - }, - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Service submit event, omitting optional arguments": function(test) { - var message = "Hello World -- " + getNextId(); - var sourcetype = "sdk-tests"; - - var service = this.service; - var indexName = this.indexName; - Async.chain( - function(done) { - service.log(message, done); - }, - function(eventInfo, done) { - test.ok(eventInfo); - test.strictEqual(eventInfo.bytes, message.length); - - // We could poll to make sure the index has eaten up the event, - // but unfortunately this can take an unbounded amount of time. - // As such, since we got a good response, we'll just be done with it. - done(); - }, - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Service submit events with multi-byte chars": function(test) { - var service = this.service; - var messages = [ - "Ummelner Straße 6", - "Ümmelner Straße 6", - "Iԉtérԉátíòлåɭìƶåtiòл", - "Intérnâtì߀лàɭíƶɑtïòл", - "ãϻét dòner turƙëy ѵ߀lù", - "ptãte ìԉ rëρrèhënԁérit ", - "ϻ߀lɭit fìɭèt ϻìǥnoԉ ɭäb߀ríѕ", - " êӽ cɦùck cüpïᏧåtåt Ꮷèѕëruлt. ", - "D߀ɭor ѵélít ìrurè, sèᏧ ѕhòr", - "t riƅѕ c߀ɰ ɭãnԁյàéɢêr drúmst", - "ícƙ. Minïm ƃàɭl tip ѕհòrt rìƃѕ,", - " ïԁ aɭïqúìρ ѕɦànƙ ρ߀rcɦéttɑ. Pìǥ", - " hãm ɦòck ìлcídíԁùԉt séԁ cüpïϻ ", - "ƙèviл láborê. Et taiɭ ѕtriρ", - " steák út üllãϻc߀ rump d߀ɭore.", - "٩(͡๏̯͡๏)۶ ٩(-̮̮̃•̃).", - "Lɑƅòré ƃrësãòlá d߀лèr ѕâlámí ", - "cíllûm ìn ѕɯìлe ϻêàtɭ߀àf dûìs ", - "ρãncettä ƅrìsƙét ԁèsêrûлt áútè", - " յòɰɭ. Lɑbòrìѕ ƙìêɭ", - "básá ԁòlòré fatƃɑck ƅêéf. Pɑѕtr", - "ämì piɢ ѕհàлƙ ùɭɭamcò ѕaû", - "ѕäǥë sɦànƙlë.", - " Cúpím ɭäƃorum drumstïcƙ jerkϒ veli", - " pïcåԉɦɑ ƙíéɭƅãsa. Alïqû", - "iρ írürë cûpíϻ, äɭìɋuâ ǥròûлd ", - "roúлᏧ toԉgüè ρàrìãtùr ", - "briѕkèt ԉostruᏧ cûɭpɑ", - " ìd còлѕèqûât làƅ߀rìs." - ]; - - var counter = 0; - Async.seriesMap( - messages, - function(val, idx, done) { - counter++; - service.log(val, done); - }, - function(err, vals) { - test.ok(!err); - test.strictEqual(counter, messages.length); - - // Verify that the full byte-length was sent for each message - for (var m in messages) { - test.notStrictEqual(messages[m].length, vals[m].bytes); - try { - test.strictEqual(Buffer.byteLength(messages[m]), vals[m].bytes); - } - catch (err) { - // Assume Buffer isn't defined, we're probably in the browser - test.strictEqual(decodeURI(encodeURIComponent(messages[m])).length, vals[m].bytes); - } - } - - test.done(); - } - ); - }, - - "Callback#Service submit event, failure": function(test) { - var message = "Hello World -- " + getNextId(); - var sourcetype = "sdk-tests"; - - var service = this.loggedOutService; - var indexName = this.indexName; - Async.chain( - function(done) { - test.ok(service); - service.log(message, done); - }, - function(err) { - test.ok(err); - test.done(); - } - ); - }, - - "Callback#remove throws an error": function(test) { - var index = this.service.indexes().item("_internal"); - test.throws(function() { - index.remove(); - }); - test.done(); - }, - - "Callback#create an index with alternate argument format": function(test) { - var indexes = this.service.indexes(); - indexes.create( - {name: "_internal"}, - function(err, newIndex) { - test.ok(err.data.messages[0].text.match("name=_internal already exists")); - test.done(); - } - ); - }, - - "Callback#Index submit event with omitted optional arguments": function(test) { - var message = "Hello world -- " + getNextId(); - - var indexName = this.indexName; - var indexes = this.service.indexes(); - - Async.chain( - [ - function(done) { - indexes.fetch(done); - }, - function(indexes, done) { - var index = indexes.item(indexName); - test.ok(index); - test.strictEqual(index.name, indexName); - index.submitEvent(message, done); - }, - function(eventInfo, index, done) { - test.ok(eventInfo); - test.strictEqual(eventInfo.bytes, message.length); - test.strictEqual(eventInfo.index, indexName); - - // We could poll to make sure the index has eaten up the event, - // but unfortunately this can take an unbounded amount of time. - // As such, since we got a good response, we'll just be done with it. - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Index submit event": function(test) { - var message = "Hello World -- " + getNextId(); - var sourcetype = "sdk-tests"; - - var indexName = this.indexName; - var indexes = this.service.indexes(); - Async.chain([ - function(done) { - indexes.fetch(done); - }, - function(indexes, done) { - var index = indexes.item(indexName); - test.ok(index); - test.strictEqual(index.name, indexName); - index.submitEvent(message, {sourcetype: sourcetype}, done); - }, - function(eventInfo, index, done) { - test.ok(eventInfo); - test.strictEqual(eventInfo.sourcetype, sourcetype); - test.strictEqual(eventInfo.bytes, message.length); - test.strictEqual(eventInfo.index, indexName); - - // We could poll to make sure the index has eaten up the event, - // but unfortunately this can take an unbounded amount of time. - // As such, since we got a good response, we'll just be done with it. - done(); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - } - }, - - "User Tests": { - setUp: function(done) { - this.service = svc; - this.loggedOutService = loggedOutSvc; - done(); - }, - - tearDown: function(done) { - this.service.logout(done); - }, - - "Callback#Current user": function(test) { - var service = this.service; - - service.currentUser(function(err, user) { - test.ok(!err); - test.ok(user); - test.strictEqual(user.name, service.username); - test.done(); - }); - }, - - "Callback#Current user fails": function(test) { - var service = this.loggedOutService; - - service.currentUser(function(err, user) { - test.ok(err); - test.done(); - }); - }, - - "Callback#List users": function(test) { - var service = this.service; - - service.users().fetch(function(err, users) { - var userList = users.list(); - test.ok(!err); - test.ok(users); - - test.ok(userList); - test.ok(userList.length > 0); - test.done(); - }); - }, - - "Callback#create user failure": function(test) { - this.loggedOutService.users().create( - {name: "jssdk_testuser", password: "abc", roles: "user"}, - function(err, response) { - test.ok(err); - test.done(); - } - ); - }, - - "Callback#Create + update + delete user": function(test) { - var service = this.service; - var name = "jssdk_testuser"; - - Async.chain([ - function(done) { - service.users().create({name: "jssdk_testuser", password: "abc", roles: "user"}, done); - }, - function(user, done) { - test.ok(user); - test.strictEqual(user.name, name); - test.strictEqual(user.properties().roles.length, 1); - test.strictEqual(user.properties().roles[0], "user"); - - user.update({realname: "JS SDK", roles: ["admin", "user"]}, done); - }, - function(user, done) { - test.ok(user); - test.strictEqual(user.properties().realname, "JS SDK"); - test.strictEqual(user.properties().roles.length, 2); - test.strictEqual(user.properties().roles[0], "admin"); - test.strictEqual(user.properties().roles[1], "user"); - - user.remove(done); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#Roles": function(test) { - var service = this.service; - var name = "jssdk_testuser_" + getNextId(); - - Async.chain([ - function(done) { - service.users().create({name: name, password: "abc", roles: "user"}, done); - }, - function(user, done) { - test.ok(user); - test.strictEqual(user.name, name); - test.strictEqual(user.properties().roles.length, 1); - test.strictEqual(user.properties().roles[0], "user"); - - user.update({roles: ["admin", "user"]}, done); - }, - function(user, done) { - test.ok(user); - test.strictEqual(user.properties().roles.length, 2); - test.strictEqual(user.properties().roles[0], "admin"); - test.strictEqual(user.properties().roles[1], "user"); - - user.update({roles: "user"}, done); - }, - function(user, done) { - test.ok(user); - test.strictEqual(user.properties().roles.length, 1); - test.strictEqual(user.properties().roles[0], "user"); - - user.update({roles: "__unknown__"}, done); - } - ], - function(err) { - test.ok(err); - test.strictEqual(err.status, 400); - test.done(); - } - ); - }, - - "Callback#Passwords": function(test) { - var service = this.service; - var newService = null; - var name = "jssdk_testuser_" + getNextId(); - - Async.chain([ - function(done) { - service.users().create({name: name, password: "abc", roles: "user"}, done); - }, - function(user, done) { - test.ok(user); - test.strictEqual(user.name, name); - test.strictEqual(user.properties().roles.length, 1); - test.strictEqual(user.properties().roles[0], "user"); - - newService = new splunkjs.Service(service.http, { - username: name, - password: "abc", - host: service.host, - port: service.port, - scheme: service.scheme, - version: service.version - }); - - newService.login(Async.augment(done, user)); - }, - function(success, user, done) { - test.ok(success); - test.ok(user); - - user.update({password: "abc2"}, done); - }, - function(user, done) { - newService.login(function(err, success) { - test.ok(err); - test.ok(!success); - - user.update({password: "abc"}, done); - }); - }, - function(user, done) { - test.ok(user); - newService.login(done); - } - ], - function(err) { - test.ok(!err); - test.done(); - } - ); - }, - - "Callback#delete test users": function(test) { - var users = this.service.users(); - users.fetch(function(err, users) { - var userList = users.list(); - - Async.parallelEach( - userList, - function(user, idx, callback) { - if (utils.startsWith(user.name, "jssdk_")) { - user.remove(callback); - } - else { - callback(); - } - }, function(err) { - test.ok(!err); - test.done(); - } - ); - }); - } - }, - - "Server Info Tests": { - setUp: function(done) { - this.service = svc; - done(); - }, - - "Callback#Basic": function(test) { - var service = this.service; - - service.serverInfo(function(err, info) { - test.ok(!err); - test.ok(info); - test.strictEqual(info.name, "server-info"); - test.ok(info.properties().hasOwnProperty("version")); - test.ok(info.properties().hasOwnProperty("serverName")); - test.ok(info.properties().hasOwnProperty("os_version")); - - test.done(); - }); - } - }, + // "Namespace Tests": { + // setUp: function(finished) { + // this.service = svc; + // var that = this; + + // var appName1 = "jssdk_testapp_" + getNextId(); + // var appName2 = "jssdk_testapp_" + getNextId(); + + // var userName1 = "jssdk_testuser_" + getNextId(); + // var userName2 = "jssdk_testuser_" + getNextId(); + + // var apps = this.service.apps(); + // var users = this.service.users(); + + // this.namespace11 = {owner: userName1, app: appName1}; + // this.namespace12 = {owner: userName1, app: appName2}; + // this.namespace21 = {owner: userName2, app: appName1}; + // this.namespace22 = {owner: userName2, app: appName2}; + + // Async.chain([ + // function(done) { + // apps.create({name: appName1}, done); + // }, + // function(app1, done) { + // that.app1 = app1; + // that.appName1 = appName1; + // apps.create({name: appName2}, done); + // }, + // function(app2, done) { + // that.app2 = app2; + // that.appName2 = appName2; + // users.create({name: userName1, password: "abc", roles: ["user"]}, done); + // }, + // function(user1, done) { + // that.user1 = user1; + // that.userName1 = userName1; + // users.create({name: userName2, password: "abc", roles: ["user"]}, done); + // }, + // function(user2, done) { + // that.user2 = user2; + // that.userName2 = userName2; + + // done(); + // } + // ], + // function(err) { + // finished(); + // } + // ); + // }, + + // "Callback#Namespace protection": function(test) { + // var searchName = "jssdk_search_" + getNextId(); + // var search = "search *"; + // var service = this.service; + + // var savedSearches11 = service.savedSearches(this.namespace11); + // var savedSearches21 = service.savedSearches(this.namespace21); + + // var that = this; + // Async.chain([ + // function(done) { + // // Create the saved search only in the 11 namespace + // savedSearches11.create({name: searchName, search: search}, done); + // }, + // function(savedSearch, done) { + // // Refresh the 11 saved searches + // savedSearches11.fetch(done); + // }, + // function(savedSearches, done) { + // // Refresh the 21 saved searches + // savedSearches21.fetch(done); + // }, + // function(savedSearches, done) { + // var entity11 = savedSearches11.item(searchName); + // var entity21 = savedSearches21.item(searchName); + + // // Make sure the saved search exists in the 11 namespace + // test.ok(entity11); + // test.strictEqual(entity11.name, searchName); + // test.strictEqual(entity11.properties().search, search); + + // // Make sure the saved search doesn't exist in the 11 namespace + // test.ok(!entity21); + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Namespace item": function(test) { + // var searchName = "jssdk_search_" + getNextId(); + // var search = "search *"; + // var service = this.service; + + // var namespace_1 = {owner: "-", app: this.appName1}; + // var namespace_nobody1 = {owner: "nobody", app: this.appName1}; + + // var savedSearches11 = service.savedSearches(this.namespace11); + // var savedSearches21 = service.savedSearches(this.namespace21); + // var savedSearches_1 = service.savedSearches(namespace_1); + // var savedSearches_nobody1 = service.savedSearches(namespace_nobody1); + + // var that = this; + // Async.chain([ + // function(done) { + // // Create a saved search in the 11 namespace + // savedSearches11.create({name: searchName, search: search}, done); + // }, + // function(savedSearch, done) { + // // Create a saved search in the 21 namespace + // savedSearches21.create({name: searchName, search: search}, done); + // }, + // function(savedSearch, done) { + // // Refresh the -/1 namespace + // savedSearches_1.fetch(done); + // }, + // function(savedSearches, done) { + // // Refresh the 1/1 namespace + // savedSearches11.fetch(done); + // }, + // function(savedSearches, done) { + // // Refresh the 2/1 namespace + // savedSearches21.fetch(done); + // }, + // function(savedSearches, done) { + // var entity11 = savedSearches11.item(searchName, that.namespace11); + // var entity21 = savedSearches21.item(searchName, that.namespace21); + + // // Ensure that the saved search exists in the 11 namespace + // test.ok(entity11); + // test.strictEqual(entity11.name, searchName); + // test.strictEqual(entity11.properties().search, search); + // test.strictEqual(entity11.namespace.owner, that.namespace11.owner); + // test.strictEqual(entity11.namespace.app, that.namespace11.app); + + // // Ensure that the saved search exists in the 21 namespace + // test.ok(entity21); + // test.strictEqual(entity21.name, searchName); + // test.strictEqual(entity21.properties().search, search); + // test.strictEqual(entity21.namespace.owner, that.namespace21.owner); + // test.strictEqual(entity21.namespace.app, that.namespace21.app); + + // done(); + // }, + // function(done) { + // // Create a saved search in the nobody/1 namespace + // savedSearches_nobody1.create({name: searchName, search: search}, done); + // }, + // function(savedSearch, done) { + // // Refresh the 1/1 namespace + // savedSearches11.fetch(done); + // }, + // function(savedSearches, done) { + // // Refresh the 2/1 namespace + // savedSearches21.fetch(done); + // }, + // function(savedSearches, done) { + // // Ensure that we can't get the item from the generic + // // namespace without specifying a namespace + // try { + // savedSearches_1.item(searchName); + // test.ok(false); + // } + // catch(err) { + // test.ok(err); + // } + + // // Ensure that we can't get the item using wildcard namespaces. + // try{ + // savedSearches_1.item(searchName, {owner:'-'}); + // test.ok(false); + // } + // catch(err){ + // test.ok(err); + // } + + // try{ + // savedSearches_1.item(searchName, {app:'-'}); + // test.ok(false); + // } + // catch(err){ + // test.ok(err); + // } + + // try{ + // savedSearches_1.item(searchName, {app:'-', owner:'-'}); + // test.ok(false); + // } + // catch(err){ + // test.ok(err); + // } + + // // Ensure we get the right entities from the -/1 namespace when we + // // specify it. + // var entity11 = savedSearches_1.item(searchName, that.namespace11); + // var entity21 = savedSearches_1.item(searchName, that.namespace21); + + // test.ok(entity11); + // test.strictEqual(entity11.name, searchName); + // test.strictEqual(entity11.properties().search, search); + // test.strictEqual(entity11.namespace.owner, that.namespace11.owner); + // test.strictEqual(entity11.namespace.app, that.namespace11.app); + + // test.ok(entity21); + // test.strictEqual(entity21.name, searchName); + // test.strictEqual(entity21.properties().search, search); + // test.strictEqual(entity21.namespace.owner, that.namespace21.owner); + // test.strictEqual(entity21.namespace.app, that.namespace21.app); + + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#delete test applications": function(test) { + // var apps = this.service.apps(); + // apps.fetch(function(err, apps) { + // test.ok(!err); + // test.ok(apps); + // var appList = apps.list(); + + // Async.parallelEach( + // appList, + // function(app, idx, callback) { + // if (utils.startsWith(app.name, "jssdk_")) { + // app.remove(callback); + // } + // else { + // callback(); + // } + // }, function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }); + // }, + + // "Callback#delete test users": function(test) { + // var users = this.service.users(); + // users.fetch(function(err, users) { + // var userList = users.list(); + + // Async.parallelEach( + // userList, + // function(user, idx, callback) { + // if (utils.startsWith(user.name, "jssdk_")) { + // user.remove(callback); + // } + // else { + // callback(); + // } + // }, function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }); + // } + // }, + + // "Job Tests": { + // setUp: function(done) { + // this.service = svc; + // done(); + // }, + + // "Callback#Create+abort job": function(test) { + // var service = this.service; + // Async.chain([ + // function(done){ + // var app_name = path.join(process.env.SPLUNK_HOME, ('/etc/apps/sdk-app-collection/build/sleep_command.tar')); + // // Fix path on Windows if $SPLUNK_HOME contains a space (ex: C:/Program%20Files/Splunk) + // app_name = app_name.replace("%20", " "); + // service.post("apps/appinstall", {update:1, name:app_name}, done); + // }, + // function(done){ + // var sid = getNextId(); + // var options = {id: sid}; + // var jobs = service.jobs({app: "sdk-app-collection"}); + // var req = jobs.oneshotSearch('search index=_internal | head 1 | sleep 10', options, function(err, job) { + // test.ok(err); + // test.ok(!job); + // test.strictEqual(err.error, "abort"); + // test.done(); + // }); + + // Async.sleep(1000, function(){ + // req.abort(); + // }); + // } + // ], + // function(err){ + // test.ok(!err); + // test.done(); + // }); + // }, + + // "Callback#Create+cancel job": function(test) { + // var sid = getNextId(); + // this.service.jobs().search('search index=_internal | head 1', {id: sid}, function(err, job) { + // test.ok(job); + // test.strictEqual(job.sid, sid); + + // job.cancel(function() { + // test.done(); + // }); + // }); + // }, + + // "Callback#Create job error": function(test) { + // var sid = getNextId(); + // this.service.jobs().search({search: 'index=_internal | head 1', id: sid}, function(err) { + // test.ok(!!err); + // test.done(); + // }); + // }, + + // "Callback#List jobs": function(test) { + // this.service.jobs().fetch(function(err, jobs) { + // test.ok(!err); + // test.ok(jobs); + + // var jobsList = jobs.list(); + // test.ok(jobsList.length > 0); + + // for(var i = 0; i < jobsList.length; i++) { + // test.ok(jobsList[i]); + // } + + // test.done(); + // }); + // }, + + // "Callback#Contains job": function(test) { + // var that = this; + // var sid = getNextId(); + // var jobs = this.service.jobs(); + + // jobs.search('search index=_internal | head 1', {id: sid}, function(err, job) { + // test.ok(!err); + // test.ok(job); + // test.strictEqual(job.sid, sid); + + // jobs.fetch(function(err, jobs) { + // test.ok(!err); + // var job = jobs.item(sid); + // test.ok(job); + + // job.cancel(function() { + // test.done(); + // }); + // }); + // }); + // }, + + // "Callback#job results": function(test) { + // var sid = getNextId(); + // var service = this.service; + // var that = this; + + // Async.chain([ + // function(done) { + // that.service.jobs().search('search index=_internal | head 1 | stats count', {id: sid}, done); + // }, + // function(job, done) { + // test.strictEqual(job.sid, sid); + // tutils.pollUntil( + // job, + // function(j) { + // return job.properties()["isDone"]; + // }, + // 10, + // done + // ); + // }, + // function(job, done) { + // job.results({}, done); + // }, + // function(results, job, done) { + // test.strictEqual(results.rows.length, 1); + // test.strictEqual(results.fields.length, 1); + // test.strictEqual(results.fields[0], "count"); + // test.strictEqual(results.rows[0][0], "1"); + // job.cancel(done); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#job events": function(test) { + // var sid = getNextId(); + // var service = this.service; + // var that = this; + + // Async.chain([ + // function(done) { + // that.service.jobs().search('search index=_internal | head 1', {id: sid}, done); + // }, + // function(job, done) { + // test.strictEqual(job.sid, sid); + // tutils.pollUntil( + // job, + // function(j) { + // return job.properties()["isDone"]; + // }, + // 10, + // done + // ); + // }, + // function(job, done) { + // job.events({}, done); + // }, + // function(results, job, done) { + // test.strictEqual(results.rows.length, 1); + // test.strictEqual(results.fields.length, results.rows[0].length); + // job.cancel(done); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#job results preview": function(test) { + // var sid = getNextId(); + // var service = this.service; + // var that = this; + + // Async.chain([ + // function(done) { + // that.service.jobs().search('search index=_internal | head 1 | stats count', {id: sid}, done); + // }, + // function(job, done) { + // test.strictEqual(job.sid, sid); + // tutils.pollUntil( + // job, + // function(j) { + // return job.properties()["isDone"]; + // }, + // 10, + // done + // ); + // }, + // function(job, done) { + // job.preview({}, done); + // }, + // function(results, job, done) { + // test.strictEqual(results.rows.length, 1); + // test.strictEqual(results.fields.length, 1); + // test.strictEqual(results.fields[0], "count"); + // test.strictEqual(results.rows[0][0], "1"); + // job.cancel(done); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#job results iterator": function(test) { + // var that = this; + + // Async.chain([ + // function(done) { + // that.service.jobs().search('search index=_internal | head 10', {}, done); + // }, + // function(job, done) { + // tutils.pollUntil( + // job, + // function(j) { + // return job.properties()["isDone"]; + // }, + // 10, + // done + // ); + // }, + // function(job, done) { + // var iterator = job.iterator("results", { pagesize: 4 }); + // var hasMore = true; + // var numElements = 0; + // var pageSizes = []; + // Async.whilst( + // function() { return hasMore; }, + // function(nextIteration) { + // iterator.next(function(err, results, _hasMore) { + // if (err) { + // nextIteration(err); + // return; + // } + + // hasMore = _hasMore; + // if (hasMore) { + // pageSizes.push(results.rows.length); + // } + // nextIteration(); + // }); + // }, + // function(err) { + // test.deepEqual(pageSizes, [4,4,2]); + // done(err); + // } + // ); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Enable + disable preview": function(test) { + // var that = this; + // var sid = getNextId(); + + // var service = this.service.specialize("nobody", "sdk-app-collection"); + + // Async.chain([ + // function(done) { + // service.jobs().search('search index=_internal | head 1 | sleep 60', {id: sid}, done); + // }, + // function(job, done) { + // job.enablePreview(done); + + // }, + // function(job, done) { + // job.disablePreview(done); + // }, + // function(job, done) { + // job.cancel(done); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Pause + unpause + finalize preview": function(test) { + // var that = this; + // var sid = getNextId(); + + // var service = this.service.specialize("nobody", "sdk-app-collection"); + + // Async.chain([ + // function(done) { + // service.jobs().search('search index=_internal | head 1 | sleep 5', {id: sid}, done); + // }, + // function(job, done) { + // job.pause(done); + // }, + // function(job, done) { + // tutils.pollUntil( + // job, + // function(j) { + // return j.properties()["isPaused"]; + // }, + // 10, + // done + // ); + // }, + // function(job, done) { + // test.ok(job.properties()["isPaused"]); + // job.unpause(done); + // }, + // function(job, done) { + // tutils.pollUntil( + // job, + // function(j) { + // return !j.properties()["isPaused"]; + // }, + // 10, + // done + // ); + // }, + // function(job, done) { + // test.ok(!job.properties()["isPaused"]); + // job.finalize(done); + // }, + // function(job, done) { + // job.cancel(done); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Set TTL": function(test) { + // var sid = getNextId(); + // var originalTTL = 0; + // var that = this; + + // Async.chain([ + // function(done) { + // that.service.jobs().search('search index=_internal | head 1', {id: sid}, done); + // }, + // function(job, done) { + // job.fetch(done); + // }, + // function(job, done) { + // var ttl = job.properties()["ttl"]; + // originalTTL = ttl; + + // job.setTTL(ttl*2, done); + // }, + // function(job, done) { + // job.fetch(done); + // }, + // function(job, done) { + // var ttl = job.properties()["ttl"]; + // test.ok(ttl > originalTTL); + // test.ok(ttl <= (originalTTL*2)); + // job.cancel(done); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Set priority": function(test) { + // var sid = getNextId(); + // var originalPriority = 0; + // var that = this; + + // var service = this.service.specialize("nobody", "sdk-app-collection"); + + // Async.chain([ + // function(done) { + // service.jobs().search('search index=_internal | head 1 | sleep 5', {id: sid}, done); + // }, + // function(job, done) { + // job.track({}, { + // ready: function(job) { + // done(null, job); + // } + // }); + // }, + // function(job, done) { + // var priority = job.properties()["priority"]; + // test.ok(priority, 5); + // job.setPriority(priority + 1, done); + // }, + // function(job, done) { + // job.fetch(done); + // }, + // function(job, done) { + // job.cancel(done); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Search log": function(test) { + // var sid = getNextId(); + // var that = this; + + // Async.chain([ + // function(done) { + // that.service.jobs().search('search index=_internal | head 1', {id: sid, exec_mode: "blocking"}, done); + // }, + // function(job, done) { + // job.searchlog(done); + // }, + // function(log, job, done) { + // test.ok(job); + // test.ok(log); + // test.ok(log.length > 0); + // test.ok(log.split("\r\n").length > 0); + // job.cancel(done); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Search summary": function(test) { + // var sid = getNextId(); + // var that = this; + + // Async.chain([ + // function(done) { + // that.service.jobs().search( + // 'search index=_internal | head 1 | eval foo="bar" | fields foo', + // { + // id: sid, + // status_buckets: 300, + // rf: ["foo"] + // }, + // done); + // }, + // function(job, done) { + // // Let's sleep for 2 second so + // // we let the server catch up + // Async.sleep(2000, function() { + // job.summary({}, done); + // }); + // }, + // function(summary, job, done) { + // test.ok(job); + // test.ok(summary); + // test.strictEqual(summary.event_count, 1); + // test.strictEqual(summary.fields.foo.count, 1); + // test.strictEqual(summary.fields.foo.distinct_count, 1); + // test.ok(summary.fields.foo.is_exact, 1); + // test.strictEqual(summary.fields.foo.modes.length, 1); + // test.strictEqual(summary.fields.foo.modes[0].count, 1); + // test.strictEqual(summary.fields.foo.modes[0].value, "bar"); + // test.ok(summary.fields.foo.modes[0].is_exact); + // job.cancel(done); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Search timeline": function(test) { + // var sid = getNextId(); + // var that = this; + + // Async.chain([ + // function(done) { + // that.service.jobs().search( + // 'search index=_internal | head 1 | eval foo="bar" | fields foo', + // { + // id: sid, + // status_buckets: 300, + // rf: ["foo"], + // exec_mode: "blocking" + // }, + // done); + // }, + // function(job, done) { + // job.timeline({}, done); + // }, + // function(timeline, job, done) { + // test.ok(job); + // test.ok(timeline); + // test.strictEqual(timeline.buckets.length, 1); + // test.strictEqual(timeline.event_count, 1); + // test.strictEqual(timeline.buckets[0].available_count, 1); + // test.strictEqual(timeline.buckets[0].duration, 0.001); + // test.strictEqual(timeline.buckets[0].earliest_time_offset, timeline.buckets[0].latest_time_offset); + // test.strictEqual(timeline.buckets[0].total_count, 1); + // test.ok(timeline.buckets[0].is_finalized); + // job.cancel(done); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Touch": function(test) { + // var sid = getNextId(); + // var that = this; + // var originalTime = ""; + + // Async.chain([ + // function(done) { + // that.service.jobs().search('search index=_internal | head 1', {id: sid}, done); + // }, + // function(job, done) { + // job.fetch(done); + // }, + // function(job, done) { + // test.ok(job); + // originalTime = job.properties().updated; + // Async.sleep(1200, function() { job.touch(done); }); + // }, + // function(job, done) { + // job.fetch(done); + // }, + // function(job, done) { + // test.ok(originalTime !== job.updated()); + // job.cancel(done); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Create failure": function(test) { + // var name = "jssdk_savedsearch_" + getNextId(); + // var originalSearch = "search index=_internal | head 1"; + + // var jobs = this.service.jobs(); + // test.throws(function() {jobs.create({search: originalSearch, name: name, exec_mode: "oneshot"}, function() {});}); + // test.done(); + // }, + + // "Callback#Create fails with no search string": function(test) { + // var jobs = this.service.jobs(); + // jobs.create( + // "", {}, + // function(err) { + // test.ok(err); + // test.done(); + // } + // ); + // }, + + // "Callback#Oneshot search": function(test) { + // var sid = getNextId(); + // var that = this; + // var originalTime = ""; + + // Async.chain([ + // function(done) { + // that.service.jobs().oneshotSearch('search index=_internal | head 1 | stats count', {id: sid}, done); + // }, + // function(results, done) { + // test.ok(results); + // test.ok(results.fields); + // test.strictEqual(results.fields.length, 1); + // test.strictEqual(results.fields[0], "count"); + // test.ok(results.rows); + // test.strictEqual(results.rows.length, 1); + // test.strictEqual(results.rows[0].length, 1); + // test.strictEqual(results.rows[0][0], "1"); + + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Oneshot search with no results": function(test) { + // var sid = getNextId(); + // var that = this; + // var originalTime = ""; + + // Async.chain([ + // function(done) { + // var query = 'search index=history MUST_NOT_EXISTABCDEF'; + // that.service.jobs().oneshotSearch(query, {id: sid}, done); + // }, + // function(results, done) { + // test.ok(results); + // test.strictEqual(results.fields.length, 0); + // test.strictEqual(results.rows.length, 0); + // test.ok(!results.preview); + + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Service oneshot search": function(test) { + // var sid = getNextId(); + // var that = this; + // var namespace = {owner: "admin", app: "search"}; + // var splunkVersion = 6.1; // Default to pre-6.2 version + // var originalLoggerLevel = "DEBUG"; + + // Async.chain([ + // function(done) { + // // If running on Splunk 6.2+, first set the search logger level to DEBUG + // Async.chain([ + // function(done1) { + // that.service.serverInfo(done1); + // }, + // function(info, done1) { + // splunkVersion = parseFloat(info.properties().version); + // if (splunkVersion < 6.2) { + // done(); // Exit the inner Async.chain + // } + // else { + // done1(); + // } + // }, + // function(done1) { + // that.service.configurations({owner: "admin", app: "search"}).fetch(done1); + // }, + // function(confs, done1) { + // try { + // confs.item("limits").fetch(done1); + // } + // catch(e) { + // done1(e); + // } + // }, + // function(conf, done1) { + // var searchInfo = conf.item("search_info"); + // // Save this so it can be restored later + // originalLoggerLevel = searchInfo.properties()["infocsv_log_level"]; + // searchInfo.update({"infocsv_log_level": "DEBUG"}, done1); + // }, + // function(conf, done1) { + // test.strictEqual("DEBUG", conf.properties()["infocsv_log_level"]); + // done1(); + // } + // ], + // function(err) { + // test.ok(!err); + // done(); + // } + // ); + // }, + // function(done) { + // that.service.oneshotSearch('search index=_internal | head 1 | stats count', {id: sid}, namespace, done); + // }, + // function(results, done) { + // test.ok(results); + // test.ok(results.fields); + // test.strictEqual(results.fields.length, 1); + // test.strictEqual(results.fields[0], "count"); + // test.ok(results.rows); + // test.strictEqual(results.rows.length, 1); + // test.strictEqual(results.rows[0].length, 1); + // test.strictEqual(results.rows[0][0], "1"); + // test.ok(results.messages[1].text.indexOf('owner="admin"')); + // test.ok(results.messages[1].text.indexOf('app="search"')); + + // done(); + // }, + // function(done) { + // Async.chain([ + // function(done1) { + // if (splunkVersion < 6.2) { + // done(); // Exit the inner Async.chain + // } + // else { + // done1(); + // } + // }, + // function(done1) { + // that.service.configurations({owner: "admin", app: "search"}).fetch(done1); + // }, + // function(confs, done1) { + // try { + // confs.item("limits").fetch(done1); + // } + // catch(e) { + // done1(e); + // } + // }, + // function(conf, done1) { + // var searchInfo = conf.item("search_info"); + // // Restore the logger level from before + // searchInfo.update({"infocsv_log_level": originalLoggerLevel}, done1); + // }, + // function(conf, done1) { + // test.strictEqual(originalLoggerLevel, conf.properties()["infocsv_log_level"]); + // done1(); + // } + // ], + // function(err) { + // test.ok(!err); + // done(); + // } + // ); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Service search": function(test) { + // var sid = getNextId(); + // var service = this.service; + // var that = this; + // var namespace = {owner: "admin", app: "search"}; + + // Async.chain([ + // function(done) { + // that.service.search('search index=_internal | head 1 | stats count', {id: sid}, namespace, done); + // }, + // function(job, done) { + // test.strictEqual(job.sid, sid); + // test.strictEqual(job.namespace, namespace); + // tutils.pollUntil( + // job, + // function(j) { + // return job.properties()["isDone"]; + // }, + // 10, + // done + // ); + // }, + // function(job, done) { + // job.results({}, done); + // }, + // function(results, job, done) { + // test.strictEqual(results.rows.length, 1); + // test.strictEqual(results.fields.length, 1); + // test.strictEqual(results.fields[0], "count"); + // test.strictEqual(results.rows[0][0], "1"); + // job.cancel(done); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Wait until job done": function(test) { + // this.service.search('search index=_internal | head 1000', {}, function(err, job) { + // test.ok(!err); + + // var numReadyEvents = 0; + // var numProgressEvents = 0; + // job.track({ period: 200 }, { + // ready: function(job) { + // test.ok(job); + + // numReadyEvents++; + // }, + // progress: function(job) { + // test.ok(job); + + // numProgressEvents++; + // }, + // done: function(job) { + // test.ok(job); + + // test.ok(numReadyEvents === 1); // all done jobs must have become ready + // test.ok(numProgressEvents >= 1); // a job that becomes ready has progress + // test.done(); + // }, + // failed: function(job) { + // test.ok(job); + + // test.ok(false, "Job failed unexpectedly."); + // test.done(); + // }, + // error: function(err) { + // test.ok(err); + + // test.ok(false, "Error while tracking job."); + // test.done(); + // } + // }); + // }); + // }, + + // "Callback#Wait until job failed": function(test) { + // this.service.search('search index=_internal | head bogusarg', {}, function(err, job) { + // if (err) { + // test.ok(!err); + // test.done(); + // return; + // } + + // var numReadyEvents = 0; + // var numProgressEvents = 0; + // job.track({ period: 200 }, { + // ready: function(job) { + // test.ok(job); + + // numReadyEvents++; + // }, + // progress: function(job) { + // test.ok(job); + + // numProgressEvents++; + // }, + // done: function(job) { + // test.ok(job); + + // test.ok(false, "Job became done unexpectedly."); + // test.done(); + // }, + // failed: function(job) { + // test.ok(job); + + // test.ok(numReadyEvents === 1); // even failed jobs become ready + // test.ok(numProgressEvents >= 1); // a job that becomes ready has progress + // test.done(); + // }, + // error: function(err) { + // test.ok(err); + + // test.ok(false, "Error while tracking job."); + // test.done(); + // } + // }); + // }); + // }, + + // "Callback#track() with default params and one function": function(test) { + // this.service.search('search index=_internal | head 1', {}, function(err, job) { + // if (err) { + // test.ok(!err); + // test.done(); + // return; + // } + + // job.track({}, function(job) { + // test.ok(job); + // test.done(); + // }); + // }); + // }, + + // "Callback#track() should stop polling if only the ready callback is specified": function(test) { + // this.service.search('search index=_internal | head 1', {}, function(err, job) { + // if (err) { + // test.ok(!err); + // test.done(); + // return; + // } + + // job.track({}, { + // ready: function(job) { + // test.ok(job); + // }, + + // _stoppedAfterReady: function(job) { + // test.done(); + // } + // }); + // }); + // }, + + // "Callback#track() a job that is not immediately ready": function(test) { + // /*jshint loopfunc:true */ + // var numJobs = 20; + // var numJobsLeft = numJobs; + // var gotJobNotImmediatelyReady = false; + // for (var i = 0; i < numJobs; i++) { + // this.service.search('search index=_internal | head 10000', {}, function(err, job) { + // if (err) { + // test.ok(!err); + // test.done(); + // return; + // } + + // job.track({}, { + // _preready: function(job) { + // gotJobNotImmediatelyReady = true; + // }, + + // ready: function(job) { + // numJobsLeft--; + + // if (numJobsLeft === 0) { + // if (!gotJobNotImmediatelyReady) { + // splunkjs.Logger.error("", "WARNING: Couldn't test code path in track() where job wasn't ready immediately."); + // } + // test.done(); + // } + // } + // }); + // }); + // } + // }, + + // "Callback#Service.getJob() works": function(test) { + // var that = this; + // var sidsMatch = false; + // this.service.search('search index=_internal | head 1', {}, function(err, job){ + // if (err) { + // test.ok(!err); + // test.done(); + // return; + // } + // var sid = job.sid; + // return Async.chain([ + // function(done) { + // that.service.getJob(sid, done); + // }, + // function(innerJob, done) { + // test.strictEqual(sid, innerJob.sid); + // sidsMatch = sid === innerJob.sid; + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.ok(sidsMatch); + // test.done(); + // } + // ); + // }); + // } + // }, + + // "Data Model tests": { + // setUp: function(done) { + // this.service = svc; + // this.dataModels = svc.dataModels(); + // this.skip = false; + // var that = this; + // this.service.serverInfo(function(err, info) { + // if (parseInt(info.properties().version.split(".")[0], 10) < 6) { + // that.skip = true; + // splunkjs.Logger.log("Skipping data model tests..."); + // } + // done(err); + // }); + // }, + + // "Callback#DataModels - fetch a built-in data model": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.fetch(done); + // }, + // function(dataModels, done) { + // var dm = dataModels.item("internal_audit_logs"); + // // Check for the 3 objects we expect + // test.ok(dm.objectByName("Audit")); + // test.ok(dm.objectByName("searches")); + // test.ok(dm.objectByName("modify")); + + // // Check for an object that shouldn't exist + // test.strictEqual(null, dm.objectByName(getNextId())); + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#DataModels - create & delete an empty data model": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/empty_data_model.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var name = "delete-me-" + getNextId(); + + // var initialSize; + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.fetch(done); + // }, + // function(dataModels, done) { + // initialSize = dataModels.list().length; + // dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // that.dataModels.fetch(done); + // }, + // function(dataModels, done) { + // // Make sure we have 1 more data model than we started with + // test.strictEqual(initialSize + 1, dataModels.list().length); + // // Delete the data model we just created, by name. + // dataModels.item(name).remove(done); + // }, + // function(done) { + // that.dataModels.fetch(done); + // }, + // function(dataModels, done) { + // // Make sure we have as many data models as we started with + // test.strictEqual(initialSize, dataModels.list().length); + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#DataModels - create a data model with spaces in the name, which are swapped for -'s": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/empty_data_model.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var name = "delete-me- " + getNextId(); + + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // test.strictEqual(name.replace(" ", "_"), dataModel.name); + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#DataModels - create a data model with 0 objects": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/empty_data_model.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var name = "delete-me-" + getNextId(); + + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // // Check for 0 objects before fetch + // test.strictEqual(0, dataModel.objects.length); + // that.dataModels.fetch(done); + // }, + // function(dataModels, done) { + // // Check for 0 objects after fetch + // test.strictEqual(0, dataModels.item(name).objects.length); + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#DataModels - create a data model with 1 search object": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var dataModels = this.service.dataModels(); + + + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/object_with_one_search.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var name = "delete-me-" + getNextId(); + + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // // Check for 1 object before fetch + // test.strictEqual(1, dataModel.objects.length); + // that.dataModels.fetch(done); + // }, + // function(dataModels, done) { + // // Check for 1 object after fetch + // test.strictEqual(1, dataModels.item(name).objects.length); + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#DataModels - create a data model with 2 search objects": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/object_with_two_searches.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var name = "delete-me-" + getNextId(); + + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // // Check for 2 objects before fetch + // test.strictEqual(2, dataModel.objects.length); + // that.dataModels.fetch(done); + // }, + // function(dataModels, done) { + // // Check for 2 objects after fetch + // test.strictEqual(2, dataModels.item(name).objects.length); + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#DataModels - data model objects are created correctly": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/object_with_two_searches.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var name = "delete-me-" + getNextId(); + + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // test.ok(dataModel.hasObject("search1")); + // test.ok(dataModel.hasObject("search2")); + + // var search1 = dataModel.objectByName("search1"); + // test.ok(search1); + // test.strictEqual("‡Øµ‡Ø±‡Ø∞‡ØØ - search 1", search1.displayName); + + // var search2 = dataModel.objectByName("search2"); + // test.ok(search2); + // test.strictEqual("‡Øµ‡Ø±‡Ø∞‡ØØ - search 2", search2.displayName); + + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#DataModels - data model handles unicode characters": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/model_with_unicode_headers.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var name = "delete-me-" + getNextId(); + + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // test.strictEqual(name, dataModel.name); + // test.strictEqual("·Ä©·öô‡Øµ", dataModel.displayName); + // test.strictEqual("‡Øµ‡Ø±‡Ø∞‡ØØ", dataModel.description); + + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#DataModels - create data model with empty headers": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/model_with_empty_headers.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var name = "delete-me-" + getNextId(); + + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // test.strictEqual(name, dataModel.name); + // test.strictEqual("", dataModel.displayName); + // test.strictEqual("", dataModel.description); + + // // Make sure we're not getting a summary of the data model + // test.strictEqual("0", dataModel.concise); + + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#DataModels - test acceleration settings": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/data_model_with_test_objects.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var name = "delete-me-" + getNextId(); + + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // dataModel.acceleration.enabled = true; + // dataModel.acceleration.earliestTime = "-2mon"; + // dataModel.acceleration.cronSchedule = "5/* * * * *"; + + // test.strictEqual(true, dataModel.isAccelerated()); + // test.strictEqual(true, dataModel.acceleration.enabled); + // test.strictEqual("-2mon", dataModel.acceleration.earliestTime); + // test.strictEqual("5/* * * * *", dataModel.acceleration.cronSchedule); + + // dataModel.acceleration.enabled = false; + // dataModel.acceleration.earliestTime = "-1mon"; + // dataModel.acceleration.cronSchedule = "* * * * *"; + + // test.strictEqual(false, dataModel.isAccelerated()); + // test.strictEqual(false, dataModel.acceleration.enabled); + // test.strictEqual("-1mon", dataModel.acceleration.earliestTime); + // test.strictEqual("* * * * *", dataModel.acceleration.cronSchedule); + + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#DataModels - test data model object metadata": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/data_model_with_test_objects.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var name = "delete-me-" + getNextId(); + + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // var obj = dataModel.objectByName("event1"); + // test.ok(obj); + + // test.strictEqual("event1 ·Ä©·öô", obj.displayName); + // test.strictEqual("event1", obj.name); + // test.same(dataModel, obj.dataModel); + + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#DataModels - test data model object parent": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/data_model_with_test_objects.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var name = "delete-me-" + getNextId(); + + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // var obj = dataModel.objectByName("event1"); + // test.ok(obj); + // test.ok(!obj.parent()); + + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#DataModels - test data model object lineage": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/inheritance_test_data.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var name = "delete-me-" + getNextId(); + + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // var obj = dataModel.objectByName("level_0"); + // test.ok(obj); + // test.strictEqual(1, obj.lineage.length); + // test.strictEqual("level_0", obj.lineage[0]); + // test.strictEqual("BaseEvent", obj.parentName); + + // obj = dataModel.objectByName("level_1"); + // test.ok(obj); + // test.strictEqual(2, obj.lineage.length); + // test.same(["level_0", "level_1"], obj.lineage); + // test.strictEqual("level_0", obj.parentName); + + // obj = dataModel.objectByName("level_2"); + // test.ok(obj); + // test.strictEqual(3, obj.lineage.length); + // test.same(["level_0", "level_1", "level_2"], obj.lineage); + // test.strictEqual("level_1", obj.parentName); + + // // Make sure there's no extra children + // test.ok(!dataModel.objectByName("level_3")); + + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#DataModels - test data model object fields": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/inheritance_test_data.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var name = "delete-me-" + getNextId(); + + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // var obj = dataModel.objectByName("level_2"); + // test.ok(obj); + + // var timeField = obj.fieldByName("_time"); + // test.ok(timeField); + // test.strictEqual("timestamp", timeField.type); + // test.ok(timeField.isTimestamp()); + // test.ok(!timeField.isNumber()); + // test.ok(!timeField.isString()); + // test.ok(!timeField.isObjectcount()); + // test.ok(!timeField.isChildcount()); + // test.ok(!timeField.isIPv4()); + // test.same(["BaseEvent"], timeField.lineage); + // test.strictEqual("_time", timeField.name); + // test.strictEqual(false, timeField.required); + // test.strictEqual(false, timeField.multivalued); + // test.strictEqual(false, timeField.hidden); + // test.strictEqual(false, timeField.editable); + // test.strictEqual(null, timeField.comment); + + // var lvl2 = obj.fieldByName("level_2"); + // test.strictEqual("level_2", lvl2.owner); + // test.same(["level_0", "level_1", "level_2"], lvl2.lineage); + // test.strictEqual("objectCount", lvl2.type); + // test.ok(!lvl2.isTimestamp()); + // test.ok(!lvl2.isNumber()); + // test.ok(!lvl2.isString()); + // test.ok(lvl2.isObjectcount()); + // test.ok(!lvl2.isChildcount()); + // test.ok(!lvl2.isIPv4()); + // test.strictEqual("level_2", lvl2.name); + // test.strictEqual("level 2", lvl2.displayName); + // test.strictEqual(false, lvl2.required); + // test.strictEqual(false, lvl2.multivalued); + // test.strictEqual(false, lvl2.hidden); + // test.strictEqual(false, lvl2.editable); + // test.strictEqual(null, lvl2.comment); + + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#DataModels - test data model object properties": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var name = "delete-me-" + getNextId(); + + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // var obj = dataModel.objectByName("test_data"); + // test.ok(obj); + // test.strictEqual(5, obj.fieldNames().length); + // test.strictEqual(10, obj.allFieldNames().length); + // test.ok(obj.fieldByName("has_boris")); + // test.ok(obj.hasField("has_boris")); + // test.ok(obj.fieldByName("_time")); + // test.ok(obj.hasField("_time")); + + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#DataModels - create local acceleration job": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/inheritance_test_data.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var name = "delete-me-" + getNextId(); + + // var obj; + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // obj = dataModel.objectByName("level_2"); + // test.ok(obj); + + // obj.createLocalAccelerationJob(null, done); + // }, + // function(job, done) { + // test.ok(job); + + // tutils.pollUntil( + // job, + // function(j) { + // return job.properties()["isDone"]; + // }, + // 10, + // done + // ); + // }, + // function(job, done) { + // test.strictEqual("| datamodel \"" + name + "\" level_2 search | tscollect", job.properties().request.search); + // job.cancel(done); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#DataModels - create local acceleration job with earliest time": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/inheritance_test_data.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var name = "delete-me-" + getNextId(); + + // var obj; + // var oldNow = Date.now(); + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // obj = dataModel.objectByName("level_2"); + // test.ok(obj); + // obj.createLocalAccelerationJob("-1d", done); + // }, + // function(job, done) { + // test.ok(job); + // tutils.pollUntil( + // job, + // function(j) { + // return job.properties()["isDone"]; + // }, + // 10, + // done + // ); + // }, + // function(job, done) { + // test.strictEqual("| datamodel \"" + name + "\" level_2 search | tscollect", job.properties().request.search); + + // // Make sure the earliest time is 1 day behind + // var yesterday = new Date(Date.now() - (1000 * 60 * 60 * 24)); + // var month = (yesterday.getMonth() + 1); + // if (month <= 9) { + // month = "0" + month; + // } + // var date = yesterday.getDate(); + // if (date <= 9) { + // date = "0" + date; + // } + // var expectedDate = yesterday.getFullYear() + "-" + month + "-" + date; + // test.ok(utils.startsWith(job._state.content.earliestTime, expectedDate)); + + // job.cancel(done); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#DataModels - test data model constraints": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/data_model_with_test_objects.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var name = "delete-me-" + getNextId(); + + // var obj; + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // obj = dataModel.objectByName("event1"); + // test.ok(obj); + // var constraints = obj.constraints; + // test.ok(constraints); + // var onlyOne = true; + + // for (var i = 0; i < constraints.length; i++) { + // var constraint = constraints[i]; + // test.ok(!!onlyOne); + + // test.strictEqual("event1", constraint.owner); + // test.strictEqual("uri=\"*.php\" OR uri=\"*.py\"\nNOT (referer=null OR referer=\"-\")", constraint.query); + // } + + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#DataModels - test data model calculations, and the different types": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/data_model_with_test_objects.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var name = "delete-me-" + getNextId(); + + // var obj; + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // obj = dataModel.objectByName("event1"); + // test.ok(obj); + + // var calculations = obj.calculations; + // test.strictEqual(4, Object.keys(calculations).length); + // test.strictEqual(4, obj.calculationIDs().length); + + // var evalCalculation = calculations["93fzsv03wa7"]; + // test.ok(evalCalculation); + // test.strictEqual("event1", evalCalculation.owner); + // test.same(["event1"], evalCalculation.lineage); + // test.strictEqual("Eval", evalCalculation.type); + // test.ok(evalCalculation.isEval()); + // test.ok(!evalCalculation.isLookup()); + // test.ok(!evalCalculation.isGeoIP()); + // test.ok(!evalCalculation.isRex()); + // test.strictEqual(null, evalCalculation.comment); + // test.strictEqual(true, evalCalculation.isEditable()); + // test.strictEqual("if(cidrmatch(\"192.0.0.0/16\", clientip), \"local\", \"other\")", evalCalculation.expression); + + // test.strictEqual(1, Object.keys(evalCalculation.outputFields).length); + // test.strictEqual(1, evalCalculation.outputFieldNames().length); + + // var field = evalCalculation.outputFields["new_field"]; + // test.ok(field); + // test.strictEqual("My New Field", field.displayName); + + // var lookupCalculation = calculations["sr3mc8o3mjr"]; + // test.ok(lookupCalculation); + // test.strictEqual("event1", lookupCalculation.owner); + // test.same(["event1"], lookupCalculation.lineage); + // test.strictEqual("Lookup", lookupCalculation.type); + // test.ok(lookupCalculation.isLookup()); + // test.ok(!lookupCalculation.isEval()); + // test.ok(!lookupCalculation.isGeoIP()); + // test.ok(!lookupCalculation.isRex()); + // test.strictEqual(null, lookupCalculation.comment); + // test.strictEqual(true, lookupCalculation.isEditable()); + // test.same({lookupField: "a_lookup_field", inputField: "host"}, lookupCalculation.inputFieldMappings); + // test.strictEqual(2, Object.keys(lookupCalculation.inputFieldMappings).length); + // test.strictEqual("a_lookup_field", lookupCalculation.inputFieldMappings.lookupField); + // test.strictEqual("host", lookupCalculation.inputFieldMappings.inputField); + // test.strictEqual("dnslookup", lookupCalculation.lookupName); + + // var regexpCalculation = calculations["a5v1k82ymic"]; + // test.ok(regexpCalculation); + // test.strictEqual("event1", regexpCalculation.owner); + // test.same(["event1"], regexpCalculation.lineage); + // test.strictEqual("Rex", regexpCalculation.type); + // test.ok(regexpCalculation.isRex()); + // test.ok(!regexpCalculation.isLookup()); + // test.ok(!regexpCalculation.isEval()); + // test.ok(!regexpCalculation.isGeoIP()); + // test.strictEqual(2, regexpCalculation.outputFieldNames().length); + // test.strictEqual("_raw", regexpCalculation.inputField); + // test.strictEqual(" From: (?.*) To: (?.*) ", regexpCalculation.expression); + + // var geoIPCalculation = calculations["pbe9bd0rp4"]; + // test.ok(geoIPCalculation); + // test.strictEqual("event1", geoIPCalculation.owner); + // test.same(["event1"], geoIPCalculation.lineage); + // test.strictEqual("GeoIP", geoIPCalculation.type); + // test.ok(geoIPCalculation.isGeoIP()); + // test.ok(!geoIPCalculation.isLookup()); + // test.ok(!geoIPCalculation.isEval()); + // test.ok(!geoIPCalculation.isRex()); + // test.strictEqual("·Ä©·öô‡Øµ comment of pbe9bd0rp4", geoIPCalculation.comment); + // test.strictEqual(5, geoIPCalculation.outputFieldNames().length); + // test.strictEqual("output_from_reverse_hostname", geoIPCalculation.inputField); + + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#DataModels - run queries": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var obj; + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.fetch(done); + // }, + // function(dataModels, done) { + // var dm = dataModels.item("internal_audit_logs"); + // obj = dm.objectByName("searches"); + // obj.startSearch({}, "", done); + // }, + // function(job, done) { + // tutils.pollUntil( + // job, + // function(j) { + // return job.properties()["isDone"]; + // }, + // 10, + // done + // ); + // }, + // function(job, done) { + // test.strictEqual("| datamodel internal_audit_logs searches search", job.properties().request.search); + // job.cancel(done); + // }, + // function(response, done) { + // obj.startSearch({status_buckets: 5, enable_lookups: false}, "| head 3", done); + // }, + // function(job, done) { + // tutils.pollUntil( + // job, + // function(j) { + // return job.properties()["isDone"]; + // }, + // 10, + // done + // ); + // }, + // function(job, done) { + // test.strictEqual("| datamodel internal_audit_logs searches search | head 3", job.properties().request.search); + // job.cancel(done); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#DataModels - baseSearch is parsed correctly": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/model_with_multiple_types.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var name = "delete-me-" + getNextId(); + + // var obj; + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // obj = dataModel.objectByName("search1"); + // test.ok(obj); + // test.ok(obj instanceof splunkjs.Service.DataModelObject); + // test.strictEqual("BaseSearch", obj.parentName); + // test.ok(obj.isBaseSearch()); + // test.ok(!obj.isBaseTransaction()); + // test.strictEqual("search index=_internal | head 10", obj.baseSearch); + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#DataModels - baseTransaction is parsed correctly": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/model_with_multiple_types.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var name = "delete-me-" + getNextId(); + + // var obj; + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // obj = dataModel.objectByName("transaction1"); + // test.ok(obj); + // test.ok(obj instanceof splunkjs.Service.DataModelObject); + // test.strictEqual("BaseTransaction", obj.parentName); + // test.ok(obj.isBaseTransaction()); + // test.ok(!obj.isBaseSearch()); + // test.same(["event1"], obj.objectsToGroup); + // test.same(["host", "from"], obj.groupByFields); + // test.strictEqual("25s", obj.maxPause); + // test.strictEqual("100m", obj.maxSpan); + + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // } + // }, + + // "Pivot tests": { + // setUp: function(done) { + // this.service = svc; + // this.dataModels = svc.dataModels({owner: "nobody", app: "search"}); + // this.skip = false; + // var that = this; + // this.service.serverInfo(function(err, info) { + // if (parseInt(info.properties().version.split(".")[0], 10) < 6) { + // that.skip = true; + // splunkjs.Logger.log("Skipping pivot tests..."); + // } + // done(err); + // }); + // }, + + // "Callback#Pivot - test constructor args": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var name = "delete-me-" + getNextId(); + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // test.ok(dataModel.objectByName("test_data")); + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Pivot - test acceleration, then pivot": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var name = "delete-me-" + getNextId(); + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // dataModel.objectByName("test_data"); + // test.ok(dataModel); + + // dataModel.acceleration.enabled = true; + // dataModel.acceleration.earliestTime = "-2mon"; + // dataModel.acceleration.cronSchedule = "0 */12 * * *"; + // dataModel.update(done); + // }, + // function(dataModel, done) { + // var props = dataModel.properties(); + + // test.strictEqual(true, dataModel.isAccelerated()); + // test.strictEqual(true, !!dataModel.acceleration.enabled); + // test.strictEqual("-2mon", dataModel.acceleration.earliest_time); + // test.strictEqual("0 */12 * * *", dataModel.acceleration.cron_schedule); + + // var dataModelObject = dataModel.objectByName("test_data"); + // var pivotSpecification = dataModelObject.createPivotSpecification(); + + // test.strictEqual(dataModelObject.dataModel.name, pivotSpecification.accelerationNamespace); + + // var name1 = "delete-me-" + getNextId(); + // pivotSpecification.setAccelerationJob(name1); + // test.strictEqual("sid=" + name1, pivotSpecification.accelerationNamespace); + + // var namespaceTemp = "delete-me-" + getNextId(); + // pivotSpecification.accelerationNamespace = namespaceTemp; + // test.strictEqual(namespaceTemp, pivotSpecification.accelerationNamespace); + + // pivotSpecification + // .addCellValue("test_data", "Source Value", "count") + // .run(done); + // }, + // function(job, pivot, done) { + // test.ok(job); + // test.ok(pivot); + // test.notStrictEqual("FAILED", job.properties().dispatchState); + + // job.track({}, function(job) { + // test.ok(pivot.tstatsSearch); + // test.strictEqual(0, job.properties().request.search.indexOf("| tstats")); + // test.strictEqual("| tstats", job.properties().request.search.match("^\\| tstats")[0]); + // test.strictEqual(1, job.properties().request.search.match("^\\| tstats").length); + + // test.strictEqual(pivot.tstatsSearch, job.properties().request.search); + // done(null, job); + // }); + // }, + // function(job, done) { + // test.ok(job); + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Pivot - test illegal filtering (all types)": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var name = "delete-me-" + getNextId(); + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // var obj = dataModel.objectByName("test_data"); + // test.ok(obj); + + // var pivotSpecification = obj.createPivotSpecification(); + + // // Boolean comparisons + // try { + // pivotSpecification.addFilter(getNextId(), "boolean", "=", true); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Cannot add filter on a nonexistent field."); + // } + // try { + // pivotSpecification.addFilter("_time", "boolean", "=", true); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Cannot add boolean filter on _time because it is of type timestamp"); + // } + + // // String comparisons + // try { + // pivotSpecification.addFilter("has_boris", "string", "contains", "abc"); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Cannot add string filter on has_boris because it is of type boolean"); + // } + // try { + // pivotSpecification.addFilter(getNextId(), "string", "contains", "abc"); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Cannot add filter on a nonexistent field."); + // } + + // // IPv4 comparisons + // try { + // pivotSpecification.addFilter("has_boris", "ipv4", "startsWith", "192.168"); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Cannot add ipv4 filter on has_boris because it is of type boolean"); + // } + // try { + // pivotSpecification.addFilter(getNextId(), "ipv4", "startsWith", "192.168"); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Cannot add filter on a nonexistent field."); + // } + + // // Number comparisons + // try { + // pivotSpecification.addFilter("has_boris", "number", "atLeast", 2.3); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Cannot add number filter on has_boris because it is of type boolean"); + // } + // try { + // pivotSpecification.addFilter(getNextId(), "number", "atLeast", 2.3); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Cannot add filter on a nonexistent field."); + // } + + // // Limit filter + // try { + // pivotSpecification.addLimitFilter("has_boris", "host", "DEFAULT", 50, "count"); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Cannot add limit filter on has_boris because it is of type boolean"); + // } + // try { + // pivotSpecification.addLimitFilter(getNextId(), "host", "DEFAULT", 50, "count"); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Cannot add limit filter on a nonexistent field."); + // } + // try { + // pivotSpecification.addLimitFilter("source", "host", "DEFAULT", 50, "sum"); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, + // "Stats function for fields of type string must be COUNT or DISTINCT_COUNT; found sum"); + // } + // try { + // pivotSpecification.addLimitFilter("epsilon", "host", "DEFAULT", 50, "duration"); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, + // "Stats function for fields of type number must be one of COUNT, DISTINCT_COUNT, SUM, or AVERAGE; found duration"); + // } + // try { + // pivotSpecification.addLimitFilter("test_data", "host", "DEFAULT", 50, "list"); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, + // "Stats function for fields of type object count must be COUNT; found list"); + // } + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Pivot - test boolean filtering": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var name = "delete-me-" + getNextId(); + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // var obj = dataModel.objectByName("test_data"); + // test.ok(obj); + + // var pivotSpecification = obj.createPivotSpecification(); + // try { + // pivotSpecification.addFilter("has_boris", "boolean", "=", true); + // test.strictEqual(1, pivotSpecification.filters.length); + + // //Test the individual parts of the filter + // var filter = pivotSpecification.filters[0]; + + // test.ok(filter.hasOwnProperty("fieldName")); + // test.ok(filter.hasOwnProperty("type")); + // test.ok(filter.hasOwnProperty("rule")); + // test.ok(filter.hasOwnProperty("owner")); + + // test.strictEqual("has_boris", filter.fieldName); + // test.strictEqual("boolean", filter.type); + // test.strictEqual("=", filter.rule.comparator); + // test.strictEqual(true, filter.rule.compareTo); + // test.strictEqual("test_data", filter.owner); + // } + // catch (e) { + // test.ok(false); + // } + + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Pivot - test string filtering": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var name = "delete-me-" + getNextId(); + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // var obj = dataModel.objectByName("test_data"); + // test.ok(obj); + + // var pivotSpecification = obj.createPivotSpecification(); + // try { + // pivotSpecification.addFilter("host", "string", "contains", "abc"); + // test.strictEqual(1, pivotSpecification.filters.length); + + // //Test the individual parts of the filter + // var filter = pivotSpecification.filters[0]; + + // test.ok(filter.hasOwnProperty("fieldName")); + // test.ok(filter.hasOwnProperty("type")); + // test.ok(filter.hasOwnProperty("rule")); + // test.ok(filter.hasOwnProperty("owner")); + + // test.strictEqual("host", filter.fieldName); + // test.strictEqual("string", filter.type); + // test.strictEqual("contains", filter.rule.comparator); + // test.strictEqual("abc", filter.rule.compareTo); + // test.strictEqual("BaseEvent", filter.owner); + // } + // catch (e) { + // test.ok(false); + // } + + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Pivot - test IPv4 filtering": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var name = "delete-me-" + getNextId(); + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // var obj = dataModel.objectByName("test_data"); + // test.ok(obj); + + // var pivotSpecification = obj.createPivotSpecification(); + // try { + // pivotSpecification.addFilter("hostip", "ipv4", "startsWith", "192.168"); + // test.strictEqual(1, pivotSpecification.filters.length); + + // //Test the individual parts of the filter + // var filter = pivotSpecification.filters[0]; + + // test.ok(filter.hasOwnProperty("fieldName")); + // test.ok(filter.hasOwnProperty("type")); + // test.ok(filter.hasOwnProperty("rule")); + // test.ok(filter.hasOwnProperty("owner")); + + // test.strictEqual("hostip", filter.fieldName); + // test.strictEqual("ipv4", filter.type); + // test.strictEqual("startsWith", filter.rule.comparator); + // test.strictEqual("192.168", filter.rule.compareTo); + // test.strictEqual("test_data", filter.owner); + // } + // catch (e) { + // test.ok(false); + // } + + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Pivot - test number filtering": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var name = "delete-me-" + getNextId(); + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // var obj = dataModel.objectByName("test_data"); + // test.ok(obj); + + // var pivotSpecification = obj.createPivotSpecification(); + // try { + // pivotSpecification.addFilter("epsilon", "number", ">=", 2.3); + // test.strictEqual(1, pivotSpecification.filters.length); + + // //Test the individual parts of the filter + // var filter = pivotSpecification.filters[0]; + + // test.ok(filter.hasOwnProperty("fieldName")); + // test.ok(filter.hasOwnProperty("type")); + // test.ok(filter.hasOwnProperty("rule")); + // test.ok(filter.hasOwnProperty("owner")); + + // test.strictEqual("epsilon", filter.fieldName); + // test.strictEqual("number", filter.type); + // test.strictEqual(">=", filter.rule.comparator); + // test.strictEqual(2.3, filter.rule.compareTo); + // test.strictEqual("test_data", filter.owner); + // } + // catch (e) { + // test.ok(false); + // } + + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + // "Callback#Pivot - test limit filtering": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var name = "delete-me-" + getNextId(); + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // var obj = dataModel.objectByName("test_data"); + // test.ok(obj); + + // var pivotSpecification = obj.createPivotSpecification(); + // try { + // pivotSpecification.addLimitFilter("epsilon", "host", "ASCENDING", 500, "average"); + // test.strictEqual(1, pivotSpecification.filters.length); + + // //Test the individual parts of the filter + // var filter = pivotSpecification.filters[0]; + + // test.ok(filter.hasOwnProperty("fieldName")); + // test.ok(filter.hasOwnProperty("type")); + // test.ok(filter.hasOwnProperty("owner")); + // test.ok(filter.hasOwnProperty("attributeName")); + // test.ok(filter.hasOwnProperty("attributeOwner")); + // test.ok(filter.hasOwnProperty("limitType")); + // test.ok(filter.hasOwnProperty("limitAmount")); + // test.ok(filter.hasOwnProperty("statsFn")); + + // test.strictEqual("epsilon", filter.fieldName); + // test.strictEqual("number", filter.type); + // test.strictEqual("test_data", filter.owner); + // test.strictEqual("host", filter.attributeName); + // test.strictEqual("BaseEvent", filter.attributeOwner); + // test.strictEqual("lowest", filter.limitType); + // test.strictEqual(500, filter.limitAmount); + // test.strictEqual("average", filter.statsFn); + // } + // catch (e) { + // test.ok(false); + // } + + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + // "Callback#Pivot - test row split": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var name = "delete-me-" + getNextId(); + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // var obj = dataModel.objectByName("test_data"); + // test.ok(obj); + + // var pivotSpecification = obj.createPivotSpecification(); + + // // Test error handling for row split + // try { + // pivotSpecification.addRowSplit("has_boris", "Wrong type here"); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Field was of type " + obj.fieldByName("has_boris").type + ", expected number or string."); + // } + // var field = getNextId(); + // try { + + // pivotSpecification.addRowSplit(field, "Break Me!"); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Did not find field " + field); + // } + + // // Test row split, number + // pivotSpecification.addRowSplit("epsilon", "My Label"); + // test.strictEqual(1, pivotSpecification.rows.length); + + // var row = pivotSpecification.rows[0]; + // test.ok(row.hasOwnProperty("fieldName")); + // test.ok(row.hasOwnProperty("owner")); + // test.ok(row.hasOwnProperty("type")); + // test.ok(row.hasOwnProperty("label")); + // test.ok(row.hasOwnProperty("display")); + + // test.strictEqual("epsilon", row.fieldName); + // test.strictEqual("test_data", row.owner); + // test.strictEqual("number", row.type); + // test.strictEqual("My Label", row.label); + // test.strictEqual("all", row.display); + // test.same({ + // fieldName: "epsilon", + // owner: "test_data", + // type: "number", + // label: "My Label", + // display: "all" + // }, + // row); + + // // Test row split, string + // pivotSpecification.addRowSplit("host", "My Label"); + // test.strictEqual(2, pivotSpecification.rows.length); + + // row = pivotSpecification.rows[pivotSpecification.rows.length - 1]; + // test.ok(row.hasOwnProperty("fieldName")); + // test.ok(row.hasOwnProperty("owner")); + // test.ok(row.hasOwnProperty("type")); + // test.ok(row.hasOwnProperty("label")); + // test.ok(!row.hasOwnProperty("display")); + + // test.strictEqual("host", row.fieldName); + // test.strictEqual("BaseEvent", row.owner); + // test.strictEqual("string", row.type); + // test.strictEqual("My Label", row.label); + // test.same({ + // fieldName: "host", + // owner: "BaseEvent", + // type: "string", + // label: "My Label" + // }, + // row); + + // // Test error handling on range row split + // try { + // pivotSpecification.addRangeRowSplit("has_boris", "Wrong type here", {start: 0, end: 100, step:20, limit:5}); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Field was of type " + obj.fieldByName("has_boris").type + ", expected number."); + // } + // try { + // pivotSpecification.addRangeRowSplit(field, "Break Me!", {start: 0, end: 100, step:20, limit:5}); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Did not find field " + field); + // } + + // // Test range row split + // pivotSpecification.addRangeRowSplit("epsilon", "My Label", {start: 0, end: 100, step:20, limit:5}); + // test.strictEqual(3, pivotSpecification.rows.length); + + // row = pivotSpecification.rows[pivotSpecification.rows.length - 1]; + // test.ok(row.hasOwnProperty("fieldName")); + // test.ok(row.hasOwnProperty("owner")); + // test.ok(row.hasOwnProperty("type")); + // test.ok(row.hasOwnProperty("label")); + // test.ok(row.hasOwnProperty("display")); + // test.ok(row.hasOwnProperty("ranges")); + + // test.strictEqual("epsilon", row.fieldName); + // test.strictEqual("test_data", row.owner); + // test.strictEqual("number", row.type); + // test.strictEqual("My Label", row.label); + // test.strictEqual("ranges", row.display); + + // var ranges = { + // start: 0, + // end: 100, + // size: 20, + // maxNumberOf: 5 + // }; + // test.same(ranges, row.ranges); + // test.same({ + // fieldName: "epsilon", + // owner: "test_data", + // type: "number", + // label: "My Label", + // display: "ranges", + // ranges: ranges + // }, + // row); + + // // Test error handling on boolean row split + // try { + // pivotSpecification.addBooleanRowSplit("epsilon", "Wrong type here", "t", "f"); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Field was of type " + obj.fieldByName("epsilon").type + ", expected boolean."); + // } + // try { + // pivotSpecification.addBooleanRowSplit(field, "Break Me!", "t", "f"); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Did not find field " + field); + // } + + // // Test boolean row split + // pivotSpecification.addBooleanRowSplit("has_boris", "My Label", "is_true", "is_false"); + // test.strictEqual(4, pivotSpecification.rows.length); + + // row = pivotSpecification.rows[pivotSpecification.rows.length - 1]; + // test.ok(row.hasOwnProperty("fieldName")); + // test.ok(row.hasOwnProperty("owner")); + // test.ok(row.hasOwnProperty("type")); + // test.ok(row.hasOwnProperty("label")); + // test.ok(row.hasOwnProperty("trueLabel")); + // test.ok(row.hasOwnProperty("falseLabel")); + + // test.strictEqual("has_boris", row.fieldName); + // test.strictEqual("My Label", row.label); + // test.strictEqual("test_data", row.owner); + // test.strictEqual("boolean", row.type); + // test.strictEqual("is_true", row.trueLabel); + // test.strictEqual("is_false", row.falseLabel); + // test.same({ + // fieldName: "has_boris", + // label: "My Label", + // owner: "test_data", + // type: "boolean", + // trueLabel: "is_true", + // falseLabel: "is_false" + // }, + // row); + + // // Test error handling on timestamp row split + // try { + // pivotSpecification.addTimestampRowSplit("epsilon", "Wrong type here", "some binning"); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Field was of type " + obj.fieldByName("epsilon").type + ", expected timestamp."); + // } + // try { + // pivotSpecification.addTimestampRowSplit(field, "Break Me!", "some binning"); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Did not find field " + field); + // } + // try { + // pivotSpecification.addTimestampRowSplit("_time", "some label", "Bogus binning value"); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Invalid binning Bogus binning value found. Valid values are: " + pivotSpecification._binning.join(", ")); + // } + + // // Test timestamp row split + // pivotSpecification.addTimestampRowSplit("_time", "My Label", "day"); + // test.strictEqual(5, pivotSpecification.rows.length); + + // row = pivotSpecification.rows[pivotSpecification.rows.length - 1]; + // test.ok(row.hasOwnProperty("fieldName")); + // test.ok(row.hasOwnProperty("owner")); + // test.ok(row.hasOwnProperty("type")); + // test.ok(row.hasOwnProperty("label")); + // test.ok(row.hasOwnProperty("period")); + + // test.strictEqual("_time", row.fieldName); + // test.strictEqual("My Label", row.label); + // test.strictEqual("BaseEvent", row.owner); + // test.strictEqual("timestamp", row.type); + // test.strictEqual("day", row.period); + // test.same({ + // fieldName: "_time", + // label: "My Label", + // owner: "BaseEvent", + // type: "timestamp", + // period: "day" + // }, + // row); + + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + // "Callback#Pivot - test column split": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var name = "delete-me-" + getNextId(); + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // var obj = dataModel.objectByName("test_data"); + // test.ok(obj); + + // var pivotSpecification = obj.createPivotSpecification(); + + // // Test error handling for column split + // try { + // pivotSpecification.addColumnSplit("has_boris", "Wrong type here"); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Field was of type " + obj.fieldByName("has_boris").type + ", expected number or string."); + // } + // var field = getNextId(); + // try { + + // pivotSpecification.addColumnSplit(field, "Break Me!"); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Did not find field " + field); + // } + + // // Test column split, number + // pivotSpecification.addColumnSplit("epsilon"); + // test.strictEqual(1, pivotSpecification.columns.length); + + // var col = pivotSpecification.columns[pivotSpecification.columns.length - 1]; + // test.ok(col.hasOwnProperty("fieldName")); + // test.ok(col.hasOwnProperty("owner")); + // test.ok(col.hasOwnProperty("type")); + // test.ok(col.hasOwnProperty("display")); + + // test.strictEqual("epsilon", col.fieldName); + // test.strictEqual("test_data", col.owner); + // test.strictEqual("number", col.type); + // test.strictEqual("all", col.display); + // test.same({ + // fieldName: "epsilon", + // owner: "test_data", + // type: "number", + // display: "all" + // }, + // col); + + // // Test column split, string + // pivotSpecification.addColumnSplit("host"); + // test.strictEqual(2, pivotSpecification.columns.length); + + // col = pivotSpecification.columns[pivotSpecification.columns.length - 1]; + // test.ok(col.hasOwnProperty("fieldName")); + // test.ok(col.hasOwnProperty("owner")); + // test.ok(col.hasOwnProperty("type")); + // test.ok(!col.hasOwnProperty("display")); + + // test.strictEqual("host", col.fieldName); + // test.strictEqual("BaseEvent", col.owner); + // test.strictEqual("string", col.type); + // test.same({ + // fieldName: "host", + // owner: "BaseEvent", + // type: "string" + // }, + // col); + + // done(); + + // // Test error handling for range column split + // try { + // pivotSpecification.addRangeColumnSplit("has_boris", "Wrong type here", {start: 0, end: 100, step:20, limit:5}); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Field was of type " + obj.fieldByName("has_boris").type + ", expected number."); + // } + // try { + // pivotSpecification.addRangeColumnSplit(field, {start: 0, end: 100, step:20, limit:5}); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Did not find field " + field); + // } + + // // Test range column split + // pivotSpecification.addRangeColumnSplit("epsilon", {start: 0, end: 100, step:20, limit:5}); + // test.strictEqual(3, pivotSpecification.columns.length); + + // col = pivotSpecification.columns[pivotSpecification.columns.length - 1]; + // test.ok(col.hasOwnProperty("fieldName")); + // test.ok(col.hasOwnProperty("owner")); + // test.ok(col.hasOwnProperty("type")); + // test.ok(col.hasOwnProperty("display")); + // test.ok(col.hasOwnProperty("ranges")); + + // test.strictEqual("epsilon", col.fieldName); + // test.strictEqual("test_data", col.owner); + // test.strictEqual("number", col.type); + // test.strictEqual("ranges", col.display); + // var ranges = { + // start: "0", + // end: "100", + // size: "20", + // maxNumberOf: "5" + // }; + // test.same(ranges, col.ranges); + // test.same({ + // fieldName: "epsilon", + // owner: "test_data", + // type: "number", + // display: "ranges", + // ranges: ranges + // }, + // col); + + // // Test error handling on boolean column split + // try { + // pivotSpecification.addBooleanColumnSplit("epsilon", "t", "f"); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Field was of type " + obj.fieldByName("epsilon").type + ", expected boolean."); + // } + // try { + // pivotSpecification.addBooleanColumnSplit(field, "t", "f"); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Did not find field " + field); + // } + + // // Test boolean column split + // pivotSpecification.addBooleanColumnSplit("has_boris", "is_true", "is_false"); + // test.strictEqual(4, pivotSpecification.columns.length); + + // col = pivotSpecification.columns[pivotSpecification.columns.length - 1]; + // test.ok(col.hasOwnProperty("fieldName")); + // test.ok(col.hasOwnProperty("owner")); + // test.ok(col.hasOwnProperty("type")); + // test.ok(!col.hasOwnProperty("label")); + // test.ok(col.hasOwnProperty("trueLabel")); + // test.ok(col.hasOwnProperty("falseLabel")); + + // test.strictEqual("has_boris", col.fieldName); + // test.strictEqual("test_data", col.owner); + // test.strictEqual("boolean", col.type); + // test.strictEqual("is_true", col.trueLabel); + // test.strictEqual("is_false", col.falseLabel); + // test.same({ + // fieldName: "has_boris", + // owner: "test_data", + // type: "boolean", + // trueLabel: "is_true", + // falseLabel: "is_false" + // }, + // col); + + // // Test error handling on timestamp column split + // try { + // pivotSpecification.addTimestampColumnSplit("epsilon", "Wrong type here"); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Field was of type " + obj.fieldByName("epsilon").type + ", expected timestamp."); + // } + // try { + // pivotSpecification.addTimestampColumnSplit(field, "Break Me!"); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Did not find field " + field); + // } + // try { + // pivotSpecification.addTimestampColumnSplit("_time", "Bogus binning value"); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Invalid binning Bogus binning value found. Valid values are: " + pivotSpecification._binning.join(", ")); + // } + + // // Test timestamp column split + // pivotSpecification.addTimestampColumnSplit("_time", "day"); + // test.strictEqual(5, pivotSpecification.columns.length); + + // col = pivotSpecification.columns[pivotSpecification.columns.length - 1]; + // test.ok(col.hasOwnProperty("fieldName")); + // test.ok(col.hasOwnProperty("owner")); + // test.ok(col.hasOwnProperty("type")); + // test.ok(!col.hasOwnProperty("label")); + // test.ok(col.hasOwnProperty("period")); + + // test.strictEqual("_time", col.fieldName); + // test.strictEqual("BaseEvent", col.owner); + // test.strictEqual("timestamp", col.type); + // test.strictEqual("day", col.period); + // test.same({ + // fieldName: "_time", + // owner: "BaseEvent", + // type: "timestamp", + // period: "day" + // }, + // col); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + // "Callback#Pivot - test cell value": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var name = "delete-me-" + getNextId(); + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // var obj = dataModel.objectByName("test_data"); + // test.ok(obj); + + // var pivotSpecification = obj.createPivotSpecification(); + + // // Test error handling for cell value, string + // try { + // pivotSpecification.addCellValue("iDontExist", "Break Me!", "explosion"); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Did not find field iDontExist"); + // } + // try { + // pivotSpecification.addCellValue("source", "Wrong Stats Function", "stdev"); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Stats function on string and IPv4 fields must be one of:" + + // " list, distinct_values, first, last, count, or distinct_count; found stdev"); + // } + + // // Add cell value, string + // pivotSpecification.addCellValue("source", "Source Value", "dc"); + // test.strictEqual(1, pivotSpecification.cells.length); + + // var cell = pivotSpecification.cells[pivotSpecification.cells.length - 1]; + // test.ok(cell.hasOwnProperty("fieldName")); + // test.ok(cell.hasOwnProperty("owner")); + // test.ok(cell.hasOwnProperty("type")); + // test.ok(cell.hasOwnProperty("label")); + // test.ok(cell.hasOwnProperty("value")); + // test.ok(cell.hasOwnProperty("sparkline")); + + // test.strictEqual("source", cell.fieldName); + // test.strictEqual("BaseEvent", cell.owner); + // test.strictEqual("string", cell.type); + // test.strictEqual("Source Value", cell.label); + // test.strictEqual("dc", cell.value); + // test.strictEqual(false, cell.sparkline); + // test.same({ + // fieldName: "source", + // owner: "BaseEvent", + // type: "string", + // label: "Source Value", + // value: "dc", + // sparkline: false + // }, cell); + + // // Test error handling for cell value, IPv4 + // try { + // pivotSpecification.addCellValue("hostip", "Wrong Stats Function", "stdev"); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Stats function on string and IPv4 fields must be one of:" + + // " list, distinct_values, first, last, count, or distinct_count; found stdev"); + // } + + // // Add cell value, IPv4 + // pivotSpecification.addCellValue("hostip", "Source Value", "dc"); + // test.strictEqual(2, pivotSpecification.cells.length); + + // cell = pivotSpecification.cells[pivotSpecification.cells.length - 1]; + // test.ok(cell.hasOwnProperty("fieldName")); + // test.ok(cell.hasOwnProperty("owner")); + // test.ok(cell.hasOwnProperty("type")); + // test.ok(cell.hasOwnProperty("label")); + // test.ok(cell.hasOwnProperty("value")); + // test.ok(cell.hasOwnProperty("sparkline")); + + // test.strictEqual("hostip", cell.fieldName); + // test.strictEqual("test_data", cell.owner); + // test.strictEqual("ipv4", cell.type); + // test.strictEqual("Source Value", cell.label); + // test.strictEqual("dc", cell.value); + // test.strictEqual(false, cell.sparkline); + // test.same({ + // fieldName: "hostip", + // owner: "test_data", + // type: "ipv4", + // label: "Source Value", + // value: "dc", + // sparkline: false + // }, cell); + + // // Test error handling for cell value, boolean + // try { + // pivotSpecification.addCellValue("has_boris", "Booleans not allowed", "sum"); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Cannot use boolean valued fields as cell values."); + // } + + // // Test error handling for cell value, number + // try { + // pivotSpecification.addCellValue("epsilon", "Wrong Stats Function", "latest"); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Stats function on number field must be must be one of:" + + // " sum, count, average, max, min, stdev, list, or distinct_values; found latest"); + // } + + // // Add cell value, number + // pivotSpecification.addCellValue("epsilon", "Source Value", "average"); + // test.strictEqual(3, pivotSpecification.cells.length); + + // cell = pivotSpecification.cells[pivotSpecification.cells.length - 1]; + // test.ok(cell.hasOwnProperty("fieldName")); + // test.ok(cell.hasOwnProperty("owner")); + // test.ok(cell.hasOwnProperty("type")); + // test.ok(cell.hasOwnProperty("label")); + // test.ok(cell.hasOwnProperty("value")); + // test.ok(cell.hasOwnProperty("sparkline")); + + // test.strictEqual("epsilon", cell.fieldName); + // test.strictEqual("test_data", cell.owner); + // test.strictEqual("number", cell.type); + // test.strictEqual("Source Value", cell.label); + // test.strictEqual("average", cell.value); + // test.strictEqual(false, cell.sparkline); + // test.same({ + // fieldName: "epsilon", + // owner: "test_data", + // type: "number", + // label: "Source Value", + // value: "average", + // sparkline: false + // }, cell); + + // // Test error handling for cell value, timestamp + // try { + // pivotSpecification.addCellValue("_time", "Wrong Stats Function", "max"); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Stats function on timestamp field must be one of:" + + // " duration, earliest, latest, list, or distinct values; found max"); + // } + + // // Add cell value, timestamp + // pivotSpecification.addCellValue("_time", "Source Value", "earliest"); + // test.strictEqual(4, pivotSpecification.cells.length); + + // cell = pivotSpecification.cells[pivotSpecification.cells.length - 1]; + // test.ok(cell.hasOwnProperty("fieldName")); + // test.ok(cell.hasOwnProperty("owner")); + // test.ok(cell.hasOwnProperty("type")); + // test.ok(cell.hasOwnProperty("label")); + // test.ok(cell.hasOwnProperty("value")); + // test.ok(cell.hasOwnProperty("sparkline")); + + // test.strictEqual("_time", cell.fieldName); + // test.strictEqual("BaseEvent", cell.owner); + // test.strictEqual("timestamp", cell.type); + // test.strictEqual("Source Value", cell.label); + // test.strictEqual("earliest", cell.value); + // test.strictEqual(false, cell.sparkline); + // test.same({ + // fieldName: "_time", + // owner: "BaseEvent", + // type: "timestamp", + // label: "Source Value", + // value: "earliest", + // sparkline: false + // }, cell); + + // // Test error handling for cell value, count + // try { + // pivotSpecification.addCellValue("test_data", "Wrong Stats Function", "min"); + // test.ok(false); + // } + // catch (e) { + // test.ok(e); + // test.strictEqual(e.message, "Stats function on childcount and objectcount fields " + + // "must be count; found " + "min"); + // } + + // // Add cell value, count + // pivotSpecification.addCellValue("test_data", "Source Value", "count"); + // test.strictEqual(5, pivotSpecification.cells.length); + + // cell = pivotSpecification.cells[pivotSpecification.cells.length - 1]; + // test.ok(cell.hasOwnProperty("fieldName")); + // test.ok(cell.hasOwnProperty("owner")); + // test.ok(cell.hasOwnProperty("type")); + // test.ok(cell.hasOwnProperty("label")); + // test.ok(cell.hasOwnProperty("value")); + // test.ok(cell.hasOwnProperty("sparkline")); + + // test.strictEqual("test_data", cell.fieldName); + // test.strictEqual("test_data", cell.owner); + // test.strictEqual("objectCount", cell.type); + // test.strictEqual("Source Value", cell.label); + // test.strictEqual("count", cell.value); + // test.strictEqual(false, cell.sparkline); + // test.same({ + // fieldName: "test_data", + // owner: "test_data", + // type: "objectCount", + // label: "Source Value", + // value: "count", + // sparkline: false + // }, cell); + + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + // "Callback#Pivot - test pivot throws HTTP exception": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var name = "delete-me-" + getNextId(); + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // var obj = dataModel.objectByName("test_data"); + // test.ok(obj); + + // obj.createPivotSpecification().pivot(done); + // }, + // function(pivot, done) { + // test.ok(false); + // } + // ], + // function(err) { + // test.ok(err); + // var expectedErr = "In handler 'datamodelpivot': Error in 'PivotReport': Must have non-empty cells or non-empty rows."; + // test.ok(utils.endsWith(err.message, expectedErr)); + // test.done(); + // } + // ); + // }, + // "Callback#Pivot - test pivot with simple namespace": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var name = "delete-me-" + getNextId(); + // var args; + // try { + // args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); + // } + // catch(err) { + // // Fail if we can't read the file, likely to occur in the browser + // test.ok(!err); + // test.done(); + // } + // var that = this; + // var obj; + // var pivotSpecification; + // var adhocjob; + // Async.chain([ + // function(done) { + // that.dataModels.create(name, args, done); + // }, + // function(dataModel, done) { + // obj = dataModel.objectByName("test_data"); + // test.ok(obj); + // obj.createLocalAccelerationJob(null, done); + // }, + // function(job, done) { + // adhocjob = job; + // test.ok(job); + // pivotSpecification = obj.createPivotSpecification(); + + // pivotSpecification.addBooleanRowSplit("has_boris", "Has Boris", "meep", "hilda"); + // pivotSpecification.addCellValue("hostip", "Distinct IPs", "count"); + + // // Test setting a job + // pivotSpecification.setAccelerationJob(job); + // test.strictEqual("string", typeof pivotSpecification.accelerationNamespace); + // test.strictEqual("sid=" + job.sid, pivotSpecification.accelerationNamespace); + + // // Test setting a job's SID + // pivotSpecification.setAccelerationJob(job.sid); + // test.strictEqual("string", typeof pivotSpecification.accelerationNamespace); + // test.strictEqual("sid=" + job.sid, pivotSpecification.accelerationNamespace); + + // pivotSpecification.pivot(done); + // }, + // function(pivot, done) { + // test.ok(pivot.tstatsSearch); + // test.ok(pivot.tstatsSearch.length > 0); + // test.strictEqual(0, pivot.tstatsSearch.indexOf("| tstats")); + // // This test won't work with utils.startsWith due to the regex escaping + // test.strictEqual("| tstats", pivot.tstatsSearch.match("^\\| tstats")[0]); + // test.strictEqual(1, pivot.tstatsSearch.match("^\\| tstats").length); + + // pivot.run(done); + // }, + // function(job, done) { + // tutils.pollUntil( + // job, + // function(j) { + // return job.properties().isDone; + // }, + // 10, + // done + // ); + // }, + // function(job, done) { + // test.ok("FAILED" !== job.properties().dispatchState); + + // test.strictEqual(0, job.properties().request.search.indexOf("| tstats")); + // // This test won't work with utils.startsWith due to the regex escaping + // test.strictEqual("| tstats", job.properties().request.search.match("^\\| tstats")[0]); + // test.strictEqual(1, job.properties().request.search.match("^\\| tstats").length); + + // adhocjob.cancel(done); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + // "Callback#Pivot - test pivot column range split": function(test) { + // // This test is here because we had a problem with fields that were supposed to be + // // numbers being expected as strings in Splunk 6.0. This was fixed in Splunk 6.1, and accepts + // // either strings or numbers. + + // if (this.skip) { + // test.done(); + // return; + // } + // var that = this; + // var search; + // Async.chain([ + // function(done) { + // that.dataModels.fetch(done); + // }, + // function(dataModels, done) { + // var dm = dataModels.item("internal_audit_logs"); + // var obj = dm.objectByName("searches"); + // var pivotSpecification = obj.createPivotSpecification(); + + // pivotSpecification.addRowSplit("user", "Executing user"); + // pivotSpecification.addRangeColumnSplit("exec_time", {start: 0, end: 12, step: 5, limit: 4}); + // pivotSpecification.addCellValue("search", "Search Query", "values"); + // pivotSpecification.pivot(done); + // }, + // function(pivot, done) { + // // If tstats is undefined, use pivotSearch + // search = pivot.tstatsSearch || pivot.pivotSearch; + // pivot.run(done); + // }, + // function(job, done) { + // tutils.pollUntil( + // job, + // function(j) { + // return job.properties().isDone; + // }, + // 10, + // done + // ); + // }, + // function(job, done) { + // test.notStrictEqual("FAILED", job.properties().dispatchState); + // // Make sure the job is run with the correct search query + // test.strictEqual(search, job.properties().request.search); + // job.cancel(done); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + // "Callback#Pivot - test pivot with PivotSpecification.run and Job.track": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // var that = this; + // Async.chain([ + // function(done) { + // that.dataModels.fetch(done); + // }, + // function(dataModels, done) { + // var dm = dataModels.item("internal_audit_logs"); + // var obj = dm.objectByName("searches"); + // var pivotSpecification = obj.createPivotSpecification(); + + // pivotSpecification.addRowSplit("user", "Executing user"); + // pivotSpecification.addRangeColumnSplit("exec_time", {start: 0, end: 12, step: 5, limit: 4}); + // pivotSpecification.addCellValue("search", "Search Query", "values"); + + // pivotSpecification.run({}, done); + // }, + // function(job, pivot, done) { + // job.track({}, function(job) { + // test.strictEqual(pivot.tstatsSearch || pivot.pivotSearch, job.properties().request.search); + // done(null, job); + // }); + // }, + // function(job, done) { + // test.notStrictEqual("FAILED", job.properties().dispatchState); + // job.cancel(done); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + // "Callback#DataModels - delete any remaining data models created by the SDK tests": function(test) { + // if (this.skip) { + // test.done(); + // return; + // } + // svc.dataModels().fetch(function(err, dataModels) { + // if (err) { + // test.ok(!err); + // } + + // var dms = dataModels.list(); + // Async.seriesEach( + // dms, + // function(datamodel, i, done) { + // // Delete any test data models that we created + // if (utils.startsWith(datamodel.name, "delete-me")) { + // datamodel.remove(done); + // } + // else { + // done(); + // } + // }, + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }); + // } + // }, + + // "App Tests": { + // setUp: function(done) { + // this.service = svc; + // done(); + // }, + + // "Callback#list applications": function(test) { + // var apps = this.service.apps(); + // apps.fetch(function(err, apps) { + // var appList = apps.list(); + // test.ok(appList.length > 0); + // test.done(); + // }); + // }, + + // "Callback#contains applications": function(test) { + // var apps = this.service.apps(); + // apps.fetch(function(err, apps) { + // var app = apps.item("search"); + // test.ok(app); + // test.done(); + // }); + // }, + + // "Callback#create + contains app": function(test) { + // var name = "jssdk_testapp_" + getNextId(); + // var apps = this.service.apps(); + + // apps.create({name: name}, function(err, app) { + // var appName = app.name; + // apps.fetch(function(err, apps) { + // var entity = apps.item(appName); + // test.ok(entity); + // app.remove(function() { + // test.done(); + // }); + // }); + // }); + // }, + + // "Callback#create + modify app": function(test) { + // var DESCRIPTION = "TEST DESCRIPTION"; + // var VERSION = "1.1.0"; + + // var name = "jssdk_testapp_" + getNextId(); + // var apps = this.service.apps(); + + // Async.chain([ + // function(callback) { + // apps.create({name: name}, callback); + // }, + // function(app, callback) { + // test.ok(app); + // test.strictEqual(app.name, name); + // var versionMatches = app.properties().version === "1.0" || + // app.properties().version == "1.0.0"; + // test.ok(versionMatches); + + // app.update({ + // description: DESCRIPTION, + // version: VERSION + // }, callback); + // }, + // function(app, callback) { + // test.ok(app); + // var properties = app.properties(); + + // test.strictEqual(properties.description, DESCRIPTION); + // test.strictEqual(properties.version, VERSION); + + // app.remove(callback); + // } + // ], function(err) { + // test.ok(!err); + // test.done(); + // }); + // }, + + // "Callback#delete test applications": function(test) { + // var apps = this.service.apps(); + // apps.fetch(function(err, apps) { + // var appList = apps.list(); + + // Async.parallelEach( + // appList, + // function(app, idx, callback) { + // if (utils.startsWith(app.name, "jssdk_")) { + // app.remove(callback); + // } + // else { + // callback(); + // } + // }, function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }); + // }, + + // "list applications with cookies as authentication": function(test) { + // this.service.serverInfo(function (err, info) { + // // Cookie authentication was added in splunk 6.2 + // var majorVersion = parseInt(info.properties().version.split(".")[0], 10); + // var minorVersion = parseInt(info.properties().version.split(".")[1], 10); + // // Skip cookie test if Splunk older than 6.2 + // if(majorVersion < 6 || (majorVersion === 6 && minorVersion < 2)) { + // splunkjs.Logger.log("Skipping cookie test..."); + // test.done(); + // return; + // } + + // var service = new splunkjs.Service( + // { + // scheme: svc.scheme, + // host: svc.host, + // port: svc.port, + // username: svc.username, + // password: svc.password, + // version: svc.version + // }); + + // var service2 = new splunkjs.Service( + // { + // scheme: svc.scheme, + // host: svc.host, + // port: svc.port, + // version: svc.version + // }); + + // Async.chain([ + // function (done) { + // service.login(done); + // }, + // function (job, done) { + // // Save the cookie store + // var cookieStore = service.http._cookieStore; + // // Test that there are cookies + // test.ok(!utils.isEmpty(cookieStore)); + + // // Add the cookies to a service with no other authenitcation information + // service2.http._cookieStore = cookieStore; + + // var apps = service2.apps(); + // apps.fetch(done); + // }, + // function (apps, done) { + // var appList = apps.list(); + // test.ok(appList.length > 0); + // test.ok(!utils.isEmpty(service2.http._cookieStore)); + // done(); + // } + // ], + // function(err) { + // // Test that no errors were returned + // test.ok(!err); + // test.done(); + // }); + // }); + // } + // }, + + // "Saved Search Tests": { + // setUp: function(done) { + // this.service = svc; + // this.loggedOutService = loggedOutSvc; + // done(); + // }, + + // "Callback#list": function(test) { + // var searches = this.service.savedSearches(); + // searches.fetch(function(err, searches) { + // var savedSearches = searches.list(); + // test.ok(savedSearches.length > 0); + + // for(var i = 0; i < savedSearches.length; i++) { + // test.ok(savedSearches[i]); + // } + + // test.done(); + // }); + // }, + + // "Callback#contains": function(test) { + // var searches = this.service.savedSearches(); + // searches.fetch(function(err, searches) { + // var search = searches.item("Errors in the last hour"); + // test.ok(search); + + // test.done(); + // }); + // }, + + // "Callback#suppress": function(test) { + // var searches = this.service.savedSearches(); + // searches.fetch(function(err, searches) { + // var search = searches.item("Errors in the last hour"); + // test.ok(search); + + // search.suppressInfo(function(err, info, search) { + // test.ok(!err); + // test.done(); + // }); + // }); + // }, + + // "Callback#list limit count": function(test) { + // var searches = this.service.savedSearches(); + // searches.fetch({count: 2}, function(err, searches) { + // var savedSearches = searches.list(); + // test.strictEqual(savedSearches.length, 2); + + // for(var i = 0; i < savedSearches.length; i++) { + // test.ok(savedSearches[i]); + // } + + // test.done(); + // }); + // }, + + // "Callback#list filter": function(test) { + // var searches = this.service.savedSearches(); + // searches.fetch({search: "Error"}, function(err, searches) { + // var savedSearches = searches.list(); + // test.ok(savedSearches.length > 0); + + // for(var i = 0; i < savedSearches.length; i++) { + // test.ok(savedSearches[i]); + // } + + // test.done(); + // }); + // }, + + // "Callback#list offset": function(test) { + // var searches = this.service.savedSearches(); + // searches.fetch({offset: 2, count: 1}, function(err, searches) { + // var savedSearches = searches.list(); + // test.strictEqual(searches.paging().offset, 2); + // test.strictEqual(searches.paging().perPage, 1); + // test.strictEqual(savedSearches.length, 1); + + // for(var i = 0; i < savedSearches.length; i++) { + // test.ok(savedSearches[i]); + // } + + // test.done(); + // }); + // }, + + // "Callback#create + modify + delete saved search": function(test) { + // var name = "jssdk_savedsearch"; + // var originalSearch = "search * | head 1"; + // var updatedSearch = "search * | head 10"; + // var updatedDescription = "description"; + + // var searches = this.service.savedSearches({owner: this.service.username, app: "sdk-app-collection"}); + + // Async.chain([ + // function(done) { + // searches.create({search: originalSearch, name: name}, done); + // }, + // function(search, done) { + // test.ok(search); + + // test.strictEqual(search.name, name); + // test.strictEqual(search.properties().search, originalSearch); + // test.ok(!search.properties().description); + + // search.update({search: updatedSearch}, done); + // }, + // function(search, done) { + // test.ok(search); + // test.ok(search); + + // test.strictEqual(search.name, name); + // test.strictEqual(search.properties().search, updatedSearch); + // test.ok(!search.properties().description); + + // search.update({description: updatedDescription}, done); + // }, + // function(search, done) { + // test.ok(search); + // test.ok(search); + + // test.strictEqual(search.name, name); + // test.strictEqual(search.properties().search, updatedSearch); + // test.strictEqual(search.properties().description, updatedDescription); + + // search.fetch(done); + // }, + // function(search, done) { + // // Verify that we have the required fields + // test.ok(search.fields().optional.length > 1); + // test.ok(utils.indexOf(search.fields().optional, "disabled") > -1); + + // search.remove(done); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#dispatch error": function(test) { + // var name = "jssdk_savedsearch_" + getNextId(); + // var originalSearch = "search index=_internal | head 1"; + // var search = new splunkjs.Service.SavedSearch( + // this.loggedOutService, + // name, + // {owner: "nobody", app: "search"} + // ); + // search.dispatch(function(err) { + // test.ok(err); + // test.done(); + // }); + // }, + + // "Callback#dispatch omitting optional arguments": function(test) { + // var name = "jssdk_savedsearch_" + getNextId(); + // var originalSearch = "search index=_internal | head 1"; + + // var searches = this.service.savedSearches({owner: this.service.username, app: "sdk-app-collection"}); + + // Async.chain( + // [function(done) { + // searches.create({search: originalSearch, name: name}, done); + // }, + // function(search, done) { + // test.ok(search); + + // test.strictEqual(search.name, name); + // test.strictEqual(search.properties().search, originalSearch); + // test.ok(!search.properties().description); + + // search.dispatch(done); + // }, + // function(job, search, done) { + // test.ok(job); + // test.ok(search); + // test.done(); + // }] + // ); + // }, + + // "Callback#history error": function(test) { + // var name = "jssdk_savedsearch_" + getNextId(); + // var originalSearch = "search index=_internal | head 1"; + // var search = new splunkjs.Service.SavedSearch( + // this.loggedOutService, + // name, + // {owner: "nobody", app: "search", sharing: "system"} + // ); + // search.history(function(err) { + // test.ok(err); + // test.done(); + // }); + // }, + + // "Callback#Update error": function(test) { + // var name = "jssdk_savedsearch_" + getNextId(); + // var originalSearch = "search index=_internal | head 1"; + // var search = new splunkjs.Service.SavedSearch( + // this.loggedOutService, + // name, + // {owner: "nobody", app: "search", sharing: "system"} + // ); + // search.update( + // {}, + // function(err) { + // test.ok(err); + // test.done(); + // }); + // }, + + // "Callback#oneshot requires search string": function(test) { + // test.throws(function() { this.service.oneshotSearch({name: "jssdk_oneshot_" + getNextId()}, function(err) {});}); + // test.done(); + // }, + + // "Callback#Create + dispatch + history": function(test) { + // var name = "jssdk_savedsearch_" + getNextId(); + // var originalSearch = "search index=_internal | head 1"; + + // var searches = this.service.savedSearches({owner: this.service.username, app: "sdk-app-collection"}); + + // Async.chain( + // function(done) { + // searches.create({search: originalSearch, name: name}, done); + // }, + // function(search, done) { + // test.ok(search); + + // test.strictEqual(search.name, name); + // test.strictEqual(search.properties().search, originalSearch); + // test.ok(!search.properties().description); + + // search.dispatch({force_dispatch: false, "dispatch.buckets": 295}, done); + // }, + // function(job, search, done) { + // test.ok(job); + // test.ok(search); + + // tutils.pollUntil( + // job, + // function(j) { + // return job.properties()["isDone"]; + // }, + // 10, + // Async.augment(done, search) + // ); + // }, + // function(job, search, done) { + // test.strictEqual(job.properties().statusBuckets, 295); + // search.history(Async.augment(done, job)); + // }, + // function(jobs, search, originalJob, done) { + // test.ok(jobs); + // test.ok(jobs.length > 0); + // test.ok(search); + // test.ok(originalJob); + + // var cancel = function(job) { + // return function(cb) { + // job.cancel(cb); + // }; + // }; + + // var found = false; + // var cancellations = []; + // for(var i = 0; i < jobs.length; i++) { + // cancellations.push(cancel(jobs[i])); + // found = found || (jobs[i].sid === originalJob.sid); + // } + + // test.ok(found); + + // search.remove(function(err) { + // if (err) { + // done(err); + // } + // else { + // Async.parallel(cancellations, done); + // } + // }); + // }, + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#job events fails": function(test) { + // var job = new splunkjs.Service.Job(this.loggedOutService, "abc", {}); + // job.events({}, function (err) { + // test.ok(err); + // test.done(); + // }); + // }, + + // "Callback#job preview fails": function(test) { + // var job = new splunkjs.Service.Job(this.loggedOutService, "abc", {}); + // job.preview({}, function(err) { + // test.ok(err); + // test.done(); + // }); + // }, + + // "Callback#job results fails": function(test) { + // var job = new splunkjs.Service.Job(this.loggedOutService, "abc", {}); + // job.results({}, function(err) { + // test.ok(err); + // test.done(); + // }); + // }, + + // "Callback#job searchlog fails": function(test) { + // var job = new splunkjs.Service.Job(this.loggedOutService, "abc", {}); + // job.searchlog(function(err) { + // test.ok(err); + // test.done(); + // }); + // }, + + // "Callback#job summary fails": function(test) { + // var job = new splunkjs.Service.Job(this.loggedOutService, "abc", {}); + // job.summary({}, function(err) { + // test.ok(err); + // test.done(); + // }); + // }, + + // "Callback#job timeline fails": function(test) { + // var job = new splunkjs.Service.Job(this.loggedOutService, "abc", {}); + // job.timeline({}, function(err) { + // test.ok(err); + // test.done(); + // }); + // }, + + // "Callback#delete test saved searches": function(test) { + // var searches = this.service.savedSearches({owner: this.service.username, app: "sdk-app-collection"}); + // searches.fetch(function(err, searches) { + // var searchList = searches.list(); + // Async.parallelEach( + // searchList, + // function(search, idx, callback) { + // if (utils.startsWith(search.name, "jssdk_")) { + // search.remove(callback); + // } + // else { + // callback(); + // } + // }, function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }); + // }, + + // "Callback#setupInfo fails": function(test) { + // var searches = new splunkjs.Service.Application(this.loggedOutService, "search"); + // searches.setupInfo(function(err, content, that) { + // test.ok(err); + // test.done(); + // }); + // }, + + // "Callback#setupInfo succeeds": function(test) { + // var app = new splunkjs.Service.Application(this.service, "sdk-app-collection"); + // app.setupInfo(function(err, content, app) { + // // This error message was removed in modern versions of Splunk + // if (err) { + // test.ok(err.data.messages[0].text.match("Setup configuration file does not")); + // splunkjs.Logger.log("ERR ---", err.data.messages[0].text); + // } + // else { + // test.ok(app); + // } + // test.done(); + // }); + // }, + + // "Callback#updateInfo": function(test) { + // var app = new splunkjs.Service.Application(this.service, "search"); + // app.updateInfo(function(err, info, app) { + // test.ok(!err); + // test.ok(app); + // test.strictEqual(app.name, 'search'); + // test.done(); + // }); + // }, + + // "Callback#updateInfo failure": function(test) { + // var app = new splunkjs.Service.Application(this.loggedOutService, "sdk-app-collection"); + // app.updateInfo(function(err, info, app) { + // test.ok(err); + // test.done(); + // }); + // } + // }, + + // "Fired Alerts Tests": { + // setUp: function(done) { + // this.service = svc; + // this.loggedOutService = loggedOutSvc; + + // var indexes = this.service.indexes(); + // done(); + // }, + + // "Callback#create + verify emptiness + delete new alert group": function(test) { + // var searches = this.service.savedSearches({owner: this.service.username}); + + // var name = "jssdk_savedsearch_alert_" + getNextId(); + // var searchConfig = { + // "name": name, + // "search": "index=_internal | head 1", + // "alert_type": "always", + // "alert.severity": "2", + // "alert.suppress": "0", + // "alert.track": "1", + // "dispatch.earliest_time": "-1h", + // "dispatch.latest_time": "now", + // "is_scheduled": "1", + // "cron_schedule": "* * * * *" + // }; + + // Async.chain([ + // function(done) { + // searches.create(searchConfig, done); + // }, + // function(search, done) { + // test.ok(search); + // test.strictEqual(search.alertCount(), 0); + // search.history(done); + // }, + // function(jobs, search, done) { + // test.strictEqual(jobs.length, 0); + // test.strictEqual(search.firedAlertGroup().count(), 0); + // searches.service.firedAlertGroups().fetch( Async.augment(done, search) ); + // }, + // function(firedAlertGroups, originalSearch, done) { + // test.strictEqual(firedAlertGroups.list().indexOf(originalSearch.name), -1); + // done(null, originalSearch); + // }, + // function(originalSearch, done) { + // originalSearch.remove(done); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // // This test is not stable, commenting it out until we figure it out + // // "Callback#alert is triggered + test firedAlert entity -- FAILS INTERMITTENTLY": function(test) { + // // var searches = this.service.savedSearches({owner: this.service.username}); + // // var indexName = "sdk-tests-alerts"; + // // var name = "jssdk_savedsearch_alert_" + getNextId(); + + // // // Real-time search config + // // var searchConfig = { + // // "name": name, + // // "search": "index="+indexName+" sourcetype=sdk-tests-alerts | head 1", + // // "alert_type": "always", + // // "alert.severity": "2", + // // "alert.suppress": "0", + // // "alert.track": "1", + // // "dispatch.earliest_time": "rt-1s", + // // "dispatch.latest_time": "rt", + // // "is_scheduled": "1", + // // "cron_schedule": "* * * * *" + // // }; + + // // Async.chain([ + // // function(done) { + // // searches.create(searchConfig, done); + // // }, + // // function(search, done) { + // // test.ok(search); + // // test.strictEqual(search.alertCount(), 0); + // // test.strictEqual(search.firedAlertGroup().count(), 0); + + // // var indexes = search.service.indexes(); + // // indexes.create(indexName, {}, function(err, index) { + // // if (err && err.status !== 409) { + // // done(new Error("Index creation failed for an unknown reason")); + // // } + // // done(null, search); + // // }); + // // }, + // // function(originalSearch, done) { + // // var indexes = originalSearch.service.indexes(); + // // indexes.fetch(function(err, indexes) { + // // if (err) { + // // done(err); + // // } + // // else { + // // var index = indexes.item(indexName); + // // test.ok(index); + // // index.enable(Async.augment(done, originalSearch)); + // // } + // // }); + // // }, + // // function(index, originalSearch, done) { + // // //Is the index enabled? + // // test.ok(!index.properties().disabled); + // // //refresh the index + // // index.fetch(Async.augment(done, originalSearch)); + // // }, + // // function(index, originalSearch, done) { + // // //Store the current event count for a later comparison + // // var eventCount = index.properties().totalEventCount; + + // // test.strictEqual(index.properties().sync, 0); + // // test.ok(!index.properties().disabled); + + // // index.fetch(Async.augment(done, originalSearch, eventCount)); + // // }, + // // function(index, originalSearch, eventCount, done) { + // // // submit an event + // // index.submitEvent( + // // "JS SDK: testing alerts", + // // { + // // sourcetype: "sdk-tests-alerts" + // // }, + // // Async.augment(done, originalSearch, eventCount) + // // ); + // // }, + // // function(result, index, originalSearch, eventCount, done) { + // // Async.sleep(1000, function(){ + // // //refresh the search + // // index.fetch(Async.augment(done, originalSearch, eventCount)); + // // }); + // // }, + // // function(index, originalSearch, eventCount, done) { + // // // Did the event get submitted + // // test.strictEqual(index.properties().totalEventCount, eventCount+1); + // // // Refresh the search + // // originalSearch.fetch(Async.augment(done, index)); + // // }, + // // function(originalSearch, index, done) { + // // splunkjs.Logger.log("\tAlert count pre-fetch", originalSearch.alertCount()); + // // var attemptNum = 1; + // // var maxAttempts = 20; + // // Async.whilst( + // // function() { + // // // When this returns false, it hits the final function in the chain + // // splunkjs.Logger.log("\tFetch attempt", attemptNum, "of", maxAttempts, "alertCount", originalSearch.alertCount()); + // // if (originalSearch.alertCount() !== 0) { + // // return false; + // // } + // // else { + // // attemptNum++; + // // return attemptNum < maxAttempts; + // // } + // // }, + // // function(callback) { + // // Async.sleep(500, function() { + // // originalSearch.fetch(callback); + // // }); + // // }, + // // function(err) { + // // splunkjs.Logger.log("Attempted fetching", attemptNum, "of", maxAttempts, "result is", originalSearch.alertCount() !== 0); + // // originalSearch.fetch(Async.augment(done, index)); + // // } + // // ); + // // }, + // // function(originalSearch, index, done) { + // // splunkjs.Logger.log("about to fetch"); + // // splunkjs.Logger.log("SavedSearch name was: " + originalSearch.name); + // // svc.firedAlertGroups({username: svc.username}).fetch(Async.augment(done, index, originalSearch)); + // // }, + // // function(firedAlertGroups, index, originalSearch, done) { + // // Async.seriesEach( + // // firedAlertGroups.list(), + // // function(firedAlertGroup, innerIndex, seriescallback) { + // // Async.chain([ + // // function(insideChainCallback) { + // // firedAlertGroup.list(insideChainCallback); + // // }, + // // function(firedAlerts, firedAlertGroup, insideChainCallback) { + // // for(var i = 0; i < firedAlerts.length; i++) { + // // var firedAlert = firedAlerts[i]; + // // firedAlert.actions(); + // // firedAlert.alertType(); + // // firedAlert.isDigestMode(); + // // firedAlert.expirationTime(); + // // firedAlert.savedSearchName(); + // // firedAlert.severity(); + // // firedAlert.sid(); + // // firedAlert.triggerTime(); + // // firedAlert.triggerTimeRendered(); + // // firedAlert.triggeredAlertCount(); + // // } + // // insideChainCallback(null); + // // } + // // ], + // // function(err) { + // // if (err) { + // // seriescallback(err); + // // } + // // seriescallback(null); + // // } + // // ); + // // }, + // // function(err) { + // // if (err) { + // // done(err, originalSearch, index); + // // } + // // done(null, originalSearch, index); + // // } + // // ); + // // }, + // // function(originalSearch, index, done) { + // // // Make sure the event count has incremented, as expected + // // test.strictEqual(originalSearch.alertCount(), 1); + // // // Remove the search, especially because it's a real-time search + // // originalSearch.remove(Async.augment(done, index)); + // // }, + // // function(index, done) { + // // Async.sleep(500, function() { + // // index.remove(done); + // // }); + // // } + // // ], + // // function(err) { + // // test.ok(!err); + // // test.done(); + // // } + // // ); + // // }, + + // "Callback#delete all alerts": function(test) { + // var namePrefix = "jssdk_savedsearch_alert_"; + // var alertList = this.service.savedSearches().list(); + + // Async.parallelEach( + // alertList, + // function(alert, idx, callback) { + // if (utils.startsWith(alert.name, namePrefix)) { + // splunkjs.Logger.log("ALERT ---", alert.name); + // alert.remove(callback); + // } + // else { + // callback(); + // } + // }, function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // } + // }, + + // "Properties Tests": { + // setUp: function(done) { + // this.service = svc; + // done(); + // }, + + // "Callback#list": function(test) { + // var that = this; + // var namespace = {owner: "admin", app: "search"}; + + // Async.chain([ + // function(done) { + // that.service.configurations(namespace).fetch(done); + // }, + // function(props, done) { + // var files = props.list(); + // test.ok(files.length > 0); + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // }); + // }, + + // "Callback#item": function(test) { + // var that = this; + // var namespace = {owner: "admin", app: "search"}; + + // Async.chain([ + // function(done) { that.service.configurations(namespace).fetch(done); }, + // function(props, done) { + // var file = props.item("web"); + // test.ok(file); + // file.fetch(done); + // }, + // function(file, done) { + // test.strictEqual(file.name, "web"); + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // }); + // }, + + // "Callback#contains stanza": function(test) { + // var that = this; + // var namespace = {owner: "admin", app: "search"}; + + // Async.chain([ + // function(done) { that.service.configurations(namespace).fetch(done); }, + // function(props, done) { + // var file = props.item("web"); + // test.ok(file); + // file.fetch(done); + // }, + // function(file, done) { + // test.strictEqual(file.name, "web"); + // var stanza = file.item("settings"); + // test.ok(stanza); + // stanza.fetch(done); + // }, + // function(stanza, done) { + // test.ok(stanza.properties().hasOwnProperty("httpport")); + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // }); + // }, + + // "Callback#create file + create stanza + update stanza": function(test) { + // var that = this; + // var fileName = "jssdk_file_" + getNextId(); + // var value = "barfoo_" + getNextId(); + // var namespace = {owner: "admin", app: "search"}; + + // Async.chain([ + // function(done) { + // var properties = that.service.configurations(namespace); + // properties.fetch(done); + // }, + // function(properties, done) { + // properties.create(fileName, done); + // }, + // function(file, done) { + // file.create("stanza", done); + // }, + // function(stanza, done) { + // stanza.update({"jssdk_foobar": value}, done); + // }, + // function(stanza, done) { + // test.strictEqual(stanza.properties()["jssdk_foobar"], value); + // done(); + // }, + // function(done) { + // var file = new splunkjs.Service.ConfigurationFile(svc, fileName); + // file.fetch(done); + // }, + // function(file, done) { + // var stanza = file.item("stanza"); + // test.ok(stanza); + // stanza.remove(done); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // }); + // } + // }, + + // "Configuration Tests": { + // setUp: function(done) { + // this.service = svc; + // done(); + // }, + + // "Callback#list": function(test) { + // var that = this; + // var namespace = {owner: "admin", app: "search"}; + + // Async.chain([ + // function(done) { that.service.configurations(namespace).fetch(done); }, + // function(props, done) { + // var files = props.list(); + // test.ok(files.length > 0); + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // }); + // }, + + // "Callback#contains": function(test) { + // var that = this; + // var namespace = {owner: "admin", app: "search"}; + + // Async.chain([ + // function(done) { that.service.configurations(namespace).fetch(done); }, + // function(props, done) { + // var file = props.item("web"); + // test.ok(file); + // file.fetch(done); + // }, + // function(file, done) { + // test.strictEqual(file.name, "web"); + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // }); + // }, + + // "Callback#contains stanza": function(test) { + // var that = this; + // var namespace = {owner: "admin", app: "search"}; + + // Async.chain([ + // function(done) { that.service.configurations(namespace).fetch(done); }, + // function(props, done) { + // var file = props.item("web"); + // test.ok(file); + // file.fetch(done); + // }, + // function(file, done) { + // test.strictEqual(file.name, "web"); + + // var stanza = file.item("settings"); + // test.ok(stanza); + // stanza.fetch(done); + // }, + // function(stanza, done) { + // test.ok(stanza.properties().hasOwnProperty("httpport")); + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // }); + // }, + + // "Callback#configurations init": function(test) { + // test.throws(function() { + // var confs = new splunkjs.Service.Configurations( + // this.service, + // {owner: "-", app: "-", sharing: "system"} + // ); + // }); + // test.done(); + // }, + + // "Callback#create file + create stanza + update stanza": function(test) { + // var that = this; + // var namespace = {owner: "nobody", app: "system"}; + // var fileName = "jssdk_file_" + getNextId(); + // var value = "barfoo_" + getNextId(); + + // Async.chain([ + // function(done) { + // var configs = svc.configurations(namespace); + // configs.fetch(done); + // }, + // function(configs, done) { + // configs.create({__conf: fileName}, done); + // }, + // function(file, done) { + // if (file.item("stanza")) { + // file.item("stanza").remove(); + // } + // file.create("stanza", done); + // }, + // function(stanza, done) { + // stanza.update({"jssdk_foobar": value}, done); + // }, + // function(stanza, done) { + // test.strictEqual(stanza.properties()["jssdk_foobar"], value); + // done(); + // }, + // function(done) { + // var file = new splunkjs.Service.ConfigurationFile(svc, fileName); + // file.fetch(done); + // }, + // function(file, done) { + // var stanza = file.item("stanza"); + // test.ok(stanza); + // stanza.remove(done); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // }); + // }, + + // "Callback#can get default stanza": function(test) { + // var that = this; + // var namespace = {owner: "admin", app: "search"}; + + // Async.chain([ + // function(done) { that.service.configurations(namespace).fetch(done); }, + // function(props, done) { + // var file = props.item("savedsearches"); + // test.strictEqual(namespace, file.namespace); + // test.ok(file); + // file.fetch(done); + // }, + // function(file, done) { + // test.strictEqual(namespace, file.namespace); + // file.getDefaultStanza().fetch(done); + // }, + // function(stanza, done) { + // test.strictEqual(stanza.name, "default"); + // test.strictEqual(namespace, stanza.namespace); + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // }); + // }, + + // "Callback#updating default stanza is noop": function(test) { + // var that = this; + // var namespace = {owner: "admin", app: "search"}; + // var backup = null; + // var invalid = "this won't work"; + + // Async.chain([ + // function(done) { that.service.configurations(namespace).fetch(done); }, + // function(props, done) { + // var file = props.item("savedsearches"); + // test.strictEqual(namespace, file.namespace); + // test.ok(file); + // file.fetch(done); + // }, + // function(file, done) { + // test.strictEqual(namespace, file.namespace); + // file.getDefaultStanza().fetch(done); + // }, + // function(stanza, done) { + // test.ok(stanza._properties.hasOwnProperty("max_concurrent")); + // test.strictEqual(namespace, stanza.namespace); + // backup = stanza._properties.max_concurrent; + // stanza.update({"max_concurrent": invalid}, done); + // }, + // function(stanza, done) { + // test.ok(stanza.properties().hasOwnProperty("max_concurrent")); + // test.strictEqual(stanza.properties()["max_concurrent"], backup); + // test.notStrictEqual(stanza.properties()["max_concurrent"], invalid); + // stanza.fetch(done); + // }, + // function(stanza, done) { + // test.ok(stanza.properties().hasOwnProperty("max_concurrent")); + // test.strictEqual(stanza.properties()["max_concurrent"], backup); + // test.notStrictEqual(stanza.properties()["max_concurrent"], invalid); + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // }); + // } + // }, + + // "Storage Passwords Tests": { + // setUp: function(done) { + // this.service = svc; + // done(); + // }, + + // "Callback#Create": function(test) { + // var startcount = -1; + // var name = "delete-me-" + getNextId(); + // var realm = "delete-me-" + getNextId(); + // var that = this; + // Async.chain([ + // function(done) { + // that.service.storagePasswords().fetch(done); + // }, + // function(storagePasswords, done) { + // startcount = storagePasswords.list().length; + // storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); + // }, + // function(storagePassword, done) { + // test.strictEqual(name, storagePassword.properties().username); + // test.strictEqual(realm + ":" + name + ":", storagePassword.name); + // test.strictEqual("changed!", storagePassword.properties().clear_password); + // test.strictEqual(realm, storagePassword.properties().realm); + // that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); + // }, + // function(storagePasswords, storagePassword, done) { + // test.strictEqual(startcount + 1, storagePasswords.list().length); + // storagePassword.remove(done); + // }, + // function(done) { + // that.service.storagePasswords().fetch(done); + // }, + // function(storagePasswords, done) { + // test.strictEqual(startcount, storagePasswords.list().length); + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Create with backslashes": function(test) { + // var startcount = -1; + // var name = "\\delete-me-" + getNextId(); + // var realm = "\\delete-me-" + getNextId(); + // var that = this; + // Async.chain([ + // function(done) { + // that.service.storagePasswords().fetch(done); + // }, + // function(storagePasswords, done) { + // startcount = storagePasswords.list().length; + // storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); + // }, + // function(storagePassword, done) { + // test.strictEqual(name, storagePassword.properties().username); + // test.strictEqual("\\" + realm + ":\\" + name + ":", storagePassword.name); + // test.strictEqual("changed!", storagePassword.properties().clear_password); + // test.strictEqual(realm, storagePassword.properties().realm); + // that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); + // }, + // function(storagePasswords, storagePassword, done) { + // test.strictEqual(startcount + 1, storagePasswords.list().length); + // storagePassword.remove(done); + // }, + // function(done) { + // that.service.storagePasswords().fetch(done); + // }, + // function(storagePasswords, done) { + // test.strictEqual(startcount, storagePasswords.list().length); + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Create with slashes": function(test) { + // var startcount = -1; + // var name = "/delete-me-" + getNextId(); + // var realm = "/delete-me-" + getNextId(); + // var that = this; + // Async.chain([ + // function(done) { + // that.service.storagePasswords().fetch(done); + // }, + // function(storagePasswords, done) { + // startcount = storagePasswords.list().length; + // storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); + // }, + // function(storagePassword, done) { + // test.strictEqual(name, storagePassword.properties().username); + // test.strictEqual(realm + ":" + name + ":", storagePassword.name); + // test.strictEqual("changed!", storagePassword.properties().clear_password); + // test.strictEqual(realm, storagePassword.properties().realm); + // that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); + // }, + // function(storagePasswords, storagePassword, done) { + // test.strictEqual(startcount + 1, storagePasswords.list().length); + // storagePassword.remove(done); + // }, + // function(done) { + // that.service.storagePasswords().fetch(done); + // }, + // function(storagePasswords, done) { + // test.strictEqual(startcount, storagePasswords.list().length); + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Create without realm": function(test) { + // var startcount = -1; + // var name = "delete-me-" + getNextId(); + // var that = this; + // Async.chain([ + // function(done) { + // that.service.storagePasswords().fetch(done); + // }, + // function(storagePasswords, done) { + // startcount = storagePasswords.list().length; + // storagePasswords.create({name: name, password: "changed!"}, done); + // }, + // function(storagePassword, done) { + // test.strictEqual(name, storagePassword.properties().username); + // test.strictEqual(":" + name + ":", storagePassword.name); + // test.strictEqual("changed!", storagePassword.properties().clear_password); + // test.strictEqual("", storagePassword.properties().realm); + // that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); + // }, + // function(storagePasswords, storagePassword, done) { + // test.strictEqual(startcount + 1, storagePasswords.list().length); + // storagePassword.remove(done); + // }, + // function(done) { + // that.service.storagePasswords().fetch(done); + // }, + // function(storagePasswords, done) { + // test.strictEqual(startcount, storagePasswords.list().length); + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Create should fail without user, or realm": function(test) { + // var that = this; + // Async.chain([ + // function(done) { + // that.service.storagePasswords().fetch(done); + // }, + // function(storagePasswords, done) { + // storagePasswords.create({name: null, password: "changed!"}, done); + // } + // ], + // function(err) { + // test.ok(err); + // test.done(); + // } + // ); + // }, + + // "Callback#Create should fail without password": function(test) { + // var that = this; + // Async.chain([ + // function(done) { + // that.service.storagePasswords().fetch(done); + // }, + // function(storagePasswords, done) { + // storagePasswords.create({name: "something", password: null}, done); + // } + // ], + // function(err) { + // test.ok(err); + // test.done(); + // } + // ); + // }, + + // "Callback#Create should fail without user, realm, or password": function(test) { + // var that = this; + // Async.chain([ + // function(done) { + // that.service.storagePasswords().fetch(done); + // }, + // function(storagePasswords, done) { + // storagePasswords.create({name: null, password: null}, done); + // } + // ], + // function(err) { + // test.ok(err); + // test.done(); + // } + // ); + // }, + + // "Callback#Create with colons": function(test) { + // var startcount = -1; + // var name = ":delete-me-" + getNextId(); + // var realm = ":delete-me-" + getNextId(); + // var that = this; + // Async.chain([ + // function(done) { + // that.service.storagePasswords().fetch(done); + // }, + // function(storagePasswords, done) { + // startcount = storagePasswords.list().length; + // storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); + // }, + // function(storagePassword, done) { + // test.strictEqual(name, storagePassword.properties().username); + // test.strictEqual("\\" + realm + ":\\" + name + ":", storagePassword.name); + // test.strictEqual("changed!", storagePassword.properties().clear_password); + // test.strictEqual(realm, storagePassword.properties().realm); + // that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); + // }, + // function(storagePasswords, storagePassword, done) { + // test.strictEqual(startcount + 1, storagePasswords.list().length); + // storagePassword.remove(done); + // }, + // function(done) { + // that.service.storagePasswords().fetch(done); + // }, + // function(storagePasswords, done) { + // test.strictEqual(startcount, storagePasswords.list().length); + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Create crazy": function(test) { + // var startcount = -1; + // var name = "delete-me-" + getNextId(); + // var realm = "delete-me-" + getNextId(); + // var that = this; + // Async.chain([ + // function(done) { + // that.service.storagePasswords().fetch(done); + // }, + // function(storagePasswords, done) { + // startcount = storagePasswords.list().length; + // storagePasswords.create({ + // name: name + ":end!@#$%^&*()_+{}:|<>?", + // realm: ":start::!@#$%^&*()_+{}:|<>?" + realm, + // password: "changed!"}, + // done); + // }, + // function(storagePassword, done) { + // test.strictEqual(name + ":end!@#$%^&*()_+{}:|<>?", storagePassword.properties().username); + // test.strictEqual("\\:start\\:\\:!@#$%^&*()_+{}\\:|<>?" + realm + ":" + name + "\\:end!@#$%^&*()_+{}\\:|<>?:", storagePassword.name); + // test.strictEqual("changed!", storagePassword.properties().clear_password); + // test.strictEqual(":start::!@#$%^&*()_+{}:|<>?" + realm, storagePassword.properties().realm); + // that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); + // }, + // function(storagePasswords, storagePassword, done) { + // test.strictEqual(startcount + 1, storagePasswords.list().length); + // storagePassword.remove(done); + // }, + // function(done) { + // that.service.storagePasswords().fetch(done); + // }, + // function(storagePasswords, done) { + // test.strictEqual(startcount, storagePasswords.list().length); + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Create with unicode chars": function(test) { + // var startcount = -1; + // var name = "delete-me-" + getNextId(); + // var realm = "delete-me-" + getNextId(); + // var that = this; + // Async.chain([ + // function(done) { + // that.service.storagePasswords().fetch(done); + // }, + // function(storagePasswords, done) { + // startcount = storagePasswords.list().length; + // storagePasswords.create({ + // name: name + ":end!@#$%^&*()_+{}:|<>?쎼 and 쎶 and <&> für", + // realm: ":start::!@#$%^&*()_+{}:|<>?" + encodeURIComponent("쎼 and 쎶 and <&> für") + realm, + // password: decodeURIComponent(encodeURIComponent("쎼 and 쎶 and <&> für"))}, + // done); + // }, + // function(storagePassword, done) { + // test.strictEqual(name + ":end!@#$%^&*()_+{}:|<>?쎼 and 쎶 and <&> für", storagePassword.properties().username); + // test.strictEqual("\\:start\\:\\:!@#$%^&*()_+{}\\:|<>?" + encodeURIComponent("쎼 and 쎶 and <&> für") + realm + ":" + name + "\\:end!@#$%^&*()_+{}\\:|<>?쎼 and 쎶 and <&> für:", storagePassword.name); + // test.strictEqual(decodeURIComponent(encodeURIComponent("쎼 and 쎶 and <&> für")), storagePassword.properties().clear_password); + // test.strictEqual(":start::!@#$%^&*()_+{}:|<>?" + encodeURIComponent("쎼 and 쎶 and <&> für") + realm, storagePassword.properties().realm); + // that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); + // }, + // function(storagePasswords, storagePassword, done) { + // test.strictEqual(startcount + 1, storagePasswords.list().length); + // storagePassword.remove(done); + // }, + // function(done) { + // that.service.storagePasswords().fetch(done); + // }, + // function(storagePasswords, done) { + // test.strictEqual(startcount, storagePasswords.list().length); + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Read": function(test) { + // var startcount = -1; + // var name = "delete-me-" + getNextId(); + // var realm = "delete-me-" + getNextId(); + // var that = this; + // Async.chain([ + // function(done) { + // that.service.storagePasswords().fetch(done); + // }, + // function(storagePasswords, done) { + // startcount = storagePasswords.list().length; + // storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); + // }, + // function(storagePassword, done) { + // test.strictEqual(name, storagePassword.properties().username); + // test.strictEqual(realm + ":" + name + ":", storagePassword.name); + // test.strictEqual("changed!", storagePassword.properties().clear_password); + // test.strictEqual(realm, storagePassword.properties().realm); + // that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); + // }, + // function(storagePasswords, storagePassword, done) { + // try { + // test.ok(!!storagePasswords.item(realm + ":" + name + ":")); + // } + // catch (e) { + // test.ok(false); + // } + + // var list = storagePasswords.list(); + // var found = false; + + // test.strictEqual(startcount + 1, list.length); + // for (var i = 0; i < list.length; i ++) { + // if (realm + ":" + name + ":" === list[i].name) { + // found = true; + // } + // } + // test.ok(found); + + // storagePassword.remove(done); + // }, + // function(done) { + // that.service.storagePasswords().fetch(done); + // }, + // function(storagePasswords, done) { + // test.strictEqual(startcount, storagePasswords.list().length); + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Read with slashes": function(test) { + // var startcount = -1; + // var name = "/delete-me-" + getNextId(); + // var realm = "/delete-me-" + getNextId(); + // var that = this; + // Async.chain([ + // function(done) { + // that.service.storagePasswords().fetch(done); + // }, + // function(storagePasswords, done) { + // startcount = storagePasswords.list().length; + // storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); + // }, + // function(storagePassword, done) { + // test.strictEqual(name, storagePassword.properties().username); + // test.strictEqual(realm + ":" + name + ":", storagePassword.name); + // test.strictEqual("changed!", storagePassword.properties().clear_password); + // test.strictEqual(realm, storagePassword.properties().realm); + // that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); + // }, + // function(storagePasswords, storagePassword, done) { + // try { + // test.ok(!!storagePasswords.item(realm + ":" + name + ":")); + // } + // catch (e) { + // test.ok(false); + // } + + // var list = storagePasswords.list(); + // var found = false; + + // test.strictEqual(startcount + 1, list.length); + // for (var i = 0; i < list.length; i ++) { + // if (realm + ":" + name + ":" === list[i].name) { + // found = true; + // } + // } + // test.ok(found); + + // storagePassword.remove(done); + // }, + // function(done) { + // that.service.storagePasswords().fetch(done); + // }, + // function(storagePasswords, done) { + // test.strictEqual(startcount, storagePasswords.list().length); + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Update": function(test) { + // var startcount = -1; + // var name = "delete-me-" + getNextId(); + // var realm = "delete-me-" + getNextId(); + // var that = this; + // Async.chain([ + // function(done) { + // that.service.storagePasswords().fetch(done); + // }, + // function(storagePasswords, done) { + // startcount = storagePasswords.list().length; + // storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); + // }, + // function(storagePassword, done) { + // test.strictEqual(name, storagePassword.properties().username); + // test.strictEqual(realm + ":" + name + ":", storagePassword.name); + // test.strictEqual("changed!", storagePassword.properties().clear_password); + // test.strictEqual(realm, storagePassword.properties().realm); + // that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); + // }, + // function(storagePasswords, storagePassword, done) { + // test.strictEqual(startcount + 1, storagePasswords.list().length); + // storagePassword.update({password: "changed"}, done); + // }, + // function(storagePassword, done) { + // test.strictEqual(name, storagePassword.properties().username); + // test.strictEqual(realm + ":" + name + ":", storagePassword.name); + // test.strictEqual("changed", storagePassword.properties().clear_password); + // test.strictEqual(realm, storagePassword.properties().realm); + // that.service.storagePasswords().fetch(done); + // }, + // function(storagePasswords, done) { + // var list = storagePasswords.list(); + // var found = false; + // var index = -1; + + // test.strictEqual(startcount + 1, list.length); + // for (var i = 0; i < list.length; i ++) { + // if (realm + ":" + name + ":" === list[i].name) { + // found = true; + // index = i; + // test.strictEqual(name, list[i].properties().username); + // test.strictEqual(realm + ":" + name + ":", list[i].name); + // test.strictEqual("changed", list[i].properties().clear_password); + // test.strictEqual(realm, list[i].properties().realm); + // } + // } + // test.ok(found); + + // if (!found) { + // done(new Error("Didn't find the created password")); + // } + // else { + // list[index].remove(done); + // } + // }, + // function(done) { + // that.service.storagePasswords().fetch(done); + // }, + // function(storagePasswords, done) { + // test.strictEqual(startcount, storagePasswords.list().length); + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Delete": function(test) { + // var startcount = -1; + // var name = "delete-me-" + getNextId(); + // var realm = "delete-me-" + getNextId(); + // var that = this; + // Async.chain([ + // function(done) { + // that.service.storagePasswords().fetch(done); + // }, + // function(storagePasswords, done) { + // startcount = storagePasswords.list().length; + // storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); + // }, + // function(storagePassword, done) { + // test.strictEqual(name, storagePassword.properties().username); + // test.strictEqual(realm + ":" + name + ":", storagePassword.name); + // test.strictEqual("changed!", storagePassword.properties().clear_password); + // test.strictEqual(realm, storagePassword.properties().realm); + // that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); + // }, + // function(storagePasswords, storagePassword, done) { + // test.strictEqual(startcount + 1, storagePasswords.list().length); + // storagePassword.remove(done); + // }, + // function(done) { + // that.service.storagePasswords().fetch(done); + // }, + // function(storagePasswords, done) { + // test.strictEqual(startcount, storagePasswords.list().length); + // storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); + // }, + // function(storagePassword, done) { + // test.strictEqual(name, storagePassword.properties().username); + // that.service.storagePasswords().fetch(done); + // }, + // function(storagePasswords, done) { + // test.strictEqual(startcount + 1, storagePasswords.list().length); + // var list = storagePasswords.list(); + // var found = false; + // var index = -1; + + // test.strictEqual(startcount + 1, list.length); + // for (var i = 0; i < list.length; i ++) { + // if (realm + ":" + name + ":" === list[i].name) { + // found = true; + // index = i; + // test.strictEqual(name, list[i].properties().username); + // test.strictEqual(realm + ":" + name + ":", list[i].name); + // test.strictEqual("changed!", list[i].properties().clear_password); + // test.strictEqual(realm, list[i].properties().realm); + // } + // } + // test.ok(found); + + // if (!found) { + // done(new Error("Didn't find the created password")); + // } + // else { + // list[index].remove(done); + // } + // }, + // function(done) { + // that.service.storagePasswords().fetch(done); + // }, + // function(storagePasswords, done) { + // test.strictEqual(startcount, storagePasswords.list().length); + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // } + // }, + + // "Index Tests": { + // setUp: function(done) { + // this.service = svc; + // this.loggedOutService = loggedOutSvc; + + // // Create the index for everyone to use + // var name = this.indexName = "sdk-tests"; + // var indexes = this.service.indexes(); + // indexes.create(name, {}, function(err, index) { + // if (err && err.status !== 409) { + // throw new Error("Index creation failed for an unknown reason"); + // } + + // done(); + // }); + // }, + + // "Callback#remove index fails on Splunk 4.x": function(test) { + // var original_version = this.service.version; + // this.service.version = "4.0"; + + // var index = this.service.indexes().item(this.indexName); + // test.throws(function() { index.remove(function(err) {}); }); + + // this.service.version = original_version; + // test.done(); + // }, + + // "Callback#remove index": function(test) { + // var indexes = this.service.indexes(); + + // // Must generate a private index because an index cannot + // // be recreated with the same name as a deleted index + // // for a certain period of time after the deletion. + // var salt = Math.floor(Math.random() * 65536); + // var myIndexName = this.indexName + '-' + salt; + + // if (this.service.versionCompare("5.0") < 0) { + // splunkjs.Logger.info("", "Must be running Splunk 5.0+ for this test to work."); + // test.done(); + // return; + // } + + // Async.chain([ + // function(callback) { + // indexes.create(myIndexName, {}, callback); + // }, + // function(index, callback) { + // index.remove(callback); + // }, + // function(callback) { + // var numTriesLeft = 50; + // var delayPerTry = 100; // ms + + // Async.whilst( + // function() { return indexes.item(myIndexName) && ((numTriesLeft--) > 0); }, + // function(iterDone) { + // Async.sleep(delayPerTry, function() { indexes.fetch(iterDone); }); + // }, + // function(err) { + // if (err) { + // callback(err); + // } + // else { + // callback(numTriesLeft <= 0 ? "Timed out" : null); + // } + // } + // ); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#list indexes": function(test) { + // var indexes = this.service.indexes(); + // indexes.fetch(function(err, indexes) { + // var indexList = indexes.list(); + // test.ok(indexList.length > 0); + // test.done(); + // }); + // }, + + // "Callback#contains index": function(test) { + // var indexes = this.service.indexes(); + // var indexName = this.indexName; + + // indexes.fetch(function(err, indexes) { + // var index = indexes.item(indexName); + // test.ok(index); + // test.done(); + // }); + // }, + + // "Callback#modify index": function(test) { + + // var name = this.indexName; + // var indexes = this.service.indexes(); + // var originalSyncMeta = false; + + // Async.chain([ + // function(callback) { + // indexes.fetch(callback); + // }, + // function(indexes, callback) { + // var index = indexes.item(name); + // test.ok(index); + + // originalSyncMeta = index.properties().syncMeta; + // index.update({ + // syncMeta: !originalSyncMeta + // }, callback); + // }, + // function(index, callback) { + // test.ok(index); + // var properties = index.properties(); + + // test.strictEqual(!originalSyncMeta, properties.syncMeta); + + // index.update({ + // syncMeta: !properties.syncMeta + // }, callback); + // }, + // function(index, callback) { + // test.ok(index); + // var properties = index.properties(); + + // test.strictEqual(originalSyncMeta, properties.syncMeta); + // callback(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Enable+disable index": function(test) { + + // var name = this.indexName; + // var indexes = this.service.indexes(); + + // Async.chain([ + // function(callback) { + // indexes.fetch(callback); + // }, + // function(indexes, callback) { + // var index = indexes.item(name); + // test.ok(index); + + // index.disable(callback); + // }, + // function(index, callback) { + // test.ok(index); + // index.fetch(callback); + // }, + // function(index, callback) { + // test.ok(index); + // test.ok(index.properties().disabled); + + // index.enable(callback); + // }, + // function(index, callback) { + // test.ok(index); + // index.fetch(callback); + // }, + // function(index, callback) { + // test.ok(index); + // test.ok(!index.properties().disabled); + + // callback(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Service submit event": function(test) { + // var message = "Hello World -- " + getNextId(); + // var sourcetype = "sdk-tests"; + + // var service = this.service; + // var indexName = this.indexName; + // Async.chain( + // function(done) { + // service.log(message, {sourcetype: sourcetype, index: indexName}, done); + // }, + // function(eventInfo, done) { + // test.ok(eventInfo); + // test.strictEqual(eventInfo.sourcetype, sourcetype); + // test.strictEqual(eventInfo.bytes, message.length); + // test.strictEqual(eventInfo.index, indexName); + + // // We could poll to make sure the index has eaten up the event, + // // but unfortunately this can take an unbounded amount of time. + // // As such, since we got a good response, we'll just be done with it. + // done(); + // }, + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Service submit event, omitting optional arguments": function(test) { + // var message = "Hello World -- " + getNextId(); + // var sourcetype = "sdk-tests"; + + // var service = this.service; + // var indexName = this.indexName; + // Async.chain( + // function(done) { + // service.log(message, done); + // }, + // function(eventInfo, done) { + // test.ok(eventInfo); + // test.strictEqual(eventInfo.bytes, message.length); + + // // We could poll to make sure the index has eaten up the event, + // // but unfortunately this can take an unbounded amount of time. + // // As such, since we got a good response, we'll just be done with it. + // done(); + // }, + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Service submit events with multi-byte chars": function(test) { + // var service = this.service; + // var messages = [ + // "Ummelner Straße 6", + // "Ümmelner Straße 6", + // "Iԉtérԉátíòлåɭìƶåtiòл", + // "Intérnâtì߀лàɭíƶɑtïòл", + // "ãϻét dòner turƙëy ѵ߀lù", + // "ptãte ìԉ rëρrèhënԁérit ", + // "ϻ߀lɭit fìɭèt ϻìǥnoԉ ɭäb߀ríѕ", + // " êӽ cɦùck cüpïᏧåtåt Ꮷèѕëruлt. ", + // "D߀ɭor ѵélít ìrurè, sèᏧ ѕhòr", + // "t riƅѕ c߀ɰ ɭãnԁյàéɢêr drúmst", + // "ícƙ. Minïm ƃàɭl tip ѕհòrt rìƃѕ,", + // " ïԁ aɭïqúìρ ѕɦànƙ ρ߀rcɦéttɑ. Pìǥ", + // " hãm ɦòck ìлcídíԁùԉt séԁ cüpïϻ ", + // "ƙèviл láborê. Et taiɭ ѕtriρ", + // " steák út üllãϻc߀ rump d߀ɭore.", + // "٩(͡๏̯͡๏)۶ ٩(-̮̮̃•̃).", + // "Lɑƅòré ƃrësãòlá d߀лèr ѕâlámí ", + // "cíllûm ìn ѕɯìлe ϻêàtɭ߀àf dûìs ", + // "ρãncettä ƅrìsƙét ԁèsêrûлt áútè", + // " յòɰɭ. Lɑbòrìѕ ƙìêɭ", + // "básá ԁòlòré fatƃɑck ƅêéf. Pɑѕtr", + // "ämì piɢ ѕհàлƙ ùɭɭamcò ѕaû", + // "ѕäǥë sɦànƙlë.", + // " Cúpím ɭäƃorum drumstïcƙ jerkϒ veli", + // " pïcåԉɦɑ ƙíéɭƅãsa. Alïqû", + // "iρ írürë cûpíϻ, äɭìɋuâ ǥròûлd ", + // "roúлᏧ toԉgüè ρàrìãtùr ", + // "briѕkèt ԉostruᏧ cûɭpɑ", + // " ìd còлѕèqûât làƅ߀rìs." + // ]; + + // var counter = 0; + // Async.seriesMap( + // messages, + // function(val, idx, done) { + // counter++; + // service.log(val, done); + // }, + // function(err, vals) { + // test.ok(!err); + // test.strictEqual(counter, messages.length); + + // // Verify that the full byte-length was sent for each message + // for (var m in messages) { + // test.notStrictEqual(messages[m].length, vals[m].bytes); + // try { + // test.strictEqual(Buffer.byteLength(messages[m]), vals[m].bytes); + // } + // catch (err) { + // // Assume Buffer isn't defined, we're probably in the browser + // test.strictEqual(decodeURI(encodeURIComponent(messages[m])).length, vals[m].bytes); + // } + // } + + // test.done(); + // } + // ); + // }, + + // "Callback#Service submit event, failure": function(test) { + // var message = "Hello World -- " + getNextId(); + // var sourcetype = "sdk-tests"; + + // var service = this.loggedOutService; + // var indexName = this.indexName; + // Async.chain( + // function(done) { + // test.ok(service); + // service.log(message, done); + // }, + // function(err) { + // test.ok(err); + // test.done(); + // } + // ); + // }, + + // "Callback#remove throws an error": function(test) { + // var index = this.service.indexes().item("_internal"); + // test.throws(function() { + // index.remove(); + // }); + // test.done(); + // }, + + // "Callback#create an index with alternate argument format": function(test) { + // var indexes = this.service.indexes(); + // indexes.create( + // {name: "_internal"}, + // function(err, newIndex) { + // test.ok(err.data.messages[0].text.match("name=_internal already exists")); + // test.done(); + // } + // ); + // }, + + // "Callback#Index submit event with omitted optional arguments": function(test) { + // var message = "Hello world -- " + getNextId(); + + // var indexName = this.indexName; + // var indexes = this.service.indexes(); + + // Async.chain( + // [ + // function(done) { + // indexes.fetch(done); + // }, + // function(indexes, done) { + // var index = indexes.item(indexName); + // test.ok(index); + // test.strictEqual(index.name, indexName); + // index.submitEvent(message, done); + // }, + // function(eventInfo, index, done) { + // test.ok(eventInfo); + // test.strictEqual(eventInfo.bytes, message.length); + // test.strictEqual(eventInfo.index, indexName); + + // // We could poll to make sure the index has eaten up the event, + // // but unfortunately this can take an unbounded amount of time. + // // As such, since we got a good response, we'll just be done with it. + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Index submit event": function(test) { + // var message = "Hello World -- " + getNextId(); + // var sourcetype = "sdk-tests"; + + // var indexName = this.indexName; + // var indexes = this.service.indexes(); + // Async.chain([ + // function(done) { + // indexes.fetch(done); + // }, + // function(indexes, done) { + // var index = indexes.item(indexName); + // test.ok(index); + // test.strictEqual(index.name, indexName); + // index.submitEvent(message, {sourcetype: sourcetype}, done); + // }, + // function(eventInfo, index, done) { + // test.ok(eventInfo); + // test.strictEqual(eventInfo.sourcetype, sourcetype); + // test.strictEqual(eventInfo.bytes, message.length); + // test.strictEqual(eventInfo.index, indexName); + + // // We could poll to make sure the index has eaten up the event, + // // but unfortunately this can take an unbounded amount of time. + // // As such, since we got a good response, we'll just be done with it. + // done(); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // } + // }, + + // "User Tests": { + // setUp: function(done) { + // this.service = svc; + // this.loggedOutService = loggedOutSvc; + // done(); + // }, + + // tearDown: function(done) { + // this.service.logout(done); + // }, + + // "Callback#Current user": function(test) { + // var service = this.service; + + // service.currentUser(function(err, user) { + // test.ok(!err); + // test.ok(user); + // test.strictEqual(user.name, service.username); + // test.done(); + // }); + // }, + + // "Callback#Current user fails": function(test) { + // var service = this.loggedOutService; + + // service.currentUser(function(err, user) { + // test.ok(err); + // test.done(); + // }); + // }, + + // "Callback#List users": function(test) { + // var service = this.service; + + // service.users().fetch(function(err, users) { + // var userList = users.list(); + // test.ok(!err); + // test.ok(users); + + // test.ok(userList); + // test.ok(userList.length > 0); + // test.done(); + // }); + // }, + + // "Callback#create user failure": function(test) { + // this.loggedOutService.users().create( + // {name: "jssdk_testuser", password: "abc", roles: "user"}, + // function(err, response) { + // test.ok(err); + // test.done(); + // } + // ); + // }, + + // "Callback#Create + update + delete user": function(test) { + // var service = this.service; + // var name = "jssdk_testuser"; + + // Async.chain([ + // function(done) { + // service.users().create({name: "jssdk_testuser", password: "abc", roles: "user"}, done); + // }, + // function(user, done) { + // test.ok(user); + // test.strictEqual(user.name, name); + // test.strictEqual(user.properties().roles.length, 1); + // test.strictEqual(user.properties().roles[0], "user"); + + // user.update({realname: "JS SDK", roles: ["admin", "user"]}, done); + // }, + // function(user, done) { + // test.ok(user); + // test.strictEqual(user.properties().realname, "JS SDK"); + // test.strictEqual(user.properties().roles.length, 2); + // test.strictEqual(user.properties().roles[0], "admin"); + // test.strictEqual(user.properties().roles[1], "user"); + + // user.remove(done); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#Roles": function(test) { + // var service = this.service; + // var name = "jssdk_testuser_" + getNextId(); + + // Async.chain([ + // function(done) { + // service.users().create({name: name, password: "abc", roles: "user"}, done); + // }, + // function(user, done) { + // test.ok(user); + // test.strictEqual(user.name, name); + // test.strictEqual(user.properties().roles.length, 1); + // test.strictEqual(user.properties().roles[0], "user"); + + // user.update({roles: ["admin", "user"]}, done); + // }, + // function(user, done) { + // test.ok(user); + // test.strictEqual(user.properties().roles.length, 2); + // test.strictEqual(user.properties().roles[0], "admin"); + // test.strictEqual(user.properties().roles[1], "user"); + + // user.update({roles: "user"}, done); + // }, + // function(user, done) { + // test.ok(user); + // test.strictEqual(user.properties().roles.length, 1); + // test.strictEqual(user.properties().roles[0], "user"); + + // user.update({roles: "__unknown__"}, done); + // } + // ], + // function(err) { + // test.ok(err); + // test.strictEqual(err.status, 400); + // test.done(); + // } + // ); + // }, + + // "Callback#Passwords": function(test) { + // var service = this.service; + // var newService = null; + // var name = "jssdk_testuser_" + getNextId(); + + // Async.chain([ + // function(done) { + // service.users().create({name: name, password: "abc", roles: "user"}, done); + // }, + // function(user, done) { + // test.ok(user); + // test.strictEqual(user.name, name); + // test.strictEqual(user.properties().roles.length, 1); + // test.strictEqual(user.properties().roles[0], "user"); + + // newService = new splunkjs.Service(service.http, { + // username: name, + // password: "abc", + // host: service.host, + // port: service.port, + // scheme: service.scheme, + // version: service.version + // }); + + // newService.login(Async.augment(done, user)); + // }, + // function(success, user, done) { + // test.ok(success); + // test.ok(user); + + // user.update({password: "abc2"}, done); + // }, + // function(user, done) { + // newService.login(function(err, success) { + // test.ok(err); + // test.ok(!success); + + // user.update({password: "abc"}, done); + // }); + // }, + // function(user, done) { + // test.ok(user); + // newService.login(done); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + // "Callback#delete test users": function(test) { + // var users = this.service.users(); + // users.fetch(function(err, users) { + // var userList = users.list(); + + // Async.parallelEach( + // userList, + // function(user, idx, callback) { + // if (utils.startsWith(user.name, "jssdk_")) { + // user.remove(callback); + // } + // else { + // callback(); + // } + // }, function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }); + // } + // }, + + // "Server Info Tests": { + // setUp: function(done) { + // this.service = svc; + // done(); + // }, + + // "Callback#Basic": function(test) { + // var service = this.service; + + // service.serverInfo(function(err, info) { + // test.ok(!err); + // test.ok(info); + // test.strictEqual(info.name, "server-info"); + // test.ok(info.properties().hasOwnProperty("version")); + // test.ok(info.properties().hasOwnProperty("serverName")); + // test.ok(info.properties().hasOwnProperty("os_version")); + + // test.done(); + // }); + // } + // }, "View Tests": { setUp: function(done) { @@ -22292,252 +22292,252 @@ exports.setup = function(svc, loggedOutSvc) { } }, - "Parser Tests": { - setUp: function(done) { - this.service = svc; - done(); - }, - - "Callback#Basic parse": function(test) { - var service = this.service; - - service.parse("search index=_internal | head 1", function(err, parse) { - test.ok(!err); - test.ok(parse); - test.ok(parse.commands.length > 0); - test.done(); - }); - }, - - "Callback#Parse error": function(test) { - var service = this.service; - - service.parse("ABCXYZ", function(err, parse) { - test.ok(err); - test.strictEqual(err.status, 400); - test.done(); - }); - } - }, - - "Typeahead Tests": { - setUp: function(done) { - this.service = svc; - this.loggedOutService = loggedOutSvc; - done(); - }, - - "Callback#Typeahead failure": function(test) { - var service = this.loggedOutService; - service.typeahead("index=", 1, function(err, options) { - test.ok(err); - test.done(); - }); - }, - - "Callback#Basic typeahead": function(test) { - var service = this.service; - - service.typeahead("index=", 1, function(err, options) { - test.ok(!err); - test.ok(options); - test.strictEqual(options.length, 1); - test.ok(options[0]); - test.done(); - }); - }, - - "Typeahead with omitted optional arguments": function(test) { - var service = this.service; - service.typeahead("index=", function(err, options) { - test.ok(!err); - test.ok(options); - test.done(); - }); - } - }, - - "Endpoint Tests": { - setUp: function(done) { - this.service = svc; - done(); - }, - - "Throws on null arguments to init": function(test) { - var service = this.service; - test.throws(function() { - var endpoint = new splunkjs.Service.Endpoint(null, "a/b"); - }); - test.throws(function() { - var endpoint = new splunkjs.Service.Endpoint(service, null); - }); - test.done(); - }, - - "Endpoint delete on a relative path": function(test) { - var service = this.service; - var endpoint = new splunkjs.Service.Endpoint(service, "/search/jobs/12345"); - endpoint.del("search/jobs/12345", {}, function() { test.done();}); - }, - - "Methods of Resource to be overridden": function(test) { - var service = this.service; - var resource = new splunkjs.Service.Resource(service, "/search/jobs/12345"); - test.throws(function() { resource.path(); }); - test.throws(function() { resource.fetch(); }); - test.ok(splunkjs.Utils.isEmpty(resource.state())); - test.done(); - } - }, - - "Entity tests": { - setUp: function(done) { - this.service = svc; - this.loggedOutService = loggedOutSvc; - done(); - }, - - "Accessors function properly": function(test) { - var entity = new splunkjs.Service.Entity( - this.service, - "/search/jobs/12345", - {owner: "boris", app: "factory", sharing: "app"} - ); - entity._load( - {acl: {owner: "boris", app: "factory", sharing: "app"}, - links: {link1: 35}, - published: "meep", - author: "Hilda"} - ); - test.ok(entity.acl().owner === "boris"); - test.ok(entity.acl().app === "factory"); - test.ok(entity.acl().sharing === "app"); - test.ok(entity.links().link1 === 35); - test.strictEqual(entity.author(), "Hilda"); - test.strictEqual(entity.published(), "meep"); - test.done(); - }, - - "Refresh throws error correctly": function(test) { - var entity = new splunkjs.Service.Entity(this.loggedOutService, "/search/jobs/12345", {owner: "boris", app: "factory", sharing: "app"}); - entity.fetch({}, function(err) { test.ok(err); test.done();}); - }, - - "Cannot update name of entity": function(test) { - var entity = new splunkjs.Service.Entity(this.service, "/search/jobs/12345", {owner: "boris", app: "factory", sharing: "app"}); - test.throws(function() { entity.update({name: "asdf"});}); - test.done(); - }, - - "Disable throws error correctly": function(test) { - var entity = new splunkjs.Service.Entity( - this.loggedOutService, - "/search/jobs/12345", - {owner: "boris", app: "factory", sharing: "app"} - ); - entity.disable(function(err) { test.ok(err); test.done();}); - }, - - "Enable throws error correctly": function(test) { - var entity = new splunkjs.Service.Entity( - this.loggedOutService, - "/search/jobs/12345", - {owner: "boris", app: "factory", sharing: "app"} - ); - entity.enable(function(err) { test.ok(err); test.done();}); - }, - - "Does reload work?": function(test) { - var idx = new splunkjs.Service.Index( - this.service, - "data/indexes/sdk-test", - { - owner: "admin", - app: "search", - sharing: "app" - } - ); - var name = "jssdk_testapp_" + getNextId(); - var apps = this.service.apps(); - - var that = this; - Async.chain( - function(done) { - apps.create({name: name}, done); - }, - function(app, done) { - app.reload(function(err) { - test.ok(!err); - done(null, app); - }); - }, - function(app, done) { - var app2 = new splunkjs.Service.Application(that.loggedOutService, app.name); - app2.reload(function(err) { - test.ok(err); - done(null, app); - }); - }, - function(app, done) { - app.remove(done); - }, - function(err) { - test.ok(!err); - test.done(); - } - ); - } - }, - - "Collection tests": { - setUp: function(done) { - this.service = svc; - this.loggedOutService = loggedOutSvc; - done(); - }, - - "Methods to be overridden throw": function(test) { - var coll = new splunkjs.Service.Collection( - this.service, - "/data/indexes", - {owner: "admin", - app: "search", - sharing: "app"} - ); - test.throws(function() { - coll.instantiateEntity({}); - }); - test.done(); - }, - - "Accessors work": function(test) { - var coll = new splunkjs.Service.Collection( - this.service, - "/data/indexes", - {owner: "admin", - app: "search", - sharing: "app"} - ); - coll._load({links: "Hilda", updated: true}); - test.strictEqual(coll.links(), "Hilda"); - test.ok(coll.updated()); - test.done(); - }, - - "Contains throws without a good id": function(test) { - var coll = new splunkjs.Service.Collection( - this.service, - "/data/indexes", - { - owner: "admin", - app: "search", - sharing: "app" - } - ); - test.throws(function() { coll.item(null);}); - test.done(); - } - } + // "Parser Tests": { + // setUp: function(done) { + // this.service = svc; + // done(); + // }, + + // "Callback#Basic parse": function(test) { + // var service = this.service; + + // service.parse("search index=_internal | head 1", function(err, parse) { + // test.ok(!err); + // test.ok(parse); + // test.ok(parse.commands.length > 0); + // test.done(); + // }); + // }, + + // "Callback#Parse error": function(test) { + // var service = this.service; + + // service.parse("ABCXYZ", function(err, parse) { + // test.ok(err); + // test.strictEqual(err.status, 400); + // test.done(); + // }); + // } + // }, + + // "Typeahead Tests": { + // setUp: function(done) { + // this.service = svc; + // this.loggedOutService = loggedOutSvc; + // done(); + // }, + + // "Callback#Typeahead failure": function(test) { + // var service = this.loggedOutService; + // service.typeahead("index=", 1, function(err, options) { + // test.ok(err); + // test.done(); + // }); + // }, + + // "Callback#Basic typeahead": function(test) { + // var service = this.service; + + // service.typeahead("index=", 1, function(err, options) { + // test.ok(!err); + // test.ok(options); + // test.strictEqual(options.length, 1); + // test.ok(options[0]); + // test.done(); + // }); + // }, + + // "Typeahead with omitted optional arguments": function(test) { + // var service = this.service; + // service.typeahead("index=", function(err, options) { + // test.ok(!err); + // test.ok(options); + // test.done(); + // }); + // } + // }, + + // "Endpoint Tests": { + // setUp: function(done) { + // this.service = svc; + // done(); + // }, + + // "Throws on null arguments to init": function(test) { + // var service = this.service; + // test.throws(function() { + // var endpoint = new splunkjs.Service.Endpoint(null, "a/b"); + // }); + // test.throws(function() { + // var endpoint = new splunkjs.Service.Endpoint(service, null); + // }); + // test.done(); + // }, + + // "Endpoint delete on a relative path": function(test) { + // var service = this.service; + // var endpoint = new splunkjs.Service.Endpoint(service, "/search/jobs/12345"); + // endpoint.del("search/jobs/12345", {}, function() { test.done();}); + // }, + + // "Methods of Resource to be overridden": function(test) { + // var service = this.service; + // var resource = new splunkjs.Service.Resource(service, "/search/jobs/12345"); + // test.throws(function() { resource.path(); }); + // test.throws(function() { resource.fetch(); }); + // test.ok(splunkjs.Utils.isEmpty(resource.state())); + // test.done(); + // } + // }, + + // "Entity tests": { + // setUp: function(done) { + // this.service = svc; + // this.loggedOutService = loggedOutSvc; + // done(); + // }, + + // "Accessors function properly": function(test) { + // var entity = new splunkjs.Service.Entity( + // this.service, + // "/search/jobs/12345", + // {owner: "boris", app: "factory", sharing: "app"} + // ); + // entity._load( + // {acl: {owner: "boris", app: "factory", sharing: "app"}, + // links: {link1: 35}, + // published: "meep", + // author: "Hilda"} + // ); + // test.ok(entity.acl().owner === "boris"); + // test.ok(entity.acl().app === "factory"); + // test.ok(entity.acl().sharing === "app"); + // test.ok(entity.links().link1 === 35); + // test.strictEqual(entity.author(), "Hilda"); + // test.strictEqual(entity.published(), "meep"); + // test.done(); + // }, + + // "Refresh throws error correctly": function(test) { + // var entity = new splunkjs.Service.Entity(this.loggedOutService, "/search/jobs/12345", {owner: "boris", app: "factory", sharing: "app"}); + // entity.fetch({}, function(err) { test.ok(err); test.done();}); + // }, + + // "Cannot update name of entity": function(test) { + // var entity = new splunkjs.Service.Entity(this.service, "/search/jobs/12345", {owner: "boris", app: "factory", sharing: "app"}); + // test.throws(function() { entity.update({name: "asdf"});}); + // test.done(); + // }, + + // "Disable throws error correctly": function(test) { + // var entity = new splunkjs.Service.Entity( + // this.loggedOutService, + // "/search/jobs/12345", + // {owner: "boris", app: "factory", sharing: "app"} + // ); + // entity.disable(function(err) { test.ok(err); test.done();}); + // }, + + // "Enable throws error correctly": function(test) { + // var entity = new splunkjs.Service.Entity( + // this.loggedOutService, + // "/search/jobs/12345", + // {owner: "boris", app: "factory", sharing: "app"} + // ); + // entity.enable(function(err) { test.ok(err); test.done();}); + // }, + + // "Does reload work?": function(test) { + // var idx = new splunkjs.Service.Index( + // this.service, + // "data/indexes/sdk-test", + // { + // owner: "admin", + // app: "search", + // sharing: "app" + // } + // ); + // var name = "jssdk_testapp_" + getNextId(); + // var apps = this.service.apps(); + + // var that = this; + // Async.chain( + // function(done) { + // apps.create({name: name}, done); + // }, + // function(app, done) { + // app.reload(function(err) { + // test.ok(!err); + // done(null, app); + // }); + // }, + // function(app, done) { + // var app2 = new splunkjs.Service.Application(that.loggedOutService, app.name); + // app2.reload(function(err) { + // test.ok(err); + // done(null, app); + // }); + // }, + // function(app, done) { + // app.remove(done); + // }, + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // } + // }, + + // "Collection tests": { + // setUp: function(done) { + // this.service = svc; + // this.loggedOutService = loggedOutSvc; + // done(); + // }, + + // "Methods to be overridden throw": function(test) { + // var coll = new splunkjs.Service.Collection( + // this.service, + // "/data/indexes", + // {owner: "admin", + // app: "search", + // sharing: "app"} + // ); + // test.throws(function() { + // coll.instantiateEntity({}); + // }); + // test.done(); + // }, + + // "Accessors work": function(test) { + // var coll = new splunkjs.Service.Collection( + // this.service, + // "/data/indexes", + // {owner: "admin", + // app: "search", + // sharing: "app"} + // ); + // coll._load({links: "Hilda", updated: true}); + // test.strictEqual(coll.links(), "Hilda"); + // test.ok(coll.updated()); + // test.done(); + // }, + + // "Contains throws without a good id": function(test) { + // var coll = new splunkjs.Service.Collection( + // this.service, + // "/data/indexes", + // { + // owner: "admin", + // app: "search", + // sharing: "app" + // } + // ); + // test.throws(function() { coll.item(null);}); + // test.done(); + // } + // } }; return suite; }; @@ -23123,7 +23123,7 @@ exports.main = function(opts, done) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; @@ -23201,7 +23201,7 @@ exports.main = function(opts, callback) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; @@ -23286,7 +23286,7 @@ exports.main = function(opts, callback) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; @@ -23425,7 +23425,7 @@ exports.main = function(opts, done) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; @@ -23523,7 +23523,7 @@ exports.main = function(opts, callback) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; @@ -23627,7 +23627,7 @@ exports.main = function(opts, done) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; @@ -23715,7 +23715,7 @@ exports.main = function(opts, done) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; @@ -23797,7 +23797,7 @@ exports.main = function(opts, callback) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; @@ -23955,7 +23955,7 @@ exports.main = function(opts, done) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; @@ -24029,7 +24029,7 @@ exports.main = function(opts, done) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; @@ -24108,7 +24108,7 @@ exports.main = function(opts, callback) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; @@ -24186,7 +24186,7 @@ exports.main = function(opts, done) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; @@ -24265,7 +24265,7 @@ exports.main = function(opts, done) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; @@ -24346,7 +24346,7 @@ exports.main = function(opts, callback) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; @@ -24446,7 +24446,7 @@ exports.main = function(opts, callback) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; @@ -24549,7 +24549,7 @@ exports.main = function(opts, callback) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; @@ -24635,7 +24635,7 @@ exports.main = function(opts, callback) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; @@ -24817,7 +24817,7 @@ exports.main = function(opts, done) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; @@ -25488,10 +25488,10 @@ require.define("/browser.test.entry.js", function (require, module, exports, __d // include it. window.SplunkTest = { - Utils : require('../../tests/test_utils'), - Async : require('../../tests/test_async'), - Http : require('../../tests/test_http'), - Context : require('../../tests/test_context'), + // Utils : require('../../tests/test_utils'), + // Async : require('../../tests/test_async'), + // Http : require('../../tests/test_http'), + // Context : require('../../tests/test_context'), Service : require('../../tests/test_service'), Examples : require('../../tests/test_examples') }; diff --git a/client/splunk.test.min.js b/client/splunk.test.min.js index aa96ad3ba..171b6965f 100644 --- a/client/splunk.test.min.js +++ b/client/splunk.test.min.js @@ -2,6 +2,6 @@ var __exportName = 'splunkjs'; -var require=function(a,b){var c=require.resolve(a,b||"/"),d=require.modules[c];if(!d)throw new Error("Failed to resolve module "+a+", tried "+c);var e=d._cached?d._cached:d();return e};require.paths=[],require.modules={},require.extensions=[".js",".coffee"],require._core={assert:!0,events:!0,fs:!0,path:!0,vm:!0},require.resolve=function(){return function(a,b){function g(a){if(require.modules[a])return a;for(var b=0;b=0;e--){if(b[e]==="node_modules")continue;var f=b.slice(0,e+1).join("/")+"/node_modules";d.push(f)}return d}b||(b="/");if(require._core[a])return a;var c=require.modules.path();b=c.resolve("/",b);var d=b||"/";if(a.match(/^(?:\.\.?\/|\/)/)){var e=g(c.resolve(d,a))||h(c.resolve(d,a));if(e)return e}var f=i(a,d);if(f)return f;throw new Error("Cannot find module '"+a+"'")}}(),require.alias=function(a,b){var c=require.modules.path(),d=null;try{d=require.resolve(a+"/package.json","/")}catch(e){d=require.resolve(a,"/")}var f=c.dirname(d),g=(Object.keys||function(a){var b=[];for(var c in a)b.push(c);return b})(require.modules);for(var h=0;h0){var c=a.shift();c()}}},!0),function(c){b?(a.push(c),window.postMessage("browserify-tick","*")):setTimeout(c,0)}}()),process.title||(process.title="browser"),process.binding||(process.binding=function(a){if(a==="evals")return require("vm");throw new Error("No such module")}),process.cwd||(process.cwd=function(){return"."}),require.define("path",function(a,b,c,d,e){function f(a,b){var c=[];for(var d=0;d=0;d--){var e=a[d];e=="."?a.splice(d,1):e===".."?(a.splice(d,1),c++):c&&(a.splice(d,1),c--)}if(b)for(;c--;c)a.unshift("..");return a}var h=/^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/;c.resolve=function(){var a="",b=!1;for(var c=arguments.length;c>=-1&&!b;c--){var d=c>=0?arguments[c]:process.cwd();if(typeof d!="string"||!d)continue;a=d+"/"+a,b=d.charAt(0)==="/"}return a=g(f(a.split("/"),function(a){return!!a}),!b).join("/"),(b?"/":"")+a||"."},c.normalize=function(a){var b=a.charAt(0)==="/",c=a.slice(-1)==="/";return a=g(f(a.split("/"),function(a){return!!a}),!b).join("/"),!a&&!b&&(a="."),a&&c&&(a+="/"),(b?"/":"")+a},c.join=function(){var a=Array.prototype.slice.call(arguments,0);return c.normalize(f(a,function(a,b){return a&&typeof a=="string"}).join("/"))},c.dirname=function(a){var b=h.exec(a)[1]||"",c=!1;return b?b.length===1||c&&b.length<=3&&b.charAt(1)===":"?b:b.substring(0,b.length-1):"."},c.basename=function(a,b){var c=h.exec(a)[2]||"";return b&&c.substr(-1*b.length)===b&&(c=c.substr(0,c.length-b.length)),c},c.extname=function(a){return h.exec(a)[3]||""}}),require.define("/tests/test_utils.js",function(a,b,c,d,e){c.setup=function(){var b=a("../index");return b.Logger.setLevel("ALL"),{"Callback#callback to object success":function(a){var b=function(a){a(null,"one","two")};b(function(b,c,d){a.strictEqual(c,"one"),a.strictEqual(d,"two"),a.done()})},"Callback#callback to object error - single argument":function(a){var b=function(a){a("one")};b(function(b,c,d){a.strictEqual(b,"one"),a.ok(!c),a.ok(!d),a.done()})},"Callback#callback to object error - multi argument":function(a){var b=function(a){a(["one","two"])};b(function(b,c,d){a.strictEqual(b[0],"one"),a.strictEqual(b[1],"two"),a.ok(!c),a.ok(!d),a.done()})},"keyOf works":function(a){a.ok(b.Utils.keyOf(3,{a:3,b:5})),a.ok(!b.Utils.keyOf(3,{a:12,b:6})),a.done()},bind:function(a){var c;(function(){c=function(a){this.a=a}})();var d={},e=b.Utils.bind(d,c);e(12),a.strictEqual(d.a,12),a.done()},trim:function(a){a.strictEqual(b.Utils.trim(" test of something \n\r \t"),"test of something");var c=String.prototype.trim;String.prototype.trim=null,a.strictEqual(b.Utils.trim(" test of something \n\r \t"),"test of something"),String.prototype.trim=c,a.done()},indexOf:function(a){a.strictEqual(b.Utils.indexOf([1,2,3,4,5],3),2),a.strictEqual(b.Utils.indexOf([1,2,3,4,3],3),2),a.strictEqual(b.Utils.indexOf([1,2,3,4,5],12),-1),a.done()},contains:function(a){a.ok(b.Utils.contains([1,2,3,4,5],3)),a.ok(b.Utils.contains([1,2,3,4,3],3)),a.ok(!b.Utils.contains([1,2,3,4,5],12)),a.done()},startsWith:function(a){a.ok(b.Utils.startsWith("abcdefg","abc")),a.ok(!b.Utils.startsWith("bcdefg","abc")),a.done()},endsWith:function(a){a.ok(b.Utils.endsWith("abcdef","def")),a.ok(!b.Utils.endsWith("abcdef","bcd")),a.done()},toArray:function(a){(function(){var c=b.Utils.toArray(arguments),d=[1,2,3,4,5];for(var e=0;e=e.ALL&&g.apply(null,arguments)},error:function(){process.env.LOG_LEVEL>=e.ERROR&&i.apply(null,arguments)},warn:function(){process.env.LOG_LEVEL>=e.WARN&&h.apply(null,arguments)},info:function(){process.env.LOG_LEVEL>=e.INFO&&j.apply(null,arguments)},printMessages:function(a){a=a||[];for(var b=0;b=0},e.startsWith=function(a,b){var c=a.match("^"+b);return c&&c.length>0&&c[0]===b},e.endsWith=function(a,b){var c=a.match(b+"$");return c&&c.length>0&&c[0]===b};var f=Object.prototype.toString;e.toArray=function(a){return Array.prototype.slice.call(a)},e.isArray=Array.isArray||function(a){return f.call(a)==="[object Array]"},e.isFunction=function(a){return!!(a&&a.constructor&&a.call&&a.apply)},e.isNumber=function(a){return!!(a===0||a&&a.toExponential&&a.toFixed)},e.isString=function(a){return!!(a===""||a&&a.charCodeAt&&a.substr)},e.isObject=function(a){return a===Object(a)},e.isEmpty=function(a){if(e.isArray(a)||e.isString(a))return a.length===0;for(var b in a)if(this.hasOwnProperty.call(a,b))return!1;return!0},e.forEach=function(a,b,c){if(a===null)return;if(Array.prototype.forEach&&a.forEach===Array.prototype.forEach)a.forEach(b,c);else if(a.length===+a.length){for(var d=0,e=a.length;dh)return 1}return 0}}),h.Sharing={USER:"user",APP:"app",GLOBAL:"global",SYSTEM:"system"}})()}),require.define("/lib/paths.js",function(a,b,c,d,e){(function(){"use strict";var a=c||this;a.Paths={apps:"/services/apps/local",capabilities:"authorization/capabilities",configurations:"configs",dataModels:"datamodel/model",deploymentClient:"deployment/client",deploymentServers:"deployment/server",deploymentServerClasses:"deployment/serverclass",deploymentTenants:"deployment/tenants",eventTypes:"saved/eventtypes",firedAlerts:"alerts/fired_alerts",indexes:"data/indexes",info:"/services/server/info",inputs:null,jobs:"search/jobs",licenseGroups:"licenser/groups",licenseMessages:"licenser/messages",licensePools:"licenser/pools",licenseSlaves:"licenser/slaves",licenseStacks:"licenser/stacks",licenses:"licenser/licenses",loggers:"server/logger",login:"/services/auth/login",messages:"messages",passwords:"admin/passwords",parser:"search/parser",pivot:"datamodel/pivot",properties:"properties",roles:"authorization/roles",savedSearches:"saved/searches",settings:"server/settings",storagePasswords:"storage/passwords",users:"/services/authentication/users",typeahead:"search/typeahead",views:"data/ui/views",currentUser:"/services/authentication/current-context",submitEvent:"/services/receivers/simple"}})()}),require.define("/lib/jquery.class.js",function(a,b,c,d,e){(function(){var a=c||this,b=!1,d=/xyz/.test(function(){return xyz})?/\b_super\b/:/.*/;a.Class=function(){},a.Class.extend=function(a){function g(){!b&&this.init&&this.init.apply(this,arguments)}var c=this.prototype;b=!0;var e=new this;b=!1;for(var f in a)e[f]=typeof a[f]=="function"&&typeof c[f]=="function"&&d.test(a[f])?function(a,b){return function(){var d=this._super;this._super=c[a];var e=b.apply(this,arguments);return this._super=d,e}}(f,a[f]):a[f];return g.prototype=e,g.constructor=g,g.extend=arguments.callee,g}})()}),require.define("/lib/http.js",function(a,b,c,d,e){(function(){"use strict";var d=a("./jquery.class").Class,e=a("./log").Logger,f=a("./utils"),g=a("cookie"),h=c||this,i=null,j={5:function(a){var b=a.query||{},c=a.post||{},d=b.output_mode||c.output_mode||"json";return f.startsWith(d,"json")||(d="json"),b.output_mode=d,b},4:function(a){return a.query||{}},"default":function(a){return j[5](a)},none:function(a){return a.query||{}}};b.exports=h=i=d.extend({init:function(){this.get=f.bind(this,this.get),this.del=f.bind(this,this.del),this.post=f.bind(this,this.post),this.request=f.bind(this,this.request),this._buildResponse=f.bind(this,this._buildResponse),this._setSplunkVersion("none"),this._cookieStore={}},_setSplunkVersion:function(a){this.version=a},_getCookieString:function(){var a="";return f.forEach(this._cookieStore,function(b,c){a+=c,a+="=",a+=b,a+="; "}),a},_parseCookieHeader:function(a){var b=g.parse(a),c={};return f.forEach(b,function(a,b){if(c.key)return;c.key=b,c.value=a}),c},get:function(a,b,c,d,e){var f={method:"GET",headers:b,timeout:d,query:c};return this.request(a,f,e)},post:function(a,b,c,d,e){b["Content-Type"]="application/x-www-form-urlencoded";var f={method:"POST",headers:b,timeout:d,post:c};return this.request(a,f,e)},del:function(a,b,c,d,e){var f={method:"DELETE",headers:b,timeout:d,query:c};return this.request(a,f,e)},request:function(a,b,c){var d=this,e=function(a){c=c||function(){};var b=a.response.headers["set-cookie"];b&&f.forEach(b,function(a){var b=d._parseCookieHeader(a);d._cookieStore[b.key]=b.value}),a.status<400&&a.status!=="abort"?c(null,a):c(a)},g=f.getWithVersion(this.version,j)(b),h=b.post||{},k=a+"?"+i.encode(g),l=b.body?b.body:i.encode(h),m=d._getCookieString();m.length!==0&&(b.headers.Cookie=m,delete b.headers.Authorization);var n={method:b.method,headers:b.headers,timeout:b.timeout,body:l};return this.makeRequest(k,n,e)},makeRequest:function(a,b,c){throw new Error("UNDEFINED FUNCTION - OVERRIDE REQUIRED")},parseJson:function(a){throw new Error("UNDEFINED FUNCTION - OVERRIDE REQUIRED")},_buildResponse:function(a,b,c){var d,g={},h=null;b&&b.headers&&(h=f.trim(b.headers["content-type"]||b.headers["Content-Type"]||b.headers["Content-type"]||b.headers.contentType));if(f.startsWith(h,"application/json")&&c)try{g=this.parseJson(c)||{}}catch(i){e.error("Error in parsing JSON:",c,i),g=c}else g=c;return g&&e.printMessages(g.messages),d={response:b,status:b?b.statusCode:0,data:g,error:a},d}}),i.encode=function(a){var b="";for(var c in a)if(a.hasOwnProperty(c)){b&&b[b.length-1]!=="&"&&(b+="&");var d=a[c];if(d instanceof Array)for(var e=0;e1&&!b)throw new Error("Ambiguous match for name '"+a+"'");for(var e=0;e","<=",">=","is","isNull","isNotNull"],ipv4:["is","isNull","isNotNull","contains","doesNotContain","startsWith"]},_binning:["auto","year","month","day","hour","minute","second"],_sortDirection:["ASCENDING","DESCENDING","DEFAULT"],_statsFunctions:["list","values","first","last","count","dc","sum","average","max","min","stdev","duration","earliest","latest"],init:function(a){this.dataModelObject=a,this.columns=[],this.rows=[],this.filters=[],this.cells=[],this.accelerationNamespace=a.dataModel.isAccelerated()?a.dataModel.name:null,this.run=i.bind(this,this.run),this.pivot=i.bind(this,this.pivot)},setAccelerationJob:function(a){a&&a instanceof k.Job&&(a=a.sid);if(!a)throw new Error("Sid to use for acceleration must not be null.");return this.accelerationNamespace="sid="+a,this},addFilter:function(a,b,c,d){if(!this.dataModelObject.hasField(a))throw new Error("Cannot add filter on a nonexistent field.");if(b!==this.dataModelObject.fieldByName(a).type)throw new Error("Cannot add "+b+" filter on "+a+" because it is of type "+this.dataModelObject.fieldByName(a).type);if(!i.contains(this._comparisons[b],c))throw new Error("Cannot add "+b+" filter because "+c+" is not a valid comparison operator");var e={fieldName:a,owner:this.dataModelObject.fieldByName(a).lineage.join("."),type:b};return i.contains(["boolean","string","ipv4","number"],e.type)&&(e.rule={comparator:c,compareTo:d}),this.filters.push(e),this},addLimitFilter:function(a,b,c,d,e){if(!this.dataModelObject.hasField(a))throw new Error("Cannot add limit filter on a nonexistent field.");var f=this.dataModelObject.fieldByName(a);if(!i.contains(["string","number","objectCount"],f.type))throw new Error("Cannot add limit filter on "+a+" because it is of type "+f.type);if("string"===f.type&&!i.contains(["count","dc"],e))throw new Error("Stats function for fields of type string must be COUNT or DISTINCT_COUNT; found "+e);if("number"===f.type&&!i.contains(["count","dc","average","sum"],e))throw new Error("Stats function for fields of type number must be one of COUNT, DISTINCT_COUNT, SUM, or AVERAGE; found "+e);if("objectCount"===f.type&&!i.contains(["count"],e))throw new Error("Stats function for fields of type object count must be COUNT; found "+e);var g={fieldName:a,owner:f.lineage.join("."),type:f.type,attributeName:b,attributeOwner:this.dataModelObject.fieldByName(b).lineage.join("."),sortDirection:c,limitAmount:d,statsFn:e};return g.limitType="ASCENDING"===c?"lowest":"highest",this.filters.push(g),this},addRowSplit:function(a,b){if(!this.dataModelObject.hasField(a))throw new Error("Did not find field "+a);var c=this.dataModelObject.fieldByName(a);if(!i.contains(["number","string"],c.type))throw new Error("Field was of type "+c.type+", expected number or string.");var d={fieldName:a,owner:c.owner,type:c.type,label:b};return"number"===c.type&&(d.display="all"),this.rows.push(d),this},addRangeRowSplit:function(a,b,c){if(!this.dataModelObject.hasField(a))throw new Error("Did not find field "+a);var d=this.dataModelObject.fieldByName(a);if("number"!==d.type)throw new Error("Field was of type "+d.type+", expected number.");var e={};return!i.isUndefined(c.start)&&c.start!==null&&(e.start=c.start),!i.isUndefined(c.end)&&c.end!==null&&(e.end=c.end),!i.isUndefined(c.step)&&c.step!==null&&(e.size=c.step),!i.isUndefined(c.limit)&&c.limit!==null&&(e.maxNumberOf=c.limit),this.rows.push({fieldName:a,owner:d.owner,type:d.type,label:b,display:"ranges",ranges:e}),this},addBooleanRowSplit:function(a,b,c,d){if(!this.dataModelObject.fieldByName(a))throw new Error("Did not find field "+a);var e=this.dataModelObject.fieldByName(a);if("boolean"!==e.type)throw new Error("Field was of type "+e.type+", expected boolean.");return this.rows.push({fieldName:a,owner:e.owner,type:e.type,label:b,trueLabel:c,falseLabel:d}),this},addTimestampRowSplit:function(a,b,c){if(!this.dataModelObject.hasField(a))throw new Error("Did not find field "+a);var d=this.dataModelObject.fieldByName(a);if("timestamp"!==d.type)throw new Error("Field was of type "+d.type+", expected timestamp.");if(!i.contains(this._binning,c))throw new Error("Invalid binning "+c+" found. Valid values are: "+this._binning.join(", "));return this.rows.push({fieldName:a,owner:d.owner,type:d.type,label:b,period:c}),this},addColumnSplit:function(a){if(!this.dataModelObject.hasField(a))throw new Error("Did not find field "+a);var b=this.dataModelObject.fieldByName(a);if(!i.contains(["number","string"],b.type))throw new Error("Field was of type "+b.type+", expected number or string.");var c={fieldName:a,owner:b.owner,type:b.type};return"number"===b.type&&(c.display="all"),this.columns.push(c),this},addRangeColumnSplit:function(a,b){if(!this.dataModelObject.hasField(a))throw new Error("Did not find field "+a);var c=this.dataModelObject.fieldByName(a);if("number"!==c.type)throw new Error("Field was of type "+c.type+", expected number.");var d={};return!i.isUndefined(b.start)&&b.start!==null&&(d.start=b.start),!i.isUndefined(b.end)&&b.end!==null&&(d.end=b.end),!i.isUndefined(b.step)&&b.step!==null&&(d.size=b.step),!i.isUndefined(b.limit)&&b.limit!==null&&(d.maxNumberOf=b.limit),this.columns.push({fieldName:a,owner:c.owner,type:c.type,display:"ranges",ranges:d}),this},addBooleanColumnSplit:function(a,b,c){if(!this.dataModelObject.fieldByName(a))throw new Error("Did not find field "+a);var d=this.dataModelObject.fieldByName(a);if("boolean"!==d.type)throw new Error("Field was of type "+d.type+", expected boolean.");return this.columns.push({fieldName:a,owner:d.owner,type:d.type,trueLabel:b,falseLabel:c}),this},addTimestampColumnSplit:function(a,b){if(!this.dataModelObject.hasField(a))throw new Error("Did not find field "+a);var c=this.dataModelObject.fieldByName(a);if("timestamp"!==c.type)throw new Error("Field was of type "+c.type+", expected timestamp.");if(!i.contains(this._binning,b))throw new Error("Invalid binning "+b+" found. Valid values are: "+this._binning.join(", "));return this.columns.push({fieldName:a,owner:c.owner,type:c.type,period:b}),this},addCellValue:function(a,b,c){if(!this.dataModelObject.hasField(a))throw new Error("Did not find field "+a);var d=this.dataModelObject.fieldByName(a);if(i.contains(["string","ipv4"],d.type)&&!i.contains(["list","values","first","last","count","dc"],c))throw new Error("Stats function on string and IPv4 fields must be one of: list, distinct_values, first, last, count, or distinct_count; found "+c);if("number"===d.type&&!i.contains(["sum","count","average","min","max","stdev","list","values"],c))throw new Error("Stats function on number field must be must be one of: sum, count, average, max, min, stdev, list, or distinct_values; found "+c);if("timestamp"===d.type&&!i.contains(["duration","earliest","latest","list","values"],c))throw new Error("Stats function on timestamp field must be one of: duration, earliest, latest, list, or distinct values; found "+c);if(i.contains(["objectCount","childCount"],d.type)&&"count"!==c)throw new Error("Stats function on childcount and objectcount fields must be count; found "+c);if("boolean"===d.type)throw new Error("Cannot use boolean valued fields as cell values.");return this.cells.push({fieldName:a,owner:d.lineage.join("."),type:d.type,label:b,sparkline:!1,value:c}),this},toJsonObject:function(){return{dataModel:this.dataModelObject.dataModel.name,baseClass:this.dataModelObject.name,rows:this.rows,columns:this.columns,cells:this.cells,filters:this.filters}},pivot:function(a){var b=this.dataModelObject.dataModel.service,c={pivot_json:JSON.stringify(this.toJsonObject())};return i.isUndefined(this.accelerationNamespace)||(c.namespace=this.accelerationNamespace),b.get(g.pivot+"/"+encodeURIComponent(this.dataModelObject.dataModel.name),c,function(c,d){if(c){a(new Error(c.data.messages[0].text),d);return}d.data.entry&&d.data.entry[0]?a(null,new j.Pivot(b,d.data.entry[0].content)):a(new Error("Didn't get a Pivot report back from Splunk"),d)})},run:function(a,b){b||(b=a,a={}),a=a||{},this.pivot(function(c,d){c?b(c,null,null):d.run(a,f.augment(b,d))})}}),j.DataModelObject=h.extend({init:function(a,b){a=a||{},a.owner=a.owner||"",this.dataModel=b,this.name=a.objectName,this.displayName=a.displayName,this.parentName=a.parentName,this.lineage=a.lineage.split("."),a.hasOwnProperty("groupByFields")&&(this.groupByFields=a.groupByFields),a.hasOwnProperty("objectsToGroup")&&(this.objectsToGroup=a.objectsToGroup),a.hasOwnProperty("transactionMaxTimeSpan")&&(this.maxSpan=a.transactionMaxTimeSpan),a.hasOwnProperty("transactionMaxPause")&&(this.maxPause=a.transactionMaxPause),a.hasOwnProperty("baseSearch")&&(this.baseSearch=a.baseSearch),this.fields={};for(var c=0;c0)}})}})})()}),require.define("/lib/async.js",function(a,b,c,d,e){(function(){"use strict";var b=a("./utils"),d=c||this;d.whilst=function(a,b,c){a=a||function(){return!1},b=b||function(a){a()},c=c||function(){};var e=function(e){e?c(e):d.whilst(a,b,c)};a()?b(e):c(null)},d.parallel=function(a,c){if(arguments.length>1&&b.isFunction(arguments[0])){var d=b.toArray(arguments);a=d.slice(0,d.length-1),c=d[d.length-1]}a=a||[],c=c||function(){},a.length===0&&c();var e=a.length,f=[],g=function(a){return function(d){if(d)c&&c(d),c=null;else{var g=b.toArray(arguments);g.shift(),g.length===1&&(g=g[0]),f[a]=g,--e===0&&(f.unshift(null),c&&c.apply(null,f))}}};for(var h=0;h1&&b.isFunction(arguments[0])){var d=b.toArray(arguments);a=d.slice(0,d.length-1),c=d[d.length-1]}a=a||[],c=c||function(){};var e=function(a,c,d,f){if(!a){d.unshift(null),f.apply(null,d);return}a(function(a){if(a)f&&f(a),f=null;else{var g=b.toArray(arguments);g.shift(),g.length===1&&(g=g[0]),d.push(g),e(c[0],c.slice(1),d,f)}})};e(a[0],a.slice(1),[],c)},d.parallelMap=function(a,c,e){a=a||[],e=e||function(){};var f=[],g=function(a,b){return function(d){c(a,b,d)}};for(var h=0;h1&&b.isFunction(arguments[0])){var d=b.toArray(arguments);a=d.slice(0,d.length-1),c=d[d.length-1]}a=a||[],c=c||function(){};if(!a.length)c();else{var e=function(a,d,f){var g=function(a){if(a)c(a),c=function(){};else{var f=b.toArray(arguments);f.shift(),e(d[0],d.slice(1),f)}},h=f;d.length?h.push(g):h.push(c),a.apply(null,h)};e(a[0],a.slice(1),[])}},d.sleep=function(a,b){setTimeout(function(){b()},a)},d.augment=function(a){var b=Array.prototype.slice.call(arguments,1);return function(){var c=Array.prototype.slice.call(arguments);for(var d=0;d tag unexpected.")}},f.parseXMLData=function(a,b){var c={},d=a.getchildren();for(var e=0;e/g,">"),d||(a=a.replace(/\n/g," "),a=a.replace(/\r/g," ")),c&&(a=a.replace(/"/g,"""))),a}function w(a,b){return v(a,b,!0)}function x(a,b){return v(a,b,!1)}function y(a,b){return v(a,b,!1,!0)}function z(a,b,c){function g(a){return a}function h(a){if(a[0]==="{"){var b=a.substring(1).split("}",2),g=b[0],h=b[1],i=e[g];i===undefined&&(i=t[g],i===undefined&&(i="ns"+Object.keys(e).length),i!=="xml"&&(e[g]=i)),i?d[a]=f("%s:%s",i,h):d[a]=h}else{if(c)throw new Error("cannot use non-qualified names with default_namespace option");d[a]=a}}var d={},e={};return c&&(e[c]=""),a.iter(null,function(a){var b,c=a.tag,e=a.text,f=a.items();if(c instanceof r&&d[c.text]===undefined)h(c.text);else if(typeof c=="string")h(c);else if(c!==null&&c!==o&&c!==p&&c!==q)throw new Error("Invalid tag type for serialization: "+c);e instanceof r&&d[e.text]===undefined&&h(e.text),f.forEach(function(a){var b=a[0],c=a[1];b instanceof r&&(b=b.text),d[b]===undefined&&h(b),c instanceof r&&d[c.text]===undefined&&h(c.text)})}),[d,e]}function A(a,b,c,d,e,h,i){var j=b.tag,k=b.text,l,m,n=h||h===0;a(Array(h+1).join(i));if(j===o)a(f("",x(k,c)));else if(j===q)a(f("",x(k,c)));else if(j===p)k=k||"",a(f("",k));else{j=d[j];if(j===undefined)k&&a(y(k,c)),b.iter(function(b){A(a,b,c,d,null,n?h+1:!1,i)});else{a("<"+j),l=b.items();if(l||e)l.sort(),l.forEach(function(b){var e=b[0],g=b[1];e instanceof r&&(e=e.text),g instanceof r?g=d[g.text]:g=w(g,c),a(f(' %s="%s"',d[e],g))}),e&&(l=g.items(e),l.sort(function(a,b){return a[1]"),!k&&n&&a("\n"),k&&a(y(k,c)),b._children.forEach(function(b){A(a,b,c,d,null,n?h+1:!1,i)}),!k&&h&&a(Array(h+1).join(i)),a("")):a(" />")}}n&&a("\n")}function B(a,b){var c=new s;return c.parse(a,b),c}function C(a,b){return(new s(a)).write(b)}var f=a("./sprintf").sprintf,g=a("./utils"),h=a("./elementpath"),i=a("./treebuilder").TreeBuilder,j=a("./parser").get_parser,k=a("./constants"),l=0;m.prototype.toString=function(){return f("",this.tag,this._id)},m.prototype.makeelement=function(a,b){return new m(a,b)},m.prototype.len=function(){return this._children.length},m.prototype.getItem=function(a){return this._children[a]},m.prototype.setItem=function(a,b){this._children[a]=b},m.prototype.delItem=function(a){this._children.splice(a,1)},m.prototype.getSlice=function(a,b){return this._children.slice(a,b)},m.prototype.setSlice=function(a,b,c){var d,e=0;for(d=a;d\n");if(a.method==="text")_serialize_text(b,self._root,encoding);else{var c,d,e,f,h=z(this._root,a.encoding,a.default_namespace);c=h[0],d=h[1],a.hasOwnProperty("indent")?(e=0,f=(new Array(a.indent+1)).join(" ")):e=!1;if(a.method==="xml")A(function(a){b.push(a)},this._root,a.encoding,c,d,e,f);else throw new Error("unknown serialization method "+a.method)}return b.join("")};var t={"http://www.w3.org/XML/1998/namespace":"xml","http://www.w3.org/1999/xhtml":"html","http://www.w3.org/1999/02/22-rdf-syntax-ns#":"rdf","http://schemas.xmlsoap.org/wsdl/":"wsdl","http://www.w3.org/2001/XMLSchema":"xs","http://www.w3.org/2001/XMLSchema-instance":"xsi","http://purl.org/dc/elements/1.1/":"dc"};c.PI=q,c.Comment=o,c.CData=p,c.ProcessingInstruction=q,c.SubElement=n,c.QName=r,c.ElementTree=s,c.ElementPath=h,c.Element=function(a,b){return new m(a,b)},c.XML=function(a){var b=new s;return b.parse(a)},c.parse=B,c.register_namespace=u,c.tostring=C}),require.define("/node_modules/elementtree/lib/sprintf.js",function(a,b,c,d,e){function h(a){var b,c,d=a,e=0,h=1,i="return '";for(b=0;b100&&(i={});if(b.charAt(0)==="/")throw new h(null,"Cannot use absolute path on element");d=k(b),c=[];function o(){return d.shift()}j=o();for(;;){var p=j[1]||"";l=r[p](o,j);if(!l)throw new h(null,f("Invalid path: %s",b));c.push(l),j=o();if(!j)break;j[1]==="/"&&(j=o());if(!j)break}i[b]=c}d=[a],n=new s(a);for(e=0,g=c.length;e0?c[0]:null}function v(a,b,c){var d=t(a,b);return d&&d.length>0?d[0].text:c}var f=a("./sprintf").sprintf,g=a("./utils"),h=a("./errors").SyntaxError,i={},j=new RegExp("('[^']*'|\"[^\"]*\"|::|//?|\\.\\.|\\(\\)|[/.*:\\[\\]\\(\\)@=])|((?:\\{[^}]+\\})?[^/\\[\\]\\(\\)@=\\s]+)|\\s+","g"),k=g.findall.bind(null,j),r={"":l,"*":m,".":n,"..":p,"//":o,"[":q};c.find=u,c.findall=t,c.findtext=v}),require.define("/node_modules/elementtree/lib/errors.js",function(a,b,c,d,e){function h(a,b){b=b||g("Syntax Error at token %s",a.toString()),this.token=a,this.message=b,Error.call(this,b)}var f=a("util"),g=a("./sprintf").sprintf;f.inherits(h,Error),c.SyntaxError=h}),require.define("util",function(a,b,c,d,e){function g(a){return a instanceof Array||Array.isArray(a)||a&&a!==Object.prototype&&g(a.__proto__)}function h(a){return a instanceof RegExp||typeof a=="object"&&Object.prototype.toString.call(a)==="[object RegExp]"}function i(a){if(a instanceof Date)return!0;if(typeof a!="object")return!1;var b=Date.prototype&&n(Date.prototype),c=a.__proto__&&n(a.__proto__);return JSON.stringify(c)===JSON.stringify(b)}function j(a){return a<10?"0"+a.toString(10):a.toString(10)}function l(){var a=new Date,b=[j(a.getHours()),j(a.getMinutes()),j(a.getSeconds())].join(":");return[a.getDate(),k[a.getMonth()],b].join(" ")}var f=a("events");c.print=function(){},c.puts=function(){},c.debug=function(){},c.inspect=function(a,b,d,e){function k(a,d){if(a&&typeof a.inspect=="function"&&a!==c&&(!a.constructor||a.constructor.prototype!==a))return a.inspect(d);switch(typeof a){case"undefined":return j("undefined","undefined");case"string":var e="'"+JSON.stringify(a).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return j(e,"string");case"number":return j(""+a,"number");case"boolean":return j(""+a,"boolean")}if(a===null)return j("null","null");var l=m(a),o=b?n(a):l;if(typeof a=="function"&&o.length===0){if(h(a))return j(""+a,"regexp");var p=a.name?": "+a.name:"";return j("[Function"+p+"]","special")}if(i(a)&&o.length===0)return j(a.toUTCString(),"date");var q,r,s;g(a)?(r="Array",s=["[","]"]):(r="Object",s=["{","}"]);if(typeof a=="function"){var t=a.name?": "+a.name:"";q=h(a)?" "+a:" [Function"+t+"]"}else q="";i(a)&&(q=" "+a.toUTCString());if(o.length===0)return s[0]+q+s[1];if(d<0)return h(a)?j(""+a,"regexp"):j("[Object]","special");f.push(a);var u=o.map(function(b){var c,e;a.__lookupGetter__&&(a.__lookupGetter__(b)?a.__lookupSetter__(b)?e=j("[Getter/Setter]","special"):e=j("[Getter]","special"):a.__lookupSetter__(b)&&(e=j("[Setter]","special"))),l.indexOf(b)<0&&(c="["+b+"]"),e||(f.indexOf(a[b])<0?(d===null?e=k(a[b]):e=k(a[b],d-1),e.indexOf("\n")>-1&&(g(a)?e=e.split("\n").map(function(a){return" "+a}).join("\n").substr(2):e="\n"+e.split("\n").map(function(a){return" "+a}).join("\n"))):e=j("[Circular]","special"));if(typeof c=="undefined"){if(r==="Array"&&b.match(/^\d+$/))return e;c=JSON.stringify(""+b),c.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(c=c.substr(1,c.length-2),c=j(c,"name")):(c=c.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),c=j(c,"string"))}return c+": "+e});f.pop();var v=0,w=u.reduce(function(a,b){return v++,b.indexOf("\n")>=0&&v++,a+b.length+1},0);return w>50?u=s[0]+(q===""?"":q+"\n ")+" "+u.join(",\n ")+" "+s[1]:u=s[0]+q+" "+u.join(", ")+" "+s[1],u}var f=[],j=function(a,b){var c={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},d={special:"cyan",number:"blue","boolean":"yellow","undefined":"grey","null":"bold",string:"green",date:"magenta",regexp:"red"}[b];return d?"["+c[d][0]+"m"+a+"["+c[d][1]+"m":a};return e||(j=function(a,b){return a}),k(a,typeof d=="undefined"?2:d)};var k=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];c.log=function(a){},c.pump=null;var m=Object.keys||function(a){var b=[];for(var c in a)b.push(c);return b},n=Object.getOwnPropertyNames||function(a){var b=[];for(var c in a)Object.hasOwnProperty.call(a,c)&&b.push(c);return b},o=Object.create||function(a,b){var c;if(a===null)c={__proto__:null};else{if(typeof a!="object")throw new TypeError("typeof prototype["+typeof a+"] != 'object'");var d=function(){};d.prototype=a,c=new d,c.__proto__=a}return typeof b!="undefined"&&Object.defineProperties&&Object.defineProperties(c,b),c};c.inherits=function(a,b){a.super_=b,a.prototype=o(b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}})}}),require.define("events",function(a,b,c,d,e){process.EventEmitter||(process.EventEmitter=function(){});var f=c.EventEmitter=process.EventEmitter,g=typeof Array.isArray=="function"?Array.isArray:function(a){return Object.toString.call(a)==="[object Array]"},h=10;f.prototype.setMaxListeners=function(a){this._events||(this._events={}),this._events.maxListeners=a},f.prototype.emit=function(a){if(a==="error")if(!this._events||!this._events.error||g(this._events.error)&&!this._events.error.length)throw arguments[1]instanceof Error?arguments[1]:new Error("Uncaught, unspecified 'error' event.");if(!this._events)return!1;var b=this._events[a];if(!b)return!1;if(typeof b=="function"){switch(arguments.length){case 1:b.call(this);break;case 2:b.call(this,arguments[1]);break;case 3:b.call(this,arguments[1],arguments[2]);break;default:var c=Array.prototype.slice.call(arguments,1);b.apply(this,c)}return!0}if(g(b)){var c=Array.prototype.slice.call(arguments,1),d=b.slice();for(var e=0,f=d.length;e0&&this._events[a].length>c&&(this._events[a].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[a].length),console.trace())}this._events[a].push(b)}else this._events[a]=[this._events[a],b];return this},f.prototype.on=f.prototype.addListener,f.prototype.once=function(a,b){var c=this;return c.on(a,function d(){c.removeListener(a,d),b.apply(this,arguments)}),this},f.prototype.removeListener=function(a,b){if("function"!=typeof b)throw new Error("removeListener only takes instances of Function");if(!this._events||!this._events[a])return this;var c=this._events[a];if(g(c)){var d=c.indexOf(b);if(d<0)return this;c.splice(d,1),c.length==0&&delete this._events[a]}else this._events[a]===b&&delete this._events[a];return this},f.prototype.removeAllListeners=function(a){return a&&this._events&&this._events[a]&&(this._events[a]=null),this},f.prototype.listeners=function(a){return this._events||(this._events={}),this._events[a]||(this._events[a]=[]),g(this._events[a])||(this._events[a]=[this._events[a]]),this._events[a]}}),require.define("/node_modules/elementtree/lib/treebuilder.js",function(a,b,c,d,e){function f(b){this._data=[],this._elem=[],this._last=null,this._tail=null,b||(b=a("./elementtree").Element),this._factory=b}f.prototype.close=function(){return this._last},f.prototype._flush=function(){if(this._data){if(this._last!==null){var a=this._data.join("");this._tail?this._last.tail=a:this._last.text=a}this._data=[]}},f.prototype.data=function(a){this._data.push(a)},f.prototype.start=function(a,b){this._flush();var c=this._factory(a,b);this._last=c,this._elem.length&&this._elem[this._elem.length-1].append(c),this._elem.push(c),this._tail=null},f.prototype.end=function(a){this._flush(),this._last=this._elem.pop();if(this._last.tag!==a)throw new Error("end tag mismatch");return this._tail=1,this._last},c.TreeBuilder=f}),require.define("/node_modules/elementtree/lib/parser.js",function(a,b,c,d,e){function h(a){if(a==="sax")return g.sax;throw new Error("Invalid parser: "+a)}var f=a("util"),g=a("./parsers/index");c.get_parser=h}),require.define("/node_modules/elementtree/lib/parsers/index.js",function(a,b,c,d,e){c.sax=a("./sax")}),require.define("/node_modules/elementtree/lib/parsers/sax.js",function(a,b,c,d,e){function i(a){this.parser=g.parser(!0),this.target=a?a:new h,this.parser.onopentag=this._handleOpenTag.bind(this),this.parser.ontext=this._handleText.bind(this),this.parser.oncdata=this._handleCdata.bind(this),this.parser.ondoctype=this._handleDoctype.bind(this),this.parser.oncomment=this._handleComment.bind(this),this.parser.onclosetag=this._handleCloseTag.bind(this),this.parser.onerror=this._handleError.bind(this)}var f=a("util"),g=a("sax"),h=a("./../treebuilder").TreeBuilder;i.prototype._handleOpenTag=function(a){this.target.start(a.name,a.attributes)},i.prototype._handleText=function(a){this.target.data(a)},i.prototype._handleCdata=function(a){this.target.data(a)},i.prototype._handleDoctype=function(a){},i.prototype._handleComment=function(a){},i.prototype._handleCloseTag=function(a){this.target.end(a)},i.prototype._handleError=function(a){throw a},i.prototype.feed=function(a){this.parser.write(a)},i.prototype.close=function(){return this.parser.close(),this.target.close()},c.XMLParser=i}),require.define("/node_modules/sax/package.json",function(a,b,c,d,e){b.exports={main:"lib/sax.js"}}),require.define("/node_modules/sax/lib/sax.js",function(a,b,c,d,e){(function(b){function d(a,c){if(!(this instanceof d))return new d(a,c);var e=this;f(e),e.q=e.c="",e.bufferCheckPosition=b.MAX_BUFFER_LENGTH,e.opt=c||{},e.tagCase=e.opt.lowercasetags?"toLowerCase":"toUpperCase",e.tags=[],e.closed=e.closedRoot=e.sawRoot=!1,e.tag=e.error=null,e.strict=!!a,e.noscript=!!a||!!e.opt.noscript,e.state=B.BEGIN,e.ENTITIES=Object.create(b.ENTITIES),e.attribList=[],e.opt.xmlns&&(e.ns=Object.create(x)),e.position=e.line=e.column=0,C(e,"onready")}function e(a){var d=Math.max(b.MAX_BUFFER_LENGTH,10),e=0;for(var f=0,g=c.length;fd)switch(c[f]){case"textNode":E(a);break;case"cdata":D(a,"oncdata",a.cdata),a.cdata="";break;case"script":D(a,"onscript",a.script),a.script="";break;default:G(a,"Max buffer length exceeded: "+c[f])}e=Math.max(e,h)}a.bufferCheckPosition=b.MAX_BUFFER_LENGTH-e+a.position}function f(a){for(var b=0,d=c.length;b",a.state=B.TEXT;return}a.tagName=c;var f=a.tags.length;while(f-->b){var g=a.tag=a.tags.pop();a.tagName=a.tag.name,D(a,"onclosetag",a.tagName);var h={};for(var i in g.ns)h[i]=g.ns[i];var j=a.tags[a.tags.length-1]||a;a.opt.xmlns&&g.ns!==j.ns&&Object.keys(g.ns).forEach(function(b){var c=g.ns[b];D(a,"onclosenamespace",{prefix:b,uri:c})})}b===0&&(a.closedRoot=!0),a.tagName=a.attribValue=a.attribName="",a.attribList.length=0,a.state=B.TEXT}function O(a){var b=a.entity.toLowerCase(),c,d="";return a.ENTITIES[b]?a.ENTITIES[b]:(b.charAt(0)==="#"&&(b.charAt(1)==="x"?(b=b.slice(2),c=parseInt(b,16),d=c.toString(16)):(b=b.slice(1),c=parseInt(b,10),d=c.toString(10))),b=b.replace(/^0+/,""),d.toLowerCase()!==b?(I(a,"Invalid character entity"),"&"+a.entity+";"):String.fromCharCode(c))}function P(a){var b=this;if(this.error)throw this.error;if(b.closed)return G(b,"Cannot write after close. Assign an onready handler.");if(a===null)return H(b);var c=0,d="";while(b.c=d=a.charAt(c++)){b.position++,d==="\n"?(b.line++,b.column=0):b.column++;switch(b.state){case B.BEGIN:d==="<"?b.state=B.OPEN_WAKA:A(l,d)&&(I(b,"Non-whitespace before first tag."),b.textNode=d,b.state=B.TEXT);continue;case B.TEXT:if(b.sawRoot&&!b.closedRoot){var f=c-1;while(d&&d!=="<"&&d!=="&")d=a.charAt(c++),d&&(b.position++,d==="\n"?(b.line++,b.column=0):b.column++);b.textNode+=a.substring(f,c-1)}d==="<"?b.state=B.OPEN_WAKA:(A(l,d)&&(!b.sawRoot||b.closedRoot)&&I("Text data outside of root node."),d==="&"?b.state=B.TEXT_ENTITY:b.textNode+=d);continue;case B.SCRIPT:d==="<"?b.state=B.SCRIPT_ENDING:b.script+=d;continue;case B.SCRIPT_ENDING:d==="/"?(D(b,"onscript",b.script),b.state=B.CLOSE_TAG,b.script="",b.tagName=""):(b.script+="<"+d,b.state=B.SCRIPT);continue;case B.OPEN_WAKA:d==="!"?(b.state=B.SGML_DECL,b.sgmlDecl=""):z(l,d)||(z(o,d)?(b.startTagPosition=b.position-1,b.state=B.OPEN_TAG,b.tagName=d):d==="/"?(b.startTagPosition=b.position-1,b.state=B.CLOSE_TAG,b.tagName=""):d==="?"?(b.state=B.PROC_INST,b.procInstName=b.procInstBody=""):(I(b,"Unencoded <"),b.textNode+="<"+d,b.state=B.TEXT));continue;case B.SGML_DECL:(b.sgmlDecl+d).toUpperCase()===t?(D(b,"onopencdata"),b.state=B.CDATA,b.sgmlDecl="",b.cdata=""):b.sgmlDecl+d==="--"?(b.state=B.COMMENT,b.comment="",b.sgmlDecl=""):(b.sgmlDecl+d).toUpperCase()===u?(b.state=B.DOCTYPE,(b.doctype||b.sawRoot)&&I(b,"Inappropriately located doctype declaration"),b.doctype="",b.sgmlDecl=""):d===">"?(D(b,"onsgmldeclaration",b.sgmlDecl),b.sgmlDecl="",b.state=B.TEXT):z(q,d)?(b.state=B.SGML_DECL_QUOTED,b.sgmlDecl+=d):b.sgmlDecl+=d;continue;case B.SGML_DECL_QUOTED:d===b.q&&(b.state=B.SGML_DECL,b.q=""),b.sgmlDecl+=d;continue;case B.DOCTYPE:d===">"?(b.state=B.TEXT,D(b,"ondoctype",b.doctype),b.doctype=!0):(b.doctype+=d,d==="["?b.state=B.DOCTYPE_DTD:z(q,d)&&(b.state=B.DOCTYPE_QUOTED,b.q=d));continue;case B.DOCTYPE_QUOTED:b.doctype+=d,d===b.q&&(b.q="",b.state=B.DOCTYPE);continue;case B.DOCTYPE_DTD:b.doctype+=d,d==="]"?b.state=B.DOCTYPE:z(q,d)&&(b.state=B.DOCTYPE_DTD_QUOTED,b.q=d);continue;case B.DOCTYPE_DTD_QUOTED:b.doctype+=d,d===b.q&&(b.state=B.DOCTYPE_DTD,b.q="");continue;case B.COMMENT:d==="-"?b.state=B.COMMENT_ENDING:b.comment+=d;continue;case B.COMMENT_ENDING:d==="-"?(b.state=B.COMMENT_ENDED,b.comment=F(b.opt,b.comment),b.comment&&D(b,"oncomment",b.comment),b.comment=""):(b.comment+="-"+d,b.state=B.COMMENT);continue;case B.COMMENT_ENDED:d!==">"?(I(b,"Malformed comment"),b.comment+="--"+d,b.state=B.COMMENT):b.state=B.TEXT;continue;case B.CDATA:d==="]"?b.state=B.CDATA_ENDING:b.cdata+=d;continue;case B.CDATA_ENDING:d==="]"?b.state=B.CDATA_ENDING_2:(b.cdata+="]"+d,b.state=B.CDATA);continue;case B.CDATA_ENDING_2:d===">"?(b.cdata&&D(b,"oncdata",b.cdata),D(b,"onclosecdata"),b.cdata="",b.state=B.TEXT):d==="]"?b.cdata+="]":(b.cdata+="]]"+d,b.state=B.CDATA);continue;case B.PROC_INST:d==="?"?b.state=B.PROC_INST_ENDING:z(l,d)?b.state=B.PROC_INST_BODY:b.procInstName+=d;continue;case B.PROC_INST_BODY:if(!b.procInstBody&&z(l,d))continue;d==="?"?b.state=B.PROC_INST_ENDING:z(q,d)?(b.state=B.PROC_INST_QUOTED,b.q=d,b.procInstBody+=d):b.procInstBody+=d;continue;case B.PROC_INST_ENDING:d===">"?(D(b,"onprocessinginstruction",{name:b.procInstName,body:b.procInstBody}),b.procInstName=b.procInstBody="",b.state=B.TEXT):(b.procInstBody+="?"+d,b.state=B.PROC_INST_BODY);continue;case B.PROC_INST_QUOTED:b.procInstBody+=d,d===b.q&&(b.state=B.PROC_INST_BODY,b.q="");continue;case B.OPEN_TAG:z(p,d)?b.tagName+=d:(J(b),d===">"?M(b):d==="/"?b.state=B.OPEN_TAG_SLASH:(A(l,d)&&I(b,"Invalid character in tag name"),b.state=B.ATTRIB));continue;case B.OPEN_TAG_SLASH:d===">"?(M(b,!0),N(b)):(I(b,"Forward-slash in opening tag not followed by >"),b.state=B.ATTRIB);continue;case B.ATTRIB:if(z(l,d))continue;d===">"?M(b):d==="/"?b.state=B.OPEN_TAG_SLASH:z(o,d)?(b.attribName=d,b.attribValue="",b.state=B.ATTRIB_NAME):I(b,"Invalid attribute name");continue;case B.ATTRIB_NAME:d==="="?b.state=B.ATTRIB_VALUE:z(l,d)?b.state=B.ATTRIB_NAME_SAW_WHITE:z(p,d)?b.attribName+=d:I(b,"Invalid attribute name");continue;case B.ATTRIB_NAME_SAW_WHITE:if(d==="=")b.state=B.ATTRIB_VALUE;else{if(z(l,d))continue;I(b,"Attribute without value"),b.tag.attributes[b.attribName]="",b.attribValue="",D(b,"onattribute",{name:b.attribName,value:""}),b.attribName="",d===">"?M(b):z(o,d)?(b.attribName=d,b.state=B.ATTRIB_NAME):(I(b,"Invalid attribute name"),b.state=B.ATTRIB)}continue;case B.ATTRIB_VALUE:if(z(l,d))continue;z(q,d)?(b.q=d,b.state=B.ATTRIB_VALUE_QUOTED):(I(b,"Unquoted attribute value"),b.state=B.ATTRIB_VALUE_UNQUOTED,b.attribValue=d);continue;case B.ATTRIB_VALUE_QUOTED:if(d!==b.q){d==="&"?b.state=B.ATTRIB_VALUE_ENTITY_Q:b.attribValue+=d;continue}L(b),b.q="",b.state=B.ATTRIB;continue;case B.ATTRIB_VALUE_UNQUOTED:if(A(s,d)){d==="&"?b.state=B.ATTRIB_VALUE_ENTITY_U:b.attribValue+=d;continue}L(b),d===">"?M(b):b.state=B.ATTRIB;continue;case B.CLOSE_TAG:if(!b.tagName){if(z(l,d))continue;A(o,d)?I(b,"Invalid tagname in closing tag."):b.tagName=d}else d===">"?N(b):z(p,d)?b.tagName+=d:(A(l,d)&&I(b,"Invalid tagname in closing tag"),b.state=B.CLOSE_TAG_SAW_WHITE);continue;case B.CLOSE_TAG_SAW_WHITE:if(z(l,d))continue;d===">"?N(b):I("Invalid characters in closing tag");continue;case B.TEXT_ENTITY:case B.ATTRIB_VALUE_ENTITY_Q:case B.ATTRIB_VALUE_ENTITY_U:switch(b.state){case B.TEXT_ENTITY:var g=B.TEXT,h="textNode";break;case B.ATTRIB_VALUE_ENTITY_Q:var g=B.ATTRIB_VALUE_QUOTED,h="attribValue";break;case B.ATTRIB_VALUE_ENTITY_U:var g=B.ATTRIB_VALUE_UNQUOTED,h="attribValue"}d===";"?(b[h]+=O(b),b.entity="",b.state=g):z(r,d)?b.entity+=d:(I("Invalid character entity"),b[h]+="&"+b.entity+d,b.entity="",b.state=g);continue;default:throw new Error(b,"Unknown state: "+b.state)}}return b.position>=b.bufferCheckPosition&&e(b),b}b.parser=function(a,b){return new d(a,b)},b.SAXParser=d,b.SAXStream=k,b.createStream=j,b.MAX_BUFFER_LENGTH=65536;var c=["comment","sgmlDecl","textNode","tagName","doctype","procInstName","procInstBody","entity","attribName","attribValue","cdata","script"];b.EVENTS=["text","processinginstruction","sgmldeclaration","doctype","comment","attribute","opentag","closetag","opencdata","cdata","closecdata","error","end","ready","script","opennamespace","closenamespace"],Object.create||(Object.create=function(a){function b(){this.__proto__=a}return b.prototype=a,new b}),Object.getPrototypeOf||(Object.getPrototypeOf=function(a){return a.__proto__}),Object.keys||(Object.keys=function(a){var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(c);return b}),d.prototype={end:function(){H(this)},write:P,resume:function(){return this.error=null,this},close:function(){return this.write(null)},end:function(){return this.write(null)}};try{var g=a("stream").Stream}catch(h){var g=function(){}}var i=b.EVENTS.filter(function(a){return a!=="error"&&a!=="end"});k.prototype=Object.create(g.prototype,{constructor:{value:k}}),k.prototype.write=function(a){return this._parser.write(a.toString()),this.emit("data",a),!0},k.prototype.end=function(a){return a&&a.length&&this._parser.write(a.toString()),this._parser.end(),!0},k.prototype.on=function(a,b){var c=this;return!c._parser["on"+a]&&i.indexOf(a)!==-1&&(c._parser["on"+a]=function(){var b=arguments.length===1?[arguments[0]]:Array.apply(null,arguments);b.splice(0,0,a),c.emit.apply(c,b)}),g.prototype.on.call(c,a,b)};var l="\r\n\t ",m="0124356789",n="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",o=n+"_:",p=o+m+"-.",q="'\"",r=m+n+"#",s=l+">",t="[CDATA[",u="DOCTYPE",v="http://www.w3.org/XML/1998/namespace",w="http://www.w3.org/2000/xmlns/",x={xml:v,xmlns:w};l=y(l),m=y(m),n=y(n),o=y(o),p=y(p),q=y(q),r=y(r),s=y(s);var B=0;b.STATE={BEGIN:B++,TEXT:B++,TEXT_ENTITY:B++,OPEN_WAKA:B++,SGML_DECL:B++,SGML_DECL_QUOTED:B++,DOCTYPE:B++,DOCTYPE_QUOTED:B++,DOCTYPE_DTD:B++,DOCTYPE_DTD_QUOTED:B++,COMMENT_STARTING:B++,COMMENT:B++,COMMENT_ENDING:B++,COMMENT_ENDED:B++,CDATA:B++,CDATA_ENDING:B++,CDATA_ENDING_2:B++,PROC_INST:B++,PROC_INST_BODY:B++,PROC_INST_QUOTED:B++,PROC_INST_ENDING:B++,OPEN_TAG:B++,OPEN_TAG_SLASH:B++,ATTRIB:B++,ATTRIB_NAME:B++,ATTRIB_NAME_SAW_WHITE:B++,ATTRIB_VALUE:B++,ATTRIB_VALUE_QUOTED:B++,ATTRIB_VALUE_UNQUOTED:B++,ATTRIB_VALUE_ENTITY_Q:B++,ATTRIB_VALUE_ENTITY_U:B++,CLOSE_TAG:B++,CLOSE_TAG_SAW_WHITE:B++,SCRIPT:B++,SCRIPT_ENDING:B++},b.ENTITIES={apos:"'",quot:'"',amp:"&",gt:">",lt:"<"};for(var B in b.STATE)b.STATE[b.STATE[B]]=B;B=b.STATE})(typeof c=="undefined"?sax={}:c)}),require.define("stream",function(a,b,c,d,e){function h(){f.EventEmitter.call(this)}var f=a("events"),g=a("util");g.inherits(h,f.EventEmitter),b.exports=h,h.Stream=h,h.prototype.pipe=function(a,b){function d(b){a.writable&&!1===a.write(b)&&c.pause&&c.pause()}function e(){c.readable&&c.resume&&c.resume()}function g(){if(f)return;f=!0,a._pipeCount--,j();if(a._pipeCount>0)return;a.end()}function h(){if(f)return;f=!0,a._pipeCount--,j();if(a._pipeCount>0)return;a.destroy()}function i(a){j();if(this.listeners("error").length===0)throw a}function j(){c.removeListener("data",d),a.removeListener("drain",e),c.removeListener("end",g),c.removeListener("close",h),c.removeListener("error",i),a.removeListener("error",i),c.removeListener("end",j),c.removeListener("close",j),a.removeListener("end",j),a.removeListener("close",j)}var c=this;c.on("data",d),a.on("drain",e),!a._isStdio&&(!b||b.end!==!1)&&(a._pipeCount=a._pipeCount||0,a._pipeCount++,c.on("end",g),c.on("close",h));var f=!1;return c.on("error",i),a.on("error",i),c.on("end",j),c.on("close",j),a.on("end",j),a.on("close",j),a.emit("pipe",c),a}}),require.define("/node_modules/elementtree/lib/constants.js",function(a,b,c,d,e){var f="sax";c.DEFAULT_PARSER=f}),require.define("/lib/modularinputs/inputdefinition.js",function(a,b,c,d,e){(function(){function e(){this.metadata={},this.inputs={}}var c=a("elementtree"),d=a("./utils");e.parse=function(a){var b=new e,f=c.parse(a).getroot().getchildren();for(var g=0;g=10?b=parseFloat(a.toString().substring(0,14)).toFixed(3):a.toString().length<=13||a.toString().indexOf(".")<10?b=parseFloat(a).toFixed(3):b=(parseFloat(a.toString().substring(0,14))/1e3).toFixed(3)):a.toString().length===13?b=(parseFloat(a)/1e3).toFixed(3):a.toString().length<=12?b=parseFloat(a).toFixed(3):b=parseFloat(a.toString().substring(0,13)/1e3).toFixed(3),b)},e.prototype._writeTo=function(a){if(!this.data)throw new Error("Events must have at least the data field set to be written to XML.");var b=c.Element("event");this.stanza&&b.set("stanza",this.stanza),b.set("unbroken",(+this.unbroken).toString()),!d.isUndefined(this.time)&&this.time!==null&&(c.SubElement(b,"time").text=e.formatTime(this.time).toString()),typeof this.data=="object"&&(this.data=JSON.stringify(this.data));var f=[{tag:"source",text:this.source},{tag:"sourcetype",text:this.sourcetype},{tag:"index",text:this.index},{tag:"host",text:this.host},{tag:"data",text:this.data}];for(var g=0;g"),this._headerWritten=!0);try{a._writeTo(this._out)}catch(b){throw b.message==="Events must have at least the data field set to be written to XML."?(e.warn("",b.message,this._err),b):(e.error("",b.message,this._err),b)}},h.prototype.writeXMLDocument=function(a){var b=c.tostring(a,{xml_declaration:!1});this._out.write(b)},h.prototype.close=function(){this._out.write("")},b.exports=h})()}),require.define("/lib/modularinputs/logger.js",function(a,b,c,d,e){(function(){"use strict";var d=a("./utils"),e=c||this;e.DEBUG="DEBUG",e.INFO="INFO",e.WARN="WARN",e.ERROR="ERROR",e.FATAL="FATAL",e._log=function(a,b,c,d){d=d||process.stderr,b&&b.length>0&&(b+=" ");var e=a+" Modular input "+b+c+"\n";d.write(e)},e.debug=function(a,b,c){try{e._log(e.DEBUG,a,b,c)}catch(d){throw d}},e.info=function(a,b,c){try{e._log(e.INFO,a,b,c)}catch(d){throw d}},e.warn=function(a,b,c){try{e._log(e.WARN,a,b,c)}catch(d){throw d}},e.error=function(a,b,c){try{e._log(e.ERROR,a,b,c)}catch(d){throw d}},e.fatal=function(a,b,c){try{e._log(e.FATAL,a,b,c)}catch(d){throw d}},b.exports=e})()}),require.define("/lib/modularinputs/argument.js",function(a,b,c,d,e){(function(){function e(a){a||(a={}),this.name=d.isUndefined(a.name)?"":a.name,this.description=d.isUndefined(a.description)?null:a.description,this.validation=d.isUndefined(a.validation)?null:a.validation,this.dataType=d.isUndefined(a.dataType)?e.dataTypeString:a.dataType,this.requiredOnEdit=d.isUndefined(a.requiredOnEdit)?!1:a.requiredOnEdit,this.requiredOnCreate=d.isUndefined(a.requiredOnCreate)?!1:a.requiredOnCreate}var c=a("elementtree"),d=a("./utils");e.dataTypeBoolean="BOOLEAN",e.dataTypeNumber="NUMBER",e.dataTypeString="STRING",e.prototype.addToDocument=function(a){var b=c.SubElement(a,"arg");b.set("name",this.name),this.description&&(c.SubElement(b,"description").text=this.description),this.validation&&(c.SubElement(b,"validation").text=this.validation);var d=[{tag:"data_type",value:this.dataType},{tag:"required_on_edit",value:this.requiredOnEdit},{tag:"required_on_create",value:this.requiredOnCreate}];for(var e=0;e")){clearTimeout(o);var g=h.parse(c);a._inputDefinition=g,k._inputDefinition=g,f.chain([function(b){f.parallelEach(Object.keys(a._inputDefinition.inputs),function(b,c,e){var g=a._inputDefinition.inputs[b];f.chain([function(c){a.start(b,g,c)},function(c){a.streamEvents(b,g,d,c)},function(c){a.end(b,g,c)}],function(a){e(a,a?1:0)})},function(a){b(a,a?1:0)})}],function(a){d._headerWritten&&d.close(),j(a,a?1:0)})}})}else if(b.length>=2&&b[1].toString().toLowerCase()==="--scheme"){var p=a.getScheme();if(!p)l.fatal("","script returned a null scheme.",d._err),j(null,1);else try{d.writeXMLDocument(p.toXML()),j(null,0)}catch(q){l.fatal("","script could not return the scheme, error: "+q,d._err),j(q,1)}}else if(b.length>=2&&b[1].toString().toLowerCase()==="--validate-arguments"){var r=setTimeout(function(){j(new Error("Receiving validation definition prior to validating timed out."),1)},30500);i.on("data",function(b){n=Buffer.concat([n,b]);var h=n.toString("utf8",0,n.length).trim();e.endsWith(h,"")&&(clearTimeout(r),f.chain([function(b){try{if(e.isUndefined(a.validateInput))b();else{var c=g.parse(n.toString("utf8",0,n.length));a.validateInput(c,b)}}catch(d){b(d)}}],function(a){if(a){l.error("",a.message),l.error("","Stack trace for a modular input error: "+a.stack);try{var b=c.Element("error");c.SubElement(b,"message").text=a.message,d.writeXMLDocument(b),j(a,1)}catch(e){j(e,1)}}else j(null,0)}))})}else{var s="Invalid arguments to modular input script: "+b.join()+"\n";l.error("",s,d._err),j(s,1)}},m.service=function(){if(this._service)return this._service;if(!this._inputDefinition)return null;var a=this._inputDefinition.metadata.server_uri,b=this._inputDefinition.metadata.session_key,c=d.parse(a),e=c.protocol.replace(":",""),f=c.hostname,g=c.port;return this._service=new k({scheme:e,host:f,port:g,token:b}),this._service},m.prototype.setup=function(a){a()},m.prototype.start=function(a,b,c){c()},m.prototype.end=function(a,b,c){c()},m.prototype.teardown=function(a){a()},b.exports=m})()}),require.define("url",function(a,b,c,d,e){function v(a,b,c){if(a&&typeof a=="object"&&a.href)return a;if(typeof a!="string")throw new TypeError("Parameter 'url' must be a string, not "+typeof a);var d={},e=a;for(var h=0,j=e.length;hn)d.hostname="";else{var G=d.hostname.split(/\./);for(var h=0,j=G.length;h127?I+="x":I+=H[J];if(!I.match(o)){var L=G.slice(0,h),M=G.slice(h+1),N=H.match(p);N&&(L.push(N[1]),M.unshift(N[2])),M.length&&(e="/"+M.join(".")+e),d.hostname=L.join(".");break}}}}d.hostname=d.hostname.toLowerCase();var O=d.hostname.split("."),P=[];for(var h=0;h0?a.host.split("@"):!1;j&&(a.auth=j.shift(),a.host=a.hostname=j.shift())}a.search=b.search,a.query=b.query;if(a.pathname!==undefined||a.search!==undefined)a.path=(a.pathname?a.pathname:"")+(a.search?a.search:"");return a.href=w(a),a}if(!h.length)return delete a.pathname,a.search?delete a.path:a.path="/"+a.search,a.href=w(a),a;var k=h.slice(-1)[0],l=(a.host||b.host)&&(k==="."||k==="..")||k==="",m=0;for(var n=h.length;n>=0;n--)k=h[n],k=="."?h.splice(n,1):k===".."?(h.splice(n,1),m++):m&&(h.splice(n,1),m--);if(!f&&!g)for(;m--;m)h.unshift("..");f&&h[0]!==""&&(!h[0]||h[0].charAt(0)!=="/")&&h.unshift(""),l&&h.join("/").substr(-1)!=="/"&&h.push("");var o=h[0]===""||h[0]&&h[0].charAt(0)==="/";if(i){a.hostname=a.host=o?"":h.length?h.shift():"";var j=a.host&&a.host.indexOf("@")>0?a.host.split("@"):!1;j&&(a.auth=j.shift(),a.host=a.hostname=j.shift())}f=f||a.host&&h.length,f&&!o&&h.unshift(""),a.pathname=h.join("/");if(a.pathname!==undefined||a.search!==undefined)a.path=(a.pathname?a.pathname:"")+(a.search?a.search:"");return a.auth=b.auth||a.auth,a.slashes=a.slashes||b.slashes,a.href=w(a),a}function z(a){var b={},c=h.exec(a);return c&&(c=c[0],b.port=c.substr(1),a=a.substr(0,a.length-c.length)),a&&(b.hostname=a),b}var f={encode:function(a){return a}};c.parse=v,c.resolve=x,c.resolveObject=y,c.format=w;var g=/^([a-z0-9.+-]+:)/i,h=/:[0-9]+$/,i=["<",">",'"',"`"," ","\r","\n","\t"],j=["{","}","|","\\","^","~","[","]","`"].concat(i),k=["'"],l=["%","/","?",";","#"].concat(j).concat(k),m=["/","@","?","#"].concat(i),n=255,o=/^[a-zA-Z0-9][a-z0-9A-Z_-]{0,62}$/,p=/^([a-zA-Z0-9][a-z0-9A-Z_-]{0,62})(.*)$/,q={javascript:!0,"javascript:":!0},r={javascript:!0,"javascript:":!0},s={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},t={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},u=a("querystring")}),require.define("querystring",function(a,b,c,d,e){function j(a,b){if(!b)throw new TypeError("stringify expects an object");return b+"="+encodeURIComponent(a)}function k(a,b){var c=[];if(!b)throw new TypeError("stringify expects an object");for(var d=0;d","Username to login with",undefined,!0).option("--password ","Username to login with",undefined,!1).option("--scheme ","Scheme to use","https",!1).option("--host ","Hostname to use","localhost",!1).option("--port ","Port to use",8089,!1).option("--version ","Which version to use","4",!1),a.parse=function(c){c=(c||[]).slice(2);var d=j();for(var e in d)if(d.hasOwnProperty(e)&&c.indexOf("--"+e)<0){var f=d[e];c.unshift(f),c.unshift("--"+e.trim())}c.unshift(""),c.unshift("");var g=b.call(a,c);return g},a.add=function(b,c,d,e,f,h){var i={};e=e||[];var j=a.command(b+(d?" "+d:"")).description(c||"");for(var k=0;k=0,m="<"+e[k]+">";j.option("--"+e[k]+" "+m,"",undefined,l)}j.action(function(){var a=g.toArray(arguments);a.unshift(b),h.apply(null,a)})},a}})()}),require.define("/tests/test_service.js",function(a,b,c,d,e){c.setup=function(b,c){var d=a("../index"),f=d.Utils,g=d.Async,h=a("./utils"),i=a("path");d.Logger.setLevel("ALL");var j=0,k=function(){return"id"+j++ +"_"+(new Date).valueOf()},l={"Namespace Tests":{setUp:function(a){this.service=b;var c=this,d="jssdk_testapp_"+k(),e="jssdk_testapp_"+k(),f="jssdk_testuser_"+k(),h="jssdk_testuser_"+k(),i=this.service.apps(),j=this.service.users();this.namespace11={owner:f,app:d},this.namespace12={owner:f,app:e},this.namespace21={owner:h,app:d},this.namespace22={owner:h,app:e},g.chain([function(a){i.create({name:d},a)},function(a,b){c.app1=a,c.appName1=d,i.create({name:e},b)},function(a,b){c.app2=a,c.appName2=e,j.create({name:f,password:"abc",roles:["user"]},b)},function(a,b){c.user1=a,c.userName1=f,j.create({name:h,password:"abc",roles:["user"]},b)},function(a,b){c.user2=a,c.userName2=h,b()}],function(b){a()})},"Callback#Namespace protection":function(a){var b="jssdk_search_"+k(),c="search *",d=this.service,e=d.savedSearches(this.namespace11),f=d.savedSearches(this.namespace21),h=this;g.chain([function(a){e.create({name:b,search:c},a)},function(a,b){e.fetch(b)},function(a,b){f.fetch(b)},function(d,g){var h=e.item(b),i=f.item(b);a.ok(h),a.strictEqual(h.name,b),a.strictEqual(h.properties().search,c),a.ok(!i),g()}],function(b){a.ok(!b),a.done()})},"Callback#Namespace item":function(a){var b="jssdk_search_"+k(),c="search *",d=this.service,e={owner:"-",app:this.appName1},f={owner:"nobody",app:this.appName1},h=d.savedSearches(this.namespace11),i=d.savedSearches(this.namespace21),j=d.savedSearches(e),l=d.savedSearches(f),m=this;g.chain([function(a){h.create({name:b,search:c},a)},function(a,d){i.create({name:b,search:c},d)},function(a,b){j.fetch(b)},function(a,b){h.fetch(b)},function(a,b){i.fetch(b)},function(d,e){var f=h.item(b,m.namespace11),g=i.item(b,m.namespace21);a.ok(f),a.strictEqual(f.name,b),a.strictEqual(f.properties().search,c),a.strictEqual(f.namespace.owner,m.namespace11.owner),a.strictEqual(f.namespace.app,m.namespace11.app),a.ok(g),a.strictEqual(g.name,b),a.strictEqual(g.properties().search,c),a.strictEqual(g.namespace.owner,m.namespace21.owner),a.strictEqual(g.namespace.app,m.namespace21.app),e()},function(a){l.create({name:b,search:c},a)},function(a,b){h.fetch(b)},function(a,b){i.fetch(b)},function(d,e){try{j.item(b),a.ok(!1)}catch(f){a.ok(f)}try{j.item(b,{owner:"-"}),a.ok(!1)}catch(f){a.ok(f)}try{j.item(b,{app:"-"}),a.ok(!1)}catch(f){a.ok(f)}try{j.item(b,{app:"-",owner:"-"}),a.ok(!1)}catch(f){a.ok(f)}var g=j.item(b,m.namespace11),h=j.item(b,m.namespace21);a.ok(g),a.strictEqual(g.name,b),a.strictEqual(g.properties().search,c),a.strictEqual(g.namespace.owner,m.namespace11.owner),a.strictEqual(g.namespace.app,m.namespace11.app),a.ok(h),a.strictEqual(h.name,b),a.strictEqual(h.properties().search,c),a.strictEqual(h.namespace.owner,m.namespace21.owner),a.strictEqual(h.namespace.app,m.namespace21.app),e()}],function(b){a.ok(!b),a.done()})},"Callback#delete test applications":function(a){var b=this.service.apps();b.fetch(function(b,c){a.ok(!b),a.ok(c);var d=c.list();g.parallelEach(d,function(a,b,c){f.startsWith(a.name,"jssdk_")?a.remove(c):c()},function(b){a.ok(!b),a.done()})})},"Callback#delete test users":function(a){var b=this.service.users();b.fetch(function(b,c){var d=c.list();g.parallelEach(d,function(a,b,c){f.startsWith(a.name,"jssdk_")?a.remove(c):c()},function(b){a.ok(!b),a.done()})})}},"Job Tests":{setUp:function(a){this.service=b,a()},"Callback#Create+abort job":function(a){var b=this.service;g.chain([function(a){var c=i.join(process.env.SPLUNK_HOME,"/etc/apps/sdk-app-collection/build/sleep_command.tar");c=c.replace("%20"," "),b.post("apps/appinstall",{update:1,name:c},a)},function(c){var d=k(),e={id:d},f=b.jobs({app:"sdk-app-collection"}),h=f.oneshotSearch("search index=_internal | head 1 | sleep 10",e,function(b,c){a.ok(b),a.ok(!c),a.strictEqual(b.error,"abort"),a.done()});g.sleep(1e3,function(){h.abort()})}],function(b){a.ok(!b),a.done()})},"Callback#Create+cancel job":function(a){var b=k();this.service.jobs().search("search index=_internal | head 1",{id:b},function(c,d){a.ok(d),a.strictEqual(d.sid,b),d.cancel(function(){a.done()})})},"Callback#Create job error":function(a){var b=k();this.service.jobs().search({search:"index=_internal | head 1",id:b},function(b){a.ok(!!b),a.done()})},"Callback#List jobs":function(a){this.service.jobs().fetch(function(b,c){a.ok(!b),a.ok(c);var d=c.list();a.ok(d.length>0);for(var e=0;ec),a.ok(e<=c*2),b.cancel(d)}],function(b){a.ok(!b),a.done()})},"Callback#Set priority":function(a){var b=k(),c=0,d=this,e=this.service.specialize("nobody","sdk-app-collection");g.chain([function(a){e.jobs().search("search index=_internal | head 1 | sleep 5",{id:b},a)},function(a,b){a.track({},{ready:function(a){b(null,a)}})},function(b,c){var d=b.properties().priority;a.ok(d,5),b.setPriority(d+1,c)},function(a,b){a.fetch(b)},function(a,b){a.cancel(b)}],function(b){a.ok(!b),a.done()})},"Callback#Search log":function(a){var b=k(),c=this;g.chain([function(a){c.service.jobs().search("search index=_internal | head 1",{id:b,exec_mode:"blocking"},a)},function(a,b){a.searchlog(b)},function(b,c,d){a.ok(c),a.ok(b),a.ok(b.length>0),a.ok(b.split("\r\n").length>0),c.cancel(d)}],function(b){a.ok(!b),a.done()})},"Callback#Search summary":function(a){var b=k(),c=this;g.chain([function(a){c.service.jobs().search('search index=_internal | head 1 | eval foo="bar" | fields foo',{id:b,status_buckets:300,rf:["foo"]},a)},function(a,b){g.sleep(2e3,function(){a.summary({},b)})},function(b,c,d){a.ok(c),a.ok(b),a.strictEqual(b.event_count,1),a.strictEqual(b.fields.foo.count,1),a.strictEqual(b.fields.foo.distinct_count,1),a.ok(b.fields.foo.is_exact,1),a.strictEqual(b.fields.foo.modes.length,1),a.strictEqual(b.fields.foo.modes[0].count,1),a.strictEqual(b.fields.foo.modes[0].value,"bar"),a.ok(b.fields.foo.modes[0].is_exact),c.cancel(d)}],function(b){a.ok(!b),a.done()})},"Callback#Search timeline":function(a){var b=k(),c=this;g.chain([function(a){c.service.jobs().search('search index=_internal | head 1 | eval foo="bar" | fields foo',{id:b,status_buckets:300,rf:["foo"],exec_mode:"blocking"},a)},function(a,b){a.timeline({},b)},function(b,c,d){a.ok(c),a.ok(b),a.strictEqual(b.buckets.length,1),a.strictEqual(b.event_count,1),a.strictEqual(b.buckets[0].available_count,1),a.strictEqual(b.buckets[0].duration,.001),a.strictEqual(b.buckets[0].earliest_time_offset,b.buckets[0].latest_time_offset),a.strictEqual(b.buckets[0].total_count,1),a.ok(b.buckets[0].is_finalized),c.cancel(d)}],function(b){a.ok(!b),a.done()})},"Callback#Touch":function(a){var b=k(),c=this,d="";g.chain([function(a){c.service.jobs().search("search index=_internal | head 1",{id:b},a)},function(a,b){a.fetch(b)},function(b,c){a.ok(b),d=b.properties().updated,g.sleep(1200,function(){b.touch(c)})},function(a,b){a.fetch(b)},function(b,c){a.ok(d!==b.updated()),b.cancel(c)}],function(b){a.ok(!b),a.done()})},"Callback#Create failure":function(a){var b="jssdk_savedsearch_"+k(),c="search index=_internal | head 1",d=this.service.jobs();a.throws(function(){d.create({search:c,name:b,exec_mode:"oneshot"},function(){})}),a.done()},"Callback#Create fails with no search string":function(a){var b=this.service.jobs();b.create("",{},function(b){a.ok(b),a.done()})},"Callback#Oneshot search":function(a){var b=k(),c=this,d="";g.chain([function(a){c.service.jobs().oneshotSearch("search index=_internal | head 1 | stats count",{id:b},a)},function(b,c){a.ok(b),a.ok(b.fields),a.strictEqual(b.fields.length,1),a.strictEqual(b.fields[0],"count"),a.ok(b.rows),a.strictEqual(b.rows.length,1),a.strictEqual(b.rows[0].length,1),a.strictEqual(b.rows[0][0],"1"),c()}],function(b){a.ok(!b),a.done()})},"Callback#Oneshot search with no results":function(a){var b=k(),c=this,d="";g.chain([function(a){var d="search index=history MUST_NOT_EXISTABCDEF";c.service.jobs().oneshotSearch(d,{id:b},a)},function(b,c){a.ok(b),a.strictEqual(b.fields.length,0),a.strictEqual(b.rows.length,0),a.ok(!b.preview),c()}],function(b){a.ok(!b),a.done()})},"Callback#Service oneshot search":function(a){var b=k(),c=this,d={owner:"admin",app:"search"},e=6.1,f="DEBUG";g.chain([function(b){g.chain([function(a){c.service.serverInfo(a)},function(a,c){e=parseFloat(a.properties().version),e<6.2?b():c()},function(a){c.service.configurations({owner:"admin",app:"search"}).fetch(a)},function(a,b){try{a.item("limits").fetch(b)}catch(c){b(c)}},function(a,b){var c=a.item("search_info");f=c.properties().infocsv_log_level,c.update({infocsv_log_level:"DEBUG"},b)},function(b,c){a.strictEqual("DEBUG",b.properties().infocsv_log_level),c()}],function(c){a.ok(!c),b()})},function(a){c.service.oneshotSearch("search index=_internal | head 1 | stats count",{id:b},d,a)},function(b,c){a.ok(b),a.ok(b.fields),a.strictEqual(b.fields.length,1),a.strictEqual(b.fields[0],"count"),a.ok(b.rows),a.strictEqual(b.rows.length,1),a.strictEqual(b.rows[0].length,1),a.strictEqual(b.rows[0][0],"1"),a.ok(b.messages[1].text.indexOf('owner="admin"')),a.ok(b.messages[1].text.indexOf('app="search"')),c()},function(b){g.chain([function(a){e<6.2?b():a()},function(a){c.service.configurations({owner:"admin",app:"search"}).fetch(a)},function(a,b){try{a.item("limits").fetch(b)}catch(c){b(c)}},function(a,b){var c=a.item("search_info");c.update({infocsv_log_level:f},b)},function(b,c){a.strictEqual(f,b.properties().infocsv_log_level),c()}],function(c){a.ok(!c),b()})}],function(b){a.ok(!b),a.done()})},"Callback#Service search":function(a){var b=k(),c=this.service,d=this,e={owner:"admin",app:"search"};g.chain([function(a){d.service.search("search index=_internal | head 1 | stats count",{id:b},e,a)},function(c,d){a.strictEqual(c.sid,b),a.strictEqual(c.namespace,e),h.pollUntil(c,function(a){return c.properties().isDone},10,d)},function(a,b){a.results({},b)},function(b,c,d){a.strictEqual(b.rows.length,1),a.strictEqual(b.fields.length,1),a.strictEqual(b.fields[0],"count"),a.strictEqual(b.rows[0][0],"1"),c.cancel(d)}],function(b){a.ok(!b),a.done()})},"Callback#Wait until job done":function(a){this.service.search("search index=_internal | head 1000",{},function(b,c){a.ok(!b);var d=0,e=0;c.track({period:200},{ready:function(b){a.ok(b),d++},progress:function(b){a.ok(b),e++},done:function(b){a.ok(b),a.ok(d===1),a.ok(e>=1),a.done()},failed:function(b){a.ok(b),a.ok(!1,"Job failed unexpectedly."),a.done()},error:function(b){a.ok(b),a.ok(!1,"Error while tracking job."),a.done()}})})},"Callback#Wait until job failed":function(a){this.service.search("search index=_internal | head bogusarg",{},function(b,c){if(b){a.ok(!b),a.done();return}var d=0,e=0;c.track({period:200},{ready:function(b){a.ok(b),d++},progress:function(b){a.ok(b),e++},done:function(b){a.ok(b),a.ok(!1,"Job became done unexpectedly."),a.done()},failed:function(b){a.ok(b),a.ok(d===1),a.ok(e>=1),a.done()},error:function(b){a.ok(b),a.ok(!1,"Error while tracking job."),a.done()}})})},"Callback#track() with default params and one function":function(a){this.service.search("search index=_internal | head 1",{},function(b,c){if(b){a.ok(!b),a.done();return}c.track({},function(b){a.ok(b),a.done()})})},"Callback#track() should stop polling if only the ready callback is specified":function(a){this.service.search("search index=_internal | head 1",{},function(b,c){if(b){a.ok(!b),a.done();return}c.track({},{ready:function(b){a.ok(b)},_stoppedAfterReady:function(b){a.done()}})})},"Callback#track() a job that is not immediately ready":function(a){var b=20,c=b,e=!1;for(var f=0;f.*) To: (?.*) ",i.expression);var j=d.pbe9bd0rp4;a.ok(j),a.strictEqual("event1",j.owner),a.same(["event1"],j.lineage),a.strictEqual("GeoIP",j.type),a.ok(j.isGeoIP()),a.ok(!j.isLookup()),a.ok(!j.isEval()),a.ok(!j.isRex()),a.strictEqual("·Ä©·öô‡Øµ comment of pbe9bd0rp4",j.comment),a.strictEqual(5,j.outputFieldNames().length),a.strictEqual("output_from_reverse_hostname",j.inputField),c()}],function(b){a.ok(!b),a.done()})},"Callback#DataModels - run queries":function(a){if(this.skip){a.done();return}var b,c=this;g.chain([function(a){c.dataModels.fetch(a)},function(a,c){var d=a.item("internal_audit_logs");b=d.objectByName("searches"),b.startSearch({},"",c)},function(a,b){h.pollUntil(a,function(b){return a.properties().isDone},10,b)},function(b,c){a.strictEqual("| datamodel internal_audit_logs searches search",b.properties().request.search),b.cancel(c)},function(a,c){b.startSearch({status_buckets:5,enable_lookups:!1},"| head 3",c)},function(a,b){h.pollUntil(a,function(b){return a.properties().isDone},10,b)},function(b,c){a.strictEqual("| datamodel internal_audit_logs searches search | head 3",b.properties().request.search),b.cancel(c)}],function(b){a.ok(!b),a.done()})},"Callback#DataModels - baseSearch is parsed correctly":function(a){if(this.skip){a.done();return}var b;try{b=JSON.parse(f.readFile(e,"../data/model_with_multiple_types.json"))}catch(c){a.ok(!c),a.done()}var h="delete-me-"+k(),i,j=this;g.chain([function(a){j.dataModels.create(h,b,a)},function(b,c){i=b.objectByName("search1"),a.ok(i),a.ok(i instanceof d.Service.DataModelObject),a.strictEqual("BaseSearch",i.parentName),a.ok(i.isBaseSearch()),a.ok(!i.isBaseTransaction()),a.strictEqual("search index=_internal | head 10",i.baseSearch),c()}],function(b){a.ok(!b),a.done()})},"Callback#DataModels - baseTransaction is parsed correctly":function(a){if(this.skip){a.done();return}var b;try{b=JSON.parse(f.readFile(e,"../data/model_with_multiple_types.json"))}catch(c){a.ok(!c),a.done()}var h="delete-me-"+k(),i,j=this;g.chain([function(a){j.dataModels.create(h,b,a)},function(b,c){i=b.objectByName("transaction1"),a.ok(i),a.ok(i instanceof d.Service.DataModelObject),a.strictEqual("BaseTransaction",i.parentName),a.ok(i.isBaseTransaction()),a.ok(!i.isBaseSearch()),a.same(["event1"],i.objectsToGroup),a.same(["host","from"],i.groupByFields),a.strictEqual("25s",i.maxPause),a.strictEqual("100m",i.maxSpan),c()}],function(b){a.ok(!b),a.done()})}},"Pivot tests":{setUp:function(a){this.service=b,this.dataModels=b.dataModels({owner:"nobody",app:"search"}),this.skip=!1;var c=this;this.service.serverInfo(function(b,e){parseInt(e.properties().version.split(".")[0],10)<6&&(c.skip=!0,d.Logger.log("Skipping pivot tests...")),a(b)})},"Callback#Pivot - test constructor args":function(a){if(this.skip){a.done();return}var b="delete-me-"+k(),c;try{c=JSON.parse(f.readFile(e,"../data/data_model_for_pivot.json"))}catch(d){a.ok(!d),a.done()}var h=this;g.chain([function(a){h.dataModels.create(b,c,a)},function(b,c){a.ok(b.objectByName("test_data")),c()}],function(b){a.ok(!b),a.done()})},"Callback#Pivot - test acceleration, then pivot":function(a){if(this.skip){a.done();return}var b="delete-me-"+k(),c;try{c=JSON.parse(f.readFile(e,"../data/data_model_for_pivot.json"))}catch(d){a.ok(!d),a.done()}var h=this;g.chain([function(a){h.dataModels.create(b,c,a)},function(b,c){b.objectByName("test_data"),a.ok(b),b.acceleration.enabled=!0,b.acceleration.earliestTime="-2mon",b.acceleration.cronSchedule="0 */12 * * *",b.update(c)},function(b,c){var d=b.properties();a.strictEqual(!0,b.isAccelerated()),a.strictEqual(!0,!!b.acceleration.enabled),a.strictEqual("-2mon",b.acceleration.earliest_time),a.strictEqual("0 */12 * * *",b.acceleration.cron_schedule);var e=b.objectByName("test_data"),f=e.createPivotSpecification();a.strictEqual(e.dataModel.name,f.accelerationNamespace);var g="delete-me-"+k();f.setAccelerationJob(g),a.strictEqual("sid="+g,f.accelerationNamespace);var h="delete-me-"+k();f.accelerationNamespace=h,a.strictEqual(h,f.accelerationNamespace),f.addCellValue("test_data","Source Value","count").run(c)},function(b,c,d){a.ok(b),a.ok(c),a.notStrictEqual("FAILED",b.properties().dispatchState),b.track({},function(b){a.ok(c.tstatsSearch),a.strictEqual(0,b.properties().request.search.indexOf("| tstats")),a.strictEqual("| tstats",b.properties().request.search.match("^\\| tstats")[0]),a.strictEqual(1,b.properties().request.search.match("^\\| tstats").length),a.strictEqual(c.tstatsSearch,b.properties().request.search),d(null,b)})},function(b,c){a.ok(b),c()}],function(b){a.ok(!b),a.done()})},"Callback#Pivot - test illegal filtering (all types)":function(a){if(this.skip){a.done();return}var b="delete-me-"+k(),c;try{c=JSON.parse(f.readFile(e,"../data/data_model_for_pivot.json"))}catch(d){a.ok(!d),a.done()}var h=this;g.chain([function(a){h.dataModels.create(b,c,a)},function(b,c){var d=b.objectByName("test_data");a.ok(d);var e=d.createPivotSpecification();try{e.addFilter(k(),"boolean","=",!0),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Cannot add filter on a nonexistent field.")}try{e.addFilter("_time","boolean","=",!0),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Cannot add boolean filter on _time because it is of type timestamp")}try{e.addFilter("has_boris","string","contains","abc"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Cannot add string filter on has_boris because it is of type boolean")}try{e.addFilter(k(),"string","contains","abc"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Cannot add filter on a nonexistent field.")}try{e.addFilter("has_boris","ipv4","startsWith","192.168"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Cannot add ipv4 filter on has_boris because it is of type boolean")}try{e.addFilter(k(),"ipv4","startsWith","192.168"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Cannot add filter on a nonexistent field.")}try{e.addFilter("has_boris","number","atLeast",2.3),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Cannot add number filter on has_boris because it is of type boolean")}try{e.addFilter(k(),"number","atLeast",2.3),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Cannot add filter on a nonexistent field.")}try{e.addLimitFilter("has_boris","host","DEFAULT",50,"count"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Cannot add limit filter on has_boris because it is of type boolean")}try{e.addLimitFilter(k(),"host","DEFAULT",50,"count"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Cannot add limit filter on a nonexistent field.")}try{e.addLimitFilter("source","host","DEFAULT",50,"sum"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Stats function for fields of type string must be COUNT or DISTINCT_COUNT; found sum")}try{e.addLimitFilter("epsilon","host","DEFAULT",50,"duration"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Stats function for fields of type number must be one of COUNT, DISTINCT_COUNT, SUM, or AVERAGE; found duration")}try{e.addLimitFilter("test_data","host","DEFAULT",50,"list"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Stats function for fields of type object count must be COUNT; found list")}c()}],function(b){a.ok(!b),a.done()})},"Callback#Pivot - test boolean filtering":function(a){if(this.skip){a.done();return}var b="delete-me-"+k(),c;try{c=JSON.parse(f.readFile(e,"../data/data_model_for_pivot.json"))}catch(d){a.ok(!d),a.done()}var h=this;g.chain([function(a){h.dataModels.create(b,c,a)},function(b,c){var d=b.objectByName("test_data");a.ok(d);var e=d.createPivotSpecification();try{e.addFilter("has_boris","boolean","=",!0),a.strictEqual(1,e.filters.length);var f=e.filters[0];a.ok(f.hasOwnProperty("fieldName")),a.ok(f.hasOwnProperty("type")),a.ok(f.hasOwnProperty("rule")),a.ok(f.hasOwnProperty("owner")),a.strictEqual("has_boris",f.fieldName),a.strictEqual("boolean",f.type),a.strictEqual("=",f.rule.comparator),a.strictEqual(!0,f.rule.compareTo),a.strictEqual("test_data",f.owner)}catch(g){a.ok(!1)}c()}],function(b){a.ok(!b),a.done()})},"Callback#Pivot - test string filtering":function(a){if(this.skip){a.done();return}var b="delete-me-"+k(),c;try{c=JSON.parse(f.readFile(e,"../data/data_model_for_pivot.json"))}catch(d){a.ok(!d),a.done()}var h=this;g.chain([function(a){h.dataModels.create(b,c,a)},function(b,c){var d=b.objectByName("test_data");a.ok(d);var e=d.createPivotSpecification();try{e.addFilter("host","string","contains","abc"),a.strictEqual(1,e.filters.length);var f=e.filters[0];a.ok(f.hasOwnProperty("fieldName")),a.ok(f.hasOwnProperty("type")),a.ok(f.hasOwnProperty("rule")),a.ok(f.hasOwnProperty("owner")),a.strictEqual("host",f.fieldName),a.strictEqual("string",f.type),a.strictEqual("contains",f.rule.comparator),a.strictEqual("abc",f.rule.compareTo),a.strictEqual("BaseEvent",f.owner)}catch(g){a.ok(!1)}c()}],function(b){a.ok(!b),a.done()})},"Callback#Pivot - test IPv4 filtering":function(a){if(this.skip){a.done();return}var b="delete-me-"+k(),c;try{c=JSON.parse(f.readFile(e,"../data/data_model_for_pivot.json"))}catch(d){a.ok(!d),a.done()}var h=this;g.chain([function(a){h.dataModels.create(b,c,a)},function(b,c){var d=b.objectByName("test_data");a.ok(d);var e=d.createPivotSpecification();try{e.addFilter("hostip","ipv4","startsWith","192.168"),a.strictEqual(1,e.filters.length);var f=e.filters[0];a.ok(f.hasOwnProperty("fieldName")),a.ok(f.hasOwnProperty("type")),a.ok(f.hasOwnProperty("rule")),a.ok(f.hasOwnProperty("owner")),a.strictEqual("hostip",f.fieldName),a.strictEqual("ipv4",f.type),a.strictEqual("startsWith",f.rule.comparator),a.strictEqual("192.168",f.rule.compareTo),a.strictEqual("test_data",f.owner)}catch(g){a.ok(!1)}c()}],function(b){a.ok(!b),a.done()})},"Callback#Pivot - test number filtering":function(a){if(this.skip){a.done();return}var b="delete-me-"+k(),c;try{c=JSON.parse(f.readFile(e,"../data/data_model_for_pivot.json"))}catch(d){a.ok(!d),a.done()}var h=this;g.chain([function(a){h.dataModels.create(b,c,a)},function(b,c){var d=b.objectByName("test_data");a.ok(d);var e=d.createPivotSpecification();try{e.addFilter("epsilon","number",">=",2.3),a.strictEqual(1,e.filters.length);var f=e.filters[0];a.ok(f.hasOwnProperty("fieldName")),a.ok(f.hasOwnProperty("type")),a.ok(f.hasOwnProperty("rule")),a.ok(f.hasOwnProperty("owner")),a.strictEqual("epsilon",f.fieldName),a.strictEqual("number",f.type),a.strictEqual(">=",f.rule.comparator),a.strictEqual(2.3,f.rule.compareTo),a.strictEqual("test_data",f.owner)}catch(g){a.ok(!1)}c()}],function(b){a.ok(!b),a.done()})},"Callback#Pivot - test limit filtering":function(a){if(this.skip){a.done();return}var b="delete-me-"+k(),c;try{c=JSON.parse(f.readFile(e,"../data/data_model_for_pivot.json"))}catch(d){a.ok(!d),a.done()}var h=this;g.chain([function(a){h.dataModels.create(b,c,a)},function(b,c){var d=b.objectByName("test_data");a.ok(d);var e=d.createPivotSpecification();try{e.addLimitFilter("epsilon","host","ASCENDING",500,"average"),a.strictEqual(1,e.filters.length);var f=e.filters[0];a.ok(f.hasOwnProperty("fieldName")),a.ok(f.hasOwnProperty("type")),a.ok(f.hasOwnProperty("owner")),a.ok(f.hasOwnProperty("attributeName")),a.ok(f.hasOwnProperty("attributeOwner")),a.ok(f.hasOwnProperty("limitType")),a.ok(f.hasOwnProperty("limitAmount")),a.ok(f.hasOwnProperty("statsFn")),a.strictEqual("epsilon",f.fieldName),a.strictEqual("number",f.type),a.strictEqual("test_data",f.owner),a.strictEqual("host",f.attributeName),a.strictEqual("BaseEvent",f.attributeOwner),a.strictEqual("lowest",f.limitType),a.strictEqual(500,f.limitAmount),a.strictEqual("average",f.statsFn)}catch(g){a.ok(!1)}c()}],function(b){a.ok(!b),a.done()})},"Callback#Pivot - test row split":function(a){if(this.skip){a.done();return}var b="delete-me-"+k(),c;try{c=JSON.parse(f.readFile(e,"../data/data_model_for_pivot.json"))}catch(d){a.ok(!d),a.done()}var h=this;g.chain([function(a){h.dataModels.create(b,c,a)},function(b,c){var d=b.objectByName("test_data");a.ok(d);var e=d.createPivotSpecification();try{e.addRowSplit("has_boris","Wrong type here"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Field was of type "+d.fieldByName("has_boris").type+", expected number or string.")}var g=k();try{e.addRowSplit(g,"Break Me!"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Did not find field "+g)}e.addRowSplit("epsilon","My Label"),a.strictEqual(1,e.rows.length);var h=e.rows[0];a.ok(h.hasOwnProperty("fieldName")),a.ok(h.hasOwnProperty("owner")),a.ok(h.hasOwnProperty("type")),a.ok(h.hasOwnProperty("label")),a.ok(h.hasOwnProperty("display")),a.strictEqual("epsilon",h.fieldName),a.strictEqual("test_data",h.owner),a.strictEqual("number",h.type),a.strictEqual("My Label",h.label),a.strictEqual("all",h.display),a.same({fieldName:"epsilon",owner:"test_data",type:"number",label:"My Label",display:"all"},h),e.addRowSplit("host","My Label"),a.strictEqual(2,e.rows.length),h=e.rows[e.rows.length-1],a.ok(h.hasOwnProperty("fieldName")),a.ok(h.hasOwnProperty("owner")),a.ok(h.hasOwnProperty("type")),a.ok(h.hasOwnProperty("label")),a.ok(!h.hasOwnProperty("display")),a.strictEqual("host",h.fieldName),a.strictEqual("BaseEvent",h.owner),a.strictEqual("string",h.type),a.strictEqual("My Label",h.label),a.same({fieldName:"host",owner:"BaseEvent",type:"string",label:"My Label"},h);try{e.addRangeRowSplit("has_boris","Wrong type here",{start:0,end:100,step:20,limit:5})}catch(f){a.ok(f),a.strictEqual(f.message,"Field was of type "+d.fieldByName("has_boris").type+", expected number.")}try{e.addRangeRowSplit(g,"Break Me!",{start:0,end:100,step:20,limit:5}),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Did not find field "+g)}e.addRangeRowSplit("epsilon","My Label",{start:0,end:100,step:20,limit:5}),a.strictEqual(3,e.rows.length),h=e.rows[e.rows.length-1],a.ok(h.hasOwnProperty("fieldName")),a.ok(h.hasOwnProperty("owner")),a.ok(h.hasOwnProperty("type")),a.ok(h.hasOwnProperty("label")),a.ok(h.hasOwnProperty("display")),a.ok(h.hasOwnProperty("ranges")),a.strictEqual("epsilon",h.fieldName),a.strictEqual("test_data",h.owner),a.strictEqual("number",h.type),a.strictEqual("My Label",h.label),a.strictEqual("ranges",h.display);var i={start:0,end:100,size:20,maxNumberOf:5};a.same(i,h.ranges),a.same({fieldName:"epsilon",owner:"test_data",type:"number",label:"My Label",display:"ranges",ranges:i},h);try{e.addBooleanRowSplit("epsilon","Wrong type here","t","f")}catch(f){a.ok(f),a.strictEqual(f.message,"Field was of type "+d.fieldByName("epsilon").type+", expected boolean.")}try{e.addBooleanRowSplit(g,"Break Me!","t","f"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Did not find field "+g)}e.addBooleanRowSplit("has_boris","My Label","is_true","is_false"),a.strictEqual(4,e.rows.length),h=e.rows[e.rows.length-1],a.ok(h.hasOwnProperty("fieldName")),a.ok(h.hasOwnProperty("owner")),a.ok(h.hasOwnProperty("type")),a.ok(h.hasOwnProperty("label")),a.ok(h.hasOwnProperty("trueLabel")),a.ok(h.hasOwnProperty("falseLabel")),a.strictEqual("has_boris",h.fieldName),a.strictEqual("My Label",h.label),a.strictEqual("test_data",h.owner),a.strictEqual("boolean",h.type),a.strictEqual("is_true",h.trueLabel),a.strictEqual("is_false",h.falseLabel),a.same({fieldName:"has_boris",label:"My Label",owner:"test_data",type:"boolean",trueLabel:"is_true",falseLabel:"is_false"},h);try{e.addTimestampRowSplit("epsilon","Wrong type here","some binning")}catch(f){a.ok(f),a.strictEqual(f.message,"Field was of type "+d.fieldByName("epsilon").type+", expected timestamp.")}try{e.addTimestampRowSplit(g,"Break Me!","some binning"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Did not find field "+g)}try{e.addTimestampRowSplit("_time","some label","Bogus binning value"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Invalid binning Bogus binning value found. Valid values are: "+e._binning.join(", "))}e.addTimestampRowSplit("_time","My Label","day"),a.strictEqual(5,e.rows.length),h=e.rows[e.rows.length-1],a.ok(h.hasOwnProperty("fieldName")),a.ok(h.hasOwnProperty("owner")),a.ok(h.hasOwnProperty("type")),a.ok(h.hasOwnProperty("label")),a.ok(h.hasOwnProperty("period")),a.strictEqual("_time",h.fieldName),a.strictEqual("My Label",h.label),a.strictEqual("BaseEvent",h.owner),a.strictEqual("timestamp",h.type),a.strictEqual("day",h.period),a.same({fieldName:"_time",label:"My Label",owner:"BaseEvent",type:"timestamp",period:"day"},h),c()}],function(b){a.ok(!b),a.done()})},"Callback#Pivot - test column split":function(a){if(this.skip){a.done();return}var b="delete-me-"+k(),c;try{c=JSON.parse(f.readFile(e,"../data/data_model_for_pivot.json"))}catch(d){a.ok(!d),a.done()}var h=this;g.chain([function(a){h.dataModels.create(b,c,a)},function(b,c){var d=b.objectByName("test_data");a.ok(d);var e=d.createPivotSpecification();try{e.addColumnSplit("has_boris","Wrong type here"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Field was of type "+d.fieldByName("has_boris").type+", expected number or string.")}var g=k();try{e.addColumnSplit(g,"Break Me!"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Did not find field "+g)}e.addColumnSplit("epsilon"),a.strictEqual(1,e.columns.length);var h=e.columns[e.columns.length-1];a.ok(h.hasOwnProperty("fieldName")),a.ok(h.hasOwnProperty("owner")),a.ok(h.hasOwnProperty("type")),a.ok(h.hasOwnProperty("display")),a.strictEqual("epsilon",h.fieldName),a.strictEqual("test_data",h.owner),a.strictEqual("number",h.type),a.strictEqual("all",h.display),a.same({fieldName:"epsilon",owner:"test_data",type:"number",display:"all"},h),e.addColumnSplit("host"),a.strictEqual(2,e.columns.length),h=e.columns[e.columns.length-1],a.ok(h.hasOwnProperty("fieldName")),a.ok(h.hasOwnProperty("owner")),a.ok(h.hasOwnProperty("type")),a.ok(!h.hasOwnProperty("display")),a.strictEqual("host",h.fieldName),a.strictEqual("BaseEvent",h.owner),a.strictEqual("string",h.type),a.same({fieldName:"host",owner:"BaseEvent",type:"string"},h),c();try{e.addRangeColumnSplit("has_boris","Wrong type here",{start:0,end:100,step:20,limit:5})}catch(f){a.ok(f),a.strictEqual(f.message,"Field was of type "+d.fieldByName("has_boris").type+", expected number.")}try{e.addRangeColumnSplit(g,{start:0,end:100,step:20,limit:5}),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Did not find field "+g)}e.addRangeColumnSplit("epsilon",{start:0,end:100,step:20,limit:5}),a.strictEqual(3,e.columns.length),h=e.columns[e.columns.length-1],a.ok(h.hasOwnProperty("fieldName")),a.ok(h.hasOwnProperty("owner")),a.ok(h.hasOwnProperty("type")),a.ok(h.hasOwnProperty("display")),a.ok(h.hasOwnProperty("ranges")),a.strictEqual("epsilon",h.fieldName),a.strictEqual("test_data",h.owner),a.strictEqual("number",h.type),a.strictEqual("ranges",h.display);var i={start:"0",end:"100",size:"20",maxNumberOf:"5"};a.same(i,h.ranges),a.same({fieldName:"epsilon",owner:"test_data",type:"number",display:"ranges",ranges:i},h);try{e.addBooleanColumnSplit("epsilon","t","f")}catch(f){a.ok(f),a.strictEqual(f.message,"Field was of type "+d.fieldByName("epsilon").type+", expected boolean.")}try{e.addBooleanColumnSplit(g,"t","f"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Did not find field "+g)}e.addBooleanColumnSplit("has_boris","is_true","is_false"),a.strictEqual(4,e.columns.length),h=e.columns[e.columns.length-1],a.ok(h.hasOwnProperty("fieldName")),a.ok(h.hasOwnProperty("owner")),a.ok(h.hasOwnProperty("type")),a.ok(!h.hasOwnProperty("label")),a.ok(h.hasOwnProperty("trueLabel")),a.ok(h.hasOwnProperty("falseLabel")),a.strictEqual("has_boris",h.fieldName),a.strictEqual("test_data",h.owner),a.strictEqual("boolean",h.type),a.strictEqual("is_true",h.trueLabel),a.strictEqual("is_false",h.falseLabel),a.same({fieldName:"has_boris",owner:"test_data",type:"boolean",trueLabel:"is_true",falseLabel:"is_false"},h);try{e.addTimestampColumnSplit("epsilon","Wrong type here")}catch(f){a.ok(f),a.strictEqual(f.message,"Field was of type "+d.fieldByName("epsilon").type+", expected timestamp.")}try{e.addTimestampColumnSplit(g,"Break Me!"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Did not find field "+g)}try{e.addTimestampColumnSplit("_time","Bogus binning value"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Invalid binning Bogus binning value found. Valid values are: "+e._binning.join(", "))}e.addTimestampColumnSplit("_time","day"),a.strictEqual(5,e.columns.length),h=e.columns[e.columns.length-1],a.ok(h.hasOwnProperty("fieldName")),a.ok(h.hasOwnProperty("owner")),a.ok(h.hasOwnProperty("type")),a.ok(!h.hasOwnProperty("label")),a.ok(h.hasOwnProperty("period")),a.strictEqual("_time",h.fieldName),a.strictEqual("BaseEvent",h.owner),a.strictEqual("timestamp",h.type),a.strictEqual("day",h.period),a.same({fieldName:"_time",owner:"BaseEvent",type:"timestamp",period:"day"},h)}],function(b){a.ok(!b),a.done()})},"Callback#Pivot - test cell value":function(a){if(this.skip){a.done();return}var b="delete-me-"+k(),c;try{c=JSON.parse(f.readFile(e,"../data/data_model_for_pivot.json"))}catch(d){a.ok(!d),a.done()}var h=this;g.chain([function(a){h.dataModels.create(b,c,a)},function(b,c){var d=b.objectByName("test_data");a.ok(d);var e=d.createPivotSpecification();try{e.addCellValue("iDontExist","Break Me!","explosion"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Did not find field iDontExist")}try{e.addCellValue("source","Wrong Stats Function","stdev"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Stats function on string and IPv4 fields must be one of: list, distinct_values, first, last, count, or distinct_count; found stdev")}e.addCellValue("source","Source Value","dc"),a.strictEqual(1,e.cells.length);var g=e.cells[e.cells.length-1];a.ok(g.hasOwnProperty("fieldName")),a.ok(g.hasOwnProperty("owner")),a.ok(g.hasOwnProperty("type")),a.ok(g.hasOwnProperty("label")),a.ok(g.hasOwnProperty("value")),a.ok(g.hasOwnProperty("sparkline")),a.strictEqual("source",g.fieldName),a.strictEqual("BaseEvent",g.owner),a.strictEqual("string",g.type),a.strictEqual("Source Value",g.label),a.strictEqual("dc",g.value),a.strictEqual(!1,g.sparkline),a.same({fieldName:"source",owner:"BaseEvent",type:"string",label:"Source Value",value:"dc",sparkline:!1},g);try{e.addCellValue("hostip","Wrong Stats Function","stdev"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Stats function on string and IPv4 fields must be one of: list, distinct_values, first, last, count, or distinct_count; found stdev")}e.addCellValue("hostip","Source Value","dc"),a.strictEqual(2,e.cells.length),g=e.cells[e.cells.length-1],a.ok(g.hasOwnProperty("fieldName")),a.ok(g.hasOwnProperty("owner")),a.ok(g.hasOwnProperty("type")),a.ok(g.hasOwnProperty("label")),a.ok(g.hasOwnProperty("value")),a.ok(g.hasOwnProperty("sparkline")),a.strictEqual("hostip",g.fieldName),a.strictEqual("test_data",g.owner),a.strictEqual("ipv4",g.type),a.strictEqual("Source Value",g.label),a.strictEqual("dc",g.value),a.strictEqual(!1,g.sparkline),a.same({fieldName:"hostip",owner:"test_data",type:"ipv4",label:"Source Value",value:"dc",sparkline:!1},g);try{e.addCellValue("has_boris","Booleans not allowed","sum"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Cannot use boolean valued fields as cell values.")}try{e.addCellValue("epsilon","Wrong Stats Function","latest"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Stats function on number field must be must be one of: sum, count, average, max, min, stdev, list, or distinct_values; found latest")}e.addCellValue("epsilon","Source Value","average"),a.strictEqual(3,e.cells.length),g=e.cells[e.cells.length-1],a.ok(g.hasOwnProperty("fieldName")),a.ok(g.hasOwnProperty("owner")),a.ok(g.hasOwnProperty("type")),a.ok(g.hasOwnProperty("label")),a.ok(g.hasOwnProperty("value")),a.ok(g.hasOwnProperty("sparkline")),a.strictEqual("epsilon",g.fieldName),a.strictEqual("test_data",g.owner),a.strictEqual("number",g.type),a.strictEqual("Source Value",g.label),a.strictEqual("average",g.value),a.strictEqual(!1,g.sparkline),a.same({fieldName:"epsilon",owner:"test_data",type:"number",label:"Source Value",value:"average",sparkline:!1},g);try{e.addCellValue("_time","Wrong Stats Function","max"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Stats function on timestamp field must be one of: duration, earliest, latest, list, or distinct values; found max")}e.addCellValue("_time","Source Value","earliest"),a.strictEqual(4,e.cells.length),g=e.cells[e.cells.length-1],a.ok(g.hasOwnProperty("fieldName")),a.ok(g.hasOwnProperty("owner")),a.ok(g.hasOwnProperty("type")),a.ok(g.hasOwnProperty("label")),a.ok(g.hasOwnProperty("value")),a.ok(g.hasOwnProperty("sparkline")),a.strictEqual("_time",g.fieldName),a.strictEqual("BaseEvent",g.owner),a.strictEqual("timestamp",g.type),a.strictEqual("Source Value",g.label),a.strictEqual("earliest",g.value),a.strictEqual(!1,g.sparkline),a.same({fieldName:"_time",owner:"BaseEvent",type:"timestamp",label:"Source Value",value:"earliest",sparkline:!1},g);try{e.addCellValue("test_data","Wrong Stats Function","min"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Stats function on childcount and objectcount fields must be count; found min")}e.addCellValue("test_data","Source Value","count"),a.strictEqual(5,e.cells.length),g=e.cells[e.cells.length-1],a.ok(g.hasOwnProperty("fieldName")),a.ok(g.hasOwnProperty("owner")),a.ok(g.hasOwnProperty("type")),a.ok(g.hasOwnProperty("label")),a.ok(g.hasOwnProperty("value")),a.ok(g.hasOwnProperty("sparkline")),a.strictEqual("test_data",g.fieldName),a.strictEqual("test_data",g.owner),a.strictEqual("objectCount",g.type),a.strictEqual("Source Value",g.label),a.strictEqual("count",g.value),a.strictEqual(!1,g.sparkline),a.same({fieldName:"test_data",owner:"test_data",type:"objectCount",label:"Source Value",value:"count",sparkline:!1},g),c()}],function(b){a.ok(!b),a.done()})},"Callback#Pivot - test pivot throws HTTP exception":function(a){if(this.skip){a.done();return}var b="delete-me-"+k(),c;try{c=JSON.parse(f.readFile(e,"../data/data_model_for_pivot.json"))}catch(d){a.ok(!d),a.done()}var h=this;g.chain([function(a){h.dataModels.create(b,c,a)},function(b,c){var d=b.objectByName("test_data");a.ok(d),d.createPivotSpecification().pivot(c)},function(b,c){a.ok(!1)}],function(b){a.ok(b);var c="In handler 'datamodelpivot': Error in 'PivotReport': Must have non-empty cells or non-empty rows.";a.ok(f.endsWith(b.message,c)),a.done()})},"Callback#Pivot - test pivot with simple namespace":function(a){if(this.skip){a.done();return}var b="delete-me-"+k(),c;try{c=JSON.parse(f.readFile(e,"../data/data_model_for_pivot.json"))}catch(d){a.ok(!d),a.done()}var i=this,j,l,m;g.chain([function(a){i.dataModels.create(b,c,a)},function(b,c){j=b.objectByName("test_data"),a.ok(j),j.createLocalAccelerationJob(null,c)},function(b,c){m=b,a.ok(b),l=j.createPivotSpecification(),l.addBooleanRowSplit("has_boris","Has Boris","meep","hilda"),l.addCellValue("hostip","Distinct IPs","count"),l.setAccelerationJob(b),a.strictEqual("string",typeof l.accelerationNamespace),a.strictEqual("sid="+b.sid,l.accelerationNamespace),l.setAccelerationJob(b.sid),a.strictEqual("string",typeof l.accelerationNamespace),a.strictEqual("sid="+b.sid,l.accelerationNamespace),l.pivot(c)},function(b,c){a.ok(b.tstatsSearch),a.ok(b.tstatsSearch.length>0),a.strictEqual(0,b.tstatsSearch.indexOf("| tstats")),a.strictEqual("| tstats",b.tstatsSearch.match("^\\| tstats")[0]),a.strictEqual(1,b.tstatsSearch.match("^\\| tstats").length),b.run(c)},function(a,b){h.pollUntil(a,function(b){return a.properties().isDone},10,b)},function(b,c){a.ok("FAILED"!==b.properties().dispatchState),a.strictEqual(0,b.properties().request.search.indexOf("| tstats")),a.strictEqual("| tstats",b.properties().request.search.match("^\\| tstats")[0]),a.strictEqual(1,b.properties().request.search.match("^\\| tstats").length),m.cancel(c)}],function(b){a.ok(!b),a.done()})},"Callback#Pivot - test pivot column range split":function(a){if(this.skip){a.done();return}var b=this,c;g.chain([function(a){b.dataModels.fetch(a)},function(a,b){var c=a.item("internal_audit_logs"),d=c.objectByName("searches"),e=d.createPivotSpecification();e.addRowSplit("user","Executing user"),e.addRangeColumnSplit("exec_time",{start:0,end:12,step:5,limit:4}),e.addCellValue("search","Search Query","values"),e.pivot(b)},function(a,b){c=a.tstatsSearch||a.pivotSearch,a.run(b)},function(a,b){h.pollUntil(a,function(b){return a.properties().isDone},10,b)},function(b,d){a.notStrictEqual("FAILED",b.properties().dispatchState),a.strictEqual(c,b.properties().request.search),b.cancel(d)}],function(b){a.ok(!b),a.done()})},"Callback#Pivot - test pivot with PivotSpecification.run and Job.track":function(a){if(this.skip){a.done();return}var b=this;g.chain([function(a){b.dataModels.fetch(a)},function(a,b){var c=a.item("internal_audit_logs"),d=c.objectByName("searches"),e=d.createPivotSpecification();e.addRowSplit("user","Executing user"),e.addRangeColumnSplit("exec_time",{start:0,end:12,step:5,limit:4}),e.addCellValue("search","Search Query","values"),e.run({},b)},function(b,c,d){b.track({},function(b){a.strictEqual(c.tstatsSearch||c.pivotSearch,b.properties().request.search),d(null,b)})},function(b,c){a.notStrictEqual("FAILED",b.properties().dispatchState),b.cancel(c)}],function(b){a.ok(!b),a.done()})},"Callback#DataModels - delete any remaining data models created by the SDK tests":function(a){if(this.skip){a.done();return}b.dataModels().fetch(function(b,c){b&&a.ok(!b);var d=c.list();g.seriesEach(d,function(a,b,c){f.startsWith(a.name,"delete-me")?a.remove(c):c()},function(b){a.ok(!b),a.done()})})}},"App Tests":{setUp:function(a){this.service=b,a()},"Callback#list applications":function(a){var b=this.service.apps();b.fetch(function(b,c){var d=c.list();a.ok(d.length>0),a.done()})},"Callback#contains applications":function(a){var b=this.service.apps();b.fetch(function(b,c){var d=c.item("search");a.ok(d),a.done()})},"Callback#create + contains app":function(a){var b="jssdk_testapp_"+k(),c=this.service.apps();c.create({name:b},function(b,d){var e=d.name;c.fetch(function(b,c){var f=c.item(e);a.ok(f),d.remove(function(){a.done()})})})},"Callback#create + modify app":function(a){var b="TEST DESCRIPTION",c="1.1.0",d="jssdk_testapp_"+k(),e=this.service.apps();g.chain([function(a){e.create({name:d},a)},function(e,f){a.ok(e),a.strictEqual(e.name,d);var g=e.properties().version==="1.0"||e.properties().version=="1.0.0";a.ok(g),e.update({description:b,version:c},f)},function(d,e){a.ok(d);var f=d.properties();a.strictEqual(f.description,b),a.strictEqual(f.version,c),d.remove(e)}],function(b){a.ok(!b),a.done()})},"Callback#delete test applications":function(a){var b=this.service.apps();b.fetch(function(b,c){var d=c.list();g.parallelEach(d,function(a,b,c){f.startsWith(a.name,"jssdk_")?a.remove(c):c()},function(b){a.ok(!b),a.done()})})},"list applications with cookies as authentication":function(a){this.service.serverInfo(function(c,e){var h=parseInt(e.properties().version.split(".")[0],10),i=parseInt(e.properties().version.split(".")[1],10);if(h<6||h===6&&i<2){d.Logger.log("Skipping cookie test..."),a.done();return}var j=new d.Service({scheme:b.scheme,host:b.host,port:b.port,username:b.username,password:b.password,version:b.version}),k=new d.Service({scheme:b.scheme,host:b.host,port:b.port,version:b.version});g.chain([function(a){j.login(a)},function(b,c){var d=j.http._cookieStore;a.ok(!f.isEmpty(d)),k.http._cookieStore=d;var e=k.apps();e.fetch(c)},function(b,c){var d=b.list();a.ok(d.length>0),a.ok(!f.isEmpty(k.http._cookieStore)),c()}],function(b){a.ok(!b),a.done()})})}},"Saved Search Tests":{setUp:function(a){this.service=b,this.loggedOutService=c,a()},"Callback#list":function(a){var b=this.service.savedSearches();b.fetch(function(b,c){var d=c.list();a.ok(d.length>0);for(var e=0;e0);for(var e=0;e1),a.ok(f.indexOf(b.fields().optional,"disabled")>-1),b.remove(c)}],function(b){a.ok(!b),a.done()})},"Callback#dispatch error":function(a){var b="jssdk_savedsearch_"+k(),c="search index=_internal | head 1",e=new d.Service.SavedSearch(this.loggedOutService,b,{owner:"nobody",app:"search"});e.dispatch(function(b){a.ok(b),a.done()})},"Callback#dispatch omitting optional arguments":function(a){var b="jssdk_savedsearch_"+k(),c="search index=_internal | head 1",d=this.service.savedSearches({owner:this.service.username,app:"sdk-app-collection"});g.chain([function(a){d.create({search:c,name:b},a)},function(d,e){a.ok(d),a.strictEqual(d.name,b),a.strictEqual(d.properties().search,c),a.ok(!d.properties().description),d.dispatch(e)},function(b,c,d){a.ok(b),a.ok(c),a.done()}])},"Callback#history error":function(a){var b="jssdk_savedsearch_"+k(),c="search index=_internal | head 1",e=new d.Service.SavedSearch(this.loggedOutService,b,{owner:"nobody",app:"search",sharing:"system"});e.history(function(b){a.ok(b),a.done()})},"Callback#Update error":function(a){var b="jssdk_savedsearch_"+k(),c="search index=_internal | head 1",e=new d.Service.SavedSearch(this.loggedOutService,b,{owner:"nobody",app:"search",sharing:"system"});e.update({},function(b){a.ok(b),a.done()})},"Callback#oneshot requires search string":function(a){a.throws(function(){this.service.oneshotSearch({name:"jssdk_oneshot_"+k()},function(a){})}),a.done()},"Callback#Create + dispatch + history":function(a){var b="jssdk_savedsearch_"+k(),c="search index=_internal | head 1",d=this.service.savedSearches({owner:this.service.username,app:"sdk-app-collection"});g.chain(function(a){d.create({search:c,name:b},a)},function(d,e){a.ok(d),a.strictEqual(d.name,b),a.strictEqual(d.properties().search,c),a.ok(!d.properties().description),d.dispatch({force_dispatch:!1,"dispatch.buckets":295},e)},function(b,c,d){a.ok(b),a.ok(c),h.pollUntil(b,function(a){return b.properties().isDone},10,g.augment(d,c))},function(b,c,d){a.strictEqual(b.properties().statusBuckets,295),c.history(g.augment(d,b))},function(b,c,d,e){a.ok(b),a.ok(b.length>0),a.ok(c),a.ok(d);var f=function(a){return function(b){a.cancel(b)}},h=!1,i=[];for(var j=0;j0),c()}],function(b){a.ok(!b),a.done()})},"Callback#item":function(a){var b=this,c={owner:"admin",app:"search"};g.chain([function(a){b.service.configurations(c).fetch(a)},function(b,c){var d=b.item("web");a.ok(d),d.fetch(c)},function(b,c){a.strictEqual(b.name,"web"),c()}],function(b){a.ok(!b),a.done()})},"Callback#contains stanza":function(a){var b=this,c={owner:"admin",app:"search"};g.chain([function(a){b.service.configurations(c).fetch(a)},function(b,c){var d=b.item("web");a.ok(d),d.fetch(c)},function(b,c){a.strictEqual(b.name,"web");var d=b.item("settings");a.ok(d),d.fetch(c)},function(b,c){a.ok(b.properties().hasOwnProperty("httpport")),c()}],function(b){a.ok(!b),a.done()})},"Callback#create file + create stanza + update stanza":function(a){var c=this,e="jssdk_file_"+k(),f="barfoo_"+k(),h={owner:"admin",app:"search"};g.chain([function(a){var b=c.service.configurations(h);b.fetch(a)},function(a,b){a.create(e,b)},function(a,b){a.create("stanza",b)},function(a,b){a.update({jssdk_foobar:f},b)},function(b,c){a.strictEqual(b.properties().jssdk_foobar,f),c()},function(a){var c=new d.Service.ConfigurationFile(b,e);c.fetch(a)},function(b,c){var d=b.item("stanza");a.ok(d),d.remove(c)}],function(b){a.ok(!b),a.done()})}},"Configuration Tests":{setUp:function(a){this.service=b,a()},"Callback#list":function(a){var b=this,c={owner:"admin",app:"search"};g.chain([function(a){b.service.configurations(c).fetch(a)},function(b,c){var d=b.list();a.ok(d.length>0),c()}],function(b){a.ok(!b),a.done()})},"Callback#contains":function(a){var b=this,c={owner:"admin",app:"search"};g.chain([function(a){b.service.configurations(c).fetch(a)},function(b,c){var d=b.item("web");a.ok(d),d.fetch(c)},function(b,c){a.strictEqual(b.name,"web"),c()}],function(b){a.ok(!b),a.done()})},"Callback#contains stanza":function(a){var b=this,c={owner:"admin",app:"search"};g.chain([function(a){b.service.configurations(c).fetch(a)},function(b,c){var d=b.item("web");a.ok(d),d.fetch(c)},function(b,c){a.strictEqual(b.name,"web");var d=b.item("settings");a.ok(d),d.fetch(c)},function(b,c){a.ok(b.properties().hasOwnProperty("httpport")),c()}],function(b){a.ok(!b),a.done()})},"Callback#configurations init":function(a){a.throws(function(){var a=new d.Service.Configurations(this.service,{owner:"-",app:"-",sharing:"system"})}),a.done()},"Callback#create file + create stanza + update stanza":function(a){var c=this,e={owner:"nobody",app:"system"},f="jssdk_file_"+k(),h="barfoo_"+k();g.chain([function(a){var c=b.configurations(e);c.fetch(a)},function(a,b){a.create({__conf:f},b)},function(a,b){a.item("stanza")&&a.item("stanza").remove(),a.create("stanza",b)},function(a,b){a.update({jssdk_foobar:h},b)},function(b,c){a.strictEqual(b.properties().jssdk_foobar,h),c()},function(a){var c=new d.Service.ConfigurationFile(b,f);c.fetch(a)},function(b,c){var d=b.item("stanza");a.ok(d),d.remove(c)}],function(b){a.ok(!b),a.done()})},"Callback#can get default stanza":function(a){var b=this,c={owner:"admin",app:"search"};g.chain([function(a){b.service.configurations(c).fetch(a)},function(b,d){var e=b.item("savedsearches");a.strictEqual(c,e.namespace),a.ok(e),e.fetch(d)},function(b,d){a.strictEqual(c,b.namespace),b.getDefaultStanza().fetch(d)},function(b,d){a.strictEqual(b.name,"default"),a.strictEqual(c,b.namespace),d()}],function(b){a.ok(!b),a.done()})},"Callback#updating default stanza is noop":function(a){var b=this,c={owner:"admin",app:"search"},d=null,e="this won't work";g.chain([function(a){b.service.configurations(c).fetch(a)},function(b,d){var e=b.item("savedsearches");a.strictEqual(c,e.namespace),a.ok(e),e.fetch(d)},function(b,d){a.strictEqual(c,b.namespace),b.getDefaultStanza().fetch(d)},function(b,f){a.ok(b._properties.hasOwnProperty("max_concurrent")),a.strictEqual(c,b.namespace),d=b._properties.max_concurrent,b.update({max_concurrent:e},f)},function(b,c){a.ok(b.properties().hasOwnProperty("max_concurrent")),a.strictEqual(b.properties().max_concurrent,d),a.notStrictEqual(b.properties().max_concurrent,e),b.fetch(c)},function(b,c){a.ok(b.properties().hasOwnProperty("max_concurrent")),a.strictEqual(b.properties().max_concurrent,d),a.notStrictEqual(b.properties().max_concurrent,e),c()}],function(b){a.ok(!b),a.done()})}},"Storage Passwords Tests":{setUp:function(a){this.service=b,a()},"Callback#Create":function(a){var b=-1,c="delete-me-"+k(),d="delete-me-"+k(),e=this;g.chain([function(a){e.service.storagePasswords().fetch(a)},function(a,e){b=a.list().length,a.create({name:c,realm:d,password:"changeme"},e)},function(b,f){a.strictEqual(c,b.properties().username),a.strictEqual(d+":"+c+":",b.name),a.strictEqual("changeme",b.properties().clear_password),a.strictEqual(d,b.properties().realm),e.service.storagePasswords().fetch(g.augment(f,b))},function(c,d,e){a.strictEqual(b+1,c.list().length),d.remove(e)},function(a){e.service.storagePasswords().fetch(a)},function(c,d){a.strictEqual(b,c.list().length),d()}],function(b){a.ok(!b),a.done()})},"Callback#Create with backslashes":function(a){var b=-1,c="\\delete-me-"+k(),d="\\delete-me-"+k(),e=this;g.chain([function(a){e.service.storagePasswords().fetch(a)},function(a,e){b=a.list().length,a.create({name:c,realm:d,password:"changeme"},e)},function(b,f){a.strictEqual(c,b.properties().username),a.strictEqual("\\"+d+":\\"+c+":",b.name),a.strictEqual("changeme",b.properties().clear_password),a.strictEqual(d,b.properties().realm),e.service.storagePasswords().fetch(g.augment(f,b))},function(c,d,e){a.strictEqual(b+1,c.list().length),d.remove(e)},function(a){e.service.storagePasswords().fetch(a)},function(c,d){a.strictEqual(b,c.list().length),d()}],function(b){a.ok(!b),a.done()})},"Callback#Create with slashes":function(a){var b=-1,c="/delete-me-"+k(),d="/delete-me-"+k(),e=this;g.chain([function(a){e.service.storagePasswords().fetch(a)},function(a,e){b=a.list().length,a.create({name:c,realm:d,password:"changeme"},e)},function(b,f){a.strictEqual(c,b.properties().username),a.strictEqual(d+":"+c+":",b.name),a.strictEqual("changeme",b.properties().clear_password),a.strictEqual(d,b.properties().realm),e.service.storagePasswords().fetch(g.augment(f,b))},function(c,d,e){a.strictEqual(b+1,c.list().length),d.remove(e)},function(a){e.service.storagePasswords().fetch(a)},function(c,d){a.strictEqual(b,c.list().length),d()}],function(b){a.ok(!b),a.done()})},"Callback#Create without realm":function(a){var b=-1,c="delete-me-"+k(),d=this;g.chain([function(a){d.service.storagePasswords().fetch(a)},function(a,d){b=a.list().length,a.create({name:c,password:"changeme"},d)},function(b,e){a.strictEqual(c,b.properties().username),a.strictEqual(":"+c+":",b.name),a.strictEqual("changeme",b.properties().clear_password),a.strictEqual("",b.properties().realm),d.service.storagePasswords().fetch(g.augment(e,b))},function(c,d,e){a.strictEqual(b+1,c.list().length),d.remove(e)},function(a){d.service.storagePasswords().fetch(a)},function(c,d){a.strictEqual(b,c.list().length),d()}],function(b){a.ok(!b),a.done()})},"Callback#Create should fail without user, or realm":function(a){var b=this;g.chain([function(a){b.service.storagePasswords().fetch(a)},function(a,b){a.create({name:null,password:"changeme"},b)}],function(b){a.ok(b),a.done()})},"Callback#Create should fail without password":function(a){var b=this;g.chain([function(a){b.service.storagePasswords().fetch(a)},function(a,b){a.create({name:"something",password:null},b)}],function(b){a.ok(b),a.done()})},"Callback#Create should fail without user, realm, or password":function(a){var b=this;g.chain([function(a){b.service.storagePasswords().fetch(a)},function(a,b){a.create({name:null,password:null},b)}],function(b){a.ok(b),a.done()})},"Callback#Create with colons":function(a){var b=-1,c=":delete-me-"+k(),d=":delete-me-"+k(),e=this;g.chain([function(a){e.service.storagePasswords().fetch(a)},function(a,e){b=a.list().length,a.create({name:c,realm:d,password:"changeme"},e)},function(b,f){a.strictEqual(c,b.properties().username),a.strictEqual("\\"+d+":\\"+c+":",b.name),a.strictEqual("changeme",b.properties().clear_password),a.strictEqual(d,b.properties().realm),e.service.storagePasswords().fetch(g.augment(f,b))},function(c,d,e){a.strictEqual(b+1,c.list().length),d.remove(e)},function(a){e.service.storagePasswords().fetch(a)},function(c,d){a.strictEqual(b,c.list().length),d()}],function(b){a.ok(!b),a.done()})},"Callback#Create crazy":function(a){var b=-1,c="delete-me-"+k(),d="delete-me-"+k(),e=this;g.chain([function(a){e.service.storagePasswords().fetch(a)},function(a,e){b=a.list().length,a.create({name:c+":end!@#$%^&*()_+{}:|<>?",realm:":start::!@#$%^&*()_+{}:|<>?"+d,password:"changeme"},e)},function(b,f){a.strictEqual(c+":end!@#$%^&*()_+{}:|<>?",b.properties().username),a.strictEqual("\\:start\\:\\:!@#$%^&*()_+{}\\:|<>?"+d+":"+c+"\\:end!@#$%^&*()_+{}\\:|<>?:",b.name),a.strictEqual("changeme",b.properties().clear_password),a.strictEqual(":start::!@#$%^&*()_+{}:|<>?"+d,b.properties().realm),e.service.storagePasswords().fetch(g.augment(f,b))},function(c,d,e){a.strictEqual(b+1,c.list().length),d.remove(e)},function(a){e.service.storagePasswords().fetch(a)},function(c,d){a.strictEqual(b,c.list().length),d()}],function(b){a.ok(!b),a.done()})},"Callback#Create with unicode chars":function(a){var b=-1,c="delete-me-"+k(),d="delete-me-"+k(),e=this;g.chain([function(a){e.service.storagePasswords().fetch(a)},function(a,e){b=a.list().length,a.create({name:c+":end!@#$%^&*()_+{}:|<>?쎼 and 쎶 and <&> für",realm:":start::!@#$%^&*()_+{}:|<>?"+encodeURIComponent("쎼 and 쎶 and <&> für")+d,password:decodeURIComponent(encodeURIComponent("쎼 and 쎶 and <&> für"))},e)},function(b,f){a.strictEqual(c+":end!@#$%^&*()_+{}:|<>?쎼 and 쎶 and <&> für",b.properties().username),a.strictEqual("\\:start\\:\\:!@#$%^&*()_+{}\\:|<>?"+encodeURIComponent("쎼 and 쎶 and <&> für")+d+":"+c+"\\:end!@#$%^&*()_+{}\\:|<>?쎼 and 쎶 and <&> für:",b.name),a.strictEqual(decodeURIComponent(encodeURIComponent("쎼 and 쎶 and <&> für")),b.properties().clear_password),a.strictEqual(":start::!@#$%^&*()_+{}:|<>?"+encodeURIComponent("쎼 and 쎶 and <&> für")+d,b.properties().realm),e.service.storagePasswords().fetch(g.augment(f,b))},function(c,d,e){a.strictEqual(b+1,c.list().length),d.remove(e)},function(a){e.service.storagePasswords().fetch(a)},function(c,d){a.strictEqual(b,c.list().length),d()}],function(b){a.ok(!b),a.done()})},"Callback#Read":function(a){var b=-1,c="delete-me-"+k(),d="delete-me-"+k(),e=this;g.chain([function(a){e.service.storagePasswords().fetch(a)},function(a,e){b=a.list().length,a.create({name:c,realm:d,password:"changeme"},e)},function(b,f){a.strictEqual(c,b.properties().username),a.strictEqual(d+":"+c+":",b.name),a.strictEqual("changeme",b.properties().clear_password),a.strictEqual(d,b.properties().realm),e.service.storagePasswords().fetch(g.augment(f,b))},function(e,f,g){try{a.ok(!!e.item(d+":"+c+":"))}catch(h){a.ok(!1)}var i=e.list(),j=!1;a.strictEqual(b+1,i.length);for(var k=0;k0},function(a){g.sleep(d,function(){b.fetch(a)})},function(b){b?a(b):a(c<=0?"Timed out":null)})}],function(b){a.ok(!b),a.done()})},"Callback#list indexes":function(a){var b=this.service.indexes();b.fetch(function(b,c){var d=c.list();a.ok(d.length>0),a.done()})},"Callback#contains index":function(a){var b=this.service.indexes(),c=this.indexName;b.fetch(function(b,d){var e=d.item(c);a.ok(e),a.done()})},"Callback#modify index":function(a){var b=this.indexName,c=this.service.indexes(),d=!1;g.chain([function(a){c.fetch(a)},function(c,e){var f=c.item(b);a.ok(f),d=f.properties().syncMeta,f.update({syncMeta:!d},e)},function(b,c){a.ok(b);var e=b.properties();a.strictEqual(!d,e.syncMeta),b.update({syncMeta:!e.syncMeta},c)},function(b,c){a.ok(b);var e=b.properties();a.strictEqual(d,e.syncMeta),c()}],function(b){a.ok(!b),a.done()})},"Callback#Enable+disable index":function(a){var b=this.indexName,c=this.service.indexes();g.chain([function(a){c.fetch(a)},function(c,d){var e=c.item(b);a.ok(e),e.disable(d)},function(b,c){a.ok(b),b.fetch(c)},function(b,c){a.ok(b),a.ok(b.properties().disabled),b.enable(c)},function(b,c){a.ok(b),b.fetch(c)},function(b,c){a.ok(b),a.ok(!b.properties().disabled),c()}],function(b){a.ok(!b),a.done()})},"Callback#Service submit event":function(a){var b="Hello World -- "+k(),c="sdk-tests",d=this.service,e=this.indexName;g.chain(function(a){d.log(b,{sourcetype:c,index:e},a)},function(d,f){a.ok(d),a.strictEqual(d.sourcetype,c),a.strictEqual(d.bytes,b.length),a.strictEqual(d.index,e),f()},function(b){a.ok(!b),a.done()})},"Callback#Service submit event, omitting optional arguments":function(a){var b="Hello World -- "+k(),c="sdk-tests",d=this.service,e=this.indexName;g.chain(function(a){d.log(b,a)},function(c,d){a.ok(c),a.strictEqual(c.bytes,b.length),d()},function(b){a.ok(!b),a.done()})},"Callback#Service submit events with multi-byte chars":function(a){var b=this.service,c=["Ummelner Straße 6","Ümmelner Straße 6","Iԉtérԉátíòлåɭìƶåtiòл","Intérnâtì߀лàɭíƶɑtïòл","ãϻét dòner turƙëy ѵ߀lù","ptãte ìԉ rëρrèhënԁérit ","ϻ߀lɭit fìɭèt ϻìǥnoԉ ɭäb߀ríѕ"," êӽ cɦùck cüpïᏧåtåt Ꮷèѕëruлt. ","D߀ɭor ѵélít ìrurè, sèᏧ ѕhòr","t riƅѕ c߀ɰ ɭãnԁյàéɢêr drúmst","ícƙ. Minïm ƃàɭl tip ѕհòrt rìƃѕ,"," ïԁ aɭïqúìρ ѕɦànƙ ρ߀rcɦéttɑ. Pìǥ"," hãm ɦòck ìлcídíԁùԉt séԁ cüpïϻ ","ƙèviл láborê. Et taiɭ ѕtriρ"," steák út üllãϻc߀ rump d߀ɭore.","٩(͡๏̯͡๏)۶ ٩(-̮̮̃•̃).","Lɑƅòré ƃrësãòlá d߀лèr ѕâlámí ","cíllûm ìn ѕɯìлe ϻêàtɭ߀àf dûìs ","ρãncettä ƅrìsƙét ԁèsêrûлt áútè"," յòɰɭ. Lɑbòrìѕ ƙìêɭ","básá ԁòlòré fatƃɑck ƅêéf. Pɑѕtr","ämì piɢ ѕհàлƙ ùɭɭamcò ѕaû","ѕäǥë sɦànƙlë."," Cúpím ɭäƃorum drumstïcƙ jerkϒ veli"," pïcåԉɦɑ ƙíéɭƅãsa. Alïqû","iρ írürë cûpíϻ, äɭìɋuâ ǥròûлd ","roúлᏧ toԉgüè ρàrìãtùr ","briѕkèt ԉostruᏧ cûɭpɑ"," ìd còлѕèqûât làƅ߀rìs."],d=0;g.seriesMap(c,function(a,c,e){d++,b.log(a,e)},function(b,e){a.ok(!b),a.strictEqual(d,c.length);for(var f in c){a.notStrictEqual(c[f].length,e[f].bytes);try{a.strictEqual(Buffer.byteLength(c[f]),e[f].bytes)}catch(b){a.strictEqual(decodeURI(encodeURIComponent(c[f])).length,e[f].bytes)}}a.done()})},"Callback#Service submit event, failure":function(a){var b="Hello World -- "+k(),c="sdk-tests",d=this.loggedOutService,e=this.indexName;g.chain(function(c){a.ok(d),d.log(b,c)},function(b){a.ok(b),a.done()})},"Callback#remove throws an error":function(a){var b=this.service.indexes().item("_internal");a.throws(function(){b.remove()}),a.done()},"Callback#create an index with alternate argument format":function(a){var b=this.service.indexes();b.create({name:"_internal"},function(b,c){a.ok(b.data.messages[0].text.match("name=_internal already exists")),a.done()})},"Callback#Index submit event with omitted optional arguments":function(a){var b="Hello world -- "+k(),c=this.indexName,d=this.service.indexes();g.chain([function(a){d.fetch(a)},function(d,e){var f=d.item(c);a.ok(f),a.strictEqual(f.name,c),f.submitEvent(b,e)},function(d,e,f){a.ok(d),a.strictEqual(d.bytes,b.length),a.strictEqual(d.index,c),f()}],function(b){a.ok(!b),a.done()})},"Callback#Index submit event":function(a){var b="Hello World -- "+k(),c="sdk-tests",d=this.indexName,e=this.service.indexes();g.chain([function(a){e.fetch(a)},function(e,f){var g=e.item(d);a.ok(g),a.strictEqual(g.name,d),g.submitEvent(b,{sourcetype:c},f)},function(e,f,g){a.ok(e),a.strictEqual(e.sourcetype,c),a.strictEqual(e.bytes,b.length),a.strictEqual(e.index,d),g()}],function(b){a.ok(!b),a.done()})}},"User Tests":{setUp:function(a){this.service=b,this.loggedOutService=c,a()},tearDown:function(a){this.service.logout(a)},"Callback#Current user":function(a){var b=this.service;b.currentUser(function(c,d){a.ok(!c),a.ok(d),a.strictEqual(d.name,b.username),a.done()})},"Callback#Current user fails":function(a){var b=this.loggedOutService;b.currentUser(function(b,c){a.ok(b),a.done()})},"Callback#List users":function(a){var b=this.service;b.users().fetch(function(b,c){var d=c.list();a.ok(!b),a.ok(c),a.ok(d),a.ok(d.length>0),a.done()})},"Callback#create user failure":function(a){this.loggedOutService.users().create({name:"jssdk_testuser",password:"abc",roles:"user"},function(b,c){a.ok(b),a.done()})},"Callback#Create + update + delete user":function(a){var b=this.service,c="jssdk_testuser";g.chain([function(a){b.users().create({name:"jssdk_testuser",password:"abc",roles:"user"},a)},function(b,d){a.ok(b),a.strictEqual(b.name,c),a.strictEqual(b.properties().roles.length,1),a.strictEqual(b.properties().roles[0],"user"),b.update({realname:"JS SDK",roles:["admin","user"]},d)},function(b,c){a.ok(b),a.strictEqual(b.properties().realname,"JS SDK"),a.strictEqual(b.properties().roles.length,2),a.strictEqual(b.properties().roles[0],"admin"),a.strictEqual(b.properties().roles[1],"user"),b.remove(c)}],function(b){a.ok(!b),a.done()})},"Callback#Roles":function(a){var b=this.service,c="jssdk_testuser_"+k();g.chain([function(a){b.users().create({name:c,password:"abc",roles:"user"},a)},function(b,d){a.ok(b),a.strictEqual(b.name,c),a.strictEqual(b.properties().roles.length,1),a.strictEqual(b.properties().roles[0],"user"),b.update({roles:["admin","user"]},d)},function(b,c){a.ok(b),a.strictEqual(b.properties().roles.length,2),a.strictEqual(b.properties().roles[0],"admin"),a.strictEqual(b.properties().roles[1],"user"),b.update({roles:"user"},c)},function(b,c){a.ok(b),a.strictEqual(b.properties().roles.length,1),a.strictEqual(b.properties().roles[0],"user"),b.update({roles:"__unknown__"},c)}],function(b){a.ok(b),a.strictEqual(b.status,400),a.done()})},"Callback#Passwords":function(a){var b=this.service,c=null,e="jssdk_testuser_"+k();g.chain([function(a){b.users().create({name:e,password:"abc",roles:"user"},a)},function(f,h){a.ok(f),a.strictEqual(f.name,e),a.strictEqual(f.properties().roles.length,1),a.strictEqual(f.properties().roles[0],"user"),c=new d.Service(b.http,{username:e,password:"abc",host:b.host,port:b.port,scheme:b.scheme,version:b.version}),c.login(g.augment(h,f))},function(b,c,d){a.ok(b),a.ok(c),c.update({password:"abc2"},d)},function(b,d){c.login(function(c,e){a.ok(c),a.ok(!e),b.update({password:"abc"},d)})},function(b,d){a.ok(b),c.login(d)}],function(b){a.ok(!b),a.done()})},"Callback#delete test users":function(a){var b=this.service.users();b.fetch(function(b,c){var d=c.list();g.parallelEach(d,function(a,b,c){f.startsWith(a.name,"jssdk_")?a.remove(c):c()},function(b){a.ok(!b),a.done()})})}},"Server Info Tests":{setUp:function(a){this.service=b,a()},"Callback#Basic":function(a){var b=this.service;b.serverInfo(function(b,c){a.ok(!b),a.ok(c),a.strictEqual(c.name,"server-info"),a.ok(c.properties().hasOwnProperty("version")),a.ok(c.properties().hasOwnProperty("serverName")),a.ok(c.properties().hasOwnProperty("os_version")),a.done()})}},"View Tests":{setUp:function(a){this.service=b,a()},"Callback#List views":function(a){var b=this.service;b.views({owner:"admin",app:"search"}).fetch(function(b,c){a.ok(!b),a.ok(c);var d=c.list();a.ok(d),a.ok(d.length>0);for(var e=0;e",e="";g.chain([function(a){b.views({owner:"admin",app:"sdk-app-collection"}).create({name:c,"eai:data":d},a)},function(b,f){a.ok(b),a.strictEqual(b.name,c),a.strictEqual(b.properties()["eai:data"],d),b.update({"eai:data":e},f)},function(b,c){a.ok(b),a.strictEqual(b.properties()["eai:data"],e),b.remove(c)}],function(b){a.ok(!b),a.done()})}},"Parser Tests":{setUp:function(a){this.service=b,a()},"Callback#Basic parse":function(a){var b=this.service;b.parse("search index=_internal | head 1",function(b,c){a.ok(!b),a.ok(c),a.ok(c.commands.length>0),a.done()})},"Callback#Parse error":function(a){var b=this.service;b.parse("ABCXYZ",function(b,c){a.ok(b),a.strictEqual(b.status,400),a.done()})}},"Typeahead Tests":{setUp:function(a){this.service=b,this.loggedOutService=c,a()},"Callback#Typeahead failure":function(a){var b=this.loggedOutService;b.typeahead("index=",1,function(b,c){a.ok(b),a.done()})},"Callback#Basic typeahead":function(a){var b=this.service;b.typeahead("index=",1,function(b,c){a.ok(!b),a.ok(c),a.strictEqual(c.length,1),a.ok(c[0]),a.done()})},"Typeahead with omitted optional arguments":function(a){var b=this.service;b.typeahead("index=",function(b,c){a.ok(!b),a.ok(c),a.done()})}},"Endpoint Tests":{setUp:function(a){this.service=b,a()},"Throws on null arguments to init":function(a){var b=this.service;a.throws(function(){var a=new d.Service.Endpoint(null,"a/b")}),a.throws(function(){var a=new d.Service.Endpoint(b,null)}),a.done()},"Endpoint delete on a relative path":function(a){var b=this.service,c=new d.Service.Endpoint(b,"/search/jobs/12345");c.del("search/jobs/12345",{},function(){a.done()})},"Methods of Resource to be overridden":function(a){var b=this.service,c=new d.Service.Resource(b,"/search/jobs/12345");a.throws(function(){c.path()}),a.throws(function(){c.fetch()}),a.ok(d.Utils.isEmpty(c.state())),a.done()}},"Entity tests":{setUp:function(a){this.service=b,this.loggedOutService=c,a()},"Accessors function properly":function(a){var b=new d.Service.Entity(this.service,"/search/jobs/12345",{owner:"boris",app:"factory",sharing:"app"});b._load({acl:{owner:"boris",app:"factory",sharing:"app"},links:{link1:35},published:"meep",author:"Hilda"}),a.ok(b.acl().owner==="boris"),a.ok(b.acl().app==="factory"),a.ok(b.acl().sharing==="app"),a.ok(b.links().link1===35),a.strictEqual(b.author(),"Hilda"),a.strictEqual(b.published(),"meep"),a.done()},"Refresh throws error correctly":function(a){var b=new d.Service.Entity(this.loggedOutService,"/search/jobs/12345",{owner:"boris",app:"factory",sharing:"app"});b.fetch({},function(b){a.ok(b),a.done()})},"Cannot update name of entity":function(a){var b=new d.Service.Entity(this.service,"/search/jobs/12345",{owner:"boris",app:"factory",sharing:"app"});a.throws(function(){b.update({name:"asdf"})}),a.done()},"Disable throws error correctly":function(a){var b=new d.Service.Entity(this.loggedOutService,"/search/jobs/12345",{owner:"boris",app:"factory",sharing:"app"});b.disable(function(b){a.ok(b),a.done()})},"Enable throws error correctly":function(a){var b=new d.Service.Entity(this.loggedOutService,"/search/jobs/12345",{owner:"boris",app:"factory",sharing:"app"});b.enable(function(b){a.ok(b),a.done()})},"Does reload work?":function(a){var b=new d.Service.Index(this.service,"data/indexes/sdk-test",{owner:"admin",app:"search",sharing:"app"}),c="jssdk_testapp_"+k(),e=this.service.apps(),f=this;g.chain(function(a){e.create({name:c},a)},function(b,c){b.reload(function(d){a.ok(!d),c(null,b)})},function(b,c){var e=new d.Service.Application(f.loggedOutService,b.name);e.reload(function(d){a.ok(d),c(null,b)})},function(a,b){a.remove(b)},function(b){a.ok(!b),a.done()})}},"Collection tests":{setUp:function(a){this.service=b,this.loggedOutService=c,a()},"Methods to be overridden throw":function(a){var b=new d.Service.Collection(this.service,"/data/indexes",{owner:"admin",app:"search",sharing:"app"});a.throws(function(){b.instantiateEntity({})}),a.done()},"Accessors work":function(a){var b=new d.Service.Collection(this.service,"/data/indexes",{owner:"admin",app:"search",sharing:"app"});b._load({links:"Hilda",updated:!0}),a.strictEqual(b.links(),"Hilda"),a.ok(b.updated()),a.done()},"Contains throws without a good id":function(a){var b=new d.Service.Collection(this.service,"/data/indexes",{owner:"admin",app:"search",sharing:"app"});a.throws(function(){b.item(null)}),a.done()}}};return l};if(b===a.main){var f=a("../index"),g=a("../examples/node/cmdline"),h=a("../contrib/nodeunit/test_reporter"),i=g.create(),j=i.parse(process.argv);if(!j)throw new Error("Error in parsing command line parameters");if(!process.env.SPLUNK_HOME)throw new Error("$PATH variable SPLUNK_HOME is not set. Please export SPLUNK_HOME to the splunk instance.");var k=new f.Service({scheme:j.opts.scheme,host:j.opts.host,port:j.opts.port,username:j.opts.username,password:j.opts.password,version:j.opts.version}),l=new f.Service({scheme:j.opts.scheme,host:j.opts.host,port:j.opts.port,username:j.opts.username,password:j.opts.password+"wrong",version:j.opts.version}),m=c.setup(k,l);k.login(function(a,b){if(a||!b)throw new Error("Login failed - not running tests",a||"");h.run([{Tests:m}])})}}),require.define("/tests/test_examples.js",function(a,b,c,d,e){c.setup=function(b,c){var d=a("../index"),e=d.Async;d.Logger.setLevel("ALL");var f=0,g=function(){return"id"+f++ +"_"+(new Date).valueOf()},h=["program","script"];return{"Hello World Tests":{Apps:function(b){var d=a("../examples/node/helloworld/apps").main;d(c,b.done)},"Apps#Async":function(b){var d=a("../examples/node/helloworld/apps_async").main;d(c,b.done)},"Pivot#Async":function(b){var d=a("../examples/node/helloworld/pivot_async").main;d(c,b.done)},"Fired Alerts":function(b){var d=a("../examples/node/helloworld/firedalerts").main;d(c,b.done)},"Fired Alerts#Async":function(b){var d=a("../examples/node/helloworld/firedalerts_async").main;d(c,b.done)},"Fired Alerts#Create":function(b){var d=a("../examples/node/helloworld/firedalerts_create").main;d(c,b.done)},"Fired Alerts#Delete":function(b){var d=a("../examples/node/helloworld/firedalerts_delete").main;d(c,b.done)},"Get Job by sid":function(b){var d=a("../examples/node/helloworld/get_job").main;d(c,b.done)},"Endpoint Instantiation":function(b){var d=a("../examples/node/helloworld/endpoint_instantiation").main;d(c,b.done)},"Saved Searches":function(b){var d=a("../examples/node/helloworld/savedsearches").main;d(c,b.done)},"Saved Searches#Async":function(b){var d=a("../examples/node/helloworld/savedsearches_async").main;d(c,b.done)},"Saved Searches#Delete":function(b){var d=a("../examples/node/helloworld/savedsearches_delete").main;d(c,b.done)},"Saved Searches#Create":function(b){var d=a("../examples/node/helloworld/savedsearches_create").main;d(c,b.done)},"Saved Searches#Delete Again":function(b){var d=a("../examples/node/helloworld/savedsearches_delete").main;d(c,b.done)},"Search#normal":function(b){var d=a("../examples/node/helloworld/search_normal").main;d(c,b.done)},"Search#blocking":function(b){var d=a("../examples/node/helloworld/search_blocking").main;d(c,b.done)},"Search#oneshot":function(b){var d=a("../examples/node/helloworld/search_oneshot").main;d(c,b.done)},"Search#realtime":function(b){var d=a("../examples/node/helloworld/search_realtime").main;d(c,b.done)},Logging:function(b){var d=a("../examples/node/helloworld/log").main;d(c,b.done)}},"Jobs Example Tests":{setUp:function(b){var c=this;this.main=a("../examples/node/jobs").main,this.run=function(a,b,d,e){var f=h.slice();a&&f.push(a);if(b)for(var g=0;g ")),console.log("\t Internal name: "+l.name),l.startSearch({},"| head 5",b)},function(a,b){a.track({},function(a){a.results({},b)})},function(a,b,c){console.log("Results:");for(var d=0;dd},function(b){g.sleep(1e3,function(){a.preview({},function(a,c){if(a){b(a);return}if(c&&c.rows){d++,console.log("========== Iteration "+d+" ==========");var e=c.fields.indexOf("sourcetype"),f=c.fields.indexOf("count");for(var g=0;g",k,[],e),c.add("preview","Fetch preview results for the specified search jobs","",k,[],e),c.add("events","Fetch events for the specified search jobs","",j,[],e),c.add("cancel","Cancel the specify search jobs","",[],[],e),c.add("list","List all search jobs or properties for those specified","[sids...]",[],[],e),c.parse(a);if(!c.executedCommand){console.log(c.helpInformation()),b("You must specify a command to run.");return}},b===a.main&&c.main(process.argv)})()}),require.define("/examples/node/search.js",function(a,b,c,d,e){(function(){var d=a("../../index"),e=d.Class,f=d.Utils,g=d.Async,h=a("./cmdline"),i=a("util").print,j=["search","earliest_time","latest_time","now","time_format","exec_mode","search_mode","rt_blocking","rt_queue_size","rt_maxblocksecs","rt_indexfilter","id","status_buckets","max_count","max_time","timeout","auto_finalize_ec","enable_lookups","reload_macros","reduce_freq","spawn_process","required_field_list","rf","auto_cancel","auto_pause"],k=function(a){return new d.Service({scheme:a.scheme,host:a.host,port:a.port,username:a.username,password:a.password,version:a.version})},l=function(a,b,c){var d=b.search,e=b.verbose,f=b.count||0,h=b.mode||"row";delete b.search,delete b.verbose,delete b.count,delete b.mode,g.chain([function(c){a.search(d,b,c)},function(a,b){g.whilst(function(){return!a.properties().isDone},function(b){a.fetch(function(a,d){if(a)c(a);else{var f=d.properties();if(e){var h=f.doneProgress*100+"%",j=f.scanCount,k=f.eventCount,l=f.resultCount,m="-- "+h+" done | "+j+" scanned | "+k+" matched | "+l+" results";i("\r"+m+" ")}g.sleep(1e3,b)}})},function(c){e&&i("\r"),b(c,a)})},function(a,b){a.results({count:f,json_mode:h},b)},function(a,b,c){process.stdout.write(JSON.stringify(a)),b.cancel(c)}],function(a){c(a)})},m=function(a,b,c){var d=b.search;delete b.search,a.oneshotSearch(d,b,function(a,b){a?c(a):(console.log(JSON.stringify(b)),c())})};c.main=function(a,b){d.Logger.setLevel("NONE"),b=b||function(a){a&&console.log(a)};var c=h.create();c.name="search",c.description("Create a search and print the results to stdout"),c.option("--verbose","Output job progress as we wait for completion"),c.option("--count ","How many results to fetch"),c.option("--mode ","Row or column mode [row|column]");var e=j,f=["search"];for(var g=0;g=0,n="<"+e[g]+">";c.option("--"+e[g]+" "+n,"",undefined,i)}c.on("--help",function(){console.log(" Examples:"),console.log(" "),console.log(" Create a regular search:"),console.log(" > node search.js --search 'search index=_internal | head 10'"),console.log(" "),console.log(" Create a oneshot search:"),console.log(" > node search.js --search 'search index=_internal | head 10' --exec_mode oneshot"),console.log(" "),console.log(" Create a regular search and only return 10 results:"),console.log(" > node search.js --search 'search index=_internal | head 20' --count 10"),console.log(" "),console.log(" Create a regular search and output the progress while the search is running"),console.log(" > node search.js --search 'search index=_internal | head 20' --verbose"),console.log(" ")}),c.parse(a);var o=k(c.opts);o.login(function(a,d){if(a||!d){b("Error logging in");return}delete c.username,delete c.password,delete c.scheme,delete c.host,delete c.port,delete c.namespace,delete c.version,c.opts.exec_mode==="oneshot"?m(o,c.opts,b):l(o,c.opts,b)})},b===a.main&&c.main(process.argv)})()}),require.define("/browser.test.entry.js",function(a,b,c,d,e){window.SplunkTest={Utils:a("../../tests/test_utils"),Async:a("../../tests/test_async"),Http:a("../../tests/test_http"),Context:a("../../tests/test_context"),Service:a("../../tests/test_service"),Examples:a("../../tests/test_examples")}}),require("/browser.test.entry.js") +var require=function(a,b){var c=require.resolve(a,b||"/"),d=require.modules[c];if(!d)throw new Error("Failed to resolve module "+a+", tried "+c);var e=d._cached?d._cached:d();return e};require.paths=[],require.modules={},require.extensions=[".js",".coffee"],require._core={assert:!0,events:!0,fs:!0,path:!0,vm:!0},require.resolve=function(){return function(a,b){function g(a){if(require.modules[a])return a;for(var b=0;b=0;e--){if(b[e]==="node_modules")continue;var f=b.slice(0,e+1).join("/")+"/node_modules";d.push(f)}return d}b||(b="/");if(require._core[a])return a;var c=require.modules.path();b=c.resolve("/",b);var d=b||"/";if(a.match(/^(?:\.\.?\/|\/)/)){var e=g(c.resolve(d,a))||h(c.resolve(d,a));if(e)return e}var f=i(a,d);if(f)return f;throw new Error("Cannot find module '"+a+"'")}}(),require.alias=function(a,b){var c=require.modules.path(),d=null;try{d=require.resolve(a+"/package.json","/")}catch(e){d=require.resolve(a,"/")}var f=c.dirname(d),g=(Object.keys||function(a){var b=[];for(var c in a)b.push(c);return b})(require.modules);for(var h=0;h0){var c=a.shift();c()}}},!0),function(c){b?(a.push(c),window.postMessage("browserify-tick","*")):setTimeout(c,0)}}()),process.title||(process.title="browser"),process.binding||(process.binding=function(a){if(a==="evals")return require("vm");throw new Error("No such module")}),process.cwd||(process.cwd=function(){return"."}),require.define("path",function(a,b,c,d,e){function f(a,b){var c=[];for(var d=0;d=0;d--){var e=a[d];e=="."?a.splice(d,1):e===".."?(a.splice(d,1),c++):c&&(a.splice(d,1),c--)}if(b)for(;c--;c)a.unshift("..");return a}var h=/^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/;c.resolve=function(){var a="",b=!1;for(var c=arguments.length;c>=-1&&!b;c--){var d=c>=0?arguments[c]:process.cwd();if(typeof d!="string"||!d)continue;a=d+"/"+a,b=d.charAt(0)==="/"}return a=g(f(a.split("/"),function(a){return!!a}),!b).join("/"),(b?"/":"")+a||"."},c.normalize=function(a){var b=a.charAt(0)==="/",c=a.slice(-1)==="/";return a=g(f(a.split("/"),function(a){return!!a}),!b).join("/"),!a&&!b&&(a="."),a&&c&&(a+="/"),(b?"/":"")+a},c.join=function(){var a=Array.prototype.slice.call(arguments,0);return c.normalize(f(a,function(a,b){return a&&typeof a=="string"}).join("/"))},c.dirname=function(a){var b=h.exec(a)[1]||"",c=!1;return b?b.length===1||c&&b.length<=3&&b.charAt(1)===":"?b:b.substring(0,b.length-1):"."},c.basename=function(a,b){var c=h.exec(a)[2]||"";return b&&c.substr(-1*b.length)===b&&(c=c.substr(0,c.length-b.length)),c},c.extname=function(a){return h.exec(a)[3]||""}}),require.define("/tests/test_utils.js",function(a,b,c,d,e){c.setup=function(){var b=a("../index");return b.Logger.setLevel("ALL"),{"Callback#callback to object success":function(a){var b=function(a){a(null,"one","two")};b(function(b,c,d){a.strictEqual(c,"one"),a.strictEqual(d,"two"),a.done()})},"Callback#callback to object error - single argument":function(a){var b=function(a){a("one")};b(function(b,c,d){a.strictEqual(b,"one"),a.ok(!c),a.ok(!d),a.done()})},"Callback#callback to object error - multi argument":function(a){var b=function(a){a(["one","two"])};b(function(b,c,d){a.strictEqual(b[0],"one"),a.strictEqual(b[1],"two"),a.ok(!c),a.ok(!d),a.done()})},"keyOf works":function(a){a.ok(b.Utils.keyOf(3,{a:3,b:5})),a.ok(!b.Utils.keyOf(3,{a:12,b:6})),a.done()},bind:function(a){var c;(function(){c=function(a){this.a=a}})();var d={},e=b.Utils.bind(d,c);e(12),a.strictEqual(d.a,12),a.done()},trim:function(a){a.strictEqual(b.Utils.trim(" test of something \n\r \t"),"test of something");var c=String.prototype.trim;String.prototype.trim=null,a.strictEqual(b.Utils.trim(" test of something \n\r \t"),"test of something"),String.prototype.trim=c,a.done()},indexOf:function(a){a.strictEqual(b.Utils.indexOf([1,2,3,4,5],3),2),a.strictEqual(b.Utils.indexOf([1,2,3,4,3],3),2),a.strictEqual(b.Utils.indexOf([1,2,3,4,5],12),-1),a.done()},contains:function(a){a.ok(b.Utils.contains([1,2,3,4,5],3)),a.ok(b.Utils.contains([1,2,3,4,3],3)),a.ok(!b.Utils.contains([1,2,3,4,5],12)),a.done()},startsWith:function(a){a.ok(b.Utils.startsWith("abcdefg","abc")),a.ok(!b.Utils.startsWith("bcdefg","abc")),a.done()},endsWith:function(a){a.ok(b.Utils.endsWith("abcdef","def")),a.ok(!b.Utils.endsWith("abcdef","bcd")),a.done()},toArray:function(a){(function(){var c=b.Utils.toArray(arguments),d=[1,2,3,4,5];for(var e=0;e=e.ALL&&g.apply(null,arguments)},error:function(){process.env.LOG_LEVEL>=e.ERROR&&i.apply(null,arguments)},warn:function(){process.env.LOG_LEVEL>=e.WARN&&h.apply(null,arguments)},info:function(){process.env.LOG_LEVEL>=e.INFO&&j.apply(null,arguments)},printMessages:function(a){a=a||[];for(var b=0;b=0},e.startsWith=function(a,b){var c=a.match("^"+b);return c&&c.length>0&&c[0]===b},e.endsWith=function(a,b){var c=a.match(b+"$");return c&&c.length>0&&c[0]===b};var f=Object.prototype.toString;e.toArray=function(a){return Array.prototype.slice.call(a)},e.isArray=Array.isArray||function(a){return f.call(a)==="[object Array]"},e.isFunction=function(a){return!!(a&&a.constructor&&a.call&&a.apply)},e.isNumber=function(a){return!!(a===0||a&&a.toExponential&&a.toFixed)},e.isString=function(a){return!!(a===""||a&&a.charCodeAt&&a.substr)},e.isObject=function(a){return a===Object(a)},e.isEmpty=function(a){if(e.isArray(a)||e.isString(a))return a.length===0;for(var b in a)if(this.hasOwnProperty.call(a,b))return!1;return!0},e.forEach=function(a,b,c){if(a===null)return;if(Array.prototype.forEach&&a.forEach===Array.prototype.forEach)a.forEach(b,c);else if(a.length===+a.length){for(var d=0,e=a.length;dh)return 1}return 0}}),h.Sharing={USER:"user",APP:"app",GLOBAL:"global",SYSTEM:"system"}})()}),require.define("/lib/paths.js",function(a,b,c,d,e){(function(){"use strict";var a=c||this;a.Paths={apps:"/services/apps/local",capabilities:"authorization/capabilities",configurations:"configs",dataModels:"datamodel/model",deploymentClient:"deployment/client",deploymentServers:"deployment/server",deploymentServerClasses:"deployment/serverclass",deploymentTenants:"deployment/tenants",eventTypes:"saved/eventtypes",firedAlerts:"alerts/fired_alerts",indexes:"data/indexes",info:"/services/server/info",inputs:null,jobs:"search/jobs",licenseGroups:"licenser/groups",licenseMessages:"licenser/messages",licensePools:"licenser/pools",licenseSlaves:"licenser/slaves",licenseStacks:"licenser/stacks",licenses:"licenser/licenses",loggers:"server/logger",login:"/services/auth/login",messages:"messages",passwords:"admin/passwords",parser:"search/parser",pivot:"datamodel/pivot",properties:"properties",roles:"authorization/roles",savedSearches:"saved/searches",settings:"server/settings",storagePasswords:"storage/passwords",users:"/services/authentication/users",typeahead:"search/typeahead",views:"data/ui/views",currentUser:"/services/authentication/current-context",submitEvent:"/services/receivers/simple"}})()}),require.define("/lib/jquery.class.js",function(a,b,c,d,e){(function(){var a=c||this,b=!1,d=/xyz/.test(function(){return xyz})?/\b_super\b/:/.*/;a.Class=function(){},a.Class.extend=function(a){function g(){!b&&this.init&&this.init.apply(this,arguments)}var c=this.prototype;b=!0;var e=new this;b=!1;for(var f in a)e[f]=typeof a[f]=="function"&&typeof c[f]=="function"&&d.test(a[f])?function(a,b){return function(){var d=this._super;this._super=c[a];var e=b.apply(this,arguments);return this._super=d,e}}(f,a[f]):a[f];return g.prototype=e,g.constructor=g,g.extend=arguments.callee,g}})()}),require.define("/lib/http.js",function(a,b,c,d,e){(function(){"use strict";var d=a("./jquery.class").Class,e=a("./log").Logger,f=a("./utils"),g=a("cookie"),h=c||this,i=null,j={5:function(a){var b=a.query||{},c=a.post||{},d=b.output_mode||c.output_mode||"json";return f.startsWith(d,"json")||(d="json"),b.output_mode=d,b},4:function(a){return a.query||{}},"default":function(a){return j[5](a)},none:function(a){return a.query||{}}};b.exports=h=i=d.extend({init:function(){this.get=f.bind(this,this.get),this.del=f.bind(this,this.del),this.post=f.bind(this,this.post),this.request=f.bind(this,this.request),this._buildResponse=f.bind(this,this._buildResponse),this._setSplunkVersion("none"),this._cookieStore={}},_setSplunkVersion:function(a){this.version=a},_getCookieString:function(){var a="";return f.forEach(this._cookieStore,function(b,c){a+=c,a+="=",a+=b,a+="; "}),a},_parseCookieHeader:function(a){var b=g.parse(a),c={};return f.forEach(b,function(a,b){if(c.key)return;c.key=b,c.value=a}),c},get:function(a,b,c,d,e){var f={method:"GET",headers:b,timeout:d,query:c};return this.request(a,f,e)},post:function(a,b,c,d,e){b["Content-Type"]="application/x-www-form-urlencoded";var f={method:"POST",headers:b,timeout:d,post:c};return this.request(a,f,e)},del:function(a,b,c,d,e){var f={method:"DELETE",headers:b,timeout:d,query:c};return this.request(a,f,e)},request:function(a,b,c){var d=this,e=function(a){c=c||function(){};var b=a.response.headers["set-cookie"];b&&f.forEach(b,function(a){var b=d._parseCookieHeader(a);d._cookieStore[b.key]=b.value}),a.status<400&&a.status!=="abort"?c(null,a):c(a)},g=f.getWithVersion(this.version,j)(b),h=b.post||{},k=a+"?"+i.encode(g),l=b.body?b.body:i.encode(h),m=d._getCookieString();m.length!==0&&(b.headers.Cookie=m,delete b.headers.Authorization);var n={method:b.method,headers:b.headers,timeout:b.timeout,body:l};return this.makeRequest(k,n,e)},makeRequest:function(a,b,c){throw new Error("UNDEFINED FUNCTION - OVERRIDE REQUIRED")},parseJson:function(a){throw new Error("UNDEFINED FUNCTION - OVERRIDE REQUIRED")},_buildResponse:function(a,b,c){var d,g={},h=null;b&&b.headers&&(h=f.trim(b.headers["content-type"]||b.headers["Content-Type"]||b.headers["Content-type"]||b.headers.contentType));if(f.startsWith(h,"application/json")&&c)try{g=this.parseJson(c)||{}}catch(i){e.error("Error in parsing JSON:",c,i),g=c}else g=c;return g&&e.printMessages(g.messages),d={response:b,status:b?b.statusCode:0,data:g,error:a},d}}),i.encode=function(a){var b="";for(var c in a)if(a.hasOwnProperty(c)){b&&b[b.length-1]!=="&"&&(b+="&");var d=a[c];if(d instanceof Array)for(var e=0;e1&&!b)throw new Error("Ambiguous match for name '"+a+"'");for(var e=0;e","<=",">=","is","isNull","isNotNull"],ipv4:["is","isNull","isNotNull","contains","doesNotContain","startsWith"]},_binning:["auto","year","month","day","hour","minute","second"],_sortDirection:["ASCENDING","DESCENDING","DEFAULT"],_statsFunctions:["list","values","first","last","count","dc","sum","average","max","min","stdev","duration","earliest","latest"],init:function(a){this.dataModelObject=a,this.columns=[],this.rows=[],this.filters=[],this.cells=[],this.accelerationNamespace=a.dataModel.isAccelerated()?a.dataModel.name:null,this.run=i.bind(this,this.run),this.pivot=i.bind(this,this.pivot)},setAccelerationJob:function(a){a&&a instanceof k.Job&&(a=a.sid);if(!a)throw new Error("Sid to use for acceleration must not be null.");return this.accelerationNamespace="sid="+a,this},addFilter:function(a,b,c,d){if(!this.dataModelObject.hasField(a))throw new Error("Cannot add filter on a nonexistent field.");if(b!==this.dataModelObject.fieldByName(a).type)throw new Error("Cannot add "+b+" filter on "+a+" because it is of type "+this.dataModelObject.fieldByName(a).type);if(!i.contains(this._comparisons[b],c))throw new Error("Cannot add "+b+" filter because "+c+" is not a valid comparison operator");var e={fieldName:a,owner:this.dataModelObject.fieldByName(a).lineage.join("."),type:b};return i.contains(["boolean","string","ipv4","number"],e.type)&&(e.rule={comparator:c,compareTo:d}),this.filters.push(e),this},addLimitFilter:function(a,b,c,d,e){if(!this.dataModelObject.hasField(a))throw new Error("Cannot add limit filter on a nonexistent field.");var f=this.dataModelObject.fieldByName(a);if(!i.contains(["string","number","objectCount"],f.type))throw new Error("Cannot add limit filter on "+a+" because it is of type "+f.type);if("string"===f.type&&!i.contains(["count","dc"],e))throw new Error("Stats function for fields of type string must be COUNT or DISTINCT_COUNT; found "+e);if("number"===f.type&&!i.contains(["count","dc","average","sum"],e))throw new Error("Stats function for fields of type number must be one of COUNT, DISTINCT_COUNT, SUM, or AVERAGE; found "+e);if("objectCount"===f.type&&!i.contains(["count"],e))throw new Error("Stats function for fields of type object count must be COUNT; found "+e);var g={fieldName:a,owner:f.lineage.join("."),type:f.type,attributeName:b,attributeOwner:this.dataModelObject.fieldByName(b).lineage.join("."),sortDirection:c,limitAmount:d,statsFn:e};return g.limitType="ASCENDING"===c?"lowest":"highest",this.filters.push(g),this},addRowSplit:function(a,b){if(!this.dataModelObject.hasField(a))throw new Error("Did not find field "+a);var c=this.dataModelObject.fieldByName(a);if(!i.contains(["number","string"],c.type))throw new Error("Field was of type "+c.type+", expected number or string.");var d={fieldName:a,owner:c.owner,type:c.type,label:b};return"number"===c.type&&(d.display="all"),this.rows.push(d),this},addRangeRowSplit:function(a,b,c){if(!this.dataModelObject.hasField(a))throw new Error("Did not find field "+a);var d=this.dataModelObject.fieldByName(a);if("number"!==d.type)throw new Error("Field was of type "+d.type+", expected number.");var e={};return!i.isUndefined(c.start)&&c.start!==null&&(e.start=c.start),!i.isUndefined(c.end)&&c.end!==null&&(e.end=c.end),!i.isUndefined(c.step)&&c.step!==null&&(e.size=c.step),!i.isUndefined(c.limit)&&c.limit!==null&&(e.maxNumberOf=c.limit),this.rows.push({fieldName:a,owner:d.owner,type:d.type,label:b,display:"ranges",ranges:e}),this},addBooleanRowSplit:function(a,b,c,d){if(!this.dataModelObject.fieldByName(a))throw new Error("Did not find field "+a);var e=this.dataModelObject.fieldByName(a);if("boolean"!==e.type)throw new Error("Field was of type "+e.type+", expected boolean.");return this.rows.push({fieldName:a,owner:e.owner,type:e.type,label:b,trueLabel:c,falseLabel:d}),this},addTimestampRowSplit:function(a,b,c){if(!this.dataModelObject.hasField(a))throw new Error("Did not find field "+a);var d=this.dataModelObject.fieldByName(a);if("timestamp"!==d.type)throw new Error("Field was of type "+d.type+", expected timestamp.");if(!i.contains(this._binning,c))throw new Error("Invalid binning "+c+" found. Valid values are: "+this._binning.join(", "));return this.rows.push({fieldName:a,owner:d.owner,type:d.type,label:b,period:c}),this},addColumnSplit:function(a){if(!this.dataModelObject.hasField(a))throw new Error("Did not find field "+a);var b=this.dataModelObject.fieldByName(a);if(!i.contains(["number","string"],b.type))throw new Error("Field was of type "+b.type+", expected number or string.");var c={fieldName:a,owner:b.owner,type:b.type};return"number"===b.type&&(c.display="all"),this.columns.push(c),this},addRangeColumnSplit:function(a,b){if(!this.dataModelObject.hasField(a))throw new Error("Did not find field "+a);var c=this.dataModelObject.fieldByName(a);if("number"!==c.type)throw new Error("Field was of type "+c.type+", expected number.");var d={};return!i.isUndefined(b.start)&&b.start!==null&&(d.start=b.start),!i.isUndefined(b.end)&&b.end!==null&&(d.end=b.end),!i.isUndefined(b.step)&&b.step!==null&&(d.size=b.step),!i.isUndefined(b.limit)&&b.limit!==null&&(d.maxNumberOf=b.limit),this.columns.push({fieldName:a,owner:c.owner,type:c.type,display:"ranges",ranges:d}),this},addBooleanColumnSplit:function(a,b,c){if(!this.dataModelObject.fieldByName(a))throw new Error("Did not find field "+a);var d=this.dataModelObject.fieldByName(a);if("boolean"!==d.type)throw new Error("Field was of type "+d.type+", expected boolean.");return this.columns.push({fieldName:a,owner:d.owner,type:d.type,trueLabel:b,falseLabel:c}),this},addTimestampColumnSplit:function(a,b){if(!this.dataModelObject.hasField(a))throw new Error("Did not find field "+a);var c=this.dataModelObject.fieldByName(a);if("timestamp"!==c.type)throw new Error("Field was of type "+c.type+", expected timestamp.");if(!i.contains(this._binning,b))throw new Error("Invalid binning "+b+" found. Valid values are: "+this._binning.join(", "));return this.columns.push({fieldName:a,owner:c.owner,type:c.type,period:b}),this},addCellValue:function(a,b,c){if(!this.dataModelObject.hasField(a))throw new Error("Did not find field "+a);var d=this.dataModelObject.fieldByName(a);if(i.contains(["string","ipv4"],d.type)&&!i.contains(["list","values","first","last","count","dc"],c))throw new Error("Stats function on string and IPv4 fields must be one of: list, distinct_values, first, last, count, or distinct_count; found "+c);if("number"===d.type&&!i.contains(["sum","count","average","min","max","stdev","list","values"],c))throw new Error("Stats function on number field must be must be one of: sum, count, average, max, min, stdev, list, or distinct_values; found "+c);if("timestamp"===d.type&&!i.contains(["duration","earliest","latest","list","values"],c))throw new Error("Stats function on timestamp field must be one of: duration, earliest, latest, list, or distinct values; found "+c);if(i.contains(["objectCount","childCount"],d.type)&&"count"!==c)throw new Error("Stats function on childcount and objectcount fields must be count; found "+c);if("boolean"===d.type)throw new Error("Cannot use boolean valued fields as cell values.");return this.cells.push({fieldName:a,owner:d.lineage.join("."),type:d.type,label:b,sparkline:!1,value:c}),this},toJsonObject:function(){return{dataModel:this.dataModelObject.dataModel.name,baseClass:this.dataModelObject.name,rows:this.rows,columns:this.columns,cells:this.cells,filters:this.filters}},pivot:function(a){var b=this.dataModelObject.dataModel.service,c={pivot_json:JSON.stringify(this.toJsonObject())};return i.isUndefined(this.accelerationNamespace)||(c.namespace=this.accelerationNamespace),b.get(g.pivot+"/"+encodeURIComponent(this.dataModelObject.dataModel.name),c,function(c,d){if(c){a(new Error(c.data.messages[0].text),d);return}d.data.entry&&d.data.entry[0]?a(null,new j.Pivot(b,d.data.entry[0].content)):a(new Error("Didn't get a Pivot report back from Splunk"),d)})},run:function(a,b){b||(b=a,a={}),a=a||{},this.pivot(function(c,d){c?b(c,null,null):d.run(a,f.augment(b,d))})}}),j.DataModelObject=h.extend({init:function(a,b){a=a||{},a.owner=a.owner||"",this.dataModel=b,this.name=a.objectName,this.displayName=a.displayName,this.parentName=a.parentName,this.lineage=a.lineage.split("."),a.hasOwnProperty("groupByFields")&&(this.groupByFields=a.groupByFields),a.hasOwnProperty("objectsToGroup")&&(this.objectsToGroup=a.objectsToGroup),a.hasOwnProperty("transactionMaxTimeSpan")&&(this.maxSpan=a.transactionMaxTimeSpan),a.hasOwnProperty("transactionMaxPause")&&(this.maxPause=a.transactionMaxPause),a.hasOwnProperty("baseSearch")&&(this.baseSearch=a.baseSearch),this.fields={};for(var c=0;c0)}})}})})()}),require.define("/lib/async.js",function(a,b,c,d,e){(function(){"use strict";var b=a("./utils"),d=c||this;d.whilst=function(a,b,c){a=a||function(){return!1},b=b||function(a){a()},c=c||function(){};var e=function(e){e?c(e):d.whilst(a,b,c)};a()?b(e):c(null)},d.parallel=function(a,c){if(arguments.length>1&&b.isFunction(arguments[0])){var d=b.toArray(arguments);a=d.slice(0,d.length-1),c=d[d.length-1]}a=a||[],c=c||function(){},a.length===0&&c();var e=a.length,f=[],g=function(a){return function(d){if(d)c&&c(d),c=null;else{var g=b.toArray(arguments);g.shift(),g.length===1&&(g=g[0]),f[a]=g,--e===0&&(f.unshift(null),c&&c.apply(null,f))}}};for(var h=0;h1&&b.isFunction(arguments[0])){var d=b.toArray(arguments);a=d.slice(0,d.length-1),c=d[d.length-1]}a=a||[],c=c||function(){};var e=function(a,c,d,f){if(!a){d.unshift(null),f.apply(null,d);return}a(function(a){if(a)f&&f(a),f=null;else{var g=b.toArray(arguments);g.shift(),g.length===1&&(g=g[0]),d.push(g),e(c[0],c.slice(1),d,f)}})};e(a[0],a.slice(1),[],c)},d.parallelMap=function(a,c,e){a=a||[],e=e||function(){};var f=[],g=function(a,b){return function(d){c(a,b,d)}};for(var h=0;h1&&b.isFunction(arguments[0])){var d=b.toArray(arguments);a=d.slice(0,d.length-1),c=d[d.length-1]}a=a||[],c=c||function(){};if(!a.length)c();else{var e=function(a,d,f){var g=function(a){if(a)c(a),c=function(){};else{var f=b.toArray(arguments);f.shift(),e(d[0],d.slice(1),f)}},h=f;d.length?h.push(g):h.push(c),a.apply(null,h)};e(a[0],a.slice(1),[])}},d.sleep=function(a,b){setTimeout(function(){b()},a)},d.augment=function(a){var b=Array.prototype.slice.call(arguments,1);return function(){var c=Array.prototype.slice.call(arguments);for(var d=0;d tag unexpected.")}},f.parseXMLData=function(a,b){var c={},d=a.getchildren();for(var e=0;e/g,">"),d||(a=a.replace(/\n/g," "),a=a.replace(/\r/g," ")),c&&(a=a.replace(/"/g,"""))),a}function w(a,b){return v(a,b,!0)}function x(a,b){return v(a,b,!1)}function y(a,b){return v(a,b,!1,!0)}function z(a,b,c){function g(a){return a}function h(a){if(a[0]==="{"){var b=a.substring(1).split("}",2),g=b[0],h=b[1],i=e[g];i===undefined&&(i=t[g],i===undefined&&(i="ns"+Object.keys(e).length),i!=="xml"&&(e[g]=i)),i?d[a]=f("%s:%s",i,h):d[a]=h}else{if(c)throw new Error("cannot use non-qualified names with default_namespace option");d[a]=a}}var d={},e={};return c&&(e[c]=""),a.iter(null,function(a){var b,c=a.tag,e=a.text,f=a.items();if(c instanceof r&&d[c.text]===undefined)h(c.text);else if(typeof c=="string")h(c);else if(c!==null&&c!==o&&c!==p&&c!==q)throw new Error("Invalid tag type for serialization: "+c);e instanceof r&&d[e.text]===undefined&&h(e.text),f.forEach(function(a){var b=a[0],c=a[1];b instanceof r&&(b=b.text),d[b]===undefined&&h(b),c instanceof r&&d[c.text]===undefined&&h(c.text)})}),[d,e]}function A(a,b,c,d,e,h,i){var j=b.tag,k=b.text,l,m,n=h||h===0;a(Array(h+1).join(i));if(j===o)a(f("",x(k,c)));else if(j===q)a(f("",x(k,c)));else if(j===p)k=k||"",a(f("",k));else{j=d[j];if(j===undefined)k&&a(y(k,c)),b.iter(function(b){A(a,b,c,d,null,n?h+1:!1,i)});else{a("<"+j),l=b.items();if(l||e)l.sort(),l.forEach(function(b){var e=b[0],g=b[1];e instanceof r&&(e=e.text),g instanceof r?g=d[g.text]:g=w(g,c),a(f(' %s="%s"',d[e],g))}),e&&(l=g.items(e),l.sort(function(a,b){return a[1]"),!k&&n&&a("\n"),k&&a(y(k,c)),b._children.forEach(function(b){A(a,b,c,d,null,n?h+1:!1,i)}),!k&&h&&a(Array(h+1).join(i)),a("")):a(" />")}}n&&a("\n")}function B(a,b){var c=new s;return c.parse(a,b),c}function C(a,b){return(new s(a)).write(b)}var f=a("./sprintf").sprintf,g=a("./utils"),h=a("./elementpath"),i=a("./treebuilder").TreeBuilder,j=a("./parser").get_parser,k=a("./constants"),l=0;m.prototype.toString=function(){return f("",this.tag,this._id)},m.prototype.makeelement=function(a,b){return new m(a,b)},m.prototype.len=function(){return this._children.length},m.prototype.getItem=function(a){return this._children[a]},m.prototype.setItem=function(a,b){this._children[a]=b},m.prototype.delItem=function(a){this._children.splice(a,1)},m.prototype.getSlice=function(a,b){return this._children.slice(a,b)},m.prototype.setSlice=function(a,b,c){var d,e=0;for(d=a;d\n");if(a.method==="text")_serialize_text(b,self._root,encoding);else{var c,d,e,f,h=z(this._root,a.encoding,a.default_namespace);c=h[0],d=h[1],a.hasOwnProperty("indent")?(e=0,f=(new Array(a.indent+1)).join(" ")):e=!1;if(a.method==="xml")A(function(a){b.push(a)},this._root,a.encoding,c,d,e,f);else throw new Error("unknown serialization method "+a.method)}return b.join("")};var t={"http://www.w3.org/XML/1998/namespace":"xml","http://www.w3.org/1999/xhtml":"html","http://www.w3.org/1999/02/22-rdf-syntax-ns#":"rdf","http://schemas.xmlsoap.org/wsdl/":"wsdl","http://www.w3.org/2001/XMLSchema":"xs","http://www.w3.org/2001/XMLSchema-instance":"xsi","http://purl.org/dc/elements/1.1/":"dc"};c.PI=q,c.Comment=o,c.CData=p,c.ProcessingInstruction=q,c.SubElement=n,c.QName=r,c.ElementTree=s,c.ElementPath=h,c.Element=function(a,b){return new m(a,b)},c.XML=function(a){var b=new s;return b.parse(a)},c.parse=B,c.register_namespace=u,c.tostring=C}),require.define("/node_modules/elementtree/lib/sprintf.js",function(a,b,c,d,e){function h(a){var b,c,d=a,e=0,h=1,i="return '";for(b=0;b100&&(i={});if(b.charAt(0)==="/")throw new h(null,"Cannot use absolute path on element");d=k(b),c=[];function o(){return d.shift()}j=o();for(;;){var p=j[1]||"";l=r[p](o,j);if(!l)throw new h(null,f("Invalid path: %s",b));c.push(l),j=o();if(!j)break;j[1]==="/"&&(j=o());if(!j)break}i[b]=c}d=[a],n=new s(a);for(e=0,g=c.length;e0?c[0]:null}function v(a,b,c){var d=t(a,b);return d&&d.length>0?d[0].text:c}var f=a("./sprintf").sprintf,g=a("./utils"),h=a("./errors").SyntaxError,i={},j=new RegExp("('[^']*'|\"[^\"]*\"|::|//?|\\.\\.|\\(\\)|[/.*:\\[\\]\\(\\)@=])|((?:\\{[^}]+\\})?[^/\\[\\]\\(\\)@=\\s]+)|\\s+","g"),k=g.findall.bind(null,j),r={"":l,"*":m,".":n,"..":p,"//":o,"[":q};c.find=u,c.findall=t,c.findtext=v}),require.define("/node_modules/elementtree/lib/errors.js",function(a,b,c,d,e){function h(a,b){b=b||g("Syntax Error at token %s",a.toString()),this.token=a,this.message=b,Error.call(this,b)}var f=a("util"),g=a("./sprintf").sprintf;f.inherits(h,Error),c.SyntaxError=h}),require.define("util",function(a,b,c,d,e){function g(a){return a instanceof Array||Array.isArray(a)||a&&a!==Object.prototype&&g(a.__proto__)}function h(a){return a instanceof RegExp||typeof a=="object"&&Object.prototype.toString.call(a)==="[object RegExp]"}function i(a){if(a instanceof Date)return!0;if(typeof a!="object")return!1;var b=Date.prototype&&n(Date.prototype),c=a.__proto__&&n(a.__proto__);return JSON.stringify(c)===JSON.stringify(b)}function j(a){return a<10?"0"+a.toString(10):a.toString(10)}function l(){var a=new Date,b=[j(a.getHours()),j(a.getMinutes()),j(a.getSeconds())].join(":");return[a.getDate(),k[a.getMonth()],b].join(" ")}var f=a("events");c.print=function(){},c.puts=function(){},c.debug=function(){},c.inspect=function(a,b,d,e){function k(a,d){if(a&&typeof a.inspect=="function"&&a!==c&&(!a.constructor||a.constructor.prototype!==a))return a.inspect(d);switch(typeof a){case"undefined":return j("undefined","undefined");case"string":var e="'"+JSON.stringify(a).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return j(e,"string");case"number":return j(""+a,"number");case"boolean":return j(""+a,"boolean")}if(a===null)return j("null","null");var l=m(a),o=b?n(a):l;if(typeof a=="function"&&o.length===0){if(h(a))return j(""+a,"regexp");var p=a.name?": "+a.name:"";return j("[Function"+p+"]","special")}if(i(a)&&o.length===0)return j(a.toUTCString(),"date");var q,r,s;g(a)?(r="Array",s=["[","]"]):(r="Object",s=["{","}"]);if(typeof a=="function"){var t=a.name?": "+a.name:"";q=h(a)?" "+a:" [Function"+t+"]"}else q="";i(a)&&(q=" "+a.toUTCString());if(o.length===0)return s[0]+q+s[1];if(d<0)return h(a)?j(""+a,"regexp"):j("[Object]","special");f.push(a);var u=o.map(function(b){var c,e;a.__lookupGetter__&&(a.__lookupGetter__(b)?a.__lookupSetter__(b)?e=j("[Getter/Setter]","special"):e=j("[Getter]","special"):a.__lookupSetter__(b)&&(e=j("[Setter]","special"))),l.indexOf(b)<0&&(c="["+b+"]"),e||(f.indexOf(a[b])<0?(d===null?e=k(a[b]):e=k(a[b],d-1),e.indexOf("\n")>-1&&(g(a)?e=e.split("\n").map(function(a){return" "+a}).join("\n").substr(2):e="\n"+e.split("\n").map(function(a){return" "+a}).join("\n"))):e=j("[Circular]","special"));if(typeof c=="undefined"){if(r==="Array"&&b.match(/^\d+$/))return e;c=JSON.stringify(""+b),c.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(c=c.substr(1,c.length-2),c=j(c,"name")):(c=c.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),c=j(c,"string"))}return c+": "+e});f.pop();var v=0,w=u.reduce(function(a,b){return v++,b.indexOf("\n")>=0&&v++,a+b.length+1},0);return w>50?u=s[0]+(q===""?"":q+"\n ")+" "+u.join(",\n ")+" "+s[1]:u=s[0]+q+" "+u.join(", ")+" "+s[1],u}var f=[],j=function(a,b){var c={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},d={special:"cyan",number:"blue","boolean":"yellow","undefined":"grey","null":"bold",string:"green",date:"magenta",regexp:"red"}[b];return d?"["+c[d][0]+"m"+a+"["+c[d][1]+"m":a};return e||(j=function(a,b){return a}),k(a,typeof d=="undefined"?2:d)};var k=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];c.log=function(a){},c.pump=null;var m=Object.keys||function(a){var b=[];for(var c in a)b.push(c);return b},n=Object.getOwnPropertyNames||function(a){var b=[];for(var c in a)Object.hasOwnProperty.call(a,c)&&b.push(c);return b},o=Object.create||function(a,b){var c;if(a===null)c={__proto__:null};else{if(typeof a!="object")throw new TypeError("typeof prototype["+typeof a+"] != 'object'");var d=function(){};d.prototype=a,c=new d,c.__proto__=a}return typeof b!="undefined"&&Object.defineProperties&&Object.defineProperties(c,b),c};c.inherits=function(a,b){a.super_=b,a.prototype=o(b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}})}}),require.define("events",function(a,b,c,d,e){process.EventEmitter||(process.EventEmitter=function(){});var f=c.EventEmitter=process.EventEmitter,g=typeof Array.isArray=="function"?Array.isArray:function(a){return Object.toString.call(a)==="[object Array]"},h=10;f.prototype.setMaxListeners=function(a){this._events||(this._events={}),this._events.maxListeners=a},f.prototype.emit=function(a){if(a==="error")if(!this._events||!this._events.error||g(this._events.error)&&!this._events.error.length)throw arguments[1]instanceof Error?arguments[1]:new Error("Uncaught, unspecified 'error' event.");if(!this._events)return!1;var b=this._events[a];if(!b)return!1;if(typeof b=="function"){switch(arguments.length){case 1:b.call(this);break;case 2:b.call(this,arguments[1]);break;case 3:b.call(this,arguments[1],arguments[2]);break;default:var c=Array.prototype.slice.call(arguments,1);b.apply(this,c)}return!0}if(g(b)){var c=Array.prototype.slice.call(arguments,1),d=b.slice();for(var e=0,f=d.length;e0&&this._events[a].length>c&&(this._events[a].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[a].length),console.trace())}this._events[a].push(b)}else this._events[a]=[this._events[a],b];return this},f.prototype.on=f.prototype.addListener,f.prototype.once=function(a,b){var c=this;return c.on(a,function d(){c.removeListener(a,d),b.apply(this,arguments)}),this},f.prototype.removeListener=function(a,b){if("function"!=typeof b)throw new Error("removeListener only takes instances of Function");if(!this._events||!this._events[a])return this;var c=this._events[a];if(g(c)){var d=c.indexOf(b);if(d<0)return this;c.splice(d,1),c.length==0&&delete this._events[a]}else this._events[a]===b&&delete this._events[a];return this},f.prototype.removeAllListeners=function(a){return a&&this._events&&this._events[a]&&(this._events[a]=null),this},f.prototype.listeners=function(a){return this._events||(this._events={}),this._events[a]||(this._events[a]=[]),g(this._events[a])||(this._events[a]=[this._events[a]]),this._events[a]}}),require.define("/node_modules/elementtree/lib/treebuilder.js",function(a,b,c,d,e){function f(b){this._data=[],this._elem=[],this._last=null,this._tail=null,b||(b=a("./elementtree").Element),this._factory=b}f.prototype.close=function(){return this._last},f.prototype._flush=function(){if(this._data){if(this._last!==null){var a=this._data.join("");this._tail?this._last.tail=a:this._last.text=a}this._data=[]}},f.prototype.data=function(a){this._data.push(a)},f.prototype.start=function(a,b){this._flush();var c=this._factory(a,b);this._last=c,this._elem.length&&this._elem[this._elem.length-1].append(c),this._elem.push(c),this._tail=null},f.prototype.end=function(a){this._flush(),this._last=this._elem.pop();if(this._last.tag!==a)throw new Error("end tag mismatch");return this._tail=1,this._last},c.TreeBuilder=f}),require.define("/node_modules/elementtree/lib/parser.js",function(a,b,c,d,e){function h(a){if(a==="sax")return g.sax;throw new Error("Invalid parser: "+a)}var f=a("util"),g=a("./parsers/index");c.get_parser=h}),require.define("/node_modules/elementtree/lib/parsers/index.js",function(a,b,c,d,e){c.sax=a("./sax")}),require.define("/node_modules/elementtree/lib/parsers/sax.js",function(a,b,c,d,e){function i(a){this.parser=g.parser(!0),this.target=a?a:new h,this.parser.onopentag=this._handleOpenTag.bind(this),this.parser.ontext=this._handleText.bind(this),this.parser.oncdata=this._handleCdata.bind(this),this.parser.ondoctype=this._handleDoctype.bind(this),this.parser.oncomment=this._handleComment.bind(this),this.parser.onclosetag=this._handleCloseTag.bind(this),this.parser.onerror=this._handleError.bind(this)}var f=a("util"),g=a("sax"),h=a("./../treebuilder").TreeBuilder;i.prototype._handleOpenTag=function(a){this.target.start(a.name,a.attributes)},i.prototype._handleText=function(a){this.target.data(a)},i.prototype._handleCdata=function(a){this.target.data(a)},i.prototype._handleDoctype=function(a){},i.prototype._handleComment=function(a){},i.prototype._handleCloseTag=function(a){this.target.end(a)},i.prototype._handleError=function(a){throw a},i.prototype.feed=function(a){this.parser.write(a)},i.prototype.close=function(){return this.parser.close(),this.target.close()},c.XMLParser=i}),require.define("/node_modules/sax/package.json",function(a,b,c,d,e){b.exports={main:"lib/sax.js"}}),require.define("/node_modules/sax/lib/sax.js",function(a,b,c,d,e){(function(b){function d(a,c){if(!(this instanceof d))return new d(a,c);var e=this;f(e),e.q=e.c="",e.bufferCheckPosition=b.MAX_BUFFER_LENGTH,e.opt=c||{},e.tagCase=e.opt.lowercasetags?"toLowerCase":"toUpperCase",e.tags=[],e.closed=e.closedRoot=e.sawRoot=!1,e.tag=e.error=null,e.strict=!!a,e.noscript=!!a||!!e.opt.noscript,e.state=B.BEGIN,e.ENTITIES=Object.create(b.ENTITIES),e.attribList=[],e.opt.xmlns&&(e.ns=Object.create(x)),e.position=e.line=e.column=0,C(e,"onready")}function e(a){var d=Math.max(b.MAX_BUFFER_LENGTH,10),e=0;for(var f=0,g=c.length;fd)switch(c[f]){case"textNode":E(a);break;case"cdata":D(a,"oncdata",a.cdata),a.cdata="";break;case"script":D(a,"onscript",a.script),a.script="";break;default:G(a,"Max buffer length exceeded: "+c[f])}e=Math.max(e,h)}a.bufferCheckPosition=b.MAX_BUFFER_LENGTH-e+a.position}function f(a){for(var b=0,d=c.length;b",a.state=B.TEXT;return}a.tagName=c;var f=a.tags.length;while(f-->b){var g=a.tag=a.tags.pop();a.tagName=a.tag.name,D(a,"onclosetag",a.tagName);var h={};for(var i in g.ns)h[i]=g.ns[i];var j=a.tags[a.tags.length-1]||a;a.opt.xmlns&&g.ns!==j.ns&&Object.keys(g.ns).forEach(function(b){var c=g.ns[b];D(a,"onclosenamespace",{prefix:b,uri:c})})}b===0&&(a.closedRoot=!0),a.tagName=a.attribValue=a.attribName="",a.attribList.length=0,a.state=B.TEXT}function O(a){var b=a.entity.toLowerCase(),c,d="";return a.ENTITIES[b]?a.ENTITIES[b]:(b.charAt(0)==="#"&&(b.charAt(1)==="x"?(b=b.slice(2),c=parseInt(b,16),d=c.toString(16)):(b=b.slice(1),c=parseInt(b,10),d=c.toString(10))),b=b.replace(/^0+/,""),d.toLowerCase()!==b?(I(a,"Invalid character entity"),"&"+a.entity+";"):String.fromCharCode(c))}function P(a){var b=this;if(this.error)throw this.error;if(b.closed)return G(b,"Cannot write after close. Assign an onready handler.");if(a===null)return H(b);var c=0,d="";while(b.c=d=a.charAt(c++)){b.position++,d==="\n"?(b.line++,b.column=0):b.column++;switch(b.state){case B.BEGIN:d==="<"?b.state=B.OPEN_WAKA:A(l,d)&&(I(b,"Non-whitespace before first tag."),b.textNode=d,b.state=B.TEXT);continue;case B.TEXT:if(b.sawRoot&&!b.closedRoot){var f=c-1;while(d&&d!=="<"&&d!=="&")d=a.charAt(c++),d&&(b.position++,d==="\n"?(b.line++,b.column=0):b.column++);b.textNode+=a.substring(f,c-1)}d==="<"?b.state=B.OPEN_WAKA:(A(l,d)&&(!b.sawRoot||b.closedRoot)&&I("Text data outside of root node."),d==="&"?b.state=B.TEXT_ENTITY:b.textNode+=d);continue;case B.SCRIPT:d==="<"?b.state=B.SCRIPT_ENDING:b.script+=d;continue;case B.SCRIPT_ENDING:d==="/"?(D(b,"onscript",b.script),b.state=B.CLOSE_TAG,b.script="",b.tagName=""):(b.script+="<"+d,b.state=B.SCRIPT);continue;case B.OPEN_WAKA:d==="!"?(b.state=B.SGML_DECL,b.sgmlDecl=""):z(l,d)||(z(o,d)?(b.startTagPosition=b.position-1,b.state=B.OPEN_TAG,b.tagName=d):d==="/"?(b.startTagPosition=b.position-1,b.state=B.CLOSE_TAG,b.tagName=""):d==="?"?(b.state=B.PROC_INST,b.procInstName=b.procInstBody=""):(I(b,"Unencoded <"),b.textNode+="<"+d,b.state=B.TEXT));continue;case B.SGML_DECL:(b.sgmlDecl+d).toUpperCase()===t?(D(b,"onopencdata"),b.state=B.CDATA,b.sgmlDecl="",b.cdata=""):b.sgmlDecl+d==="--"?(b.state=B.COMMENT,b.comment="",b.sgmlDecl=""):(b.sgmlDecl+d).toUpperCase()===u?(b.state=B.DOCTYPE,(b.doctype||b.sawRoot)&&I(b,"Inappropriately located doctype declaration"),b.doctype="",b.sgmlDecl=""):d===">"?(D(b,"onsgmldeclaration",b.sgmlDecl),b.sgmlDecl="",b.state=B.TEXT):z(q,d)?(b.state=B.SGML_DECL_QUOTED,b.sgmlDecl+=d):b.sgmlDecl+=d;continue;case B.SGML_DECL_QUOTED:d===b.q&&(b.state=B.SGML_DECL,b.q=""),b.sgmlDecl+=d;continue;case B.DOCTYPE:d===">"?(b.state=B.TEXT,D(b,"ondoctype",b.doctype),b.doctype=!0):(b.doctype+=d,d==="["?b.state=B.DOCTYPE_DTD:z(q,d)&&(b.state=B.DOCTYPE_QUOTED,b.q=d));continue;case B.DOCTYPE_QUOTED:b.doctype+=d,d===b.q&&(b.q="",b.state=B.DOCTYPE);continue;case B.DOCTYPE_DTD:b.doctype+=d,d==="]"?b.state=B.DOCTYPE:z(q,d)&&(b.state=B.DOCTYPE_DTD_QUOTED,b.q=d);continue;case B.DOCTYPE_DTD_QUOTED:b.doctype+=d,d===b.q&&(b.state=B.DOCTYPE_DTD,b.q="");continue;case B.COMMENT:d==="-"?b.state=B.COMMENT_ENDING:b.comment+=d;continue;case B.COMMENT_ENDING:d==="-"?(b.state=B.COMMENT_ENDED,b.comment=F(b.opt,b.comment),b.comment&&D(b,"oncomment",b.comment),b.comment=""):(b.comment+="-"+d,b.state=B.COMMENT);continue;case B.COMMENT_ENDED:d!==">"?(I(b,"Malformed comment"),b.comment+="--"+d,b.state=B.COMMENT):b.state=B.TEXT;continue;case B.CDATA:d==="]"?b.state=B.CDATA_ENDING:b.cdata+=d;continue;case B.CDATA_ENDING:d==="]"?b.state=B.CDATA_ENDING_2:(b.cdata+="]"+d,b.state=B.CDATA);continue;case B.CDATA_ENDING_2:d===">"?(b.cdata&&D(b,"oncdata",b.cdata),D(b,"onclosecdata"),b.cdata="",b.state=B.TEXT):d==="]"?b.cdata+="]":(b.cdata+="]]"+d,b.state=B.CDATA);continue;case B.PROC_INST:d==="?"?b.state=B.PROC_INST_ENDING:z(l,d)?b.state=B.PROC_INST_BODY:b.procInstName+=d;continue;case B.PROC_INST_BODY:if(!b.procInstBody&&z(l,d))continue;d==="?"?b.state=B.PROC_INST_ENDING:z(q,d)?(b.state=B.PROC_INST_QUOTED,b.q=d,b.procInstBody+=d):b.procInstBody+=d;continue;case B.PROC_INST_ENDING:d===">"?(D(b,"onprocessinginstruction",{name:b.procInstName,body:b.procInstBody}),b.procInstName=b.procInstBody="",b.state=B.TEXT):(b.procInstBody+="?"+d,b.state=B.PROC_INST_BODY);continue;case B.PROC_INST_QUOTED:b.procInstBody+=d,d===b.q&&(b.state=B.PROC_INST_BODY,b.q="");continue;case B.OPEN_TAG:z(p,d)?b.tagName+=d:(J(b),d===">"?M(b):d==="/"?b.state=B.OPEN_TAG_SLASH:(A(l,d)&&I(b,"Invalid character in tag name"),b.state=B.ATTRIB));continue;case B.OPEN_TAG_SLASH:d===">"?(M(b,!0),N(b)):(I(b,"Forward-slash in opening tag not followed by >"),b.state=B.ATTRIB);continue;case B.ATTRIB:if(z(l,d))continue;d===">"?M(b):d==="/"?b.state=B.OPEN_TAG_SLASH:z(o,d)?(b.attribName=d,b.attribValue="",b.state=B.ATTRIB_NAME):I(b,"Invalid attribute name");continue;case B.ATTRIB_NAME:d==="="?b.state=B.ATTRIB_VALUE:z(l,d)?b.state=B.ATTRIB_NAME_SAW_WHITE:z(p,d)?b.attribName+=d:I(b,"Invalid attribute name");continue;case B.ATTRIB_NAME_SAW_WHITE:if(d==="=")b.state=B.ATTRIB_VALUE;else{if(z(l,d))continue;I(b,"Attribute without value"),b.tag.attributes[b.attribName]="",b.attribValue="",D(b,"onattribute",{name:b.attribName,value:""}),b.attribName="",d===">"?M(b):z(o,d)?(b.attribName=d,b.state=B.ATTRIB_NAME):(I(b,"Invalid attribute name"),b.state=B.ATTRIB)}continue;case B.ATTRIB_VALUE:if(z(l,d))continue;z(q,d)?(b.q=d,b.state=B.ATTRIB_VALUE_QUOTED):(I(b,"Unquoted attribute value"),b.state=B.ATTRIB_VALUE_UNQUOTED,b.attribValue=d);continue;case B.ATTRIB_VALUE_QUOTED:if(d!==b.q){d==="&"?b.state=B.ATTRIB_VALUE_ENTITY_Q:b.attribValue+=d;continue}L(b),b.q="",b.state=B.ATTRIB;continue;case B.ATTRIB_VALUE_UNQUOTED:if(A(s,d)){d==="&"?b.state=B.ATTRIB_VALUE_ENTITY_U:b.attribValue+=d;continue}L(b),d===">"?M(b):b.state=B.ATTRIB;continue;case B.CLOSE_TAG:if(!b.tagName){if(z(l,d))continue;A(o,d)?I(b,"Invalid tagname in closing tag."):b.tagName=d}else d===">"?N(b):z(p,d)?b.tagName+=d:(A(l,d)&&I(b,"Invalid tagname in closing tag"),b.state=B.CLOSE_TAG_SAW_WHITE);continue;case B.CLOSE_TAG_SAW_WHITE:if(z(l,d))continue;d===">"?N(b):I("Invalid characters in closing tag");continue;case B.TEXT_ENTITY:case B.ATTRIB_VALUE_ENTITY_Q:case B.ATTRIB_VALUE_ENTITY_U:switch(b.state){case B.TEXT_ENTITY:var g=B.TEXT,h="textNode";break;case B.ATTRIB_VALUE_ENTITY_Q:var g=B.ATTRIB_VALUE_QUOTED,h="attribValue";break;case B.ATTRIB_VALUE_ENTITY_U:var g=B.ATTRIB_VALUE_UNQUOTED,h="attribValue"}d===";"?(b[h]+=O(b),b.entity="",b.state=g):z(r,d)?b.entity+=d:(I("Invalid character entity"),b[h]+="&"+b.entity+d,b.entity="",b.state=g);continue;default:throw new Error(b,"Unknown state: "+b.state)}}return b.position>=b.bufferCheckPosition&&e(b),b}b.parser=function(a,b){return new d(a,b)},b.SAXParser=d,b.SAXStream=k,b.createStream=j,b.MAX_BUFFER_LENGTH=65536;var c=["comment","sgmlDecl","textNode","tagName","doctype","procInstName","procInstBody","entity","attribName","attribValue","cdata","script"];b.EVENTS=["text","processinginstruction","sgmldeclaration","doctype","comment","attribute","opentag","closetag","opencdata","cdata","closecdata","error","end","ready","script","opennamespace","closenamespace"],Object.create||(Object.create=function(a){function b(){this.__proto__=a}return b.prototype=a,new b}),Object.getPrototypeOf||(Object.getPrototypeOf=function(a){return a.__proto__}),Object.keys||(Object.keys=function(a){var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(c);return b}),d.prototype={end:function(){H(this)},write:P,resume:function(){return this.error=null,this},close:function(){return this.write(null)},end:function(){return this.write(null)}};try{var g=a("stream").Stream}catch(h){var g=function(){}}var i=b.EVENTS.filter(function(a){return a!=="error"&&a!=="end"});k.prototype=Object.create(g.prototype,{constructor:{value:k}}),k.prototype.write=function(a){return this._parser.write(a.toString()),this.emit("data",a),!0},k.prototype.end=function(a){return a&&a.length&&this._parser.write(a.toString()),this._parser.end(),!0},k.prototype.on=function(a,b){var c=this;return!c._parser["on"+a]&&i.indexOf(a)!==-1&&(c._parser["on"+a]=function(){var b=arguments.length===1?[arguments[0]]:Array.apply(null,arguments);b.splice(0,0,a),c.emit.apply(c,b)}),g.prototype.on.call(c,a,b)};var l="\r\n\t ",m="0124356789",n="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",o=n+"_:",p=o+m+"-.",q="'\"",r=m+n+"#",s=l+">",t="[CDATA[",u="DOCTYPE",v="http://www.w3.org/XML/1998/namespace",w="http://www.w3.org/2000/xmlns/",x={xml:v,xmlns:w};l=y(l),m=y(m),n=y(n),o=y(o),p=y(p),q=y(q),r=y(r),s=y(s);var B=0;b.STATE={BEGIN:B++,TEXT:B++,TEXT_ENTITY:B++,OPEN_WAKA:B++,SGML_DECL:B++,SGML_DECL_QUOTED:B++,DOCTYPE:B++,DOCTYPE_QUOTED:B++,DOCTYPE_DTD:B++,DOCTYPE_DTD_QUOTED:B++,COMMENT_STARTING:B++,COMMENT:B++,COMMENT_ENDING:B++,COMMENT_ENDED:B++,CDATA:B++,CDATA_ENDING:B++,CDATA_ENDING_2:B++,PROC_INST:B++,PROC_INST_BODY:B++,PROC_INST_QUOTED:B++,PROC_INST_ENDING:B++,OPEN_TAG:B++,OPEN_TAG_SLASH:B++,ATTRIB:B++,ATTRIB_NAME:B++,ATTRIB_NAME_SAW_WHITE:B++,ATTRIB_VALUE:B++,ATTRIB_VALUE_QUOTED:B++,ATTRIB_VALUE_UNQUOTED:B++,ATTRIB_VALUE_ENTITY_Q:B++,ATTRIB_VALUE_ENTITY_U:B++,CLOSE_TAG:B++,CLOSE_TAG_SAW_WHITE:B++,SCRIPT:B++,SCRIPT_ENDING:B++},b.ENTITIES={apos:"'",quot:'"',amp:"&",gt:">",lt:"<"};for(var B in b.STATE)b.STATE[b.STATE[B]]=B;B=b.STATE})(typeof c=="undefined"?sax={}:c)}),require.define("stream",function(a,b,c,d,e){function h(){f.EventEmitter.call(this)}var f=a("events"),g=a("util");g.inherits(h,f.EventEmitter),b.exports=h,h.Stream=h,h.prototype.pipe=function(a,b){function d(b){a.writable&&!1===a.write(b)&&c.pause&&c.pause()}function e(){c.readable&&c.resume&&c.resume()}function g(){if(f)return;f=!0,a._pipeCount--,j();if(a._pipeCount>0)return;a.end()}function h(){if(f)return;f=!0,a._pipeCount--,j();if(a._pipeCount>0)return;a.destroy()}function i(a){j();if(this.listeners("error").length===0)throw a}function j(){c.removeListener("data",d),a.removeListener("drain",e),c.removeListener("end",g),c.removeListener("close",h),c.removeListener("error",i),a.removeListener("error",i),c.removeListener("end",j),c.removeListener("close",j),a.removeListener("end",j),a.removeListener("close",j)}var c=this;c.on("data",d),a.on("drain",e),!a._isStdio&&(!b||b.end!==!1)&&(a._pipeCount=a._pipeCount||0,a._pipeCount++,c.on("end",g),c.on("close",h));var f=!1;return c.on("error",i),a.on("error",i),c.on("end",j),c.on("close",j),a.on("end",j),a.on("close",j),a.emit("pipe",c),a}}),require.define("/node_modules/elementtree/lib/constants.js",function(a,b,c,d,e){var f="sax";c.DEFAULT_PARSER=f}),require.define("/lib/modularinputs/inputdefinition.js",function(a,b,c,d,e){(function(){function e(){this.metadata={},this.inputs={}}var c=a("elementtree"),d=a("./utils");e.parse=function(a){var b=new e,f=c.parse(a).getroot().getchildren();for(var g=0;g=10?b=parseFloat(a.toString().substring(0,14)).toFixed(3):a.toString().length<=13||a.toString().indexOf(".")<10?b=parseFloat(a).toFixed(3):b=(parseFloat(a.toString().substring(0,14))/1e3).toFixed(3)):a.toString().length===13?b=(parseFloat(a)/1e3).toFixed(3):a.toString().length<=12?b=parseFloat(a).toFixed(3):b=parseFloat(a.toString().substring(0,13)/1e3).toFixed(3),b)},e.prototype._writeTo=function(a){if(!this.data)throw new Error("Events must have at least the data field set to be written to XML.");var b=c.Element("event");this.stanza&&b.set("stanza",this.stanza),b.set("unbroken",(+this.unbroken).toString()),!d.isUndefined(this.time)&&this.time!==null&&(c.SubElement(b,"time").text=e.formatTime(this.time).toString()),typeof this.data=="object"&&(this.data=JSON.stringify(this.data));var f=[{tag:"source",text:this.source},{tag:"sourcetype",text:this.sourcetype},{tag:"index",text:this.index},{tag:"host",text:this.host},{tag:"data",text:this.data}];for(var g=0;g"),this._headerWritten=!0);try{a._writeTo(this._out)}catch(b){throw b.message==="Events must have at least the data field set to be written to XML."?(e.warn("",b.message,this._err),b):(e.error("",b.message,this._err),b)}},h.prototype.writeXMLDocument=function(a){var b=c.tostring(a,{xml_declaration:!1});this._out.write(b)},h.prototype.close=function(){this._out.write("")},b.exports=h})()}),require.define("/lib/modularinputs/logger.js",function(a,b,c,d,e){(function(){"use strict";var d=a("./utils"),e=c||this;e.DEBUG="DEBUG",e.INFO="INFO",e.WARN="WARN",e.ERROR="ERROR",e.FATAL="FATAL",e._log=function(a,b,c,d){d=d||process.stderr,b&&b.length>0&&(b+=" ");var e=a+" Modular input "+b+c+"\n";d.write(e)},e.debug=function(a,b,c){try{e._log(e.DEBUG,a,b,c)}catch(d){throw d}},e.info=function(a,b,c){try{e._log(e.INFO,a,b,c)}catch(d){throw d}},e.warn=function(a,b,c){try{e._log(e.WARN,a,b,c)}catch(d){throw d}},e.error=function(a,b,c){try{e._log(e.ERROR,a,b,c)}catch(d){throw d}},e.fatal=function(a,b,c){try{e._log(e.FATAL,a,b,c)}catch(d){throw d}},b.exports=e})()}),require.define("/lib/modularinputs/argument.js",function(a,b,c,d,e){(function(){function e(a){a||(a={}),this.name=d.isUndefined(a.name)?"":a.name,this.description=d.isUndefined(a.description)?null:a.description,this.validation=d.isUndefined(a.validation)?null:a.validation,this.dataType=d.isUndefined(a.dataType)?e.dataTypeString:a.dataType,this.requiredOnEdit=d.isUndefined(a.requiredOnEdit)?!1:a.requiredOnEdit,this.requiredOnCreate=d.isUndefined(a.requiredOnCreate)?!1:a.requiredOnCreate}var c=a("elementtree"),d=a("./utils");e.dataTypeBoolean="BOOLEAN",e.dataTypeNumber="NUMBER",e.dataTypeString="STRING",e.prototype.addToDocument=function(a){var b=c.SubElement(a,"arg");b.set("name",this.name),this.description&&(c.SubElement(b,"description").text=this.description),this.validation&&(c.SubElement(b,"validation").text=this.validation);var d=[{tag:"data_type",value:this.dataType},{tag:"required_on_edit",value:this.requiredOnEdit},{tag:"required_on_create",value:this.requiredOnCreate}];for(var e=0;e")){clearTimeout(o);var g=h.parse(c);a._inputDefinition=g,k._inputDefinition=g,f.chain([function(b){f.parallelEach(Object.keys(a._inputDefinition.inputs),function(b,c,e){var g=a._inputDefinition.inputs[b];f.chain([function(c){a.start(b,g,c)},function(c){a.streamEvents(b,g,d,c)},function(c){a.end(b,g,c)}],function(a){e(a,a?1:0)})},function(a){b(a,a?1:0)})}],function(a){d._headerWritten&&d.close(),j(a,a?1:0)})}})}else if(b.length>=2&&b[1].toString().toLowerCase()==="--scheme"){var p=a.getScheme();if(!p)l.fatal("","script returned a null scheme.",d._err),j(null,1);else try{d.writeXMLDocument(p.toXML()),j(null,0)}catch(q){l.fatal("","script could not return the scheme, error: "+q,d._err),j(q,1)}}else if(b.length>=2&&b[1].toString().toLowerCase()==="--validate-arguments"){var r=setTimeout(function(){j(new Error("Receiving validation definition prior to validating timed out."),1)},30500);i.on("data",function(b){n=Buffer.concat([n,b]);var h=n.toString("utf8",0,n.length).trim();e.endsWith(h,"")&&(clearTimeout(r),f.chain([function(b){try{if(e.isUndefined(a.validateInput))b();else{var c=g.parse(n.toString("utf8",0,n.length));a.validateInput(c,b)}}catch(d){b(d)}}],function(a){if(a){l.error("",a.message),l.error("","Stack trace for a modular input error: "+a.stack);try{var b=c.Element("error");c.SubElement(b,"message").text=a.message,d.writeXMLDocument(b),j(a,1)}catch(e){j(e,1)}}else j(null,0)}))})}else{var s="Invalid arguments to modular input script: "+b.join()+"\n";l.error("",s,d._err),j(s,1)}},m.service=function(){if(this._service)return this._service;if(!this._inputDefinition)return null;var a=this._inputDefinition.metadata.server_uri,b=this._inputDefinition.metadata.session_key,c=d.parse(a),e=c.protocol.replace(":",""),f=c.hostname,g=c.port;return this._service=new k({scheme:e,host:f,port:g,token:b}),this._service},m.prototype.setup=function(a){a()},m.prototype.start=function(a,b,c){c()},m.prototype.end=function(a,b,c){c()},m.prototype.teardown=function(a){a()},b.exports=m})()}),require.define("url",function(a,b,c,d,e){function v(a,b,c){if(a&&typeof a=="object"&&a.href)return a;if(typeof a!="string")throw new TypeError("Parameter 'url' must be a string, not "+typeof a);var d={},e=a;for(var h=0,j=e.length;hn)d.hostname="";else{var G=d.hostname.split(/\./);for(var h=0,j=G.length;h127?I+="x":I+=H[J];if(!I.match(o)){var L=G.slice(0,h),M=G.slice(h+1),N=H.match(p);N&&(L.push(N[1]),M.unshift(N[2])),M.length&&(e="/"+M.join(".")+e),d.hostname=L.join(".");break}}}}d.hostname=d.hostname.toLowerCase();var O=d.hostname.split("."),P=[];for(var h=0;h0?a.host.split("@"):!1;j&&(a.auth=j.shift(),a.host=a.hostname=j.shift())}a.search=b.search,a.query=b.query;if(a.pathname!==undefined||a.search!==undefined)a.path=(a.pathname?a.pathname:"")+(a.search?a.search:"");return a.href=w(a),a}if(!h.length)return delete a.pathname,a.search?delete a.path:a.path="/"+a.search,a.href=w(a),a;var k=h.slice(-1)[0],l=(a.host||b.host)&&(k==="."||k==="..")||k==="",m=0;for(var n=h.length;n>=0;n--)k=h[n],k=="."?h.splice(n,1):k===".."?(h.splice(n,1),m++):m&&(h.splice(n,1),m--);if(!f&&!g)for(;m--;m)h.unshift("..");f&&h[0]!==""&&(!h[0]||h[0].charAt(0)!=="/")&&h.unshift(""),l&&h.join("/").substr(-1)!=="/"&&h.push("");var o=h[0]===""||h[0]&&h[0].charAt(0)==="/";if(i){a.hostname=a.host=o?"":h.length?h.shift():"";var j=a.host&&a.host.indexOf("@")>0?a.host.split("@"):!1;j&&(a.auth=j.shift(),a.host=a.hostname=j.shift())}f=f||a.host&&h.length,f&&!o&&h.unshift(""),a.pathname=h.join("/");if(a.pathname!==undefined||a.search!==undefined)a.path=(a.pathname?a.pathname:"")+(a.search?a.search:"");return a.auth=b.auth||a.auth,a.slashes=a.slashes||b.slashes,a.href=w(a),a}function z(a){var b={},c=h.exec(a);return c&&(c=c[0],b.port=c.substr(1),a=a.substr(0,a.length-c.length)),a&&(b.hostname=a),b}var f={encode:function(a){return a}};c.parse=v,c.resolve=x,c.resolveObject=y,c.format=w;var g=/^([a-z0-9.+-]+:)/i,h=/:[0-9]+$/,i=["<",">",'"',"`"," ","\r","\n","\t"],j=["{","}","|","\\","^","~","[","]","`"].concat(i),k=["'"],l=["%","/","?",";","#"].concat(j).concat(k),m=["/","@","?","#"].concat(i),n=255,o=/^[a-zA-Z0-9][a-z0-9A-Z_-]{0,62}$/,p=/^([a-zA-Z0-9][a-z0-9A-Z_-]{0,62})(.*)$/,q={javascript:!0,"javascript:":!0},r={javascript:!0,"javascript:":!0},s={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},t={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},u=a("querystring")}),require.define("querystring",function(a,b,c,d,e){function j(a,b){if(!b)throw new TypeError("stringify expects an object");return b+"="+encodeURIComponent(a)}function k(a,b){var c=[];if(!b)throw new TypeError("stringify expects an object");for(var d=0;d","Username to login with",undefined,!0).option("--password ","Username to login with",undefined,!1).option("--scheme ","Scheme to use","https",!1).option("--host ","Hostname to use","localhost",!1).option("--port ","Port to use",8089,!1).option("--version ","Which version to use","4",!1),a.parse=function(c){c=(c||[]).slice(2);var d=j();for(var e in d)if(d.hasOwnProperty(e)&&c.indexOf("--"+e)<0){var f=d[e];c.unshift(f),c.unshift("--"+e.trim())}c.unshift(""),c.unshift("");var g=b.call(a,c);return g},a.add=function(b,c,d,e,f,h){var i={};e=e||[];var j=a.command(b+(d?" "+d:"")).description(c||"");for(var k=0;k=0,m="<"+e[k]+">";j.option("--"+e[k]+" "+m,"",undefined,l)}j.action(function(){var a=g.toArray(arguments);a.unshift(b),h.apply(null,a)})},a}})()}),require.define("/tests/test_service.js",function(a,b,c,d,e){c.setup=function(b,c){var d=a("../index"),f=d.Utils,g=d.Async,h=a("./utils"),i=a("path");d.Logger.setLevel("ALL");var j=0,k=function(){return"id"+j++ +"_"+(new Date).valueOf()},l={"Namespace Tests":{setUp:function(a){this.service=b;var c=this,d="jssdk_testapp_"+k(),e="jssdk_testapp_"+k(),f="jssdk_testuser_"+k(),h="jssdk_testuser_"+k(),i=this.service.apps(),j=this.service.users();this.namespace11={owner:f,app:d},this.namespace12={owner:f,app:e},this.namespace21={owner:h,app:d},this.namespace22={owner:h,app:e},g.chain([function(a){i.create({name:d},a)},function(a,b){c.app1=a,c.appName1=d,i.create({name:e},b)},function(a,b){c.app2=a,c.appName2=e,j.create({name:f,password:"abc",roles:["user"]},b)},function(a,b){c.user1=a,c.userName1=f,j.create({name:h,password:"abc",roles:["user"]},b)},function(a,b){c.user2=a,c.userName2=h,b()}],function(b){a()})},"Callback#Namespace protection":function(a){var b="jssdk_search_"+k(),c="search *",d=this.service,e=d.savedSearches(this.namespace11),f=d.savedSearches(this.namespace21),h=this;g.chain([function(a){e.create({name:b,search:c},a)},function(a,b){e.fetch(b)},function(a,b){f.fetch(b)},function(d,g){var h=e.item(b),i=f.item(b);a.ok(h),a.strictEqual(h.name,b),a.strictEqual(h.properties().search,c),a.ok(!i),g()}],function(b){a.ok(!b),a.done()})},"Callback#Namespace item":function(a){var b="jssdk_search_"+k(),c="search *",d=this.service,e={owner:"-",app:this.appName1},f={owner:"nobody",app:this.appName1},h=d.savedSearches(this.namespace11),i=d.savedSearches(this.namespace21),j=d.savedSearches(e),l=d.savedSearches(f),m=this;g.chain([function(a){h.create({name:b,search:c},a)},function(a,d){i.create({name:b,search:c},d)},function(a,b){j.fetch(b)},function(a,b){h.fetch(b)},function(a,b){i.fetch(b)},function(d,e){var f=h.item(b,m.namespace11),g=i.item(b,m.namespace21);a.ok(f),a.strictEqual(f.name,b),a.strictEqual(f.properties().search,c),a.strictEqual(f.namespace.owner,m.namespace11.owner),a.strictEqual(f.namespace.app,m.namespace11.app),a.ok(g),a.strictEqual(g.name,b),a.strictEqual(g.properties().search,c),a.strictEqual(g.namespace.owner,m.namespace21.owner),a.strictEqual(g.namespace.app,m.namespace21.app),e()},function(a){l.create({name:b,search:c},a)},function(a,b){h.fetch(b)},function(a,b){i.fetch(b)},function(d,e){try{j.item(b),a.ok(!1)}catch(f){a.ok(f)}try{j.item(b,{owner:"-"}),a.ok(!1)}catch(f){a.ok(f)}try{j.item(b,{app:"-"}),a.ok(!1)}catch(f){a.ok(f)}try{j.item(b,{app:"-",owner:"-"}),a.ok(!1)}catch(f){a.ok(f)}var g=j.item(b,m.namespace11),h=j.item(b,m.namespace21);a.ok(g),a.strictEqual(g.name,b),a.strictEqual(g.properties().search,c),a.strictEqual(g.namespace.owner,m.namespace11.owner),a.strictEqual(g.namespace.app,m.namespace11.app),a.ok(h),a.strictEqual(h.name,b),a.strictEqual(h.properties().search,c),a.strictEqual(h.namespace.owner,m.namespace21.owner),a.strictEqual(h.namespace.app,m.namespace21.app),e()}],function(b){a.ok(!b),a.done()})},"Callback#delete test applications":function(a){var b=this.service.apps();b.fetch(function(b,c){a.ok(!b),a.ok(c);var d=c.list();g.parallelEach(d,function(a,b,c){f.startsWith(a.name,"jssdk_")?a.remove(c):c()},function(b){a.ok(!b),a.done()})})},"Callback#delete test users":function(a){var b=this.service.users();b.fetch(function(b,c){var d=c.list();g.parallelEach(d,function(a,b,c){f.startsWith(a.name,"jssdk_")?a.remove(c):c()},function(b){a.ok(!b),a.done()})})}},"Job Tests":{setUp:function(a){this.service=b,a()},"Callback#Create+abort job":function(a){var b=this.service;g.chain([function(a){var c=i.join(process.env.SPLUNK_HOME,"/etc/apps/sdk-app-collection/build/sleep_command.tar");c=c.replace("%20"," "),b.post("apps/appinstall",{update:1,name:c},a)},function(c){var d=k(),e={id:d},f=b.jobs({app:"sdk-app-collection"}),h=f.oneshotSearch("search index=_internal | head 1 | sleep 10",e,function(b,c){a.ok(b),a.ok(!c),a.strictEqual(b.error,"abort"),a.done()});g.sleep(1e3,function(){h.abort()})}],function(b){a.ok(!b),a.done()})},"Callback#Create+cancel job":function(a){var b=k();this.service.jobs().search("search index=_internal | head 1",{id:b},function(c,d){a.ok(d),a.strictEqual(d.sid,b),d.cancel(function(){a.done()})})},"Callback#Create job error":function(a){var b=k();this.service.jobs().search({search:"index=_internal | head 1",id:b},function(b){a.ok(!!b),a.done()})},"Callback#List jobs":function(a){this.service.jobs().fetch(function(b,c){a.ok(!b),a.ok(c);var d=c.list();a.ok(d.length>0);for(var e=0;ec),a.ok(e<=c*2),b.cancel(d)}],function(b){a.ok(!b),a.done()})},"Callback#Set priority":function(a){var b=k(),c=0,d=this,e=this.service.specialize("nobody","sdk-app-collection");g.chain([function(a){e.jobs().search("search index=_internal | head 1 | sleep 5",{id:b},a)},function(a,b){a.track({},{ready:function(a){b(null,a)}})},function(b,c){var d=b.properties().priority;a.ok(d,5),b.setPriority(d+1,c)},function(a,b){a.fetch(b)},function(a,b){a.cancel(b)}],function(b){a.ok(!b),a.done()})},"Callback#Search log":function(a){var b=k(),c=this;g.chain([function(a){c.service.jobs().search("search index=_internal | head 1",{id:b,exec_mode:"blocking"},a)},function(a,b){a.searchlog(b)},function(b,c,d){a.ok(c),a.ok(b),a.ok(b.length>0),a.ok(b.split("\r\n").length>0),c.cancel(d)}],function(b){a.ok(!b),a.done()})},"Callback#Search summary":function(a){var b=k(),c=this;g.chain([function(a){c.service.jobs().search('search index=_internal | head 1 | eval foo="bar" | fields foo',{id:b,status_buckets:300,rf:["foo"]},a)},function(a,b){g.sleep(2e3,function(){a.summary({},b)})},function(b,c,d){a.ok(c),a.ok(b),a.strictEqual(b.event_count,1),a.strictEqual(b.fields.foo.count,1),a.strictEqual(b.fields.foo.distinct_count,1),a.ok(b.fields.foo.is_exact,1),a.strictEqual(b.fields.foo.modes.length,1),a.strictEqual(b.fields.foo.modes[0].count,1),a.strictEqual(b.fields.foo.modes[0].value,"bar"),a.ok(b.fields.foo.modes[0].is_exact),c.cancel(d)}],function(b){a.ok(!b),a.done()})},"Callback#Search timeline":function(a){var b=k(),c=this;g.chain([function(a){c.service.jobs().search('search index=_internal | head 1 | eval foo="bar" | fields foo',{id:b,status_buckets:300,rf:["foo"],exec_mode:"blocking"},a)},function(a,b){a.timeline({},b)},function(b,c,d){a.ok(c),a.ok(b),a.strictEqual(b.buckets.length,1),a.strictEqual(b.event_count,1),a.strictEqual(b.buckets[0].available_count,1),a.strictEqual(b.buckets[0].duration,.001),a.strictEqual(b.buckets[0].earliest_time_offset,b.buckets[0].latest_time_offset),a.strictEqual(b.buckets[0].total_count,1),a.ok(b.buckets[0].is_finalized),c.cancel(d)}],function(b){a.ok(!b),a.done()})},"Callback#Touch":function(a){var b=k(),c=this,d="";g.chain([function(a){c.service.jobs().search("search index=_internal | head 1",{id:b},a)},function(a,b){a.fetch(b)},function(b,c){a.ok(b),d=b.properties().updated,g.sleep(1200,function(){b.touch(c)})},function(a,b){a.fetch(b)},function(b,c){a.ok(d!==b.updated()),b.cancel(c)}],function(b){a.ok(!b),a.done()})},"Callback#Create failure":function(a){var b="jssdk_savedsearch_"+k(),c="search index=_internal | head 1",d=this.service.jobs();a.throws(function(){d.create({search:c,name:b,exec_mode:"oneshot"},function(){})}),a.done()},"Callback#Create fails with no search string":function(a){var b=this.service.jobs();b.create("",{},function(b){a.ok(b),a.done()})},"Callback#Oneshot search":function(a){var b=k(),c=this,d="";g.chain([function(a){c.service.jobs().oneshotSearch("search index=_internal | head 1 | stats count",{id:b},a)},function(b,c){a.ok(b),a.ok(b.fields),a.strictEqual(b.fields.length,1),a.strictEqual(b.fields[0],"count"),a.ok(b.rows),a.strictEqual(b.rows.length,1),a.strictEqual(b.rows[0].length,1),a.strictEqual(b.rows[0][0],"1"),c()}],function(b){a.ok(!b),a.done()})},"Callback#Oneshot search with no results":function(a){var b=k(),c=this,d="";g.chain([function(a){var d="search index=history MUST_NOT_EXISTABCDEF";c.service.jobs().oneshotSearch(d,{id:b},a)},function(b,c){a.ok(b),a.strictEqual(b.fields.length,0),a.strictEqual(b.rows.length,0),a.ok(!b.preview),c()}],function(b){a.ok(!b),a.done()})},"Callback#Service oneshot search":function(a){var b=k(),c=this,d={owner:"admin",app:"search"},e=6.1,f="DEBUG";g.chain([function(b){g.chain([function(a){c.service.serverInfo(a)},function(a,c){e=parseFloat(a.properties().version),e<6.2?b():c()},function(a){c.service.configurations({owner:"admin",app:"search"}).fetch(a)},function(a,b){try{a.item("limits").fetch(b)}catch(c){b(c)}},function(a,b){var c=a.item("search_info");f=c.properties().infocsv_log_level,c.update({infocsv_log_level:"DEBUG"},b)},function(b,c){a.strictEqual("DEBUG",b.properties().infocsv_log_level),c()}],function(c){a.ok(!c),b()})},function(a){c.service.oneshotSearch("search index=_internal | head 1 | stats count",{id:b},d,a)},function(b,c){a.ok(b),a.ok(b.fields),a.strictEqual(b.fields.length,1),a.strictEqual(b.fields[0],"count"),a.ok(b.rows),a.strictEqual(b.rows.length,1),a.strictEqual(b.rows[0].length,1),a.strictEqual(b.rows[0][0],"1"),a.ok(b.messages[1].text.indexOf('owner="admin"')),a.ok(b.messages[1].text.indexOf('app="search"')),c()},function(b){g.chain([function(a){e<6.2?b():a()},function(a){c.service.configurations({owner:"admin",app:"search"}).fetch(a)},function(a,b){try{a.item("limits").fetch(b)}catch(c){b(c)}},function(a,b){var c=a.item("search_info");c.update({infocsv_log_level:f},b)},function(b,c){a.strictEqual(f,b.properties().infocsv_log_level),c()}],function(c){a.ok(!c),b()})}],function(b){a.ok(!b),a.done()})},"Callback#Service search":function(a){var b=k(),c=this.service,d=this,e={owner:"admin",app:"search"};g.chain([function(a){d.service.search("search index=_internal | head 1 | stats count",{id:b},e,a)},function(c,d){a.strictEqual(c.sid,b),a.strictEqual(c.namespace,e),h.pollUntil(c,function(a){return c.properties().isDone},10,d)},function(a,b){a.results({},b)},function(b,c,d){a.strictEqual(b.rows.length,1),a.strictEqual(b.fields.length,1),a.strictEqual(b.fields[0],"count"),a.strictEqual(b.rows[0][0],"1"),c.cancel(d)}],function(b){a.ok(!b),a.done()})},"Callback#Wait until job done":function(a){this.service.search("search index=_internal | head 1000",{},function(b,c){a.ok(!b);var d=0,e=0;c.track({period:200},{ready:function(b){a.ok(b),d++},progress:function(b){a.ok(b),e++},done:function(b){a.ok(b),a.ok(d===1),a.ok(e>=1),a.done()},failed:function(b){a.ok(b),a.ok(!1,"Job failed unexpectedly."),a.done()},error:function(b){a.ok(b),a.ok(!1,"Error while tracking job."),a.done()}})})},"Callback#Wait until job failed":function(a){this.service.search("search index=_internal | head bogusarg",{},function(b,c){if(b){a.ok(!b),a.done();return}var d=0,e=0;c.track({period:200},{ready:function(b){a.ok(b),d++},progress:function(b){a.ok(b),e++},done:function(b){a.ok(b),a.ok(!1,"Job became done unexpectedly."),a.done()},failed:function(b){a.ok(b),a.ok(d===1),a.ok(e>=1),a.done()},error:function(b){a.ok(b),a.ok(!1,"Error while tracking job."),a.done()}})})},"Callback#track() with default params and one function":function(a){this.service.search("search index=_internal | head 1",{},function(b,c){if(b){a.ok(!b),a.done();return}c.track({},function(b){a.ok(b),a.done()})})},"Callback#track() should stop polling if only the ready callback is specified":function(a){this.service.search("search index=_internal | head 1",{},function(b,c){if(b){a.ok(!b),a.done();return}c.track({},{ready:function(b){a.ok(b)},_stoppedAfterReady:function(b){a.done()}})})},"Callback#track() a job that is not immediately ready":function(a){var b=20,c=b,e=!1;for(var f=0;f.*) To: (?.*) ",i.expression);var j=d.pbe9bd0rp4;a.ok(j),a.strictEqual("event1",j.owner),a.same(["event1"],j.lineage),a.strictEqual("GeoIP",j.type),a.ok(j.isGeoIP()),a.ok(!j.isLookup()),a.ok(!j.isEval()),a.ok(!j.isRex()),a.strictEqual("·Ä©·öô‡Øµ comment of pbe9bd0rp4",j.comment),a.strictEqual(5,j.outputFieldNames().length),a.strictEqual("output_from_reverse_hostname",j.inputField),c()}],function(b){a.ok(!b),a.done()})},"Callback#DataModels - run queries":function(a){if(this.skip){a.done();return}var b,c=this;g.chain([function(a){c.dataModels.fetch(a)},function(a,c){var d=a.item("internal_audit_logs");b=d.objectByName("searches"),b.startSearch({},"",c)},function(a,b){h.pollUntil(a,function(b){return a.properties().isDone},10,b)},function(b,c){a.strictEqual("| datamodel internal_audit_logs searches search",b.properties().request.search),b.cancel(c)},function(a,c){b.startSearch({status_buckets:5,enable_lookups:!1},"| head 3",c)},function(a,b){h.pollUntil(a,function(b){return a.properties().isDone},10,b)},function(b,c){a.strictEqual("| datamodel internal_audit_logs searches search | head 3",b.properties().request.search),b.cancel(c)}],function(b){a.ok(!b),a.done()})},"Callback#DataModels - baseSearch is parsed correctly":function(a){if(this.skip){a.done();return}var b;try{b=JSON.parse(f.readFile(e,"../data/model_with_multiple_types.json"))}catch(c){a.ok(!c),a.done()}var h="delete-me-"+k(),i,j=this;g.chain([function(a){j.dataModels.create(h,b,a)},function(b,c){i=b.objectByName("search1"),a.ok(i),a.ok(i instanceof d.Service.DataModelObject),a.strictEqual("BaseSearch",i.parentName),a.ok(i.isBaseSearch()),a.ok(!i.isBaseTransaction()),a.strictEqual("search index=_internal | head 10",i.baseSearch),c()}],function(b){a.ok(!b),a.done()})},"Callback#DataModels - baseTransaction is parsed correctly":function(a){if(this.skip){a.done();return}var b;try{b=JSON.parse(f.readFile(e,"../data/model_with_multiple_types.json"))}catch(c){a.ok(!c),a.done()}var h="delete-me-"+k(),i,j=this;g.chain([function(a){j.dataModels.create(h,b,a)},function(b,c){i=b.objectByName("transaction1"),a.ok(i),a.ok(i instanceof d.Service.DataModelObject),a.strictEqual("BaseTransaction",i.parentName),a.ok(i.isBaseTransaction()),a.ok(!i.isBaseSearch()),a.same(["event1"],i.objectsToGroup),a.same(["host","from"],i.groupByFields),a.strictEqual("25s",i.maxPause),a.strictEqual("100m",i.maxSpan),c()}],function(b){a.ok(!b),a.done()})}},"Pivot tests":{setUp:function(a){this.service=b,this.dataModels=b.dataModels({owner:"nobody",app:"search"}),this.skip=!1;var c=this;this.service.serverInfo(function(b,e){parseInt(e.properties().version.split(".")[0],10)<6&&(c.skip=!0,d.Logger.log("Skipping pivot tests...")),a(b)})},"Callback#Pivot - test constructor args":function(a){if(this.skip){a.done();return}var b="delete-me-"+k(),c;try{c=JSON.parse(f.readFile(e,"../data/data_model_for_pivot.json"))}catch(d){a.ok(!d),a.done()}var h=this;g.chain([function(a){h.dataModels.create(b,c,a)},function(b,c){a.ok(b.objectByName("test_data")),c()}],function(b){a.ok(!b),a.done()})},"Callback#Pivot - test acceleration, then pivot":function(a){if(this.skip){a.done();return}var b="delete-me-"+k(),c;try{c=JSON.parse(f.readFile(e,"../data/data_model_for_pivot.json"))}catch(d){a.ok(!d),a.done()}var h=this;g.chain([function(a){h.dataModels.create(b,c,a)},function(b,c){b.objectByName("test_data"),a.ok(b),b.acceleration.enabled=!0,b.acceleration.earliestTime="-2mon",b.acceleration.cronSchedule="0 */12 * * *",b.update(c)},function(b,c){var d=b.properties();a.strictEqual(!0,b.isAccelerated()),a.strictEqual(!0,!!b.acceleration.enabled),a.strictEqual("-2mon",b.acceleration.earliest_time),a.strictEqual("0 */12 * * *",b.acceleration.cron_schedule);var e=b.objectByName("test_data"),f=e.createPivotSpecification();a.strictEqual(e.dataModel.name,f.accelerationNamespace);var g="delete-me-"+k();f.setAccelerationJob(g),a.strictEqual("sid="+g,f.accelerationNamespace);var h="delete-me-"+k();f.accelerationNamespace=h,a.strictEqual(h,f.accelerationNamespace),f.addCellValue("test_data","Source Value","count").run(c)},function(b,c,d){a.ok(b),a.ok(c),a.notStrictEqual("FAILED",b.properties().dispatchState),b.track({},function(b){a.ok(c.tstatsSearch),a.strictEqual(0,b.properties().request.search.indexOf("| tstats")),a.strictEqual("| tstats",b.properties().request.search.match("^\\| tstats")[0]),a.strictEqual(1,b.properties().request.search.match("^\\| tstats").length),a.strictEqual(c.tstatsSearch,b.properties().request.search),d(null,b)})},function(b,c){a.ok(b),c()}],function(b){a.ok(!b),a.done()})},"Callback#Pivot - test illegal filtering (all types)":function(a){if(this.skip){a.done();return}var b="delete-me-"+k(),c;try{c=JSON.parse(f.readFile(e,"../data/data_model_for_pivot.json"))}catch(d){a.ok(!d),a.done()}var h=this;g.chain([function(a){h.dataModels.create(b,c,a)},function(b,c){var d=b.objectByName("test_data");a.ok(d);var e=d.createPivotSpecification();try{e.addFilter(k(),"boolean","=",!0),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Cannot add filter on a nonexistent field.")}try{e.addFilter("_time","boolean","=",!0),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Cannot add boolean filter on _time because it is of type timestamp")}try{e.addFilter("has_boris","string","contains","abc"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Cannot add string filter on has_boris because it is of type boolean")}try{e.addFilter(k(),"string","contains","abc"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Cannot add filter on a nonexistent field.")}try{e.addFilter("has_boris","ipv4","startsWith","192.168"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Cannot add ipv4 filter on has_boris because it is of type boolean")}try{e.addFilter(k(),"ipv4","startsWith","192.168"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Cannot add filter on a nonexistent field.")}try{e.addFilter("has_boris","number","atLeast",2.3),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Cannot add number filter on has_boris because it is of type boolean")}try{e.addFilter(k(),"number","atLeast",2.3),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Cannot add filter on a nonexistent field.")}try{e.addLimitFilter("has_boris","host","DEFAULT",50,"count"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Cannot add limit filter on has_boris because it is of type boolean")}try{e.addLimitFilter(k(),"host","DEFAULT",50,"count"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Cannot add limit filter on a nonexistent field.")}try{e.addLimitFilter("source","host","DEFAULT",50,"sum"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Stats function for fields of type string must be COUNT or DISTINCT_COUNT; found sum")}try{e.addLimitFilter("epsilon","host","DEFAULT",50,"duration"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Stats function for fields of type number must be one of COUNT, DISTINCT_COUNT, SUM, or AVERAGE; found duration")}try{e.addLimitFilter("test_data","host","DEFAULT",50,"list"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Stats function for fields of type object count must be COUNT; found list")}c()}],function(b){a.ok(!b),a.done()})},"Callback#Pivot - test boolean filtering":function(a){if(this.skip){a.done();return}var b="delete-me-"+k(),c;try{c=JSON.parse(f.readFile(e,"../data/data_model_for_pivot.json"))}catch(d){a.ok(!d),a.done()}var h=this;g.chain([function(a){h.dataModels.create(b,c,a)},function(b,c){var d=b.objectByName("test_data");a.ok(d);var e=d.createPivotSpecification();try{e.addFilter("has_boris","boolean","=",!0),a.strictEqual(1,e.filters.length);var f=e.filters[0];a.ok(f.hasOwnProperty("fieldName")),a.ok(f.hasOwnProperty("type")),a.ok(f.hasOwnProperty("rule")),a.ok(f.hasOwnProperty("owner")),a.strictEqual("has_boris",f.fieldName),a.strictEqual("boolean",f.type),a.strictEqual("=",f.rule.comparator),a.strictEqual(!0,f.rule.compareTo),a.strictEqual("test_data",f.owner)}catch(g){a.ok(!1)}c()}],function(b){a.ok(!b),a.done()})},"Callback#Pivot - test string filtering":function(a){if(this.skip){a.done();return}var b="delete-me-"+k(),c;try{c=JSON.parse(f.readFile(e,"../data/data_model_for_pivot.json"))}catch(d){a.ok(!d),a.done()}var h=this;g.chain([function(a){h.dataModels.create(b,c,a)},function(b,c){var d=b.objectByName("test_data");a.ok(d);var e=d.createPivotSpecification();try{e.addFilter("host","string","contains","abc"),a.strictEqual(1,e.filters.length);var f=e.filters[0];a.ok(f.hasOwnProperty("fieldName")),a.ok(f.hasOwnProperty("type")),a.ok(f.hasOwnProperty("rule")),a.ok(f.hasOwnProperty("owner")),a.strictEqual("host",f.fieldName),a.strictEqual("string",f.type),a.strictEqual("contains",f.rule.comparator),a.strictEqual("abc",f.rule.compareTo),a.strictEqual("BaseEvent",f.owner)}catch(g){a.ok(!1)}c()}],function(b){a.ok(!b),a.done()})},"Callback#Pivot - test IPv4 filtering":function(a){if(this.skip){a.done();return}var b="delete-me-"+k(),c;try{c=JSON.parse(f.readFile(e,"../data/data_model_for_pivot.json"))}catch(d){a.ok(!d),a.done()}var h=this;g.chain([function(a){h.dataModels.create(b,c,a)},function(b,c){var d=b.objectByName("test_data");a.ok(d);var e=d.createPivotSpecification();try{e.addFilter("hostip","ipv4","startsWith","192.168"),a.strictEqual(1,e.filters.length);var f=e.filters[0];a.ok(f.hasOwnProperty("fieldName")),a.ok(f.hasOwnProperty("type")),a.ok(f.hasOwnProperty("rule")),a.ok(f.hasOwnProperty("owner")),a.strictEqual("hostip",f.fieldName),a.strictEqual("ipv4",f.type),a.strictEqual("startsWith",f.rule.comparator),a.strictEqual("192.168",f.rule.compareTo),a.strictEqual("test_data",f.owner)}catch(g){a.ok(!1)}c()}],function(b){a.ok(!b),a.done()})},"Callback#Pivot - test number filtering":function(a){if(this.skip){a.done();return}var b="delete-me-"+k(),c;try{c=JSON.parse(f.readFile(e,"../data/data_model_for_pivot.json"))}catch(d){a.ok(!d),a.done()}var h=this;g.chain([function(a){h.dataModels.create(b,c,a)},function(b,c){var d=b.objectByName("test_data");a.ok(d);var e=d.createPivotSpecification();try{e.addFilter("epsilon","number",">=",2.3),a.strictEqual(1,e.filters.length);var f=e.filters[0];a.ok(f.hasOwnProperty("fieldName")),a.ok(f.hasOwnProperty("type")),a.ok(f.hasOwnProperty("rule")),a.ok(f.hasOwnProperty("owner")),a.strictEqual("epsilon",f.fieldName),a.strictEqual("number",f.type),a.strictEqual(">=",f.rule.comparator),a.strictEqual(2.3,f.rule.compareTo),a.strictEqual("test_data",f.owner)}catch(g){a.ok(!1)}c()}],function(b){a.ok(!b),a.done()})},"Callback#Pivot - test limit filtering":function(a){if(this.skip){a.done();return}var b="delete-me-"+k(),c;try{c=JSON.parse(f.readFile(e,"../data/data_model_for_pivot.json"))}catch(d){a.ok(!d),a.done()}var h=this;g.chain([function(a){h.dataModels.create(b,c,a)},function(b,c){var d=b.objectByName("test_data");a.ok(d);var e=d.createPivotSpecification();try{e.addLimitFilter("epsilon","host","ASCENDING",500,"average"),a.strictEqual(1,e.filters.length);var f=e.filters[0];a.ok(f.hasOwnProperty("fieldName")),a.ok(f.hasOwnProperty("type")),a.ok(f.hasOwnProperty("owner")),a.ok(f.hasOwnProperty("attributeName")),a.ok(f.hasOwnProperty("attributeOwner")),a.ok(f.hasOwnProperty("limitType")),a.ok(f.hasOwnProperty("limitAmount")),a.ok(f.hasOwnProperty("statsFn")),a.strictEqual("epsilon",f.fieldName),a.strictEqual("number",f.type),a.strictEqual("test_data",f.owner),a.strictEqual("host",f.attributeName),a.strictEqual("BaseEvent",f.attributeOwner),a.strictEqual("lowest",f.limitType),a.strictEqual(500,f.limitAmount),a.strictEqual("average",f.statsFn)}catch(g){a.ok(!1)}c()}],function(b){a.ok(!b),a.done()})},"Callback#Pivot - test row split":function(a){if(this.skip){a.done();return}var b="delete-me-"+k(),c;try{c=JSON.parse(f.readFile(e,"../data/data_model_for_pivot.json"))}catch(d){a.ok(!d),a.done()}var h=this;g.chain([function(a){h.dataModels.create(b,c,a)},function(b,c){var d=b.objectByName("test_data");a.ok(d);var e=d.createPivotSpecification();try{e.addRowSplit("has_boris","Wrong type here"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Field was of type "+d.fieldByName("has_boris").type+", expected number or string.")}var g=k();try{e.addRowSplit(g,"Break Me!"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Did not find field "+g)}e.addRowSplit("epsilon","My Label"),a.strictEqual(1,e.rows.length);var h=e.rows[0];a.ok(h.hasOwnProperty("fieldName")),a.ok(h.hasOwnProperty("owner")),a.ok(h.hasOwnProperty("type")),a.ok(h.hasOwnProperty("label")),a.ok(h.hasOwnProperty("display")),a.strictEqual("epsilon",h.fieldName),a.strictEqual("test_data",h.owner),a.strictEqual("number",h.type),a.strictEqual("My Label",h.label),a.strictEqual("all",h.display),a.same({fieldName:"epsilon",owner:"test_data",type:"number",label:"My Label",display:"all"},h),e.addRowSplit("host","My Label"),a.strictEqual(2,e.rows.length),h=e.rows[e.rows.length-1],a.ok(h.hasOwnProperty("fieldName")),a.ok(h.hasOwnProperty("owner")),a.ok(h.hasOwnProperty("type")),a.ok(h.hasOwnProperty("label")),a.ok(!h.hasOwnProperty("display")),a.strictEqual("host",h.fieldName),a.strictEqual("BaseEvent",h.owner),a.strictEqual("string",h.type),a.strictEqual("My Label",h.label),a.same({fieldName:"host",owner:"BaseEvent",type:"string",label:"My Label"},h);try{e.addRangeRowSplit("has_boris","Wrong type here",{start:0,end:100,step:20,limit:5})}catch(f){a.ok(f),a.strictEqual(f.message,"Field was of type "+d.fieldByName("has_boris").type+", expected number.")}try{e.addRangeRowSplit(g,"Break Me!",{start:0,end:100,step:20,limit:5}),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Did not find field "+g)}e.addRangeRowSplit("epsilon","My Label",{start:0,end:100,step:20,limit:5}),a.strictEqual(3,e.rows.length),h=e.rows[e.rows.length-1],a.ok(h.hasOwnProperty("fieldName")),a.ok(h.hasOwnProperty("owner")),a.ok(h.hasOwnProperty("type")),a.ok(h.hasOwnProperty("label")),a.ok(h.hasOwnProperty("display")),a.ok(h.hasOwnProperty("ranges")),a.strictEqual("epsilon",h.fieldName),a.strictEqual("test_data",h.owner),a.strictEqual("number",h.type),a.strictEqual("My Label",h.label),a.strictEqual("ranges",h.display);var i={start:0,end:100,size:20,maxNumberOf:5};a.same(i,h.ranges),a.same({fieldName:"epsilon",owner:"test_data",type:"number",label:"My Label",display:"ranges",ranges:i},h);try{e.addBooleanRowSplit("epsilon","Wrong type here","t","f")}catch(f){a.ok(f),a.strictEqual(f.message,"Field was of type "+d.fieldByName("epsilon").type+", expected boolean.")}try{e.addBooleanRowSplit(g,"Break Me!","t","f"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Did not find field "+g)}e.addBooleanRowSplit("has_boris","My Label","is_true","is_false"),a.strictEqual(4,e.rows.length),h=e.rows[e.rows.length-1],a.ok(h.hasOwnProperty("fieldName")),a.ok(h.hasOwnProperty("owner")),a.ok(h.hasOwnProperty("type")),a.ok(h.hasOwnProperty("label")),a.ok(h.hasOwnProperty("trueLabel")),a.ok(h.hasOwnProperty("falseLabel")),a.strictEqual("has_boris",h.fieldName),a.strictEqual("My Label",h.label),a.strictEqual("test_data",h.owner),a.strictEqual("boolean",h.type),a.strictEqual("is_true",h.trueLabel),a.strictEqual("is_false",h.falseLabel),a.same({fieldName:"has_boris",label:"My Label",owner:"test_data",type:"boolean",trueLabel:"is_true",falseLabel:"is_false"},h);try{e.addTimestampRowSplit("epsilon","Wrong type here","some binning")}catch(f){a.ok(f),a.strictEqual(f.message,"Field was of type "+d.fieldByName("epsilon").type+", expected timestamp.")}try{e.addTimestampRowSplit(g,"Break Me!","some binning"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Did not find field "+g)}try{e.addTimestampRowSplit("_time","some label","Bogus binning value"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Invalid binning Bogus binning value found. Valid values are: "+e._binning.join(", "))}e.addTimestampRowSplit("_time","My Label","day"),a.strictEqual(5,e.rows.length),h=e.rows[e.rows.length-1],a.ok(h.hasOwnProperty("fieldName")),a.ok(h.hasOwnProperty("owner")),a.ok(h.hasOwnProperty("type")),a.ok(h.hasOwnProperty("label")),a.ok(h.hasOwnProperty("period")),a.strictEqual("_time",h.fieldName),a.strictEqual("My Label",h.label),a.strictEqual("BaseEvent",h.owner),a.strictEqual("timestamp",h.type),a.strictEqual("day",h.period),a.same({fieldName:"_time",label:"My Label",owner:"BaseEvent",type:"timestamp",period:"day"},h),c()}],function(b){a.ok(!b),a.done()})},"Callback#Pivot - test column split":function(a){if(this.skip){a.done();return}var b="delete-me-"+k(),c;try{c=JSON.parse(f.readFile(e,"../data/data_model_for_pivot.json"))}catch(d){a.ok(!d),a.done()}var h=this;g.chain([function(a){h.dataModels.create(b,c,a)},function(b,c){var d=b.objectByName("test_data");a.ok(d);var e=d.createPivotSpecification();try{e.addColumnSplit("has_boris","Wrong type here"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Field was of type "+d.fieldByName("has_boris").type+", expected number or string.")}var g=k();try{e.addColumnSplit(g,"Break Me!"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Did not find field "+g)}e.addColumnSplit("epsilon"),a.strictEqual(1,e.columns.length);var h=e.columns[e.columns.length-1];a.ok(h.hasOwnProperty("fieldName")),a.ok(h.hasOwnProperty("owner")),a.ok(h.hasOwnProperty("type")),a.ok(h.hasOwnProperty("display")),a.strictEqual("epsilon",h.fieldName),a.strictEqual("test_data",h.owner),a.strictEqual("number",h.type),a.strictEqual("all",h.display),a.same({fieldName:"epsilon",owner:"test_data",type:"number",display:"all"},h),e.addColumnSplit("host"),a.strictEqual(2,e.columns.length),h=e.columns[e.columns.length-1],a.ok(h.hasOwnProperty("fieldName")),a.ok(h.hasOwnProperty("owner")),a.ok(h.hasOwnProperty("type")),a.ok(!h.hasOwnProperty("display")),a.strictEqual("host",h.fieldName),a.strictEqual("BaseEvent",h.owner),a.strictEqual("string",h.type),a.same({fieldName:"host",owner:"BaseEvent",type:"string"},h),c();try{e.addRangeColumnSplit("has_boris","Wrong type here",{start:0,end:100,step:20,limit:5})}catch(f){a.ok(f),a.strictEqual(f.message,"Field was of type "+d.fieldByName("has_boris").type+", expected number.")}try{e.addRangeColumnSplit(g,{start:0,end:100,step:20,limit:5}),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Did not find field "+g)}e.addRangeColumnSplit("epsilon",{start:0,end:100,step:20,limit:5}),a.strictEqual(3,e.columns.length),h=e.columns[e.columns.length-1],a.ok(h.hasOwnProperty("fieldName")),a.ok(h.hasOwnProperty("owner")),a.ok(h.hasOwnProperty("type")),a.ok(h.hasOwnProperty("display")),a.ok(h.hasOwnProperty("ranges")),a.strictEqual("epsilon",h.fieldName),a.strictEqual("test_data",h.owner),a.strictEqual("number",h.type),a.strictEqual("ranges",h.display);var i={start:"0",end:"100",size:"20",maxNumberOf:"5"};a.same(i,h.ranges),a.same({fieldName:"epsilon",owner:"test_data",type:"number",display:"ranges",ranges:i},h);try{e.addBooleanColumnSplit("epsilon","t","f")}catch(f){a.ok(f),a.strictEqual(f.message,"Field was of type "+d.fieldByName("epsilon").type+", expected boolean.")}try{e.addBooleanColumnSplit(g,"t","f"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Did not find field "+g)}e.addBooleanColumnSplit("has_boris","is_true","is_false"),a.strictEqual(4,e.columns.length),h=e.columns[e.columns.length-1],a.ok(h.hasOwnProperty("fieldName")),a.ok(h.hasOwnProperty("owner")),a.ok(h.hasOwnProperty("type")),a.ok(!h.hasOwnProperty("label")),a.ok(h.hasOwnProperty("trueLabel")),a.ok(h.hasOwnProperty("falseLabel")),a.strictEqual("has_boris",h.fieldName),a.strictEqual("test_data",h.owner),a.strictEqual("boolean",h.type),a.strictEqual("is_true",h.trueLabel),a.strictEqual("is_false",h.falseLabel),a.same({fieldName:"has_boris",owner:"test_data",type:"boolean",trueLabel:"is_true",falseLabel:"is_false"},h);try{e.addTimestampColumnSplit("epsilon","Wrong type here")}catch(f){a.ok(f),a.strictEqual(f.message,"Field was of type "+d.fieldByName("epsilon").type+", expected timestamp.")}try{e.addTimestampColumnSplit(g,"Break Me!"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Did not find field "+g)}try{e.addTimestampColumnSplit("_time","Bogus binning value"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Invalid binning Bogus binning value found. Valid values are: "+e._binning.join(", "))}e.addTimestampColumnSplit("_time","day"),a.strictEqual(5,e.columns.length),h=e.columns[e.columns.length-1],a.ok(h.hasOwnProperty("fieldName")),a.ok(h.hasOwnProperty("owner")),a.ok(h.hasOwnProperty("type")),a.ok(!h.hasOwnProperty("label")),a.ok(h.hasOwnProperty("period")),a.strictEqual("_time",h.fieldName),a.strictEqual("BaseEvent",h.owner),a.strictEqual("timestamp",h.type),a.strictEqual("day",h.period),a.same({fieldName:"_time",owner:"BaseEvent",type:"timestamp",period:"day"},h)}],function(b){a.ok(!b),a.done()})},"Callback#Pivot - test cell value":function(a){if(this.skip){a.done();return}var b="delete-me-"+k(),c;try{c=JSON.parse(f.readFile(e,"../data/data_model_for_pivot.json"))}catch(d){a.ok(!d),a.done()}var h=this;g.chain([function(a){h.dataModels.create(b,c,a)},function(b,c){var d=b.objectByName("test_data");a.ok(d);var e=d.createPivotSpecification();try{e.addCellValue("iDontExist","Break Me!","explosion"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Did not find field iDontExist")}try{e.addCellValue("source","Wrong Stats Function","stdev"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Stats function on string and IPv4 fields must be one of: list, distinct_values, first, last, count, or distinct_count; found stdev")}e.addCellValue("source","Source Value","dc"),a.strictEqual(1,e.cells.length);var g=e.cells[e.cells.length-1];a.ok(g.hasOwnProperty("fieldName")),a.ok(g.hasOwnProperty("owner")),a.ok(g.hasOwnProperty("type")),a.ok(g.hasOwnProperty("label")),a.ok(g.hasOwnProperty("value")),a.ok(g.hasOwnProperty("sparkline")),a.strictEqual("source",g.fieldName),a.strictEqual("BaseEvent",g.owner),a.strictEqual("string",g.type),a.strictEqual("Source Value",g.label),a.strictEqual("dc",g.value),a.strictEqual(!1,g.sparkline),a.same({fieldName:"source",owner:"BaseEvent",type:"string",label:"Source Value",value:"dc",sparkline:!1},g);try{e.addCellValue("hostip","Wrong Stats Function","stdev"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Stats function on string and IPv4 fields must be one of: list, distinct_values, first, last, count, or distinct_count; found stdev")}e.addCellValue("hostip","Source Value","dc"),a.strictEqual(2,e.cells.length),g=e.cells[e.cells.length-1],a.ok(g.hasOwnProperty("fieldName")),a.ok(g.hasOwnProperty("owner")),a.ok(g.hasOwnProperty("type")),a.ok(g.hasOwnProperty("label")),a.ok(g.hasOwnProperty("value")),a.ok(g.hasOwnProperty("sparkline")),a.strictEqual("hostip",g.fieldName),a.strictEqual("test_data",g.owner),a.strictEqual("ipv4",g.type),a.strictEqual("Source Value",g.label),a.strictEqual("dc",g.value),a.strictEqual(!1,g.sparkline),a.same({fieldName:"hostip",owner:"test_data",type:"ipv4",label:"Source Value",value:"dc",sparkline:!1},g);try{e.addCellValue("has_boris","Booleans not allowed","sum"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Cannot use boolean valued fields as cell values.")}try{e.addCellValue("epsilon","Wrong Stats Function","latest"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Stats function on number field must be must be one of: sum, count, average, max, min, stdev, list, or distinct_values; found latest")}e.addCellValue("epsilon","Source Value","average"),a.strictEqual(3,e.cells.length),g=e.cells[e.cells.length-1],a.ok(g.hasOwnProperty("fieldName")),a.ok(g.hasOwnProperty("owner")),a.ok(g.hasOwnProperty("type")),a.ok(g.hasOwnProperty("label")),a.ok(g.hasOwnProperty("value")),a.ok(g.hasOwnProperty("sparkline")),a.strictEqual("epsilon",g.fieldName),a.strictEqual("test_data",g.owner),a.strictEqual("number",g.type),a.strictEqual("Source Value",g.label),a.strictEqual("average",g.value),a.strictEqual(!1,g.sparkline),a.same({fieldName:"epsilon",owner:"test_data",type:"number",label:"Source Value",value:"average",sparkline:!1},g);try{e.addCellValue("_time","Wrong Stats Function","max"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Stats function on timestamp field must be one of: duration, earliest, latest, list, or distinct values; found max")}e.addCellValue("_time","Source Value","earliest"),a.strictEqual(4,e.cells.length),g=e.cells[e.cells.length-1],a.ok(g.hasOwnProperty("fieldName")),a.ok(g.hasOwnProperty("owner")),a.ok(g.hasOwnProperty("type")),a.ok(g.hasOwnProperty("label")),a.ok(g.hasOwnProperty("value")),a.ok(g.hasOwnProperty("sparkline")),a.strictEqual("_time",g.fieldName),a.strictEqual("BaseEvent",g.owner),a.strictEqual("timestamp",g.type),a.strictEqual("Source Value",g.label),a.strictEqual("earliest",g.value),a.strictEqual(!1,g.sparkline),a.same({fieldName:"_time",owner:"BaseEvent",type:"timestamp",label:"Source Value",value:"earliest",sparkline:!1},g);try{e.addCellValue("test_data","Wrong Stats Function","min"),a.ok(!1)}catch(f){a.ok(f),a.strictEqual(f.message,"Stats function on childcount and objectcount fields must be count; found min")}e.addCellValue("test_data","Source Value","count"),a.strictEqual(5,e.cells.length),g=e.cells[e.cells.length-1],a.ok(g.hasOwnProperty("fieldName")),a.ok(g.hasOwnProperty("owner")),a.ok(g.hasOwnProperty("type")),a.ok(g.hasOwnProperty("label")),a.ok(g.hasOwnProperty("value")),a.ok(g.hasOwnProperty("sparkline")),a.strictEqual("test_data",g.fieldName),a.strictEqual("test_data",g.owner),a.strictEqual("objectCount",g.type),a.strictEqual("Source Value",g.label),a.strictEqual("count",g.value),a.strictEqual(!1,g.sparkline),a.same({fieldName:"test_data",owner:"test_data",type:"objectCount",label:"Source Value",value:"count",sparkline:!1},g),c()}],function(b){a.ok(!b),a.done()})},"Callback#Pivot - test pivot throws HTTP exception":function(a){if(this.skip){a.done();return}var b="delete-me-"+k(),c;try{c=JSON.parse(f.readFile(e,"../data/data_model_for_pivot.json"))}catch(d){a.ok(!d),a.done()}var h=this;g.chain([function(a){h.dataModels.create(b,c,a)},function(b,c){var d=b.objectByName("test_data");a.ok(d),d.createPivotSpecification().pivot(c)},function(b,c){a.ok(!1)}],function(b){a.ok(b);var c="In handler 'datamodelpivot': Error in 'PivotReport': Must have non-empty cells or non-empty rows.";a.ok(f.endsWith(b.message,c)),a.done()})},"Callback#Pivot - test pivot with simple namespace":function(a){if(this.skip){a.done();return}var b="delete-me-"+k(),c;try{c=JSON.parse(f.readFile(e,"../data/data_model_for_pivot.json"))}catch(d){a.ok(!d),a.done()}var i=this,j,l,m;g.chain([function(a){i.dataModels.create(b,c,a)},function(b,c){j=b.objectByName("test_data"),a.ok(j),j.createLocalAccelerationJob(null,c)},function(b,c){m=b,a.ok(b),l=j.createPivotSpecification(),l.addBooleanRowSplit("has_boris","Has Boris","meep","hilda"),l.addCellValue("hostip","Distinct IPs","count"),l.setAccelerationJob(b),a.strictEqual("string",typeof l.accelerationNamespace),a.strictEqual("sid="+b.sid,l.accelerationNamespace),l.setAccelerationJob(b.sid),a.strictEqual("string",typeof l.accelerationNamespace),a.strictEqual("sid="+b.sid,l.accelerationNamespace),l.pivot(c)},function(b,c){a.ok(b.tstatsSearch),a.ok(b.tstatsSearch.length>0),a.strictEqual(0,b.tstatsSearch.indexOf("| tstats")),a.strictEqual("| tstats",b.tstatsSearch.match("^\\| tstats")[0]),a.strictEqual(1,b.tstatsSearch.match("^\\| tstats").length),b.run(c)},function(a,b){h.pollUntil(a,function(b){return a.properties().isDone},10,b)},function(b,c){a.ok("FAILED"!==b.properties().dispatchState),a.strictEqual(0,b.properties().request.search.indexOf("| tstats")),a.strictEqual("| tstats",b.properties().request.search.match("^\\| tstats")[0]),a.strictEqual(1,b.properties().request.search.match("^\\| tstats").length),m.cancel(c)}],function(b){a.ok(!b),a.done()})},"Callback#Pivot - test pivot column range split":function(a){if(this.skip){a.done();return}var b=this,c;g.chain([function(a){b.dataModels.fetch(a)},function(a,b){var c=a.item("internal_audit_logs"),d=c.objectByName("searches"),e=d.createPivotSpecification();e.addRowSplit("user","Executing user"),e.addRangeColumnSplit("exec_time",{start:0,end:12,step:5,limit:4}),e.addCellValue("search","Search Query","values"),e.pivot(b)},function(a,b){c=a.tstatsSearch||a.pivotSearch,a.run(b)},function(a,b){h.pollUntil(a,function(b){return a.properties().isDone},10,b)},function(b,d){a.notStrictEqual("FAILED",b.properties().dispatchState),a.strictEqual(c,b.properties().request.search),b.cancel(d)}],function(b){a.ok(!b),a.done()})},"Callback#Pivot - test pivot with PivotSpecification.run and Job.track":function(a){if(this.skip){a.done();return}var b=this;g.chain([function(a){b.dataModels.fetch(a)},function(a,b){var c=a.item("internal_audit_logs"),d=c.objectByName("searches"),e=d.createPivotSpecification();e.addRowSplit("user","Executing user"),e.addRangeColumnSplit("exec_time",{start:0,end:12,step:5,limit:4}),e.addCellValue("search","Search Query","values"),e.run({},b)},function(b,c,d){b.track({},function(b){a.strictEqual(c.tstatsSearch||c.pivotSearch,b.properties().request.search),d(null,b)})},function(b,c){a.notStrictEqual("FAILED",b.properties().dispatchState),b.cancel(c)}],function(b){a.ok(!b),a.done()})},"Callback#DataModels - delete any remaining data models created by the SDK tests":function(a){if(this.skip){a.done();return}b.dataModels().fetch(function(b,c){b&&a.ok(!b);var d=c.list();g.seriesEach(d,function(a,b,c){f.startsWith(a.name,"delete-me")?a.remove(c):c()},function(b){a.ok(!b),a.done()})})}},"App Tests":{setUp:function(a){this.service=b,a()},"Callback#list applications":function(a){var b=this.service.apps();b.fetch(function(b,c){var d=c.list();a.ok(d.length>0),a.done()})},"Callback#contains applications":function(a){var b=this.service.apps();b.fetch(function(b,c){var d=c.item("search");a.ok(d),a.done()})},"Callback#create + contains app":function(a){var b="jssdk_testapp_"+k(),c=this.service.apps();c.create({name:b},function(b,d){var e=d.name;c.fetch(function(b,c){var f=c.item(e);a.ok(f),d.remove(function(){a.done()})})})},"Callback#create + modify app":function(a){var b="TEST DESCRIPTION",c="1.1.0",d="jssdk_testapp_"+k(),e=this.service.apps();g.chain([function(a){e.create({name:d},a)},function(e,f){a.ok(e),a.strictEqual(e.name,d);var g=e.properties().version==="1.0"||e.properties().version=="1.0.0";a.ok(g),e.update({description:b,version:c},f)},function(d,e){a.ok(d);var f=d.properties();a.strictEqual(f.description,b),a.strictEqual(f.version,c),d.remove(e)}],function(b){a.ok(!b),a.done()})},"Callback#delete test applications":function(a){var b=this.service.apps();b.fetch(function(b,c){var d=c.list();g.parallelEach(d,function(a,b,c){f.startsWith(a.name,"jssdk_")?a.remove(c):c()},function(b){a.ok(!b),a.done()})})},"list applications with cookies as authentication":function(a){this.service.serverInfo(function(c,e){var h=parseInt(e.properties().version.split(".")[0],10),i=parseInt(e.properties().version.split(".")[1],10);if(h<6||h===6&&i<2){d.Logger.log("Skipping cookie test..."),a.done();return}var j=new d.Service({scheme:b.scheme,host:b.host,port:b.port,username:b.username,password:b.password,version:b.version}),k=new d.Service({scheme:b.scheme,host:b.host,port:b.port,version:b.version});g.chain([function(a){j.login(a)},function(b,c){var d=j.http._cookieStore;a.ok(!f.isEmpty(d)),k.http._cookieStore=d;var e=k.apps();e.fetch(c)},function(b,c){var d=b.list();a.ok(d.length>0),a.ok(!f.isEmpty(k.http._cookieStore)),c()}],function(b){a.ok(!b),a.done()})})}},"Saved Search Tests":{setUp:function(a){this.service=b,this.loggedOutService=c,a()},"Callback#list":function(a){var b=this.service.savedSearches();b.fetch(function(b,c){var d=c.list();a.ok(d.length>0);for(var e=0;e0);for(var e=0;e1),a.ok(f.indexOf(b.fields().optional,"disabled")>-1),b.remove(c)}],function(b){a.ok(!b),a.done()})},"Callback#dispatch error":function(a){var b="jssdk_savedsearch_"+k(),c="search index=_internal | head 1",e=new d.Service.SavedSearch(this.loggedOutService,b,{owner:"nobody",app:"search"});e.dispatch(function(b){a.ok(b),a.done()})},"Callback#dispatch omitting optional arguments":function(a){var b="jssdk_savedsearch_"+k(),c="search index=_internal | head 1",d=this.service.savedSearches({owner:this.service.username,app:"sdk-app-collection"});g.chain([function(a){d.create({search:c,name:b},a)},function(d,e){a.ok(d),a.strictEqual(d.name,b),a.strictEqual(d.properties().search,c),a.ok(!d.properties().description),d.dispatch(e)},function(b,c,d){a.ok(b),a.ok(c),a.done()}])},"Callback#history error":function(a){var b="jssdk_savedsearch_"+k(),c="search index=_internal | head 1",e=new d.Service.SavedSearch(this.loggedOutService,b,{owner:"nobody",app:"search",sharing:"system"});e.history(function(b){a.ok(b),a.done()})},"Callback#Update error":function(a){var b="jssdk_savedsearch_"+k(),c="search index=_internal | head 1",e=new d.Service.SavedSearch(this.loggedOutService,b,{owner:"nobody",app:"search",sharing:"system"});e.update({},function(b){a.ok(b),a.done()})},"Callback#oneshot requires search string":function(a){a.throws(function(){this.service.oneshotSearch({name:"jssdk_oneshot_"+k()},function(a){})}),a.done()},"Callback#Create + dispatch + history":function(a){var b="jssdk_savedsearch_"+k(),c="search index=_internal | head 1",d=this.service.savedSearches({owner:this.service.username,app:"sdk-app-collection"});g.chain(function(a){d.create({search:c,name:b},a)},function(d,e){a.ok(d),a.strictEqual(d.name,b),a.strictEqual(d.properties().search,c),a.ok(!d.properties().description),d.dispatch({force_dispatch:!1,"dispatch.buckets":295},e)},function(b,c,d){a.ok(b),a.ok(c),h.pollUntil(b,function(a){return b.properties().isDone},10,g.augment(d,c))},function(b,c,d){a.strictEqual(b.properties().statusBuckets,295),c.history(g.augment(d,b))},function(b,c,d,e){a.ok(b),a.ok(b.length>0),a.ok(c),a.ok(d);var f=function(a){return function(b){a.cancel(b)}},h=!1,i=[];for(var j=0;j0),c()}],function(b){a.ok(!b),a.done()})},"Callback#item":function(a){var b=this,c={owner:"admin",app:"search"};g.chain([function(a){b.service.configurations(c).fetch(a)},function(b,c){var d=b.item("web");a.ok(d),d.fetch(c)},function(b,c){a.strictEqual(b.name,"web"),c()}],function(b){a.ok(!b),a.done()})},"Callback#contains stanza":function(a){var b=this,c={owner:"admin",app:"search"};g.chain([function(a){b.service.configurations(c).fetch(a)},function(b,c){var d=b.item("web");a.ok(d),d.fetch(c)},function(b,c){a.strictEqual(b.name,"web");var d=b.item("settings");a.ok(d),d.fetch(c)},function(b,c){a.ok(b.properties().hasOwnProperty("httpport")),c()}],function(b){a.ok(!b),a.done()})},"Callback#create file + create stanza + update stanza":function(a){var c=this,e="jssdk_file_"+k(),f="barfoo_"+k(),h={owner:"admin",app:"search"};g.chain([function(a){var b=c.service.configurations(h);b.fetch(a)},function(a,b){a.create(e,b)},function(a,b){a.create("stanza",b)},function(a,b){a.update({jssdk_foobar:f},b)},function(b,c){a.strictEqual(b.properties().jssdk_foobar,f),c()},function(a){var c=new d.Service.ConfigurationFile(b,e);c.fetch(a)},function(b,c){var d=b.item("stanza");a.ok(d),d.remove(c)}],function(b){a.ok(!b),a.done()})}},"Configuration Tests":{setUp:function(a){this.service=b,a()},"Callback#list":function(a){var b=this,c={owner:"admin",app:"search"};g.chain([function(a){b.service.configurations(c).fetch(a)},function(b,c){var d=b.list();a.ok(d.length>0),c()}],function(b){a.ok(!b),a.done()})},"Callback#contains":function(a){var b=this,c={owner:"admin",app:"search"};g.chain([function(a){b.service.configurations(c).fetch(a)},function(b,c){var d=b.item("web");a.ok(d),d.fetch(c)},function(b,c){a.strictEqual(b.name,"web"),c()}],function(b){a.ok(!b),a.done()})},"Callback#contains stanza":function(a){var b=this,c={owner:"admin",app:"search"};g.chain([function(a){b.service.configurations(c).fetch(a)},function(b,c){var d=b.item("web");a.ok(d),d.fetch(c)},function(b,c){a.strictEqual(b.name,"web");var d=b.item("settings");a.ok(d),d.fetch(c)},function(b,c){a.ok(b.properties().hasOwnProperty("httpport")),c()}],function(b){a.ok(!b),a.done()})},"Callback#configurations init":function(a){a.throws(function(){var a=new d.Service.Configurations(this.service,{owner:"-",app:"-",sharing:"system"})}),a.done()},"Callback#create file + create stanza + update stanza":function(a){var c=this,e={owner:"nobody",app:"system"},f="jssdk_file_"+k(),h="barfoo_"+k();g.chain([function(a){var c=b.configurations(e);c.fetch(a)},function(a,b){a.create({__conf:f},b)},function(a,b){a.item("stanza")&&a.item("stanza").remove(),a.create("stanza",b)},function(a,b){a.update({jssdk_foobar:h},b)},function(b,c){a.strictEqual(b.properties().jssdk_foobar,h),c()},function(a){var c=new d.Service.ConfigurationFile(b,f);c.fetch(a)},function(b,c){var d=b.item("stanza");a.ok(d),d.remove(c)}],function(b){a.ok(!b),a.done()})},"Callback#can get default stanza":function(a){var b=this,c={owner:"admin",app:"search"};g.chain([function(a){b.service.configurations(c).fetch(a)},function(b,d){var e=b.item("savedsearches");a.strictEqual(c,e.namespace),a.ok(e),e.fetch(d)},function(b,d){a.strictEqual(c,b.namespace),b.getDefaultStanza().fetch(d)},function(b,d){a.strictEqual(b.name,"default"),a.strictEqual(c,b.namespace),d()}],function(b){a.ok(!b),a.done()})},"Callback#updating default stanza is noop":function(a){var b=this,c={owner:"admin",app:"search"},d=null,e="this won't work";g.chain([function(a){b.service.configurations(c).fetch(a)},function(b,d){var e=b.item("savedsearches");a.strictEqual(c,e.namespace),a.ok(e),e.fetch(d)},function(b,d){a.strictEqual(c,b.namespace),b.getDefaultStanza().fetch(d)},function(b,f){a.ok(b._properties.hasOwnProperty("max_concurrent")),a.strictEqual(c,b.namespace),d=b._properties.max_concurrent,b.update({max_concurrent:e},f)},function(b,c){a.ok(b.properties().hasOwnProperty("max_concurrent")),a.strictEqual(b.properties().max_concurrent,d),a.notStrictEqual(b.properties().max_concurrent,e),b.fetch(c)},function(b,c){a.ok(b.properties().hasOwnProperty("max_concurrent")),a.strictEqual(b.properties().max_concurrent,d),a.notStrictEqual(b.properties().max_concurrent,e),c()}],function(b){a.ok(!b),a.done()})}},"Storage Passwords Tests":{setUp:function(a){this.service=b,a()},"Callback#Create":function(a){var b=-1,c="delete-me-"+k(),d="delete-me-"+k(),e=this;g.chain([function(a){e.service.storagePasswords().fetch(a)},function(a,e){b=a.list().length,a.create({name:c,realm:d,password:"changed!"},e)},function(b,f){a.strictEqual(c,b.properties().username),a.strictEqual(d+":"+c+":",b.name),a.strictEqual("changed!",b.properties().clear_password),a.strictEqual(d,b.properties().realm),e.service.storagePasswords().fetch(g.augment(f,b))},function(c,d,e){a.strictEqual(b+1,c.list().length),d.remove(e)},function(a){e.service.storagePasswords().fetch(a)},function(c,d){a.strictEqual(b,c.list().length),d()}],function(b){a.ok(!b),a.done()})},"Callback#Create with backslashes":function(a){var b=-1,c="\\delete-me-"+k(),d="\\delete-me-"+k(),e=this;g.chain([function(a){e.service.storagePasswords().fetch(a)},function(a,e){b=a.list().length,a.create({name:c,realm:d,password:"changed!"},e)},function(b,f){a.strictEqual(c,b.properties().username),a.strictEqual("\\"+d+":\\"+c+":",b.name),a.strictEqual("changed!",b.properties().clear_password),a.strictEqual(d,b.properties().realm),e.service.storagePasswords().fetch(g.augment(f,b))},function(c,d,e){a.strictEqual(b+1,c.list().length),d.remove(e)},function(a){e.service.storagePasswords().fetch(a)},function(c,d){a.strictEqual(b,c.list().length),d()}],function(b){a.ok(!b),a.done()})},"Callback#Create with slashes":function(a){var b=-1,c="/delete-me-"+k(),d="/delete-me-"+k(),e=this;g.chain([function(a){e.service.storagePasswords().fetch(a)},function(a,e){b=a.list().length,a.create({name:c,realm:d,password:"changed!"},e)},function(b,f){a.strictEqual(c,b.properties().username),a.strictEqual(d+":"+c+":",b.name),a.strictEqual("changed!",b.properties().clear_password),a.strictEqual(d,b.properties().realm),e.service.storagePasswords().fetch(g.augment(f,b))},function(c,d,e){a.strictEqual(b+1,c.list().length),d.remove(e)},function(a){e.service.storagePasswords().fetch(a)},function(c,d){a.strictEqual(b,c.list().length),d()}],function(b){a.ok(!b),a.done()})},"Callback#Create without realm":function(a){var b=-1,c="delete-me-"+k(),d=this;g.chain([function(a){d.service.storagePasswords().fetch(a)},function(a,d){b=a.list().length,a.create({name:c,password:"changed!"},d)},function(b,e){a.strictEqual(c,b.properties().username),a.strictEqual(":"+c+":",b.name),a.strictEqual("changed!",b.properties().clear_password),a.strictEqual("",b.properties().realm),d.service.storagePasswords().fetch(g.augment(e,b))},function(c,d,e){a.strictEqual(b+1,c.list().length),d.remove(e)},function(a){d.service.storagePasswords().fetch(a)},function(c,d){a.strictEqual(b,c.list().length),d()}],function(b){a.ok(!b),a.done()})},"Callback#Create should fail without user, or realm":function(a){var b=this;g.chain([function(a){b.service.storagePasswords().fetch(a)},function(a,b){a.create({name:null,password:"changed!"},b)}],function(b){a.ok(b),a.done()})},"Callback#Create should fail without password":function(a){var b=this;g.chain([function(a){b.service.storagePasswords().fetch(a)},function(a,b){a.create({name:"something",password:null},b)}],function(b){a.ok(b),a.done()})},"Callback#Create should fail without user, realm, or password":function(a){var b=this;g.chain([function(a){b.service.storagePasswords().fetch(a)},function(a,b){a.create({name:null,password:null},b)}],function(b){a.ok(b),a.done()})},"Callback#Create with colons":function(a){var b=-1,c=":delete-me-"+k(),d=":delete-me-"+k(),e=this;g.chain([function(a){e.service.storagePasswords().fetch(a)},function(a,e){b=a.list().length,a.create({name:c,realm:d,password:"changed!"},e)},function(b,f){a.strictEqual(c,b.properties().username),a.strictEqual("\\"+d+":\\"+c+":",b.name),a.strictEqual("changed!",b.properties().clear_password),a.strictEqual(d,b.properties().realm),e.service.storagePasswords().fetch(g.augment(f,b))},function(c,d,e){a.strictEqual(b+1,c.list().length),d.remove(e)},function(a){e.service.storagePasswords().fetch(a)},function(c,d){a.strictEqual(b,c.list().length),d()}],function(b){a.ok(!b),a.done()})},"Callback#Create crazy":function(a){var b=-1,c="delete-me-"+k(),d="delete-me-"+k(),e=this;g.chain([function(a){e.service.storagePasswords().fetch(a)},function(a,e){b=a.list().length,a.create({name:c+":end!@#$%^&*()_+{}:|<>?",realm:":start::!@#$%^&*()_+{}:|<>?"+d,password:"changed!"},e)},function(b,f){a.strictEqual(c+":end!@#$%^&*()_+{}:|<>?",b.properties().username),a.strictEqual("\\:start\\:\\:!@#$%^&*()_+{}\\:|<>?"+d+":"+c+"\\:end!@#$%^&*()_+{}\\:|<>?:",b.name),a.strictEqual("changed!",b.properties().clear_password),a.strictEqual(":start::!@#$%^&*()_+{}:|<>?"+d,b.properties().realm),e.service.storagePasswords().fetch(g.augment(f,b))},function(c,d,e){a.strictEqual(b+1,c.list().length),d.remove(e)},function(a){e.service.storagePasswords().fetch(a)},function(c,d){a.strictEqual(b,c.list().length),d()}],function(b){a.ok(!b),a.done()})},"Callback#Create with unicode chars":function(a){var b=-1,c="delete-me-"+k(),d="delete-me-"+k(),e=this;g.chain([function(a){e.service.storagePasswords().fetch(a)},function(a,e){b=a.list().length,a.create({name:c+":end!@#$%^&*()_+{}:|<>?쎼 and 쎶 and <&> für",realm:":start::!@#$%^&*()_+{}:|<>?"+encodeURIComponent("쎼 and 쎶 and <&> für")+d,password:decodeURIComponent(encodeURIComponent("쎼 and 쎶 and <&> für"))},e)},function(b,f){a.strictEqual(c+":end!@#$%^&*()_+{}:|<>?쎼 and 쎶 and <&> für",b.properties().username),a.strictEqual("\\:start\\:\\:!@#$%^&*()_+{}\\:|<>?"+encodeURIComponent("쎼 and 쎶 and <&> für")+d+":"+c+"\\:end!@#$%^&*()_+{}\\:|<>?쎼 and 쎶 and <&> für:",b.name),a.strictEqual(decodeURIComponent(encodeURIComponent("쎼 and 쎶 and <&> für")),b.properties().clear_password),a.strictEqual(":start::!@#$%^&*()_+{}:|<>?"+encodeURIComponent("쎼 and 쎶 and <&> für")+d,b.properties().realm),e.service.storagePasswords().fetch(g.augment(f,b))},function(c,d,e){a.strictEqual(b+1,c.list().length),d.remove(e)},function(a){e.service.storagePasswords().fetch(a)},function(c,d){a.strictEqual(b,c.list().length),d()}],function(b){a.ok(!b),a.done()})},"Callback#Read":function(a){var b=-1,c="delete-me-"+k(),d="delete-me-"+k(),e=this;g.chain([function(a){e.service.storagePasswords().fetch(a)},function(a,e){b=a.list().length,a.create({name:c,realm:d,password:"changed!"},e)},function(b,f){a.strictEqual(c,b.properties().username),a.strictEqual(d+":"+c+":",b.name),a.strictEqual("changed!",b.properties().clear_password),a.strictEqual(d,b.properties().realm),e.service.storagePasswords().fetch(g.augment(f,b))},function(e,f,g){try{a.ok(!!e.item(d+":"+c+":"))}catch(h){a.ok(!1)}var i=e.list(),j=!1;a.strictEqual(b+1,i.length);for(var k=0;k0},function(a){g.sleep(d,function(){b.fetch(a)})},function(b){b?a(b):a(c<=0?"Timed out":null)})}],function(b){a.ok(!b),a.done()})},"Callback#list indexes":function(a){var b=this.service.indexes();b.fetch(function(b,c){var d=c.list();a.ok(d.length>0),a.done()})},"Callback#contains index":function(a){var b=this.service.indexes(),c=this.indexName;b.fetch(function(b,d){var e=d.item(c);a.ok(e),a.done()})},"Callback#modify index":function(a){var b=this.indexName,c=this.service.indexes(),d=!1;g.chain([function(a){c.fetch(a)},function(c,e){var f=c.item(b);a.ok(f),d=f.properties().syncMeta,f.update({syncMeta:!d},e)},function(b,c){a.ok(b);var e=b.properties();a.strictEqual(!d,e.syncMeta),b.update({syncMeta:!e.syncMeta},c)},function(b,c){a.ok(b);var e=b.properties();a.strictEqual(d,e.syncMeta),c()}],function(b){a.ok(!b),a.done()})},"Callback#Enable+disable index":function(a){var b=this.indexName,c=this.service.indexes();g.chain([function(a){c.fetch(a)},function(c,d){var e=c.item(b);a.ok(e),e.disable(d)},function(b,c){a.ok(b),b.fetch(c)},function(b,c){a.ok(b),a.ok(b.properties().disabled),b.enable(c)},function(b,c){a.ok(b),b.fetch(c)},function(b,c){a.ok(b),a.ok(!b.properties().disabled),c()}],function(b){a.ok(!b),a.done()})},"Callback#Service submit event":function(a){var b="Hello World -- "+k(),c="sdk-tests",d=this.service,e=this.indexName;g.chain(function(a){d.log(b,{sourcetype:c,index:e},a)},function(d,f){a.ok(d),a.strictEqual(d.sourcetype,c),a.strictEqual(d.bytes,b.length),a.strictEqual(d.index,e),f()},function(b){a.ok(!b),a.done()})},"Callback#Service submit event, omitting optional arguments":function(a){var b="Hello World -- "+k(),c="sdk-tests",d=this.service,e=this.indexName;g.chain(function(a){d.log(b,a)},function(c,d){a.ok(c),a.strictEqual(c.bytes,b.length),d()},function(b){a.ok(!b),a.done()})},"Callback#Service submit events with multi-byte chars":function(a){var b=this.service,c=["Ummelner Straße 6","Ümmelner Straße 6","Iԉtérԉátíòлåɭìƶåtiòл","Intérnâtì߀лàɭíƶɑtïòл","ãϻét dòner turƙëy ѵ߀lù","ptãte ìԉ rëρrèhënԁérit ","ϻ߀lɭit fìɭèt ϻìǥnoԉ ɭäb߀ríѕ"," êӽ cɦùck cüpïᏧåtåt Ꮷèѕëruлt. ","D߀ɭor ѵélít ìrurè, sèᏧ ѕhòr","t riƅѕ c߀ɰ ɭãnԁյàéɢêr drúmst","ícƙ. Minïm ƃàɭl tip ѕհòrt rìƃѕ,"," ïԁ aɭïqúìρ ѕɦànƙ ρ߀rcɦéttɑ. Pìǥ"," hãm ɦòck ìлcídíԁùԉt séԁ cüpïϻ ","ƙèviл láborê. Et taiɭ ѕtriρ"," steák út üllãϻc߀ rump d߀ɭore.","٩(͡๏̯͡๏)۶ ٩(-̮̮̃•̃).","Lɑƅòré ƃrësãòlá d߀лèr ѕâlámí ","cíllûm ìn ѕɯìлe ϻêàtɭ߀àf dûìs ","ρãncettä ƅrìsƙét ԁèsêrûлt áútè"," յòɰɭ. Lɑbòrìѕ ƙìêɭ","básá ԁòlòré fatƃɑck ƅêéf. Pɑѕtr","ämì piɢ ѕհàлƙ ùɭɭamcò ѕaû","ѕäǥë sɦànƙlë."," Cúpím ɭäƃorum drumstïcƙ jerkϒ veli"," pïcåԉɦɑ ƙíéɭƅãsa. Alïqû","iρ írürë cûpíϻ, äɭìɋuâ ǥròûлd ","roúлᏧ toԉgüè ρàrìãtùr ","briѕkèt ԉostruᏧ cûɭpɑ"," ìd còлѕèqûât làƅ߀rìs."],d=0;g.seriesMap(c,function(a,c,e){d++,b.log(a,e)},function(b,e){a.ok(!b),a.strictEqual(d,c.length);for(var f in c){a.notStrictEqual(c[f].length,e[f].bytes);try{a.strictEqual(Buffer.byteLength(c[f]),e[f].bytes)}catch(b){a.strictEqual(decodeURI(encodeURIComponent(c[f])).length,e[f].bytes)}}a.done()})},"Callback#Service submit event, failure":function(a){var b="Hello World -- "+k(),c="sdk-tests",d=this.loggedOutService,e=this.indexName;g.chain(function(c){a.ok(d),d.log(b,c)},function(b){a.ok(b),a.done()})},"Callback#remove throws an error":function(a){var b=this.service.indexes().item("_internal");a.throws(function(){b.remove()}),a.done()},"Callback#create an index with alternate argument format":function(a){var b=this.service.indexes();b.create({name:"_internal"},function(b,c){a.ok(b.data.messages[0].text.match("name=_internal already exists")),a.done()})},"Callback#Index submit event with omitted optional arguments":function(a){var b="Hello world -- "+k(),c=this.indexName,d=this.service.indexes();g.chain([function(a){d.fetch(a)},function(d,e){var f=d.item(c);a.ok(f),a.strictEqual(f.name,c),f.submitEvent(b,e)},function(d,e,f){a.ok(d),a.strictEqual(d.bytes,b.length),a.strictEqual(d.index,c),f()}],function(b){a.ok(!b),a.done()})},"Callback#Index submit event":function(a){var b="Hello World -- "+k(),c="sdk-tests",d=this.indexName,e=this.service.indexes();g.chain([function(a){e.fetch(a)},function(e,f){var g=e.item(d);a.ok(g),a.strictEqual(g.name,d),g.submitEvent(b,{sourcetype:c},f)},function(e,f,g){a.ok(e),a.strictEqual(e.sourcetype,c),a.strictEqual(e.bytes,b.length),a.strictEqual(e.index,d),g()}],function(b){a.ok(!b),a.done()})}},"User Tests":{setUp:function(a){this.service=b,this.loggedOutService=c,a()},tearDown:function(a){this.service.logout(a)},"Callback#Current user":function(a){var b=this.service;b.currentUser(function(c,d){a.ok(!c),a.ok(d),a.strictEqual(d.name,b.username),a.done()})},"Callback#Current user fails":function(a){var b=this.loggedOutService;b.currentUser(function(b,c){a.ok(b),a.done()})},"Callback#List users":function(a){var b=this.service;b.users().fetch(function(b,c){var d=c.list();a.ok(!b),a.ok(c),a.ok(d),a.ok(d.length>0),a.done()})},"Callback#create user failure":function(a){this.loggedOutService.users().create({name:"jssdk_testuser",password:"abc",roles:"user"},function(b,c){a.ok(b),a.done()})},"Callback#Create + update + delete user":function(a){var b=this.service,c="jssdk_testuser";g.chain([function(a){b.users().create({name:"jssdk_testuser",password:"abc",roles:"user"},a)},function(b,d){a.ok(b),a.strictEqual(b.name,c),a.strictEqual(b.properties().roles.length,1),a.strictEqual(b.properties().roles[0],"user"),b.update({realname:"JS SDK",roles:["admin","user"]},d)},function(b,c){a.ok(b),a.strictEqual(b.properties().realname,"JS SDK"),a.strictEqual(b.properties().roles.length,2),a.strictEqual(b.properties().roles[0],"admin"),a.strictEqual(b.properties().roles[1],"user"),b.remove(c)}],function(b){a.ok(!b),a.done()})},"Callback#Roles":function(a){var b=this.service,c="jssdk_testuser_"+k();g.chain([function(a){b.users().create({name:c,password:"abc",roles:"user"},a)},function(b,d){a.ok(b),a.strictEqual(b.name,c),a.strictEqual(b.properties().roles.length,1),a.strictEqual(b.properties().roles[0],"user"),b.update({roles:["admin","user"]},d)},function(b,c){a.ok(b),a.strictEqual(b.properties().roles.length,2),a.strictEqual(b.properties().roles[0],"admin"),a.strictEqual(b.properties().roles[1],"user"),b.update({roles:"user"},c)},function(b,c){a.ok(b),a.strictEqual(b.properties().roles.length,1),a.strictEqual(b.properties().roles[0],"user"),b.update({roles:"__unknown__"},c)}],function(b){a.ok(b),a.strictEqual(b.status,400),a.done()})},"Callback#Passwords":function(a){var b=this.service,c=null,e="jssdk_testuser_"+k();g.chain([function(a){b.users().create({name:e,password:"abc",roles:"user"},a)},function(f,h){a.ok(f),a.strictEqual(f.name,e),a.strictEqual(f.properties().roles.length,1),a.strictEqual(f.properties().roles[0],"user"),c=new d.Service(b.http,{username:e,password:"abc",host:b.host,port:b.port,scheme:b.scheme,version:b.version}),c.login(g.augment(h,f))},function(b,c,d){a.ok(b),a.ok(c),c.update({password:"abc2"},d)},function(b,d){c.login(function(c,e){a.ok(c),a.ok(!e),b.update({password:"abc"},d)})},function(b,d){a.ok(b),c.login(d)}],function(b){a.ok(!b),a.done()})},"Callback#delete test users":function(a){var b=this.service.users();b.fetch(function(b,c){var d=c.list();g.parallelEach(d,function(a,b,c){f.startsWith(a.name,"jssdk_")?a.remove(c):c()},function(b){a.ok(!b),a.done()})})}},"Server Info Tests":{setUp:function(a){this.service=b,a()},"Callback#Basic":function(a){var b=this.service;b.serverInfo(function(b,c){a.ok(!b),a.ok(c),a.strictEqual(c.name,"server-info"),a.ok(c.properties().hasOwnProperty("version")),a.ok(c.properties().hasOwnProperty("serverName")),a.ok(c.properties().hasOwnProperty("os_version")),a.done()})}},"View Tests":{setUp:function(a){this.service=b,a()},"Callback#List views":function(a){var b=this.service;b.views({owner:"admin",app:"search"}).fetch(function(b,c){a.ok(!b),a.ok(c);var d=c.list();a.ok(d),a.ok(d.length>0);for(var e=0;e",e="";g.chain([function(a){b.views({owner:"admin",app:"sdk-app-collection"}).create({name:c,"eai:data":d},a)},function(b,f){a.ok(b),a.strictEqual(b.name,c),a.strictEqual(b.properties()["eai:data"],d),b.update({"eai:data":e},f)},function(b,c){a.ok(b),a.strictEqual(b.properties()["eai:data"],e),b.remove(c)}],function(b){a.ok(!b),a.done()})}},"Parser Tests":{setUp:function(a){this.service=b,a()},"Callback#Basic parse":function(a){var b=this.service;b.parse("search index=_internal | head 1",function(b,c){a.ok(!b),a.ok(c),a.ok(c.commands.length>0),a.done()})},"Callback#Parse error":function(a){var b=this.service;b.parse("ABCXYZ",function(b,c){a.ok(b),a.strictEqual(b.status,400),a.done()})}},"Typeahead Tests":{setUp:function(a){this.service=b,this.loggedOutService=c,a()},"Callback#Typeahead failure":function(a){var b=this.loggedOutService;b.typeahead("index=",1,function(b,c){a.ok(b),a.done()})},"Callback#Basic typeahead":function(a){var b=this.service;b.typeahead("index=",1,function(b,c){a.ok(!b),a.ok(c),a.strictEqual(c.length,1),a.ok(c[0]),a.done()})},"Typeahead with omitted optional arguments":function(a){var b=this.service;b.typeahead("index=",function(b,c){a.ok(!b),a.ok(c),a.done()})}},"Endpoint Tests":{setUp:function(a){this.service=b,a()},"Throws on null arguments to init":function(a){var b=this.service;a.throws(function(){var a=new d.Service.Endpoint(null,"a/b")}),a.throws(function(){var a=new d.Service.Endpoint(b,null)}),a.done()},"Endpoint delete on a relative path":function(a){var b=this.service,c=new d.Service.Endpoint(b,"/search/jobs/12345");c.del("search/jobs/12345",{},function(){a.done()})},"Methods of Resource to be overridden":function(a){var b=this.service,c=new d.Service.Resource(b,"/search/jobs/12345");a.throws(function(){c.path()}),a.throws(function(){c.fetch()}),a.ok(d.Utils.isEmpty(c.state())),a.done()}},"Entity tests":{setUp:function(a){this.service=b,this.loggedOutService=c,a()},"Accessors function properly":function(a){var b=new d.Service.Entity(this.service,"/search/jobs/12345",{owner:"boris",app:"factory",sharing:"app"});b._load({acl:{owner:"boris",app:"factory",sharing:"app"},links:{link1:35},published:"meep",author:"Hilda"}),a.ok(b.acl().owner==="boris"),a.ok(b.acl().app==="factory"),a.ok(b.acl().sharing==="app"),a.ok(b.links().link1===35),a.strictEqual(b.author(),"Hilda"),a.strictEqual(b.published(),"meep"),a.done()},"Refresh throws error correctly":function(a){var b=new d.Service.Entity(this.loggedOutService,"/search/jobs/12345",{owner:"boris",app:"factory",sharing:"app"});b.fetch({},function(b){a.ok(b),a.done()})},"Cannot update name of entity":function(a){var b=new d.Service.Entity(this.service,"/search/jobs/12345",{owner:"boris",app:"factory",sharing:"app"});a.throws(function(){b.update({name:"asdf"})}),a.done()},"Disable throws error correctly":function(a){var b=new d.Service.Entity(this.loggedOutService,"/search/jobs/12345",{owner:"boris",app:"factory",sharing:"app"});b.disable(function(b){a.ok(b),a.done()})},"Enable throws error correctly":function(a){var b=new d.Service.Entity(this.loggedOutService,"/search/jobs/12345",{owner:"boris",app:"factory",sharing:"app"});b.enable(function(b){a.ok(b),a.done()})},"Does reload work?":function(a){var b=new d.Service.Index(this.service,"data/indexes/sdk-test",{owner:"admin",app:"search",sharing:"app"}),c="jssdk_testapp_"+k(),e=this.service.apps(),f=this;g.chain(function(a){e.create({name:c},a)},function(b,c){b.reload(function(d){a.ok(!d),c(null,b)})},function(b,c){var e=new d.Service.Application(f.loggedOutService,b.name);e.reload(function(d){a.ok(d),c(null,b)})},function(a,b){a.remove(b)},function(b){a.ok(!b),a.done()})}},"Collection tests":{setUp:function(a){this.service=b,this.loggedOutService=c,a()},"Methods to be overridden throw":function(a){var b=new d.Service.Collection(this.service,"/data/indexes",{owner:"admin",app:"search",sharing:"app"});a.throws(function(){b.instantiateEntity({})}),a.done()},"Accessors work":function(a){var b=new d.Service.Collection(this.service,"/data/indexes",{owner:"admin",app:"search",sharing:"app"});b._load({links:"Hilda",updated:!0}),a.strictEqual(b.links(),"Hilda"),a.ok(b.updated()),a.done()},"Contains throws without a good id":function(a){var b=new d.Service.Collection(this.service,"/data/indexes",{owner:"admin",app:"search",sharing:"app"});a.throws(function(){b.item(null)}),a.done()}}};return l};if(b===a.main){var f=a("../index"),g=a("../examples/node/cmdline"),h=a("../contrib/nodeunit/test_reporter"),i=g.create(),j=i.parse(process.argv);if(!j)throw new Error("Error in parsing command line parameters");if(!process.env.SPLUNK_HOME)throw new Error("$PATH variable SPLUNK_HOME is not set. Please export SPLUNK_HOME to the splunk instance.");var k=new f.Service({scheme:j.opts.scheme,host:j.opts.host,port:j.opts.port,username:j.opts.username,password:j.opts.password,version:j.opts.version}),l=new f.Service({scheme:j.opts.scheme,host:j.opts.host,port:j.opts.port,username:j.opts.username,password:j.opts.password+"wrong",version:j.opts.version}),m=c.setup(k,l);k.login(function(a,b){if(a||!b)throw new Error("Login failed - not running tests",a||"");h.run([{Tests:m}])})}}),require.define("/tests/test_examples.js",function(a,b,c,d,e){c.setup=function(b,c){var d=a("../index"),e=d.Async;d.Logger.setLevel("ALL");var f=0,g=function(){return"id"+f++ +"_"+(new Date).valueOf()},h=["program","script"];return{"Hello World Tests":{Apps:function(b){var d=a("../examples/node/helloworld/apps").main;d(c,b.done)},"Apps#Async":function(b){var d=a("../examples/node/helloworld/apps_async").main;d(c,b.done)},"Pivot#Async":function(b){var d=a("../examples/node/helloworld/pivot_async").main;d(c,b.done)},"Fired Alerts":function(b){var d=a("../examples/node/helloworld/firedalerts").main;d(c,b.done)},"Fired Alerts#Async":function(b){var d=a("../examples/node/helloworld/firedalerts_async").main;d(c,b.done)},"Fired Alerts#Create":function(b){var d=a("../examples/node/helloworld/firedalerts_create").main;d(c,b.done)},"Fired Alerts#Delete":function(b){var d=a("../examples/node/helloworld/firedalerts_delete").main;d(c,b.done)},"Get Job by sid":function(b){var d=a("../examples/node/helloworld/get_job").main;d(c,b.done)},"Endpoint Instantiation":function(b){var d=a("../examples/node/helloworld/endpoint_instantiation").main;d(c,b.done)},"Saved Searches":function(b){var d=a("../examples/node/helloworld/savedsearches").main;d(c,b.done)},"Saved Searches#Async":function(b){var d=a("../examples/node/helloworld/savedsearches_async").main;d(c,b.done)},"Saved Searches#Delete":function(b){var d=a("../examples/node/helloworld/savedsearches_delete").main;d(c,b.done)},"Saved Searches#Create":function(b){var d=a("../examples/node/helloworld/savedsearches_create").main;d(c,b.done)},"Saved Searches#Delete Again":function(b){var d=a("../examples/node/helloworld/savedsearches_delete").main;d(c,b.done)},"Search#normal":function(b){var d=a("../examples/node/helloworld/search_normal").main;d(c,b.done)},"Search#blocking":function(b){var d=a("../examples/node/helloworld/search_blocking").main;d(c,b.done)},"Search#oneshot":function(b){var d=a("../examples/node/helloworld/search_oneshot").main;d(c,b.done)},"Search#realtime":function(b){var d=a("../examples/node/helloworld/search_realtime").main;d(c,b.done)},Logging:function(b){var d=a("../examples/node/helloworld/log").main;d(c,b.done)}},"Jobs Example Tests":{setUp:function(b){var c=this;this.main=a("../examples/node/jobs").main,this.run=function(a,b,d,e){var f=h.slice();a&&f.push(a);if(b)for(var g=0;g ")),console.log("\t Internal name: "+l.name),l.startSearch({},"| head 5",b)},function(a,b){a.track({},function(a){a.results({},b)})},function(a,b,c){console.log("Results:");for(var d=0;dd},function(b){g.sleep(1e3,function(){a.preview({},function(a,c){if(a){b(a);return}if(c&&c.rows){d++,console.log("========== Iteration "+d+" ==========");var e=c.fields.indexOf("sourcetype"),f=c.fields.indexOf("count");for(var g=0;g",k,[],e),c.add("preview","Fetch preview results for the specified search jobs","",k,[],e),c.add("events","Fetch events for the specified search jobs","",j,[],e),c.add("cancel","Cancel the specify search jobs","",[],[],e),c.add("list","List all search jobs or properties for those specified","[sids...]",[],[],e),c.parse(a);if(!c.executedCommand){console.log(c.helpInformation()),b("You must specify a command to run.");return}},b===a.main&&c.main(process.argv)})()}),require.define("/examples/node/search.js",function(a,b,c,d,e){(function(){var d=a("../../index"),e=d.Class,f=d.Utils,g=d.Async,h=a("./cmdline"),i=a("util").print,j=["search","earliest_time","latest_time","now","time_format","exec_mode","search_mode","rt_blocking","rt_queue_size","rt_maxblocksecs","rt_indexfilter","id","status_buckets","max_count","max_time","timeout","auto_finalize_ec","enable_lookups","reload_macros","reduce_freq","spawn_process","required_field_list","rf","auto_cancel","auto_pause"],k=function(a){return new d.Service({scheme:a.scheme,host:a.host,port:a.port,username:a.username,password:a.password,version:a.version})},l=function(a,b,c){var d=b.search,e=b.verbose,f=b.count||0,h=b.mode||"row";delete b.search,delete b.verbose,delete b.count,delete b.mode,g.chain([function(c){a.search(d,b,c)},function(a,b){g.whilst(function(){return!a.properties().isDone},function(b){a.fetch(function(a,d){if(a)c(a);else{var f=d.properties();if(e){var h=f.doneProgress*100+"%",j=f.scanCount,k=f.eventCount,l=f.resultCount,m="-- "+h+" done | "+j+" scanned | "+k+" matched | "+l+" results";i("\r"+m+" ")}g.sleep(1e3,b)}})},function(c){e&&i("\r"),b(c,a)})},function(a,b){a.results({count:f,json_mode:h},b)},function(a,b,c){process.stdout.write(JSON.stringify(a)),b.cancel(c)}],function(a){c(a)})},m=function(a,b,c){var d=b.search;delete b.search,a.oneshotSearch(d,b,function(a,b){a?c(a):(console.log(JSON.stringify(b)),c())})};c.main=function(a,b){d.Logger.setLevel("NONE"),b=b||function(a){a&&console.log(a)};var c=h.create();c.name="search",c.description("Create a search and print the results to stdout"),c.option("--verbose","Output job progress as we wait for completion"),c.option("--count ","How many results to fetch"),c.option("--mode ","Row or column mode [row|column]");var e=j,f=["search"];for(var g=0;g=0,n="<"+e[g]+">";c.option("--"+e[g]+" "+n,"",undefined,i)}c.on("--help",function(){console.log(" Examples:"),console.log(" "),console.log(" Create a regular search:"),console.log(" > node search.js --search 'search index=_internal | head 10'"),console.log(" "),console.log(" Create a oneshot search:"),console.log(" > node search.js --search 'search index=_internal | head 10' --exec_mode oneshot"),console.log(" "),console.log(" Create a regular search and only return 10 results:"),console.log(" > node search.js --search 'search index=_internal | head 20' --count 10"),console.log(" "),console.log(" Create a regular search and output the progress while the search is running"),console.log(" > node search.js --search 'search index=_internal | head 20' --verbose"),console.log(" ")}),c.parse(a);var o=k(c.opts);o.login(function(a,d){if(a||!d){b("Error logging in");return}delete c.username,delete c.password,delete c.scheme,delete c.host,delete c.port,delete c.namespace,delete c.version,c.opts.exec_mode==="oneshot"?m(o,c.opts,b):l(o,c.opts,b)})},b===a.main&&c.main(process.argv)})()}),require.define("/browser.test.entry.js",function(a,b,c,d,e){window.SplunkTest={Utils:a("../../tests/test_utils"),Async:a("../../tests/test_async"),Http:a("../../tests/test_http"),Context:a("../../tests/test_context"),Service:a("../../tests/test_service"),Examples:a("../../tests/test_examples")}}),require("/browser.test.entry.js") })(); \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index b1a26ade7..7275e23fa 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: '3.6' +version: '3.8' services: splunk: diff --git a/examples/browser/helloworld/index.html b/examples/browser/helloworld/index.html index cc3c849da..02990ca87 100644 --- a/examples/browser/helloworld/index.html +++ b/examples/browser/helloworld/index.html @@ -78,7 +78,7 @@ }; username = "admin"; - password = "changeme"; + password = "changed!"; scheme = "https"; host = "localhost"; port = "8089"; @@ -89,7 +89,7 @@ var updateConnectionInformation = function() { username = utils.trim($("#id_username").pVal()) || "admin"; - password = utils.trim($("#id_password").pVal()) || "changeme"; + password = utils.trim($("#id_password").pVal()) || "changed!"; scheme = utils.trim($("#id_scheme").pVal()) || "https"; host = utils.trim($("#id_host").pVal()) || "localhost"; port = utils.trim($("#id_port").pVal()) || "8089"; @@ -296,7 +296,7 @@
  • - +
  • diff --git a/examples/browser/minisplunk/index.html b/examples/browser/minisplunk/index.html index 977ff46f4..ac6237e55 100644 --- a/examples/browser/minisplunk/index.html +++ b/examples/browser/minisplunk/index.html @@ -225,7 +225,7 @@

    Sign In

    - +
    diff --git a/examples/browser/minisplunk/views.js b/examples/browser/minisplunk/views.js index d32e04648..e9dd7f50b 100644 --- a/examples/browser/minisplunk/views.js +++ b/examples/browser/minisplunk/views.js @@ -941,7 +941,7 @@ var SigninView = BootstrapModalView.extend({ var that = this; var username = this.$("#id_username").val() || "admin"; - var password = this.$("#id_password").val() || "changeme"; + var password = this.$("#id_password").val() || "changed!"; var scheme = this.$("#id_scheme").val() || "https"; var host = this.$("#id_host").val() || "localhost"; var port = this.$("#id_port").val() || "8089"; diff --git a/examples/browser/ui/index.html b/examples/browser/ui/index.html index ba2a88b21..c16fdb852 100644 --- a/examples/browser/ui/index.html +++ b/examples/browser/ui/index.html @@ -82,7 +82,7 @@ }; username = "admin"; - password = "changeme"; + password = "changed!"; scheme = "https"; host = "localhost"; port = "8089"; @@ -93,7 +93,7 @@ var updateConnectionInformation = function() { username = utils.trim($("#id_username").pVal()) || "admin"; - password = utils.trim($("#id_password").pVal()) || "changeme"; + password = utils.trim($("#id_password").pVal()) || "changed!"; scheme = utils.trim($("#id_scheme").pVal()) || "https"; host = utils.trim($("#id_host").pVal()) || "localhost"; port = utils.trim($("#id_port").pVal()) || "8089"; @@ -201,7 +201,7 @@
  • - +
  • diff --git a/examples/browser/viz/index.html b/examples/browser/viz/index.html index a504113c5..a88037c57 100644 --- a/examples/browser/viz/index.html +++ b/examples/browser/viz/index.html @@ -123,7 +123,7 @@ }; username = "admin"; - password = "changeme"; + password = "changed!"; scheme = "https"; host = "localhost"; port = "8089"; @@ -134,7 +134,7 @@ var updateConnectionInformation = function() { username = utils.trim($("#id_username").pVal()) || "admin"; - password = utils.trim($("#id_password").pVal()) || "changeme"; + password = utils.trim($("#id_password").pVal()) || "changed!"; scheme = utils.trim($("#id_scheme").pVal()) || "https"; host = utils.trim($("#id_host").pVal()) || "localhost"; port = utils.trim($("#id_port").pVal()) || "8089"; @@ -244,7 +244,7 @@
  • - +
  • diff --git a/examples/node/helloworld/apps.js b/examples/node/helloworld/apps.js index f9e342c8b..6ef1e23ea 100644 --- a/examples/node/helloworld/apps.js +++ b/examples/node/helloworld/apps.js @@ -23,7 +23,7 @@ exports.main = function(opts, done) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; diff --git a/examples/node/helloworld/apps_async.js b/examples/node/helloworld/apps_async.js index fa2a9d73c..6a8cccc8a 100644 --- a/examples/node/helloworld/apps_async.js +++ b/examples/node/helloworld/apps_async.js @@ -25,7 +25,7 @@ exports.main = function(opts, callback) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; diff --git a/examples/node/helloworld/endpoint_instantiation.js b/examples/node/helloworld/endpoint_instantiation.js index 10bea337b..c21147872 100644 --- a/examples/node/helloworld/endpoint_instantiation.js +++ b/examples/node/helloworld/endpoint_instantiation.js @@ -80,7 +80,7 @@ exports.main = function(opts, done) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; diff --git a/examples/node/helloworld/firedalerts.js b/examples/node/helloworld/firedalerts.js index c9bdd74cc..73cb6aadb 100644 --- a/examples/node/helloworld/firedalerts.js +++ b/examples/node/helloworld/firedalerts.js @@ -22,7 +22,7 @@ exports.main = function(opts, done) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; diff --git a/examples/node/helloworld/firedalerts_async.js b/examples/node/helloworld/firedalerts_async.js index 6d94974eb..ed65774c5 100644 --- a/examples/node/helloworld/firedalerts_async.js +++ b/examples/node/helloworld/firedalerts_async.js @@ -24,7 +24,7 @@ exports.main = function(opts, callback) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; diff --git a/examples/node/helloworld/firedalerts_create.js b/examples/node/helloworld/firedalerts_create.js index bb4f71f90..6e0a55bf3 100644 --- a/examples/node/helloworld/firedalerts_create.js +++ b/examples/node/helloworld/firedalerts_create.js @@ -21,7 +21,7 @@ exports.main = function(opts, done) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; diff --git a/examples/node/helloworld/firedalerts_delete.js b/examples/node/helloworld/firedalerts_delete.js index 05482146d..723daf0d8 100644 --- a/examples/node/helloworld/firedalerts_delete.js +++ b/examples/node/helloworld/firedalerts_delete.js @@ -22,7 +22,7 @@ exports.main = function(opts, done) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; diff --git a/examples/node/helloworld/get_job.js b/examples/node/helloworld/get_job.js index a9f97554b..d9a3e5d1a 100644 --- a/examples/node/helloworld/get_job.js +++ b/examples/node/helloworld/get_job.js @@ -24,7 +24,7 @@ exports.main = function(opts, callback) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; diff --git a/examples/node/helloworld/log.js b/examples/node/helloworld/log.js index 073819f70..0e2a4f6bb 100644 --- a/examples/node/helloworld/log.js +++ b/examples/node/helloworld/log.js @@ -85,7 +85,7 @@ exports.main = function(opts, done) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; diff --git a/examples/node/helloworld/pivot_async.js b/examples/node/helloworld/pivot_async.js index e95d3684d..1e747e7c9 100644 --- a/examples/node/helloworld/pivot_async.js +++ b/examples/node/helloworld/pivot_async.js @@ -32,7 +32,7 @@ exports.main = function(opts, callback) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; diff --git a/examples/node/helloworld/savedsearches.js b/examples/node/helloworld/savedsearches.js index 5c7b7bab0..7e69007d0 100644 --- a/examples/node/helloworld/savedsearches.js +++ b/examples/node/helloworld/savedsearches.js @@ -23,7 +23,7 @@ exports.main = function(opts, done) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; diff --git a/examples/node/helloworld/savedsearches_async.js b/examples/node/helloworld/savedsearches_async.js index 75fe92d0b..8c12d710c 100644 --- a/examples/node/helloworld/savedsearches_async.js +++ b/examples/node/helloworld/savedsearches_async.js @@ -25,7 +25,7 @@ exports.main = function(opts, callback) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; diff --git a/examples/node/helloworld/savedsearches_create.js b/examples/node/helloworld/savedsearches_create.js index fb9a36e99..351d96608 100644 --- a/examples/node/helloworld/savedsearches_create.js +++ b/examples/node/helloworld/savedsearches_create.js @@ -22,7 +22,7 @@ exports.main = function(opts, done) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; diff --git a/examples/node/helloworld/savedsearches_delete.js b/examples/node/helloworld/savedsearches_delete.js index f0a5995ba..114b5db7b 100644 --- a/examples/node/helloworld/savedsearches_delete.js +++ b/examples/node/helloworld/savedsearches_delete.js @@ -23,7 +23,7 @@ exports.main = function(opts, done) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; diff --git a/examples/node/helloworld/search_blocking.js b/examples/node/helloworld/search_blocking.js index 991b29ebb..8fc84fd00 100644 --- a/examples/node/helloworld/search_blocking.js +++ b/examples/node/helloworld/search_blocking.js @@ -25,7 +25,7 @@ exports.main = function(opts, callback) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; diff --git a/examples/node/helloworld/search_normal.js b/examples/node/helloworld/search_normal.js index 5cb5060bb..90dcccb6a 100644 --- a/examples/node/helloworld/search_normal.js +++ b/examples/node/helloworld/search_normal.js @@ -24,7 +24,7 @@ exports.main = function(opts, callback) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; diff --git a/examples/node/helloworld/search_oneshot.js b/examples/node/helloworld/search_oneshot.js index de1ebd807..ca578faf3 100644 --- a/examples/node/helloworld/search_oneshot.js +++ b/examples/node/helloworld/search_oneshot.js @@ -26,7 +26,7 @@ exports.main = function(opts, callback) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; diff --git a/examples/node/helloworld/search_realtime.js b/examples/node/helloworld/search_realtime.js index 1c74543ad..a4db8b6bd 100644 --- a/examples/node/helloworld/search_realtime.js +++ b/examples/node/helloworld/search_realtime.js @@ -25,7 +25,7 @@ exports.main = function(opts, callback) { opts = opts || {}; var username = opts.username || "admin"; - var password = opts.password || "changeme"; + var password = opts.password || "changed!"; var scheme = opts.scheme || "https"; var host = opts.host || "localhost"; var port = opts.port || "8089"; diff --git a/index.js b/index.js index 9d76b812f..e20b05a89 100644 --- a/index.js +++ b/index.js @@ -18,6 +18,7 @@ // Declare a process environment so that we can set // some globals here and have interop with node + var env = require("dotenv").config(); process.env = process.env || {}; module.exports = root = { diff --git a/package-lock.json b/package-lock.json index 8bb6c6e00..0d6ae8716 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1000,6 +1000,11 @@ "integrity": "sha512-jnjyiM6eRyZl2H+W8Q/zLMA481hzi0eszAaBUzIVnmYVDBbnLxVNnfu1HgEBvCbL+71FrxMl3E6lpKH7Ge3OXA==", "dev": true }, + "dotenv": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz", + "integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==" + }, "duplexer2": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/duplexer2/-/duplexer2-0.1.4.tgz", @@ -1438,6 +1443,14 @@ "integrity": "sha1-7AbBDgo0wPL68Zn3/X/Hj//QPHM=", "dev": true }, + "iconv-lite": { + "version": "0.4.24", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", + "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "requires": { + "safer-buffer": ">= 2.1.2 < 3" + } + }, "ieee754": { "version": "1.1.12", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.12.tgz", @@ -2022,8 +2035,7 @@ "ms": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", - "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==", - "dev": true + "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==" }, "mustache": { "version": "2.2.1", @@ -2031,6 +2043,31 @@ "integrity": "sha1-LEDKIcJ49TFQaCvPkJDkGjM5uHY=", "dev": true }, + "needle": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/needle/-/needle-2.6.0.tgz", + "integrity": "sha512-KKYdza4heMsEfSWD7VPUIz3zX2XDwOyX2d+geb4vrERZMT5RMU6ujjaD+I5Yr54uZxQ2w6XRTAhHBbSCyovZBg==", + "requires": { + "debug": "^3.2.6", + "iconv-lite": "^0.4.4", + "sax": "^1.2.4" + }, + "dependencies": { + "debug": { + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", + "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", + "requires": { + "ms": "^2.1.1" + } + }, + "sax": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", + "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==" + } + } + }, "neo-async": { "version": "2.6.0", "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.0.tgz", diff --git a/package.json b/package.json index e6d3eadc3..b0b32af8a 100644 --- a/package.json +++ b/package.json @@ -22,9 +22,10 @@ ], "dependencies": { "cookie": "0.2.0", + "dotenv": "^10.0.0", "elementtree": "0.1.6", - "request": "^2.x.x", - "needle": "2.6.0" + "needle": "2.6.0", + "request": "^2.x.x" }, "devDependencies": { "browserify": "^16.2.3", diff --git a/tests/service_tests/storagepasswords.js b/tests/service_tests/storagepasswords.js index c53e806fe..0e4077d2c 100644 --- a/tests/service_tests/storagepasswords.js +++ b/tests/service_tests/storagepasswords.js @@ -24,12 +24,12 @@ module.exports = function(svc) { }, function(storagePasswords, done) { startcount = storagePasswords.list().length; - storagePasswords.create({name: name, realm: realm, password: "changeme"}, done); + storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); }, function(storagePassword, done) { test.strictEqual(name, storagePassword.properties().username); test.strictEqual(realm + ":" + name + ":", storagePassword.name); - test.strictEqual("changeme", storagePassword.properties().clear_password); + test.strictEqual("changed!", storagePassword.properties().clear_password); test.strictEqual(realm, storagePassword.properties().realm); that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); }, @@ -63,12 +63,12 @@ module.exports = function(svc) { }, function(storagePasswords, done) { startcount = storagePasswords.list().length; - storagePasswords.create({name: name, realm: realm, password: "changeme"}, done); + storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); }, function(storagePassword, done) { test.strictEqual(name, storagePassword.properties().username); test.strictEqual("\\" + realm + ":\\" + name + ":", storagePassword.name); - test.strictEqual("changeme", storagePassword.properties().clear_password); + test.strictEqual("changed!", storagePassword.properties().clear_password); test.strictEqual(realm, storagePassword.properties().realm); that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); }, @@ -102,12 +102,12 @@ module.exports = function(svc) { }, function(storagePasswords, done) { startcount = storagePasswords.list().length; - storagePasswords.create({name: name, realm: realm, password: "changeme"}, done); + storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); }, function(storagePassword, done) { test.strictEqual(name, storagePassword.properties().username); test.strictEqual(realm + ":" + name + ":", storagePassword.name); - test.strictEqual("changeme", storagePassword.properties().clear_password); + test.strictEqual("changed!", storagePassword.properties().clear_password); test.strictEqual(realm, storagePassword.properties().realm); that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); }, @@ -140,12 +140,12 @@ module.exports = function(svc) { }, function(storagePasswords, done) { startcount = storagePasswords.list().length; - storagePasswords.create({name: name, password: "changeme"}, done); + storagePasswords.create({name: name, password: "changed!"}, done); }, function(storagePassword, done) { test.strictEqual(name, storagePassword.properties().username); test.strictEqual(":" + name + ":", storagePassword.name); - test.strictEqual("changeme", storagePassword.properties().clear_password); + test.strictEqual("changed!", storagePassword.properties().clear_password); test.strictEqual("", storagePassword.properties().realm); that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); }, @@ -175,7 +175,7 @@ module.exports = function(svc) { that.service.storagePasswords().fetch(done); }, function(storagePasswords, done) { - storagePasswords.create({name: null, password: "changeme"}, done); + storagePasswords.create({name: null, password: "changed!"}, done); } ], function(err) { @@ -230,12 +230,12 @@ module.exports = function(svc) { }, function(storagePasswords, done) { startcount = storagePasswords.list().length; - storagePasswords.create({name: name, realm: realm, password: "changeme"}, done); + storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); }, function(storagePassword, done) { test.strictEqual(name, storagePassword.properties().username); test.strictEqual("\\" + realm + ":\\" + name + ":", storagePassword.name); - test.strictEqual("changeme", storagePassword.properties().clear_password); + test.strictEqual("changed!", storagePassword.properties().clear_password); test.strictEqual(realm, storagePassword.properties().realm); that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); }, @@ -272,13 +272,13 @@ module.exports = function(svc) { storagePasswords.create({ name: name + ":end!@#$%^&*()_+{}:|<>?", realm: ":start::!@#$%^&*()_+{}:|<>?" + realm, - password: "changeme"}, + password: "changed!"}, done); }, function(storagePassword, done) { test.strictEqual(name + ":end!@#$%^&*()_+{}:|<>?", storagePassword.properties().username); test.strictEqual("\\:start\\:\\:!@#$%^&*()_+{}\\:|<>?" + realm + ":" + name + "\\:end!@#$%^&*()_+{}\\:|<>?:", storagePassword.name); - test.strictEqual("changeme", storagePassword.properties().clear_password); + test.strictEqual("changed!", storagePassword.properties().clear_password); test.strictEqual(":start::!@#$%^&*()_+{}:|<>?" + realm, storagePassword.properties().realm); that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); }, @@ -355,12 +355,12 @@ module.exports = function(svc) { }, function(storagePasswords, done) { startcount = storagePasswords.list().length; - storagePasswords.create({name: name, realm: realm, password: "changeme"}, done); + storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); }, function(storagePassword, done) { test.strictEqual(name, storagePassword.properties().username); test.strictEqual(realm + ":" + name + ":", storagePassword.name); - test.strictEqual("changeme", storagePassword.properties().clear_password); + test.strictEqual("changed!", storagePassword.properties().clear_password); test.strictEqual(realm, storagePassword.properties().realm); that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); }, @@ -411,12 +411,12 @@ module.exports = function(svc) { }, function(storagePasswords, done) { startcount = storagePasswords.list().length; - storagePasswords.create({name: name, realm: realm, password: "changeme"}, done); + storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); }, function(storagePassword, done) { test.strictEqual(name, storagePassword.properties().username); test.strictEqual(realm + ":" + name + ":", storagePassword.name); - test.strictEqual("changeme", storagePassword.properties().clear_password); + test.strictEqual("changed!", storagePassword.properties().clear_password); test.strictEqual(realm, storagePassword.properties().realm); that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); }, @@ -470,12 +470,12 @@ module.exports = function(svc) { // }, // function(storagePasswords, done) { // startcount = storagePasswords.list().length; - // storagePasswords.create({name: name, realm: realm, password: "changeme"}, done); + // storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); // }, // function(storagePassword, done) { // test.strictEqual(name, storagePassword.properties().username); // test.strictEqual(realm + ":" + name + ":", storagePassword.name); - // test.strictEqual("changeme", storagePassword.properties().clear_password); + // test.strictEqual("changed!", storagePassword.properties().clear_password); // test.strictEqual(realm, storagePassword.properties().realm); // that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); // }, @@ -541,12 +541,12 @@ module.exports = function(svc) { }, function(storagePasswords, done) { startcount = storagePasswords.list().length; - storagePasswords.create({name: name, realm: realm, password: "changeme"}, done); + storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); }, function(storagePassword, done) { test.strictEqual(name, storagePassword.properties().username); test.strictEqual(realm + ":" + name + ":", storagePassword.name); - test.strictEqual("changeme", storagePassword.properties().clear_password); + test.strictEqual("changed!", storagePassword.properties().clear_password); test.strictEqual(realm, storagePassword.properties().realm); that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); }, @@ -559,7 +559,7 @@ module.exports = function(svc) { }, function(storagePasswords, done) { test.strictEqual(startcount, storagePasswords.list().length); - storagePasswords.create({name: name, realm: realm, password: "changeme"}, done); + storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); }, function(storagePassword, done) { test.strictEqual(name, storagePassword.properties().username); @@ -578,7 +578,7 @@ module.exports = function(svc) { index = i; test.strictEqual(name, list[i].properties().username); test.strictEqual(realm + ":" + name + ":", list[i].name); - test.strictEqual("changeme", list[i].properties().clear_password); + test.strictEqual("changed!", list[i].properties().clear_password); test.strictEqual(realm, list[i].properties().realm); } } diff --git a/tests/tests.browser.html b/tests/tests.browser.html index 117e60589..461ebe2ee 100644 --- a/tests/tests.browser.html +++ b/tests/tests.browser.html @@ -120,7 +120,7 @@ var host = $("#server-host").val() || "localhost"; var port = $("#server-port").val() || "8089"; var username = $("#server-username").val() || "admin"; - var password = $("#server-password").val() || "changeme"; + var password = $("#server-password").val() || "changed!"; var version = $("#server-version").val() || "5.0"; var options = { @@ -155,9 +155,9 @@ // - HTTP tests (require cross-domain) // - Examples Tests (require command line and process capabilities) - "Utils Tests": SplunkTest.Utils.setup(svc), - "Async Tests": SplunkTest.Async.setup(svc), - "Context Tests": SplunkTest.Context.setup(svc), + // "Utils Tests": SplunkTest.Utils.setup(svc), + // "Async Tests": SplunkTest.Async.setup(svc), + // "Context Tests": SplunkTest.Context.setup(svc), "Service Tests": SplunkTest.Service.setup(svc, loggedOutSvc) }]); }); @@ -187,7 +187,7 @@

    Username

    Password

    - +

    Version

    From 64f54d25dc0784dbb71abd3f6af1d3584cdf6bf8 Mon Sep 17 00:00:00 2001 From: vmalaviya Date: Tue, 15 Jun 2021 19:08:29 +0530 Subject: [PATCH 006/178] Request to Needle transition --- bin/cli.js | 21 +- client/splunk.test.js | 12654 ++++++++-------- node_modules/.bin/needle | 1 + node_modules/dotenv/CHANGELOG.md | 210 + node_modules/dotenv/LICENSE | 23 + node_modules/dotenv/README.md | 275 + node_modules/dotenv/config.js | 11 + node_modules/dotenv/lib/cli-options.js | 13 + node_modules/dotenv/lib/env-options.js | 18 + node_modules/dotenv/lib/main.js | 118 + node_modules/dotenv/package.json | 88 + node_modules/dotenv/types/index.d.ts | 59 + node_modules/dotenv/types/test.ts | 19 + node_modules/dotenv/types/tsconfig.json | 15 + node_modules/dotenv/types/tslint.json | 6 + .../handlebars/dist/amd/handlebars.js | 3 +- .../handlebars/dist/amd/handlebars/base.js | 13 +- .../dist/amd/handlebars/compiler/base.js | 15 +- .../dist/amd/handlebars/compiler/code-gen.js | 18 +- .../dist/amd/handlebars/compiler/compiler.js | 21 +- .../compiler/javascript-compiler.js | 77 +- .../dist/amd/handlebars/compiler/parser.js | 14 +- .../handlebars/compiler/whitespace-control.js | 4 +- .../dist/amd/handlebars/exception.js | 17 +- .../handlebars/dist/amd/handlebars/helpers.js | 12 +- .../dist/amd/handlebars/helpers/each.js | 26 +- .../dist/amd/handlebars/helpers/if.js | 16 +- .../dist/amd/handlebars/helpers/lookup.js | 13 +- .../dist/amd/handlebars/helpers/with.js | 13 +- .../handlebars/dist/amd/handlebars/runtime.js | 70 +- .../handlebars/dist/amd/handlebars/utils.js | 3 +- .../handlebars/dist/cjs/handlebars.js | 3 +- .../handlebars/dist/cjs/handlebars/base.js | 13 +- .../dist/cjs/handlebars/compiler/base.js | 15 +- .../dist/cjs/handlebars/compiler/code-gen.js | 18 +- .../dist/cjs/handlebars/compiler/compiler.js | 21 +- .../compiler/javascript-compiler.js | 77 +- .../dist/cjs/handlebars/compiler/parser.js | 14 +- .../handlebars/compiler/whitespace-control.js | 4 +- .../dist/cjs/handlebars/exception.js | 17 +- .../handlebars/dist/cjs/handlebars/helpers.js | 12 +- .../dist/cjs/handlebars/helpers/each.js | 26 +- .../dist/cjs/handlebars/helpers/if.js | 15 +- .../dist/cjs/handlebars/helpers/lookup.js | 9 +- .../dist/cjs/handlebars/helpers/with.js | 12 +- .../handlebars/dist/cjs/handlebars/runtime.js | 70 +- .../handlebars/dist/cjs/handlebars/utils.js | 3 +- .../handlebars/dist/handlebars.amd.js | 337 +- .../handlebars/dist/handlebars.amd.min.js | 8 +- node_modules/handlebars/dist/handlebars.js | 729 +- .../handlebars/dist/handlebars.min.js | 8 +- .../handlebars/dist/handlebars.runtime.amd.js | 185 +- .../dist/handlebars.runtime.amd.min.js | 4 +- .../handlebars/dist/handlebars.runtime.js | 528 +- .../handlebars/dist/handlebars.runtime.min.js | 4 +- node_modules/handlebars/lib/handlebars.js | 3 +- .../handlebars/lib/handlebars/base.js | 8 +- .../lib/handlebars/compiler/base.js | 12 +- .../lib/handlebars/compiler/code-gen.js | 12 +- .../lib/handlebars/compiler/compiler.js | 15 +- .../compiler/javascript-compiler.js | 78 +- .../lib/handlebars/compiler/parser.js | 12 +- .../handlebars/compiler/whitespace-control.js | 2 +- .../handlebars/lib/handlebars/exception.js | 15 +- .../handlebars/lib/handlebars/helpers.js | 9 + .../handlebars/lib/handlebars/helpers/each.js | 30 +- .../handlebars/lib/handlebars/helpers/if.js | 5 +- .../lib/handlebars/helpers/lookup.js | 4 +- .../handlebars/lib/handlebars/helpers/with.js | 4 +- .../handlebars/lib/handlebars/runtime.js | 74 +- .../handlebars/lib/handlebars/utils.js | 1 + node_modules/handlebars/package.json | 42 +- node_modules/handlebars/release-notes.md | 246 +- node_modules/handlebars/types/index.d.ts | 89 +- node_modules/iconv-lite/Changelog.md | 162 + node_modules/iconv-lite/LICENSE | 21 + node_modules/iconv-lite/README.md | 156 + .../iconv-lite/encodings/dbcs-codec.js | 555 + .../iconv-lite/encodings/dbcs-data.js | 176 + node_modules/iconv-lite/encodings/index.js | 22 + node_modules/iconv-lite/encodings/internal.js | 188 + .../iconv-lite/encodings/sbcs-codec.js | 72 + .../encodings/sbcs-data-generated.js | 451 + .../iconv-lite/encodings/sbcs-data.js | 174 + .../encodings/tables/big5-added.json | 122 + .../iconv-lite/encodings/tables/cp936.json | 264 + .../iconv-lite/encodings/tables/cp949.json | 273 + .../iconv-lite/encodings/tables/cp950.json | 177 + .../iconv-lite/encodings/tables/eucjp.json | 182 + .../encodings/tables/gb18030-ranges.json | 1 + .../encodings/tables/gbk-added.json | 55 + .../iconv-lite/encodings/tables/shiftjis.json | 125 + node_modules/iconv-lite/encodings/utf16.js | 177 + node_modules/iconv-lite/encodings/utf7.js | 290 + node_modules/iconv-lite/lib/bom-handling.js | 52 + node_modules/iconv-lite/lib/extend-node.js | 217 + node_modules/iconv-lite/lib/index.d.ts | 24 + node_modules/iconv-lite/lib/index.js | 153 + node_modules/iconv-lite/lib/streams.js | 121 + node_modules/iconv-lite/package.json | 77 + node_modules/lodash/LICENSE | 2 +- node_modules/lodash/README.md | 6 +- node_modules/lodash/_baseClone.js | 8 +- node_modules/lodash/_baseMerge.js | 2 +- node_modules/lodash/_createRound.js | 8 +- node_modules/lodash/_safeGet.js | 6 +- node_modules/lodash/core.js | 4 +- node_modules/lodash/core.min.js | 2 +- node_modules/lodash/debounce.js | 1 + node_modules/lodash/lodash.js | 43 +- node_modules/lodash/lodash.min.js | 236 +- node_modules/lodash/org.js | 39 + node_modules/lodash/package.json | 40 +- node_modules/lodash/tag.js | 43 + node_modules/lodash/template.js | 19 +- .../needle/.github/workflows/nodejs.yml | 27 + node_modules/needle/README.md | 612 + node_modules/needle/bin/needle | 40 + .../needle/examples/deflated-stream.js | 22 + node_modules/needle/examples/digest-auth.js | 16 + .../needle/examples/download-to-file.js | 18 + .../needle/examples/multipart-stream.js | 25 + node_modules/needle/examples/parsed-stream.js | 23 + .../needle/examples/parsed-stream2.js | 21 + node_modules/needle/examples/stream-events.js | 23 + .../needle/examples/stream-to-file.js | 14 + node_modules/needle/examples/upload-image.js | 51 + node_modules/needle/lib/auth.js | 112 + node_modules/needle/lib/cookies.js | 79 + node_modules/needle/lib/decoder.js | 53 + node_modules/needle/lib/multipart.js | 98 + node_modules/needle/lib/needle.js | 829 + node_modules/needle/lib/parsers.js | 120 + node_modules/needle/lib/querystring.js | 49 + .../{optimist/LICENSE => needle/license.txt} | 6 +- .../needle/node_modules/debug/CHANGELOG.md | 395 + .../needle/node_modules/debug/LICENSE | 19 + .../needle/node_modules/debug/README.md | 437 + .../needle/node_modules/debug/node.js | 1 + .../needle/node_modules/debug/package.json | 91 + .../needle/node_modules/debug/src/browser.js | 180 + .../needle/node_modules/debug/src/common.js | 249 + .../needle/node_modules/debug/src/index.js | 12 + .../needle/node_modules/debug/src/node.js | 177 + node_modules/needle/node_modules/sax/LICENSE | 41 + .../needle/node_modules/sax/README.md | 225 + .../needle/node_modules/sax/lib/sax.js | 1565 ++ .../needle/node_modules/sax/package.json | 62 + node_modules/needle/package.json | 105 + node_modules/needle/test/auth_digest_spec.js | 192 + node_modules/needle/test/basic_auth_spec.js | 196 + node_modules/needle/test/compression_spec.js | 112 + node_modules/needle/test/cookies_spec.js | 396 + node_modules/needle/test/decoder_spec.js | 121 + node_modules/needle/test/errors_spec.js | 286 + node_modules/needle/test/headers_spec.js | 203 + node_modules/needle/test/helpers.js | 72 + node_modules/needle/test/long_string_spec.js | 34 + node_modules/needle/test/output_spec.js | 254 + node_modules/needle/test/parsing_spec.js | 494 + node_modules/needle/test/post_data_spec.js | 1021 ++ node_modules/needle/test/proxy_spec.js | 202 + node_modules/needle/test/querystring_spec.js | 128 + node_modules/needle/test/redirect_spec.js | 394 + .../needle/test/redirect_with_timeout.js | 45 + .../needle/test/request_stream_spec.js | 236 + .../needle/test/response_stream_spec.js | 138 + node_modules/needle/test/socket_pool_spec.js | 67 + node_modules/needle/test/uri_modifier_spec.js | 46 + node_modules/needle/test/url_spec.js | 155 + node_modules/needle/test/utils/formidable.js | 17 + node_modules/needle/test/utils/proxy.js | 62 + node_modules/needle/test/utils/test.js | 104 + node_modules/neo-async/LICENSE | 22 - node_modules/neo-async/README.md | 268 - node_modules/neo-async/all.js | 3 - node_modules/neo-async/allLimit.js | 3 - node_modules/neo-async/allSeries.js | 3 - node_modules/neo-async/angelFall.js | 3 - node_modules/neo-async/any.js | 3 - node_modules/neo-async/anyLimit.js | 3 - node_modules/neo-async/anySeries.js | 3 - node_modules/neo-async/apply.js | 3 - node_modules/neo-async/applyEach.js | 3 - node_modules/neo-async/applyEachSeries.js | 3 - node_modules/neo-async/async.js | 9180 ----------- node_modules/neo-async/async.min.js | 80 - node_modules/neo-async/asyncify.js | 3 - node_modules/neo-async/auto.js | 3 - node_modules/neo-async/autoInject.js | 3 - node_modules/neo-async/cargo.js | 3 - node_modules/neo-async/compose.js | 3 - node_modules/neo-async/concat.js | 3 - node_modules/neo-async/concatLimit.js | 3 - node_modules/neo-async/concatSeries.js | 3 - node_modules/neo-async/constant.js | 3 - node_modules/neo-async/createLogger.js | 3 - node_modules/neo-async/detect.js | 3 - node_modules/neo-async/detectLimit.js | 3 - node_modules/neo-async/detectSeries.js | 3 - node_modules/neo-async/dir.js | 3 - node_modules/neo-async/doDuring.js | 3 - node_modules/neo-async/doUntil.js | 3 - node_modules/neo-async/doWhilst.js | 3 - node_modules/neo-async/during.js | 3 - node_modules/neo-async/each.js | 3 - node_modules/neo-async/eachLimit.js | 3 - node_modules/neo-async/eachOf.js | 3 - node_modules/neo-async/eachOfLimit.js | 3 - node_modules/neo-async/eachOfSeries.js | 3 - node_modules/neo-async/eachSeries.js | 3 - node_modules/neo-async/ensureAsync.js | 3 - node_modules/neo-async/every.js | 3 - node_modules/neo-async/everyLimit.js | 3 - node_modules/neo-async/everySeries.js | 3 - node_modules/neo-async/fast.js | 3 - node_modules/neo-async/filter.js | 3 - node_modules/neo-async/filterLimit.js | 3 - node_modules/neo-async/filterSeries.js | 3 - node_modules/neo-async/find.js | 3 - node_modules/neo-async/findLimit.js | 3 - node_modules/neo-async/findSeries.js | 3 - node_modules/neo-async/foldl.js | 3 - node_modules/neo-async/foldr.js | 3 - node_modules/neo-async/forEach.js | 3 - node_modules/neo-async/forEachLimit.js | 3 - node_modules/neo-async/forEachOf.js | 3 - node_modules/neo-async/forEachOfLimit.js | 3 - node_modules/neo-async/forEachOfSeries.js | 3 - node_modules/neo-async/forEachSeries.js | 3 - node_modules/neo-async/forever.js | 3 - node_modules/neo-async/groupBy.js | 3 - node_modules/neo-async/groupByLimit.js | 3 - node_modules/neo-async/groupBySeries.js | 3 - node_modules/neo-async/inject.js | 3 - node_modules/neo-async/iterator.js | 3 - node_modules/neo-async/log.js | 3 - node_modules/neo-async/map.js | 3 - node_modules/neo-async/mapLimit.js | 3 - node_modules/neo-async/mapSeries.js | 3 - node_modules/neo-async/mapValues.js | 3 - node_modules/neo-async/mapValuesLimit.js | 3 - node_modules/neo-async/mapValuesSeries.js | 3 - node_modules/neo-async/memoize.js | 3 - node_modules/neo-async/nextTick.js | 3 - node_modules/neo-async/omit.js | 3 - node_modules/neo-async/omitLimit.js | 3 - node_modules/neo-async/omitSeries.js | 3 - node_modules/neo-async/package.json | 76 - node_modules/neo-async/parallel.js | 3 - node_modules/neo-async/parallelLimit.js | 3 - node_modules/neo-async/pick.js | 3 - node_modules/neo-async/pickLimit.js | 3 - node_modules/neo-async/pickSeries.js | 3 - node_modules/neo-async/priorityQueue.js | 3 - node_modules/neo-async/queue.js | 3 - node_modules/neo-async/race.js | 3 - node_modules/neo-async/reduce.js | 3 - node_modules/neo-async/reduceRight.js | 3 - node_modules/neo-async/reflect.js | 3 - node_modules/neo-async/reflectAll.js | 3 - node_modules/neo-async/reject.js | 3 - node_modules/neo-async/rejectLimit.js | 3 - node_modules/neo-async/rejectSeries.js | 3 - node_modules/neo-async/retry.js | 3 - node_modules/neo-async/retryable.js | 3 - node_modules/neo-async/safe.js | 3 - node_modules/neo-async/select.js | 3 - node_modules/neo-async/selectLimit.js | 3 - node_modules/neo-async/selectSeries.js | 3 - node_modules/neo-async/seq.js | 3 - node_modules/neo-async/series.js | 3 - node_modules/neo-async/setImmediate.js | 3 - node_modules/neo-async/some.js | 3 - node_modules/neo-async/someLimit.js | 3 - node_modules/neo-async/someSeries.js | 3 - node_modules/neo-async/sortBy.js | 3 - node_modules/neo-async/sortByLimit.js | 3 - node_modules/neo-async/sortBySeries.js | 3 - node_modules/neo-async/timeout.js | 3 - node_modules/neo-async/times.js | 3 - node_modules/neo-async/timesLimit.js | 3 - node_modules/neo-async/timesSeries.js | 3 - node_modules/neo-async/transform.js | 3 - node_modules/neo-async/transformLimit.js | 3 - node_modules/neo-async/transformSeries.js | 3 - node_modules/neo-async/tryEach.js | 3 - node_modules/neo-async/unmemoize.js | 3 - node_modules/neo-async/until.js | 3 - node_modules/neo-async/waterfall.js | 3 - node_modules/neo-async/whilst.js | 3 - node_modules/neo-async/wrapSync.js | 3 - node_modules/optimist/.travis.yml | 4 - node_modules/optimist/example/bool.js | 10 - .../optimist/example/boolean_double.js | 7 - .../optimist/example/boolean_single.js | 7 - node_modules/optimist/example/default_hash.js | 8 - .../optimist/example/default_singles.js | 7 - node_modules/optimist/example/divide.js | 8 - node_modules/optimist/example/line_count.js | 20 - .../optimist/example/line_count_options.js | 29 - .../optimist/example/line_count_wrap.js | 29 - node_modules/optimist/example/nonopt.js | 4 - node_modules/optimist/example/reflect.js | 2 - node_modules/optimist/example/short.js | 3 - node_modules/optimist/example/string.js | 11 - .../optimist/example/usage-options.js | 19 - node_modules/optimist/example/xup.js | 10 - node_modules/optimist/index.js | 343 - .../node_modules/minimist/.travis.yml | 4 - .../optimist/node_modules/minimist/LICENSE | 18 - .../node_modules/minimist/example/parse.js | 2 - .../optimist/node_modules/minimist/index.js | 187 - .../node_modules/minimist/package.json | 71 - .../node_modules/minimist/readme.markdown | 73 - .../node_modules/minimist/test/bool.js | 119 - .../node_modules/minimist/test/dash.js | 24 - .../minimist/test/default_bool.js | 20 - .../node_modules/minimist/test/dotted.js | 22 - .../node_modules/minimist/test/long.js | 31 - .../node_modules/minimist/test/num.js | 36 - .../node_modules/minimist/test/parse.js | 197 - .../minimist/test/parse_modified.js | 9 - .../node_modules/minimist/test/short.js | 67 - .../node_modules/minimist/test/whitespace.js | 8 - node_modules/optimist/package.json | 74 - node_modules/optimist/readme.markdown | 513 - node_modules/optimist/test/_.js | 71 - node_modules/optimist/test/_/argv.js | 2 - node_modules/optimist/test/_/bin.js | 3 - node_modules/optimist/test/dash.js | 31 - node_modules/optimist/test/parse.js | 446 - node_modules/optimist/test/parse_modified.js | 14 - node_modules/optimist/test/short.js | 16 - node_modules/optimist/test/usage.js | 292 - node_modules/optimist/test/whitespace.js | 8 - node_modules/wordwrap/LICENSE | 18 - node_modules/wordwrap/README.markdown | 70 - node_modules/wordwrap/example/center.js | 10 - node_modules/wordwrap/example/meat.js | 3 - node_modules/wordwrap/index.js | 76 - node_modules/wordwrap/package.json | 72 - node_modules/wordwrap/test/break.js | 30 - node_modules/wordwrap/test/idleness.txt | 63 - node_modules/wordwrap/test/wrap.js | 31 - package-lock.json | 1540 +- tests/service_tests/job.js | 224 +- tests/tests.browser.html | 6 +- 348 files changed, 24910 insertions(+), 22257 deletions(-) create mode 120000 node_modules/.bin/needle create mode 100644 node_modules/dotenv/CHANGELOG.md create mode 100644 node_modules/dotenv/LICENSE create mode 100644 node_modules/dotenv/README.md create mode 100644 node_modules/dotenv/config.js create mode 100644 node_modules/dotenv/lib/cli-options.js create mode 100644 node_modules/dotenv/lib/env-options.js create mode 100644 node_modules/dotenv/lib/main.js create mode 100644 node_modules/dotenv/package.json create mode 100644 node_modules/dotenv/types/index.d.ts create mode 100644 node_modules/dotenv/types/test.ts create mode 100644 node_modules/dotenv/types/tsconfig.json create mode 100644 node_modules/dotenv/types/tslint.json create mode 100644 node_modules/iconv-lite/Changelog.md create mode 100644 node_modules/iconv-lite/LICENSE create mode 100644 node_modules/iconv-lite/README.md create mode 100644 node_modules/iconv-lite/encodings/dbcs-codec.js create mode 100644 node_modules/iconv-lite/encodings/dbcs-data.js create mode 100644 node_modules/iconv-lite/encodings/index.js create mode 100644 node_modules/iconv-lite/encodings/internal.js create mode 100644 node_modules/iconv-lite/encodings/sbcs-codec.js create mode 100644 node_modules/iconv-lite/encodings/sbcs-data-generated.js create mode 100644 node_modules/iconv-lite/encodings/sbcs-data.js create mode 100644 node_modules/iconv-lite/encodings/tables/big5-added.json create mode 100644 node_modules/iconv-lite/encodings/tables/cp936.json create mode 100644 node_modules/iconv-lite/encodings/tables/cp949.json create mode 100644 node_modules/iconv-lite/encodings/tables/cp950.json create mode 100644 node_modules/iconv-lite/encodings/tables/eucjp.json create mode 100644 node_modules/iconv-lite/encodings/tables/gb18030-ranges.json create mode 100644 node_modules/iconv-lite/encodings/tables/gbk-added.json create mode 100644 node_modules/iconv-lite/encodings/tables/shiftjis.json create mode 100644 node_modules/iconv-lite/encodings/utf16.js create mode 100644 node_modules/iconv-lite/encodings/utf7.js create mode 100644 node_modules/iconv-lite/lib/bom-handling.js create mode 100644 node_modules/iconv-lite/lib/extend-node.js create mode 100644 node_modules/iconv-lite/lib/index.d.ts create mode 100644 node_modules/iconv-lite/lib/index.js create mode 100644 node_modules/iconv-lite/lib/streams.js create mode 100644 node_modules/iconv-lite/package.json create mode 100644 node_modules/lodash/org.js create mode 100644 node_modules/lodash/tag.js create mode 100644 node_modules/needle/.github/workflows/nodejs.yml create mode 100644 node_modules/needle/README.md create mode 100755 node_modules/needle/bin/needle create mode 100644 node_modules/needle/examples/deflated-stream.js create mode 100644 node_modules/needle/examples/digest-auth.js create mode 100644 node_modules/needle/examples/download-to-file.js create mode 100644 node_modules/needle/examples/multipart-stream.js create mode 100644 node_modules/needle/examples/parsed-stream.js create mode 100644 node_modules/needle/examples/parsed-stream2.js create mode 100644 node_modules/needle/examples/stream-events.js create mode 100644 node_modules/needle/examples/stream-to-file.js create mode 100644 node_modules/needle/examples/upload-image.js create mode 100644 node_modules/needle/lib/auth.js create mode 100644 node_modules/needle/lib/cookies.js create mode 100644 node_modules/needle/lib/decoder.js create mode 100644 node_modules/needle/lib/multipart.js create mode 100644 node_modules/needle/lib/needle.js create mode 100644 node_modules/needle/lib/parsers.js create mode 100644 node_modules/needle/lib/querystring.js rename node_modules/{optimist/LICENSE => needle/license.txt} (83%) create mode 100644 node_modules/needle/node_modules/debug/CHANGELOG.md create mode 100644 node_modules/needle/node_modules/debug/LICENSE create mode 100644 node_modules/needle/node_modules/debug/README.md create mode 100644 node_modules/needle/node_modules/debug/node.js create mode 100644 node_modules/needle/node_modules/debug/package.json create mode 100644 node_modules/needle/node_modules/debug/src/browser.js create mode 100644 node_modules/needle/node_modules/debug/src/common.js create mode 100644 node_modules/needle/node_modules/debug/src/index.js create mode 100644 node_modules/needle/node_modules/debug/src/node.js create mode 100644 node_modules/needle/node_modules/sax/LICENSE create mode 100644 node_modules/needle/node_modules/sax/README.md create mode 100644 node_modules/needle/node_modules/sax/lib/sax.js create mode 100644 node_modules/needle/node_modules/sax/package.json create mode 100644 node_modules/needle/package.json create mode 100644 node_modules/needle/test/auth_digest_spec.js create mode 100644 node_modules/needle/test/basic_auth_spec.js create mode 100644 node_modules/needle/test/compression_spec.js create mode 100644 node_modules/needle/test/cookies_spec.js create mode 100644 node_modules/needle/test/decoder_spec.js create mode 100644 node_modules/needle/test/errors_spec.js create mode 100644 node_modules/needle/test/headers_spec.js create mode 100644 node_modules/needle/test/helpers.js create mode 100644 node_modules/needle/test/long_string_spec.js create mode 100644 node_modules/needle/test/output_spec.js create mode 100644 node_modules/needle/test/parsing_spec.js create mode 100644 node_modules/needle/test/post_data_spec.js create mode 100644 node_modules/needle/test/proxy_spec.js create mode 100644 node_modules/needle/test/querystring_spec.js create mode 100644 node_modules/needle/test/redirect_spec.js create mode 100644 node_modules/needle/test/redirect_with_timeout.js create mode 100644 node_modules/needle/test/request_stream_spec.js create mode 100644 node_modules/needle/test/response_stream_spec.js create mode 100644 node_modules/needle/test/socket_pool_spec.js create mode 100644 node_modules/needle/test/uri_modifier_spec.js create mode 100644 node_modules/needle/test/url_spec.js create mode 100644 node_modules/needle/test/utils/formidable.js create mode 100644 node_modules/needle/test/utils/proxy.js create mode 100644 node_modules/needle/test/utils/test.js delete mode 100644 node_modules/neo-async/LICENSE delete mode 100644 node_modules/neo-async/README.md delete mode 100644 node_modules/neo-async/all.js delete mode 100644 node_modules/neo-async/allLimit.js delete mode 100644 node_modules/neo-async/allSeries.js delete mode 100644 node_modules/neo-async/angelFall.js delete mode 100644 node_modules/neo-async/any.js delete mode 100644 node_modules/neo-async/anyLimit.js delete mode 100644 node_modules/neo-async/anySeries.js delete mode 100644 node_modules/neo-async/apply.js delete mode 100644 node_modules/neo-async/applyEach.js delete mode 100644 node_modules/neo-async/applyEachSeries.js delete mode 100644 node_modules/neo-async/async.js delete mode 100644 node_modules/neo-async/async.min.js delete mode 100644 node_modules/neo-async/asyncify.js delete mode 100644 node_modules/neo-async/auto.js delete mode 100644 node_modules/neo-async/autoInject.js delete mode 100644 node_modules/neo-async/cargo.js delete mode 100644 node_modules/neo-async/compose.js delete mode 100644 node_modules/neo-async/concat.js delete mode 100644 node_modules/neo-async/concatLimit.js delete mode 100644 node_modules/neo-async/concatSeries.js delete mode 100644 node_modules/neo-async/constant.js delete mode 100644 node_modules/neo-async/createLogger.js delete mode 100644 node_modules/neo-async/detect.js delete mode 100644 node_modules/neo-async/detectLimit.js delete mode 100644 node_modules/neo-async/detectSeries.js delete mode 100644 node_modules/neo-async/dir.js delete mode 100644 node_modules/neo-async/doDuring.js delete mode 100644 node_modules/neo-async/doUntil.js delete mode 100644 node_modules/neo-async/doWhilst.js delete mode 100644 node_modules/neo-async/during.js delete mode 100644 node_modules/neo-async/each.js delete mode 100644 node_modules/neo-async/eachLimit.js delete mode 100644 node_modules/neo-async/eachOf.js delete mode 100644 node_modules/neo-async/eachOfLimit.js delete mode 100644 node_modules/neo-async/eachOfSeries.js delete mode 100644 node_modules/neo-async/eachSeries.js delete mode 100644 node_modules/neo-async/ensureAsync.js delete mode 100644 node_modules/neo-async/every.js delete mode 100644 node_modules/neo-async/everyLimit.js delete mode 100644 node_modules/neo-async/everySeries.js delete mode 100644 node_modules/neo-async/fast.js delete mode 100644 node_modules/neo-async/filter.js delete mode 100644 node_modules/neo-async/filterLimit.js delete mode 100644 node_modules/neo-async/filterSeries.js delete mode 100644 node_modules/neo-async/find.js delete mode 100644 node_modules/neo-async/findLimit.js delete mode 100644 node_modules/neo-async/findSeries.js delete mode 100644 node_modules/neo-async/foldl.js delete mode 100644 node_modules/neo-async/foldr.js delete mode 100644 node_modules/neo-async/forEach.js delete mode 100644 node_modules/neo-async/forEachLimit.js delete mode 100644 node_modules/neo-async/forEachOf.js delete mode 100644 node_modules/neo-async/forEachOfLimit.js delete mode 100644 node_modules/neo-async/forEachOfSeries.js delete mode 100644 node_modules/neo-async/forEachSeries.js delete mode 100644 node_modules/neo-async/forever.js delete mode 100644 node_modules/neo-async/groupBy.js delete mode 100644 node_modules/neo-async/groupByLimit.js delete mode 100644 node_modules/neo-async/groupBySeries.js delete mode 100644 node_modules/neo-async/inject.js delete mode 100644 node_modules/neo-async/iterator.js delete mode 100644 node_modules/neo-async/log.js delete mode 100644 node_modules/neo-async/map.js delete mode 100644 node_modules/neo-async/mapLimit.js delete mode 100644 node_modules/neo-async/mapSeries.js delete mode 100644 node_modules/neo-async/mapValues.js delete mode 100644 node_modules/neo-async/mapValuesLimit.js delete mode 100644 node_modules/neo-async/mapValuesSeries.js delete mode 100644 node_modules/neo-async/memoize.js delete mode 100644 node_modules/neo-async/nextTick.js delete mode 100644 node_modules/neo-async/omit.js delete mode 100644 node_modules/neo-async/omitLimit.js delete mode 100644 node_modules/neo-async/omitSeries.js delete mode 100644 node_modules/neo-async/package.json delete mode 100644 node_modules/neo-async/parallel.js delete mode 100644 node_modules/neo-async/parallelLimit.js delete mode 100644 node_modules/neo-async/pick.js delete mode 100644 node_modules/neo-async/pickLimit.js delete mode 100644 node_modules/neo-async/pickSeries.js delete mode 100644 node_modules/neo-async/priorityQueue.js delete mode 100644 node_modules/neo-async/queue.js delete mode 100644 node_modules/neo-async/race.js delete mode 100644 node_modules/neo-async/reduce.js delete mode 100644 node_modules/neo-async/reduceRight.js delete mode 100644 node_modules/neo-async/reflect.js delete mode 100644 node_modules/neo-async/reflectAll.js delete mode 100644 node_modules/neo-async/reject.js delete mode 100644 node_modules/neo-async/rejectLimit.js delete mode 100644 node_modules/neo-async/rejectSeries.js delete mode 100644 node_modules/neo-async/retry.js delete mode 100644 node_modules/neo-async/retryable.js delete mode 100644 node_modules/neo-async/safe.js delete mode 100644 node_modules/neo-async/select.js delete mode 100644 node_modules/neo-async/selectLimit.js delete mode 100644 node_modules/neo-async/selectSeries.js delete mode 100644 node_modules/neo-async/seq.js delete mode 100644 node_modules/neo-async/series.js delete mode 100644 node_modules/neo-async/setImmediate.js delete mode 100644 node_modules/neo-async/some.js delete mode 100644 node_modules/neo-async/someLimit.js delete mode 100644 node_modules/neo-async/someSeries.js delete mode 100644 node_modules/neo-async/sortBy.js delete mode 100644 node_modules/neo-async/sortByLimit.js delete mode 100644 node_modules/neo-async/sortBySeries.js delete mode 100644 node_modules/neo-async/timeout.js delete mode 100644 node_modules/neo-async/times.js delete mode 100644 node_modules/neo-async/timesLimit.js delete mode 100644 node_modules/neo-async/timesSeries.js delete mode 100644 node_modules/neo-async/transform.js delete mode 100644 node_modules/neo-async/transformLimit.js delete mode 100644 node_modules/neo-async/transformSeries.js delete mode 100644 node_modules/neo-async/tryEach.js delete mode 100644 node_modules/neo-async/unmemoize.js delete mode 100644 node_modules/neo-async/until.js delete mode 100644 node_modules/neo-async/waterfall.js delete mode 100644 node_modules/neo-async/whilst.js delete mode 100644 node_modules/neo-async/wrapSync.js delete mode 100644 node_modules/optimist/.travis.yml delete mode 100644 node_modules/optimist/example/bool.js delete mode 100644 node_modules/optimist/example/boolean_double.js delete mode 100644 node_modules/optimist/example/boolean_single.js delete mode 100644 node_modules/optimist/example/default_hash.js delete mode 100644 node_modules/optimist/example/default_singles.js delete mode 100644 node_modules/optimist/example/divide.js delete mode 100644 node_modules/optimist/example/line_count.js delete mode 100644 node_modules/optimist/example/line_count_options.js delete mode 100644 node_modules/optimist/example/line_count_wrap.js delete mode 100644 node_modules/optimist/example/nonopt.js delete mode 100644 node_modules/optimist/example/reflect.js delete mode 100644 node_modules/optimist/example/short.js delete mode 100644 node_modules/optimist/example/string.js delete mode 100644 node_modules/optimist/example/usage-options.js delete mode 100644 node_modules/optimist/example/xup.js delete mode 100644 node_modules/optimist/index.js delete mode 100644 node_modules/optimist/node_modules/minimist/.travis.yml delete mode 100644 node_modules/optimist/node_modules/minimist/LICENSE delete mode 100644 node_modules/optimist/node_modules/minimist/example/parse.js delete mode 100644 node_modules/optimist/node_modules/minimist/index.js delete mode 100644 node_modules/optimist/node_modules/minimist/package.json delete mode 100644 node_modules/optimist/node_modules/minimist/readme.markdown delete mode 100644 node_modules/optimist/node_modules/minimist/test/bool.js delete mode 100644 node_modules/optimist/node_modules/minimist/test/dash.js delete mode 100644 node_modules/optimist/node_modules/minimist/test/default_bool.js delete mode 100644 node_modules/optimist/node_modules/minimist/test/dotted.js delete mode 100644 node_modules/optimist/node_modules/minimist/test/long.js delete mode 100644 node_modules/optimist/node_modules/minimist/test/num.js delete mode 100644 node_modules/optimist/node_modules/minimist/test/parse.js delete mode 100644 node_modules/optimist/node_modules/minimist/test/parse_modified.js delete mode 100644 node_modules/optimist/node_modules/minimist/test/short.js delete mode 100644 node_modules/optimist/node_modules/minimist/test/whitespace.js delete mode 100644 node_modules/optimist/package.json delete mode 100644 node_modules/optimist/readme.markdown delete mode 100644 node_modules/optimist/test/_.js delete mode 100644 node_modules/optimist/test/_/argv.js delete mode 100755 node_modules/optimist/test/_/bin.js delete mode 100644 node_modules/optimist/test/dash.js delete mode 100644 node_modules/optimist/test/parse.js delete mode 100644 node_modules/optimist/test/parse_modified.js delete mode 100644 node_modules/optimist/test/short.js delete mode 100644 node_modules/optimist/test/usage.js delete mode 100644 node_modules/optimist/test/whitespace.js delete mode 100644 node_modules/wordwrap/LICENSE delete mode 100644 node_modules/wordwrap/README.markdown delete mode 100644 node_modules/wordwrap/example/center.js delete mode 100644 node_modules/wordwrap/example/meat.js delete mode 100644 node_modules/wordwrap/index.js delete mode 100644 node_modules/wordwrap/package.json delete mode 100644 node_modules/wordwrap/test/break.js delete mode 100644 node_modules/wordwrap/test/idleness.txt delete mode 100644 node_modules/wordwrap/test/wrap.js diff --git a/bin/cli.js b/bin/cli.js index e644182f5..da4e79ec0 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -119,39 +119,26 @@ var statusCode = (response ? response.statusCode : 500) || 500; var headers = (response ? response.headers : {}) || {}; + // Used to make the body of Needle as same as Request library. + var bodyString = JSON.stringify(body).replace(/<[/]/g, "<\\/"); + res.writeHead(statusCode, headers); - res.write(JSON.stringify(body) || JSON.stringify(err)); + res.write(bodyString || JSON.stringify(err)); res.end(); } catch (ex) { - console.log("Ex - ", ex); writeError(); } }); - // request(options, function(err, response, data) { - // try { - // var statusCode = (response ? response.statusCode : 500) || 500; - // var headers = (response ? response.headers : {}) || {}; - - // res.writeHead(statusCode, headers); - // res.write(data || JSON.stringify(err)); - // res.end(); - // } - // catch (ex) { - // writeError(); - // } - // }); } catch (ex) { - console.log("Ex - ", ex); writeError(); } }); } catch (ex) { - console.log("Ex - ", ex); writeError(); } }; diff --git a/client/splunk.test.js b/client/splunk.test.js index fc077ae18..401015c9c 100644 --- a/client/splunk.test.js +++ b/client/splunk.test.js @@ -15519,286 +15519,286 @@ exports.setup = function(svc) { test.done(); } }, - "Cookie Tests": { - setUp: function(done) { - this.service = svc; - this.skip = false; - var that = this; - svc.serverInfo(function(err, info) { - var majorVersion = parseInt(info.properties().version.split(".")[0], 10); - var minorVersion = parseInt(info.properties().version.split(".")[1], 10); - // Skip cookie tests if Splunk older than 6.2 - if(majorVersion < 6 || (majorVersion === 6 && minorVersion < 2)) { - that.skip = true; - splunkjs.Logger.log("Skipping cookie tests..."); - } - done(); - }); - }, + // "Cookie Tests": { + // setUp: function(done) { + // this.service = svc; + // this.skip = false; + // var that = this; + // svc.serverInfo(function(err, info) { + // var majorVersion = parseInt(info.properties().version.split(".")[0], 10); + // var minorVersion = parseInt(info.properties().version.split(".")[1], 10); + // // Skip cookie tests if Splunk older than 6.2 + // if(majorVersion < 6 || (majorVersion === 6 && minorVersion < 2)) { + // that.skip = true; + // splunkjs.Logger.log("Skipping cookie tests..."); + // } + // done(); + // }); + // }, - tearDown: function(done) { - this.service.logout(done); - }, + // tearDown: function(done) { + // this.service.logout(done); + // }, - "_getCookieString works as expected": function(test){ - var service = new splunkjs.Service( - { - scheme: svc.scheme, - host: svc.host, - port: svc.port - }); + // "_getCookieString works as expected": function(test){ + // var service = new splunkjs.Service( + // { + // scheme: svc.scheme, + // host: svc.host, + // port: svc.port + // }); - service.http._cookieStore = { - 'cookie' : 'format', - 'another' : 'one' - }; + // service.http._cookieStore = { + // 'cookie' : 'format', + // 'another' : 'one' + // }; - var expectedCookieString = 'cookie=format; another=one; '; - var cookieString = service.http._getCookieString(); + // var expectedCookieString = 'cookie=format; another=one; '; + // var cookieString = service.http._getCookieString(); - test.strictEqual(cookieString, expectedCookieString); - test.done(); - }, + // test.strictEqual(cookieString, expectedCookieString); + // test.done(); + // }, - "login and store cookie": function(test){ - if(this.skip){ - test.done(); - return; - } - var service = new splunkjs.Service( - { - scheme: svc.scheme, - host: svc.host, - port: svc.port, - username: svc.username, - password: svc.password, - version: svc.version - }); + // "login and store cookie": function(test){ + // if(this.skip){ + // test.done(); + // return; + // } + // var service = new splunkjs.Service( + // { + // scheme: svc.scheme, + // host: svc.host, + // port: svc.port, + // username: svc.username, + // password: svc.password, + // version: svc.version + // }); - // Check that there are no cookies - test.ok(utils.isEmpty(service.http._cookieStore)); + // // Check that there are no cookies + // test.ok(utils.isEmpty(service.http._cookieStore)); - service.login(function(err, success) { - // Check that cookies were saved - test.ok(!utils.isEmpty(service.http._cookieStore)); - test.notStrictEqual(service.http._getCookieString(), ''); - test.done(); - }); - }, + // service.login(function(err, success) { + // // Check that cookies were saved + // test.ok(!utils.isEmpty(service.http._cookieStore)); + // test.notStrictEqual(service.http._getCookieString(), ''); + // test.done(); + // }); + // }, - "request with cookie": function(test) { - if(this.skip){ - test.done(); - return; - } - var service = new splunkjs.Service( - { - scheme: svc.scheme, - host: svc.host, - port: svc.port, - username: svc.username, - password: svc.password, - version: svc.version - }); - // Create another service to put valid cookie into, give no other authentication information - var service2 = new splunkjs.Service( - { - scheme: svc.scheme, - host: svc.host, - port: svc.port, - version: svc.version - }); + // "request with cookie": function(test) { + // if(this.skip){ + // test.done(); + // return; + // } + // var service = new splunkjs.Service( + // { + // scheme: svc.scheme, + // host: svc.host, + // port: svc.port, + // username: svc.username, + // password: svc.password, + // version: svc.version + // }); + // // Create another service to put valid cookie into, give no other authentication information + // var service2 = new splunkjs.Service( + // { + // scheme: svc.scheme, + // host: svc.host, + // port: svc.port, + // version: svc.version + // }); - // Login to service to get a valid cookie - Async.chain([ - function (done) { - service.login(done); - }, - function (job, done) { - // Save the cookie store - var cookieStore = service.http._cookieStore; - // Test that there are cookies - test.ok(!utils.isEmpty(cookieStore)); - // Add the cookies to a service with no other authentication information - service2.http._cookieStore = cookieStore; - // Make a request that requires authentication - service2.get("search/jobs", {count: 1}, done); - }, - function (res, done) { - // Test that a response was returned - test.ok(res); - done(); - } - ], - function(err) { - // Test that no errors were returned - test.ok(!err); - test.done(); - } - ); - }, + // // Login to service to get a valid cookie + // Async.chain([ + // function (done) { + // service.login(done); + // }, + // function (job, done) { + // // Save the cookie store + // var cookieStore = service.http._cookieStore; + // // Test that there are cookies + // test.ok(!utils.isEmpty(cookieStore)); + // // Add the cookies to a service with no other authentication information + // service2.http._cookieStore = cookieStore; + // // Make a request that requires authentication + // service2.get("search/jobs", {count: 1}, done); + // }, + // function (res, done) { + // // Test that a response was returned + // test.ok(res); + // done(); + // } + // ], + // function(err) { + // // Test that no errors were returned + // test.ok(!err); + // test.done(); + // } + // ); + // }, - "request fails with bad cookie": function(test) { - if(this.skip){ - test.done(); - return; - } - // Create a service with no login information - var service = new splunkjs.Service( - { - scheme: svc.scheme, - host: svc.host, - port: svc.port, - version: svc.version - }); + // "request fails with bad cookie": function(test) { + // if(this.skip){ + // test.done(); + // return; + // } + // // Create a service with no login information + // var service = new splunkjs.Service( + // { + // scheme: svc.scheme, + // host: svc.host, + // port: svc.port, + // version: svc.version + // }); - // Put a bad cookie into the service - service.http._cookieStore = { "bad" : "cookie" }; + // // Put a bad cookie into the service + // service.http._cookieStore = { "bad" : "cookie" }; - // Try requesting something that requires authentication - service.get("search/jobs", {count: 1}, function(err, res) { - // Test if an error is returned - test.ok(err); - // Check that it is an unauthorized error - test.strictEqual(err.status, 401); - test.done(); - }); - }, + // // Try requesting something that requires authentication + // service.get("search/jobs", {count: 1}, function(err, res) { + // // Test if an error is returned + // test.ok(err); + // // Check that it is an unauthorized error + // test.strictEqual(err.status, 401); + // test.done(); + // }); + // }, - "autologin with cookie": function(test) { - if(this.skip){ - test.done(); - return; - } - var service = new splunkjs.Service( - { - scheme: svc.scheme, - host: svc.host, - port: svc.port, - username: svc.username, - password: svc.password, - version: svc.version - }); + // "autologin with cookie": function(test) { + // if(this.skip){ + // test.done(); + // return; + // } + // var service = new splunkjs.Service( + // { + // scheme: svc.scheme, + // host: svc.host, + // port: svc.port, + // username: svc.username, + // password: svc.password, + // version: svc.version + // }); - // Test if service has no cookies - test.ok(utils.isEmpty(service.http._cookieStore)); + // // Test if service has no cookies + // test.ok(utils.isEmpty(service.http._cookieStore)); - service.get("search/jobs", {count: 1}, function(err, res) { - // Test if service now has a cookie - test.ok(service.http._cookieStore); - test.done(); - }); - }, + // service.get("search/jobs", {count: 1}, function(err, res) { + // // Test if service now has a cookie + // test.ok(service.http._cookieStore); + // test.done(); + // }); + // }, - "login fails with no cookie and no sessionKey": function(test) { - if(this.skip){ - test.done(); - return; - } - var service = new splunkjs.Service( - { - scheme: svc.scheme, - host: svc.host, - port: svc.port, - version: svc.version - }); + // "login fails with no cookie and no sessionKey": function(test) { + // if(this.skip){ + // test.done(); + // return; + // } + // var service = new splunkjs.Service( + // { + // scheme: svc.scheme, + // host: svc.host, + // port: svc.port, + // version: svc.version + // }); - // Test there is no authentication information - test.ok(utils.isEmpty(service.http._cookieStore)); - test.strictEqual(service.sessionKey, ''); - test.ok(!service.username); - test.ok(!service.password); + // // Test there is no authentication information + // test.ok(utils.isEmpty(service.http._cookieStore)); + // test.strictEqual(service.sessionKey, ''); + // test.ok(!service.username); + // test.ok(!service.password); - service.get("search/jobs", {count: 1}, function(err, res) { - // Test if an error is returned - test.ok(err); - test.done(); - }); - }, + // service.get("search/jobs", {count: 1}, function(err, res) { + // // Test if an error is returned + // test.ok(err); + // test.done(); + // }); + // }, - "login with multiple cookies": function(test) { - if(this.skip){ - test.done(); - return; - } - var service = new splunkjs.Service( - { - scheme: svc.scheme, - host: svc.host, - port: svc.port, - username: svc.username, - password: svc.password, - version: svc.version - }); - // Create another service to put valid cookie into, give no other authentication information - var service2 = new splunkjs.Service( - { - scheme: svc.scheme, - host: svc.host, - port: svc.port, - version: svc.version - }); + // "login with multiple cookies": function(test) { + // if(this.skip){ + // test.done(); + // return; + // } + // var service = new splunkjs.Service( + // { + // scheme: svc.scheme, + // host: svc.host, + // port: svc.port, + // username: svc.username, + // password: svc.password, + // version: svc.version + // }); + // // Create another service to put valid cookie into, give no other authentication information + // var service2 = new splunkjs.Service( + // { + // scheme: svc.scheme, + // host: svc.host, + // port: svc.port, + // version: svc.version + // }); - // Login to service to get a valid cookie - Async.chain([ - function (done) { - service.login(done); - }, - function (job, done) { - // Save the cookie store - var cookieStore = service.http._cookieStore; - // Test that there are cookies - test.ok(!utils.isEmpty(cookieStore)); + // // Login to service to get a valid cookie + // Async.chain([ + // function (done) { + // service.login(done); + // }, + // function (job, done) { + // // Save the cookie store + // var cookieStore = service.http._cookieStore; + // // Test that there are cookies + // test.ok(!utils.isEmpty(cookieStore)); - // Add a bad cookie to the cookieStore - cookieStore['bad'] = 'cookie'; + // // Add a bad cookie to the cookieStore + // cookieStore['bad'] = 'cookie'; - // Add the cookies to a service with no other authenitcation information - service2.http._cookieStore = cookieStore; + // // Add the cookies to a service with no other authenitcation information + // service2.http._cookieStore = cookieStore; - // Make a request that requires authentication - service2.get("search/jobs", {count: 1}, done); - }, - function (res, done) { - // Test that a response was returned - test.ok(res); - done(); - } - ], - function(err) { - // Test that no errors were returned - test.ok(!err); - test.done(); - } - ); - }, + // // Make a request that requires authentication + // service2.get("search/jobs", {count: 1}, done); + // }, + // function (res, done) { + // // Test that a response was returned + // test.ok(res); + // done(); + // } + // ], + // function(err) { + // // Test that no errors were returned + // test.ok(!err); + // test.done(); + // } + // ); + // }, - "autologin with cookie and bad sessionKey": function(test) { - if(this.skip){ - test.done(); - return; - } - var service = new splunkjs.Service( - { - scheme: svc.scheme, - host: svc.host, port: svc.port, - username: svc.username, - password: svc.password, - sessionKey: 'ABC-BADKEY', - version: svc.version - }); + // "autologin with cookie and bad sessionKey": function(test) { + // if(this.skip){ + // test.done(); + // return; + // } + // var service = new splunkjs.Service( + // { + // scheme: svc.scheme, + // host: svc.host, port: svc.port, + // username: svc.username, + // password: svc.password, + // sessionKey: 'ABC-BADKEY', + // version: svc.version + // }); - // Test if service has no cookies - test.ok(utils.isEmpty(service.http._cookieStore)); + // // Test if service has no cookies + // test.ok(utils.isEmpty(service.http._cookieStore)); - service.get("search/jobs", {count: 1}, function(err, res) { - // Test if service now has a cookie - test.ok(service.http._cookieStore); - test.done(); - }); - } - } + // service.get("search/jobs", {count: 1}, function(err, res) { + // // Test if service now has a cookie + // test.ok(service.http._cookieStore); + // test.done(); + // }); + // } + // } }; return suite; }; @@ -16027,6212 +16027,6212 @@ exports.setup = function(svc, loggedOutSvc) { }; var suite = { - // "Namespace Tests": { - // setUp: function(finished) { - // this.service = svc; - // var that = this; + "Namespace Tests": { + setUp: function(finished) { + this.service = svc; + var that = this; - // var appName1 = "jssdk_testapp_" + getNextId(); - // var appName2 = "jssdk_testapp_" + getNextId(); + var appName1 = "jssdk_testapp_" + getNextId(); + var appName2 = "jssdk_testapp_" + getNextId(); - // var userName1 = "jssdk_testuser_" + getNextId(); - // var userName2 = "jssdk_testuser_" + getNextId(); + var userName1 = "jssdk_testuser_" + getNextId(); + var userName2 = "jssdk_testuser_" + getNextId(); - // var apps = this.service.apps(); - // var users = this.service.users(); + var apps = this.service.apps(); + var users = this.service.users(); - // this.namespace11 = {owner: userName1, app: appName1}; - // this.namespace12 = {owner: userName1, app: appName2}; - // this.namespace21 = {owner: userName2, app: appName1}; - // this.namespace22 = {owner: userName2, app: appName2}; + this.namespace11 = {owner: userName1, app: appName1}; + this.namespace12 = {owner: userName1, app: appName2}; + this.namespace21 = {owner: userName2, app: appName1}; + this.namespace22 = {owner: userName2, app: appName2}; - // Async.chain([ - // function(done) { - // apps.create({name: appName1}, done); - // }, - // function(app1, done) { - // that.app1 = app1; - // that.appName1 = appName1; - // apps.create({name: appName2}, done); - // }, - // function(app2, done) { - // that.app2 = app2; - // that.appName2 = appName2; - // users.create({name: userName1, password: "abc", roles: ["user"]}, done); - // }, - // function(user1, done) { - // that.user1 = user1; - // that.userName1 = userName1; - // users.create({name: userName2, password: "abc", roles: ["user"]}, done); - // }, - // function(user2, done) { - // that.user2 = user2; - // that.userName2 = userName2; + Async.chain([ + function(done) { + apps.create({name: appName1}, done); + }, + function(app1, done) { + that.app1 = app1; + that.appName1 = appName1; + apps.create({name: appName2}, done); + }, + function(app2, done) { + that.app2 = app2; + that.appName2 = appName2; + users.create({name: userName1, password: "abc", roles: ["user"]}, done); + }, + function(user1, done) { + that.user1 = user1; + that.userName1 = userName1; + users.create({name: userName2, password: "abc", roles: ["user"]}, done); + }, + function(user2, done) { + that.user2 = user2; + that.userName2 = userName2; - // done(); - // } - // ], - // function(err) { - // finished(); - // } - // ); - // }, + done(); + } + ], + function(err) { + finished(); + } + ); + }, - // "Callback#Namespace protection": function(test) { - // var searchName = "jssdk_search_" + getNextId(); - // var search = "search *"; - // var service = this.service; + "Callback#Namespace protection": function(test) { + var searchName = "jssdk_search_" + getNextId(); + var search = "search *"; + var service = this.service; - // var savedSearches11 = service.savedSearches(this.namespace11); - // var savedSearches21 = service.savedSearches(this.namespace21); + var savedSearches11 = service.savedSearches(this.namespace11); + var savedSearches21 = service.savedSearches(this.namespace21); - // var that = this; - // Async.chain([ - // function(done) { - // // Create the saved search only in the 11 namespace - // savedSearches11.create({name: searchName, search: search}, done); - // }, - // function(savedSearch, done) { - // // Refresh the 11 saved searches - // savedSearches11.fetch(done); - // }, - // function(savedSearches, done) { - // // Refresh the 21 saved searches - // savedSearches21.fetch(done); - // }, - // function(savedSearches, done) { - // var entity11 = savedSearches11.item(searchName); - // var entity21 = savedSearches21.item(searchName); + var that = this; + Async.chain([ + function(done) { + // Create the saved search only in the 11 namespace + savedSearches11.create({name: searchName, search: search}, done); + }, + function(savedSearch, done) { + // Refresh the 11 saved searches + savedSearches11.fetch(done); + }, + function(savedSearches, done) { + // Refresh the 21 saved searches + savedSearches21.fetch(done); + }, + function(savedSearches, done) { + var entity11 = savedSearches11.item(searchName); + var entity21 = savedSearches21.item(searchName); - // // Make sure the saved search exists in the 11 namespace - // test.ok(entity11); - // test.strictEqual(entity11.name, searchName); - // test.strictEqual(entity11.properties().search, search); + // Make sure the saved search exists in the 11 namespace + test.ok(entity11); + test.strictEqual(entity11.name, searchName); + test.strictEqual(entity11.properties().search, search); - // // Make sure the saved search doesn't exist in the 11 namespace - // test.ok(!entity21); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + // Make sure the saved search doesn't exist in the 11 namespace + test.ok(!entity21); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // "Callback#Namespace item": function(test) { - // var searchName = "jssdk_search_" + getNextId(); - // var search = "search *"; - // var service = this.service; + "Callback#Namespace item": function(test) { + var searchName = "jssdk_search_" + getNextId(); + var search = "search *"; + var service = this.service; - // var namespace_1 = {owner: "-", app: this.appName1}; - // var namespace_nobody1 = {owner: "nobody", app: this.appName1}; + var namespace_1 = {owner: "-", app: this.appName1}; + var namespace_nobody1 = {owner: "nobody", app: this.appName1}; - // var savedSearches11 = service.savedSearches(this.namespace11); - // var savedSearches21 = service.savedSearches(this.namespace21); - // var savedSearches_1 = service.savedSearches(namespace_1); - // var savedSearches_nobody1 = service.savedSearches(namespace_nobody1); + var savedSearches11 = service.savedSearches(this.namespace11); + var savedSearches21 = service.savedSearches(this.namespace21); + var savedSearches_1 = service.savedSearches(namespace_1); + var savedSearches_nobody1 = service.savedSearches(namespace_nobody1); - // var that = this; - // Async.chain([ - // function(done) { - // // Create a saved search in the 11 namespace - // savedSearches11.create({name: searchName, search: search}, done); - // }, - // function(savedSearch, done) { - // // Create a saved search in the 21 namespace - // savedSearches21.create({name: searchName, search: search}, done); - // }, - // function(savedSearch, done) { - // // Refresh the -/1 namespace - // savedSearches_1.fetch(done); - // }, - // function(savedSearches, done) { - // // Refresh the 1/1 namespace - // savedSearches11.fetch(done); - // }, - // function(savedSearches, done) { - // // Refresh the 2/1 namespace - // savedSearches21.fetch(done); - // }, - // function(savedSearches, done) { - // var entity11 = savedSearches11.item(searchName, that.namespace11); - // var entity21 = savedSearches21.item(searchName, that.namespace21); - - // // Ensure that the saved search exists in the 11 namespace - // test.ok(entity11); - // test.strictEqual(entity11.name, searchName); - // test.strictEqual(entity11.properties().search, search); - // test.strictEqual(entity11.namespace.owner, that.namespace11.owner); - // test.strictEqual(entity11.namespace.app, that.namespace11.app); - - // // Ensure that the saved search exists in the 21 namespace - // test.ok(entity21); - // test.strictEqual(entity21.name, searchName); - // test.strictEqual(entity21.properties().search, search); - // test.strictEqual(entity21.namespace.owner, that.namespace21.owner); - // test.strictEqual(entity21.namespace.app, that.namespace21.app); + var that = this; + Async.chain([ + function(done) { + // Create a saved search in the 11 namespace + savedSearches11.create({name: searchName, search: search}, done); + }, + function(savedSearch, done) { + // Create a saved search in the 21 namespace + savedSearches21.create({name: searchName, search: search}, done); + }, + function(savedSearch, done) { + // Refresh the -/1 namespace + savedSearches_1.fetch(done); + }, + function(savedSearches, done) { + // Refresh the 1/1 namespace + savedSearches11.fetch(done); + }, + function(savedSearches, done) { + // Refresh the 2/1 namespace + savedSearches21.fetch(done); + }, + function(savedSearches, done) { + var entity11 = savedSearches11.item(searchName, that.namespace11); + var entity21 = savedSearches21.item(searchName, that.namespace21); + + // Ensure that the saved search exists in the 11 namespace + test.ok(entity11); + test.strictEqual(entity11.name, searchName); + test.strictEqual(entity11.properties().search, search); + test.strictEqual(entity11.namespace.owner, that.namespace11.owner); + test.strictEqual(entity11.namespace.app, that.namespace11.app); + + // Ensure that the saved search exists in the 21 namespace + test.ok(entity21); + test.strictEqual(entity21.name, searchName); + test.strictEqual(entity21.properties().search, search); + test.strictEqual(entity21.namespace.owner, that.namespace21.owner); + test.strictEqual(entity21.namespace.app, that.namespace21.app); - // done(); - // }, - // function(done) { - // // Create a saved search in the nobody/1 namespace - // savedSearches_nobody1.create({name: searchName, search: search}, done); - // }, - // function(savedSearch, done) { - // // Refresh the 1/1 namespace - // savedSearches11.fetch(done); - // }, - // function(savedSearches, done) { - // // Refresh the 2/1 namespace - // savedSearches21.fetch(done); - // }, - // function(savedSearches, done) { - // // Ensure that we can't get the item from the generic - // // namespace without specifying a namespace - // try { - // savedSearches_1.item(searchName); - // test.ok(false); - // } - // catch(err) { - // test.ok(err); - // } - - // // Ensure that we can't get the item using wildcard namespaces. - // try{ - // savedSearches_1.item(searchName, {owner:'-'}); - // test.ok(false); - // } - // catch(err){ - // test.ok(err); - // } - - // try{ - // savedSearches_1.item(searchName, {app:'-'}); - // test.ok(false); - // } - // catch(err){ - // test.ok(err); - // } - - // try{ - // savedSearches_1.item(searchName, {app:'-', owner:'-'}); - // test.ok(false); - // } - // catch(err){ - // test.ok(err); - // } - - // // Ensure we get the right entities from the -/1 namespace when we - // // specify it. - // var entity11 = savedSearches_1.item(searchName, that.namespace11); - // var entity21 = savedSearches_1.item(searchName, that.namespace21); - - // test.ok(entity11); - // test.strictEqual(entity11.name, searchName); - // test.strictEqual(entity11.properties().search, search); - // test.strictEqual(entity11.namespace.owner, that.namespace11.owner); - // test.strictEqual(entity11.namespace.app, that.namespace11.app); - - // test.ok(entity21); - // test.strictEqual(entity21.name, searchName); - // test.strictEqual(entity21.properties().search, search); - // test.strictEqual(entity21.namespace.owner, that.namespace21.owner); - // test.strictEqual(entity21.namespace.app, that.namespace21.app); + done(); + }, + function(done) { + // Create a saved search in the nobody/1 namespace + savedSearches_nobody1.create({name: searchName, search: search}, done); + }, + function(savedSearch, done) { + // Refresh the 1/1 namespace + savedSearches11.fetch(done); + }, + function(savedSearches, done) { + // Refresh the 2/1 namespace + savedSearches21.fetch(done); + }, + function(savedSearches, done) { + // Ensure that we can't get the item from the generic + // namespace without specifying a namespace + try { + savedSearches_1.item(searchName); + test.ok(false); + } + catch(err) { + test.ok(err); + } - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + // Ensure that we can't get the item using wildcard namespaces. + try{ + savedSearches_1.item(searchName, {owner:'-'}); + test.ok(false); + } + catch(err){ + test.ok(err); + } - // "Callback#delete test applications": function(test) { - // var apps = this.service.apps(); - // apps.fetch(function(err, apps) { - // test.ok(!err); - // test.ok(apps); - // var appList = apps.list(); - - // Async.parallelEach( - // appList, - // function(app, idx, callback) { - // if (utils.startsWith(app.name, "jssdk_")) { - // app.remove(callback); - // } - // else { - // callback(); - // } - // }, function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }); - // }, + try{ + savedSearches_1.item(searchName, {app:'-'}); + test.ok(false); + } + catch(err){ + test.ok(err); + } - // "Callback#delete test users": function(test) { - // var users = this.service.users(); - // users.fetch(function(err, users) { - // var userList = users.list(); - - // Async.parallelEach( - // userList, - // function(user, idx, callback) { - // if (utils.startsWith(user.name, "jssdk_")) { - // user.remove(callback); - // } - // else { - // callback(); - // } - // }, function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }); - // } - // }, + try{ + savedSearches_1.item(searchName, {app:'-', owner:'-'}); + test.ok(false); + } + catch(err){ + test.ok(err); + } - // "Job Tests": { - // setUp: function(done) { - // this.service = svc; - // done(); - // }, + // Ensure we get the right entities from the -/1 namespace when we + // specify it. + var entity11 = savedSearches_1.item(searchName, that.namespace11); + var entity21 = savedSearches_1.item(searchName, that.namespace21); - // "Callback#Create+abort job": function(test) { - // var service = this.service; - // Async.chain([ - // function(done){ - // var app_name = path.join(process.env.SPLUNK_HOME, ('/etc/apps/sdk-app-collection/build/sleep_command.tar')); - // // Fix path on Windows if $SPLUNK_HOME contains a space (ex: C:/Program%20Files/Splunk) - // app_name = app_name.replace("%20", " "); - // service.post("apps/appinstall", {update:1, name:app_name}, done); - // }, - // function(done){ - // var sid = getNextId(); - // var options = {id: sid}; - // var jobs = service.jobs({app: "sdk-app-collection"}); - // var req = jobs.oneshotSearch('search index=_internal | head 1 | sleep 10', options, function(err, job) { - // test.ok(err); - // test.ok(!job); - // test.strictEqual(err.error, "abort"); - // test.done(); - // }); - - // Async.sleep(1000, function(){ - // req.abort(); - // }); - // } - // ], - // function(err){ - // test.ok(!err); - // test.done(); - // }); - // }, + test.ok(entity11); + test.strictEqual(entity11.name, searchName); + test.strictEqual(entity11.properties().search, search); + test.strictEqual(entity11.namespace.owner, that.namespace11.owner); + test.strictEqual(entity11.namespace.app, that.namespace11.app); - // "Callback#Create+cancel job": function(test) { - // var sid = getNextId(); - // this.service.jobs().search('search index=_internal | head 1', {id: sid}, function(err, job) { - // test.ok(job); - // test.strictEqual(job.sid, sid); + test.ok(entity21); + test.strictEqual(entity21.name, searchName); + test.strictEqual(entity21.properties().search, search); + test.strictEqual(entity21.namespace.owner, that.namespace21.owner); + test.strictEqual(entity21.namespace.app, that.namespace21.app); - // job.cancel(function() { - // test.done(); - // }); - // }); - // }, + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // "Callback#Create job error": function(test) { - // var sid = getNextId(); - // this.service.jobs().search({search: 'index=_internal | head 1', id: sid}, function(err) { - // test.ok(!!err); - // test.done(); - // }); - // }, + "Callback#delete test applications": function(test) { + var apps = this.service.apps(); + apps.fetch(function(err, apps) { + test.ok(!err); + test.ok(apps); + var appList = apps.list(); + + Async.parallelEach( + appList, + function(app, idx, callback) { + if (utils.startsWith(app.name, "jssdk_")) { + app.remove(callback); + } + else { + callback(); + } + }, function(err) { + test.ok(!err); + test.done(); + } + ); + }); + }, - // "Callback#List jobs": function(test) { - // this.service.jobs().fetch(function(err, jobs) { - // test.ok(!err); - // test.ok(jobs); + "Callback#delete test users": function(test) { + var users = this.service.users(); + users.fetch(function(err, users) { + var userList = users.list(); - // var jobsList = jobs.list(); - // test.ok(jobsList.length > 0); + Async.parallelEach( + userList, + function(user, idx, callback) { + if (utils.startsWith(user.name, "jssdk_")) { + user.remove(callback); + } + else { + callback(); + } + }, function(err) { + test.ok(!err); + test.done(); + } + ); + }); + } + }, - // for(var i = 0; i < jobsList.length; i++) { - // test.ok(jobsList[i]); - // } + "Job Tests": { + setUp: function(done) { + this.service = svc; + done(); + }, - // test.done(); - // }); - // }, + "Callback#Create+abort job": function(test) { + var service = this.service; + Async.chain([ + function(done){ + var app_name = path.join(process.env.SPLUNK_HOME, ('/etc/apps/sdk-app-collection/build/sleep_command.tar')); + // Fix path on Windows if $SPLUNK_HOME contains a space (ex: C:/Program%20Files/Splunk) + app_name = app_name.replace("%20", " "); + service.post("apps/appinstall", {update:1, name:app_name}, done); + }, + function(done){ + var sid = getNextId(); + var options = {id: sid}; + var jobs = service.jobs({app: "sdk-app-collection"}); + var req = jobs.oneshotSearch('search index=_internal | head 1 | sleep 10', options, function(err, job) { + test.ok(err); + test.ok(!job); + test.strictEqual(err.error, "abort"); + test.done(); + }); - // "Callback#Contains job": function(test) { - // var that = this; - // var sid = getNextId(); - // var jobs = this.service.jobs(); + Async.sleep(1000, function(){ + req.abort(); + }); + } + ], + function(err){ + test.ok(!err); + test.done(); + }); + }, - // jobs.search('search index=_internal | head 1', {id: sid}, function(err, job) { - // test.ok(!err); - // test.ok(job); - // test.strictEqual(job.sid, sid); + "Callback#Create+cancel job": function(test) { + var sid = getNextId(); + this.service.jobs().search('search index=_internal | head 1', {id: sid}, function(err, job) { + test.ok(job); + test.strictEqual(job.sid, sid); - // jobs.fetch(function(err, jobs) { - // test.ok(!err); - // var job = jobs.item(sid); - // test.ok(job); + job.cancel(function() { + test.done(); + }); + }); + }, - // job.cancel(function() { - // test.done(); - // }); - // }); - // }); - // }, + "Callback#Create job error": function(test) { + var sid = getNextId(); + this.service.jobs().search({search: 'index=_internal | head 1', id: sid}, function(err) { + test.ok(!!err); + test.done(); + }); + }, - // "Callback#job results": function(test) { - // var sid = getNextId(); - // var service = this.service; - // var that = this; + "Callback#List jobs": function(test) { + this.service.jobs().fetch(function(err, jobs) { + test.ok(!err); + test.ok(jobs); - // Async.chain([ - // function(done) { - // that.service.jobs().search('search index=_internal | head 1 | stats count', {id: sid}, done); - // }, - // function(job, done) { - // test.strictEqual(job.sid, sid); - // tutils.pollUntil( - // job, - // function(j) { - // return job.properties()["isDone"]; - // }, - // 10, - // done - // ); - // }, - // function(job, done) { - // job.results({}, done); - // }, - // function(results, job, done) { - // test.strictEqual(results.rows.length, 1); - // test.strictEqual(results.fields.length, 1); - // test.strictEqual(results.fields[0], "count"); - // test.strictEqual(results.rows[0][0], "1"); - // job.cancel(done); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + var jobsList = jobs.list(); + test.ok(jobsList.length > 0); - // "Callback#job events": function(test) { - // var sid = getNextId(); - // var service = this.service; - // var that = this; + for(var i = 0; i < jobsList.length; i++) { + test.ok(jobsList[i]); + } - // Async.chain([ - // function(done) { - // that.service.jobs().search('search index=_internal | head 1', {id: sid}, done); - // }, - // function(job, done) { - // test.strictEqual(job.sid, sid); - // tutils.pollUntil( - // job, - // function(j) { - // return job.properties()["isDone"]; - // }, - // 10, - // done - // ); - // }, - // function(job, done) { - // job.events({}, done); - // }, - // function(results, job, done) { - // test.strictEqual(results.rows.length, 1); - // test.strictEqual(results.fields.length, results.rows[0].length); - // job.cancel(done); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + test.done(); + }); + }, - // "Callback#job results preview": function(test) { - // var sid = getNextId(); - // var service = this.service; - // var that = this; + "Callback#Contains job": function(test) { + var that = this; + var sid = getNextId(); + var jobs = this.service.jobs(); - // Async.chain([ - // function(done) { - // that.service.jobs().search('search index=_internal | head 1 | stats count', {id: sid}, done); - // }, - // function(job, done) { - // test.strictEqual(job.sid, sid); - // tutils.pollUntil( - // job, - // function(j) { - // return job.properties()["isDone"]; - // }, - // 10, - // done - // ); - // }, - // function(job, done) { - // job.preview({}, done); - // }, - // function(results, job, done) { - // test.strictEqual(results.rows.length, 1); - // test.strictEqual(results.fields.length, 1); - // test.strictEqual(results.fields[0], "count"); - // test.strictEqual(results.rows[0][0], "1"); - // job.cancel(done); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + jobs.search('search index=_internal | head 1', {id: sid}, function(err, job) { + test.ok(!err); + test.ok(job); + test.strictEqual(job.sid, sid); - // "Callback#job results iterator": function(test) { - // var that = this; + jobs.fetch(function(err, jobs) { + test.ok(!err); + var job = jobs.item(sid); + test.ok(job); - // Async.chain([ - // function(done) { - // that.service.jobs().search('search index=_internal | head 10', {}, done); - // }, - // function(job, done) { - // tutils.pollUntil( - // job, - // function(j) { - // return job.properties()["isDone"]; - // }, - // 10, - // done - // ); - // }, - // function(job, done) { - // var iterator = job.iterator("results", { pagesize: 4 }); - // var hasMore = true; - // var numElements = 0; - // var pageSizes = []; - // Async.whilst( - // function() { return hasMore; }, - // function(nextIteration) { - // iterator.next(function(err, results, _hasMore) { - // if (err) { - // nextIteration(err); - // return; - // } - - // hasMore = _hasMore; - // if (hasMore) { - // pageSizes.push(results.rows.length); - // } - // nextIteration(); - // }); - // }, - // function(err) { - // test.deepEqual(pageSizes, [4,4,2]); - // done(err); - // } - // ); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + job.cancel(function() { + test.done(); + }); + }); + }); + }, - // "Callback#Enable + disable preview": function(test) { - // var that = this; - // var sid = getNextId(); + "Callback#job results": function(test) { + var sid = getNextId(); + var service = this.service; + var that = this; - // var service = this.service.specialize("nobody", "sdk-app-collection"); + Async.chain([ + function(done) { + that.service.jobs().search('search index=_internal | head 1 | stats count', {id: sid}, done); + }, + function(job, done) { + test.strictEqual(job.sid, sid); + tutils.pollUntil( + job, + function(j) { + return job.properties()["isDone"]; + }, + 10, + done + ); + }, + function(job, done) { + job.results({}, done); + }, + function(results, job, done) { + test.strictEqual(results.rows.length, 1); + test.strictEqual(results.fields.length, 1); + test.strictEqual(results.fields[0], "count"); + test.strictEqual(results.rows[0][0], "1"); + job.cancel(done); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // Async.chain([ - // function(done) { - // service.jobs().search('search index=_internal | head 1 | sleep 60', {id: sid}, done); - // }, - // function(job, done) { - // job.enablePreview(done); + "Callback#job events": function(test) { + var sid = getNextId(); + var service = this.service; + var that = this; - // }, - // function(job, done) { - // job.disablePreview(done); - // }, - // function(job, done) { - // job.cancel(done); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, - - // "Callback#Pause + unpause + finalize preview": function(test) { - // var that = this; - // var sid = getNextId(); - - // var service = this.service.specialize("nobody", "sdk-app-collection"); + Async.chain([ + function(done) { + that.service.jobs().search('search index=_internal | head 1', {id: sid}, done); + }, + function(job, done) { + test.strictEqual(job.sid, sid); + tutils.pollUntil( + job, + function(j) { + return job.properties()["isDone"]; + }, + 10, + done + ); + }, + function(job, done) { + job.events({}, done); + }, + function(results, job, done) { + test.strictEqual(results.rows.length, 1); + test.strictEqual(results.fields.length, results.rows[0].length); + job.cancel(done); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // Async.chain([ - // function(done) { - // service.jobs().search('search index=_internal | head 1 | sleep 5', {id: sid}, done); - // }, - // function(job, done) { - // job.pause(done); - // }, - // function(job, done) { - // tutils.pollUntil( - // job, - // function(j) { - // return j.properties()["isPaused"]; - // }, - // 10, - // done - // ); - // }, - // function(job, done) { - // test.ok(job.properties()["isPaused"]); - // job.unpause(done); - // }, - // function(job, done) { - // tutils.pollUntil( - // job, - // function(j) { - // return !j.properties()["isPaused"]; - // }, - // 10, - // done - // ); - // }, - // function(job, done) { - // test.ok(!job.properties()["isPaused"]); - // job.finalize(done); - // }, - // function(job, done) { - // job.cancel(done); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + "Callback#job results preview": function(test) { + var sid = getNextId(); + var service = this.service; + var that = this; - // "Callback#Set TTL": function(test) { - // var sid = getNextId(); - // var originalTTL = 0; - // var that = this; + Async.chain([ + function(done) { + that.service.jobs().search('search index=_internal | head 1 | stats count', {id: sid}, done); + }, + function(job, done) { + test.strictEqual(job.sid, sid); + tutils.pollUntil( + job, + function(j) { + return job.properties()["isDone"]; + }, + 10, + done + ); + }, + function(job, done) { + job.preview({}, done); + }, + function(results, job, done) { + test.strictEqual(results.rows.length, 1); + test.strictEqual(results.fields.length, 1); + test.strictEqual(results.fields[0], "count"); + test.strictEqual(results.rows[0][0], "1"); + job.cancel(done); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // Async.chain([ - // function(done) { - // that.service.jobs().search('search index=_internal | head 1', {id: sid}, done); - // }, - // function(job, done) { - // job.fetch(done); - // }, - // function(job, done) { - // var ttl = job.properties()["ttl"]; - // originalTTL = ttl; + "Callback#job results iterator": function(test) { + var that = this; - // job.setTTL(ttl*2, done); - // }, - // function(job, done) { - // job.fetch(done); - // }, - // function(job, done) { - // var ttl = job.properties()["ttl"]; - // test.ok(ttl > originalTTL); - // test.ok(ttl <= (originalTTL*2)); - // job.cancel(done); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + Async.chain([ + function(done) { + that.service.jobs().search('search index=_internal | head 10', {}, done); + }, + function(job, done) { + tutils.pollUntil( + job, + function(j) { + return job.properties()["isDone"]; + }, + 10, + done + ); + }, + function(job, done) { + var iterator = job.iterator("results", { pagesize: 4 }); + var hasMore = true; + var numElements = 0; + var pageSizes = []; + Async.whilst( + function() { return hasMore; }, + function(nextIteration) { + iterator.next(function(err, results, _hasMore) { + if (err) { + nextIteration(err); + return; + } + + hasMore = _hasMore; + if (hasMore) { + pageSizes.push(results.rows.length); + } + nextIteration(); + }); + }, + function(err) { + test.deepEqual(pageSizes, [4,4,2]); + done(err); + } + ); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // "Callback#Set priority": function(test) { - // var sid = getNextId(); - // var originalPriority = 0; - // var that = this; + "Callback#Enable + disable preview": function(test) { + var that = this; + var sid = getNextId(); - // var service = this.service.specialize("nobody", "sdk-app-collection"); + var service = this.service.specialize("nobody", "sdk-app-collection"); - // Async.chain([ - // function(done) { - // service.jobs().search('search index=_internal | head 1 | sleep 5', {id: sid}, done); - // }, - // function(job, done) { - // job.track({}, { - // ready: function(job) { - // done(null, job); - // } - // }); - // }, - // function(job, done) { - // var priority = job.properties()["priority"]; - // test.ok(priority, 5); - // job.setPriority(priority + 1, done); - // }, - // function(job, done) { - // job.fetch(done); - // }, - // function(job, done) { - // job.cancel(done); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + Async.chain([ + function(done) { + service.jobs().search('search index=_internal | head 1 | sleep 60', {id: sid}, done); + }, + function(job, done) { + job.enablePreview(done); - // "Callback#Search log": function(test) { - // var sid = getNextId(); - // var that = this; + }, + function(job, done) { + job.disablePreview(done); + }, + function(job, done) { + job.cancel(done); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // Async.chain([ - // function(done) { - // that.service.jobs().search('search index=_internal | head 1', {id: sid, exec_mode: "blocking"}, done); - // }, - // function(job, done) { - // job.searchlog(done); - // }, - // function(log, job, done) { - // test.ok(job); - // test.ok(log); - // test.ok(log.length > 0); - // test.ok(log.split("\r\n").length > 0); - // job.cancel(done); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + "Callback#Pause + unpause + finalize preview": function(test) { + var that = this; + var sid = getNextId(); - // "Callback#Search summary": function(test) { - // var sid = getNextId(); - // var that = this; + var service = this.service.specialize("nobody", "sdk-app-collection"); - // Async.chain([ - // function(done) { - // that.service.jobs().search( - // 'search index=_internal | head 1 | eval foo="bar" | fields foo', - // { - // id: sid, - // status_buckets: 300, - // rf: ["foo"] - // }, - // done); - // }, - // function(job, done) { - // // Let's sleep for 2 second so - // // we let the server catch up - // Async.sleep(2000, function() { - // job.summary({}, done); - // }); - // }, - // function(summary, job, done) { - // test.ok(job); - // test.ok(summary); - // test.strictEqual(summary.event_count, 1); - // test.strictEqual(summary.fields.foo.count, 1); - // test.strictEqual(summary.fields.foo.distinct_count, 1); - // test.ok(summary.fields.foo.is_exact, 1); - // test.strictEqual(summary.fields.foo.modes.length, 1); - // test.strictEqual(summary.fields.foo.modes[0].count, 1); - // test.strictEqual(summary.fields.foo.modes[0].value, "bar"); - // test.ok(summary.fields.foo.modes[0].is_exact); - // job.cancel(done); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + Async.chain([ + function(done) { + service.jobs().search('search index=_internal | head 1 | sleep 5', {id: sid}, done); + }, + function(job, done) { + job.pause(done); + }, + function(job, done) { + tutils.pollUntil( + job, + function(j) { + return j.properties()["isPaused"]; + }, + 10, + done + ); + }, + function(job, done) { + test.ok(job.properties()["isPaused"]); + job.unpause(done); + }, + function(job, done) { + tutils.pollUntil( + job, + function(j) { + return !j.properties()["isPaused"]; + }, + 10, + done + ); + }, + function(job, done) { + test.ok(!job.properties()["isPaused"]); + job.finalize(done); + }, + function(job, done) { + job.cancel(done); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // "Callback#Search timeline": function(test) { - // var sid = getNextId(); - // var that = this; + "Callback#Set TTL": function(test) { + var sid = getNextId(); + var originalTTL = 0; + var that = this; - // Async.chain([ - // function(done) { - // that.service.jobs().search( - // 'search index=_internal | head 1 | eval foo="bar" | fields foo', - // { - // id: sid, - // status_buckets: 300, - // rf: ["foo"], - // exec_mode: "blocking" - // }, - // done); - // }, - // function(job, done) { - // job.timeline({}, done); - // }, - // function(timeline, job, done) { - // test.ok(job); - // test.ok(timeline); - // test.strictEqual(timeline.buckets.length, 1); - // test.strictEqual(timeline.event_count, 1); - // test.strictEqual(timeline.buckets[0].available_count, 1); - // test.strictEqual(timeline.buckets[0].duration, 0.001); - // test.strictEqual(timeline.buckets[0].earliest_time_offset, timeline.buckets[0].latest_time_offset); - // test.strictEqual(timeline.buckets[0].total_count, 1); - // test.ok(timeline.buckets[0].is_finalized); - // job.cancel(done); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + Async.chain([ + function(done) { + that.service.jobs().search('search index=_internal | head 1', {id: sid}, done); + }, + function(job, done) { + job.fetch(done); + }, + function(job, done) { + var ttl = job.properties()["ttl"]; + originalTTL = ttl; - // "Callback#Touch": function(test) { - // var sid = getNextId(); - // var that = this; - // var originalTime = ""; + job.setTTL(ttl*2, done); + }, + function(job, done) { + job.fetch(done); + }, + function(job, done) { + var ttl = job.properties()["ttl"]; + test.ok(ttl > originalTTL); + test.ok(ttl <= (originalTTL*2)); + job.cancel(done); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // Async.chain([ - // function(done) { - // that.service.jobs().search('search index=_internal | head 1', {id: sid}, done); - // }, - // function(job, done) { - // job.fetch(done); - // }, - // function(job, done) { - // test.ok(job); - // originalTime = job.properties().updated; - // Async.sleep(1200, function() { job.touch(done); }); - // }, - // function(job, done) { - // job.fetch(done); - // }, - // function(job, done) { - // test.ok(originalTime !== job.updated()); - // job.cancel(done); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + "Callback#Set priority": function(test) { + var sid = getNextId(); + var originalPriority = 0; + var that = this; - // "Callback#Create failure": function(test) { - // var name = "jssdk_savedsearch_" + getNextId(); - // var originalSearch = "search index=_internal | head 1"; + var service = this.service.specialize("nobody", "sdk-app-collection"); - // var jobs = this.service.jobs(); - // test.throws(function() {jobs.create({search: originalSearch, name: name, exec_mode: "oneshot"}, function() {});}); - // test.done(); - // }, + Async.chain([ + function(done) { + service.jobs().search('search index=_internal | head 1 | sleep 5', {id: sid}, done); + }, + function(job, done) { + job.track({}, { + ready: function(job) { + done(null, job); + } + }); + }, + function(job, done) { + var priority = job.properties()["priority"]; + test.ok(priority, 5); + job.setPriority(priority + 1, done); + }, + function(job, done) { + job.fetch(done); + }, + function(job, done) { + job.cancel(done); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // "Callback#Create fails with no search string": function(test) { - // var jobs = this.service.jobs(); - // jobs.create( - // "", {}, - // function(err) { - // test.ok(err); - // test.done(); - // } - // ); - // }, + "Callback#Search log": function(test) { + var sid = getNextId(); + var that = this; - // "Callback#Oneshot search": function(test) { - // var sid = getNextId(); - // var that = this; - // var originalTime = ""; + Async.chain([ + function(done) { + that.service.jobs().search('search index=_internal | head 1', {id: sid, exec_mode: "blocking"}, done); + }, + function(job, done) { + job.searchlog(done); + }, + function(log, job, done) { + test.ok(job); + test.ok(log); + test.ok(log.length > 0); + test.ok(log.split("\r\n").length > 0); + job.cancel(done); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // Async.chain([ - // function(done) { - // that.service.jobs().oneshotSearch('search index=_internal | head 1 | stats count', {id: sid}, done); - // }, - // function(results, done) { - // test.ok(results); - // test.ok(results.fields); - // test.strictEqual(results.fields.length, 1); - // test.strictEqual(results.fields[0], "count"); - // test.ok(results.rows); - // test.strictEqual(results.rows.length, 1); - // test.strictEqual(results.rows[0].length, 1); - // test.strictEqual(results.rows[0][0], "1"); + "Callback#Search summary": function(test) { + var sid = getNextId(); + var that = this; - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + Async.chain([ + function(done) { + that.service.jobs().search( + 'search index=_internal | head 1 | eval foo="bar" | fields foo', + { + id: sid, + status_buckets: 300, + rf: ["foo"] + }, + done); + }, + function(job, done) { + // Let's sleep for 2 second so + // we let the server catch up + Async.sleep(2000, function() { + job.summary({}, done); + }); + }, + function(summary, job, done) { + test.ok(job); + test.ok(summary); + test.strictEqual(summary.event_count, 1); + test.strictEqual(summary.fields.foo.count, 1); + test.strictEqual(summary.fields.foo.distinct_count, 1); + test.ok(summary.fields.foo.is_exact, 1); + test.strictEqual(summary.fields.foo.modes.length, 1); + test.strictEqual(summary.fields.foo.modes[0].count, 1); + test.strictEqual(summary.fields.foo.modes[0].value, "bar"); + test.ok(summary.fields.foo.modes[0].is_exact); + job.cancel(done); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // "Callback#Oneshot search with no results": function(test) { - // var sid = getNextId(); - // var that = this; - // var originalTime = ""; + "Callback#Search timeline": function(test) { + var sid = getNextId(); + var that = this; - // Async.chain([ - // function(done) { - // var query = 'search index=history MUST_NOT_EXISTABCDEF'; - // that.service.jobs().oneshotSearch(query, {id: sid}, done); - // }, - // function(results, done) { - // test.ok(results); - // test.strictEqual(results.fields.length, 0); - // test.strictEqual(results.rows.length, 0); - // test.ok(!results.preview); + Async.chain([ + function(done) { + that.service.jobs().search( + 'search index=_internal | head 1 | eval foo="bar" | fields foo', + { + id: sid, + status_buckets: 300, + rf: ["foo"], + exec_mode: "blocking" + }, + done); + }, + function(job, done) { + job.timeline({}, done); + }, + function(timeline, job, done) { + test.ok(job); + test.ok(timeline); + test.strictEqual(timeline.buckets.length, 1); + test.strictEqual(timeline.event_count, 1); + test.strictEqual(timeline.buckets[0].available_count, 1); + test.strictEqual(timeline.buckets[0].duration, 0.001); + test.strictEqual(timeline.buckets[0].earliest_time_offset, timeline.buckets[0].latest_time_offset); + test.strictEqual(timeline.buckets[0].total_count, 1); + test.ok(timeline.buckets[0].is_finalized); + job.cancel(done); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + "Callback#Touch": function(test) { + var sid = getNextId(); + var that = this; + var originalTime = ""; - // "Callback#Service oneshot search": function(test) { - // var sid = getNextId(); - // var that = this; - // var namespace = {owner: "admin", app: "search"}; - // var splunkVersion = 6.1; // Default to pre-6.2 version - // var originalLoggerLevel = "DEBUG"; + Async.chain([ + function(done) { + that.service.jobs().search('search index=_internal | head 1', {id: sid}, done); + }, + function(job, done) { + job.fetch(done); + }, + function(job, done) { + test.ok(job); + originalTime = job.properties().updated; + Async.sleep(1200, function() { job.touch(done); }); + }, + function(job, done) { + job.fetch(done); + }, + function(job, done) { + test.ok(originalTime !== job.updated()); + job.cancel(done); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // Async.chain([ - // function(done) { - // // If running on Splunk 6.2+, first set the search logger level to DEBUG - // Async.chain([ - // function(done1) { - // that.service.serverInfo(done1); - // }, - // function(info, done1) { - // splunkVersion = parseFloat(info.properties().version); - // if (splunkVersion < 6.2) { - // done(); // Exit the inner Async.chain - // } - // else { - // done1(); - // } - // }, - // function(done1) { - // that.service.configurations({owner: "admin", app: "search"}).fetch(done1); - // }, - // function(confs, done1) { - // try { - // confs.item("limits").fetch(done1); - // } - // catch(e) { - // done1(e); - // } - // }, - // function(conf, done1) { - // var searchInfo = conf.item("search_info"); - // // Save this so it can be restored later - // originalLoggerLevel = searchInfo.properties()["infocsv_log_level"]; - // searchInfo.update({"infocsv_log_level": "DEBUG"}, done1); - // }, - // function(conf, done1) { - // test.strictEqual("DEBUG", conf.properties()["infocsv_log_level"]); - // done1(); - // } - // ], - // function(err) { - // test.ok(!err); - // done(); - // } - // ); - // }, - // function(done) { - // that.service.oneshotSearch('search index=_internal | head 1 | stats count', {id: sid}, namespace, done); - // }, - // function(results, done) { - // test.ok(results); - // test.ok(results.fields); - // test.strictEqual(results.fields.length, 1); - // test.strictEqual(results.fields[0], "count"); - // test.ok(results.rows); - // test.strictEqual(results.rows.length, 1); - // test.strictEqual(results.rows[0].length, 1); - // test.strictEqual(results.rows[0][0], "1"); - // test.ok(results.messages[1].text.indexOf('owner="admin"')); - // test.ok(results.messages[1].text.indexOf('app="search"')); + "Callback#Create failure": function(test) { + var name = "jssdk_savedsearch_" + getNextId(); + var originalSearch = "search index=_internal | head 1"; - // done(); - // }, - // function(done) { - // Async.chain([ - // function(done1) { - // if (splunkVersion < 6.2) { - // done(); // Exit the inner Async.chain - // } - // else { - // done1(); - // } - // }, - // function(done1) { - // that.service.configurations({owner: "admin", app: "search"}).fetch(done1); - // }, - // function(confs, done1) { - // try { - // confs.item("limits").fetch(done1); - // } - // catch(e) { - // done1(e); - // } - // }, - // function(conf, done1) { - // var searchInfo = conf.item("search_info"); - // // Restore the logger level from before - // searchInfo.update({"infocsv_log_level": originalLoggerLevel}, done1); - // }, - // function(conf, done1) { - // test.strictEqual(originalLoggerLevel, conf.properties()["infocsv_log_level"]); - // done1(); - // } - // ], - // function(err) { - // test.ok(!err); - // done(); - // } - // ); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + var jobs = this.service.jobs(); + test.throws(function() {jobs.create({search: originalSearch, name: name, exec_mode: "oneshot"}, function() {});}); + test.done(); + }, - // "Callback#Service search": function(test) { - // var sid = getNextId(); - // var service = this.service; - // var that = this; - // var namespace = {owner: "admin", app: "search"}; + "Callback#Create fails with no search string": function(test) { + var jobs = this.service.jobs(); + jobs.create( + "", {}, + function(err) { + test.ok(err); + test.done(); + } + ); + }, - // Async.chain([ - // function(done) { - // that.service.search('search index=_internal | head 1 | stats count', {id: sid}, namespace, done); - // }, - // function(job, done) { - // test.strictEqual(job.sid, sid); - // test.strictEqual(job.namespace, namespace); - // tutils.pollUntil( - // job, - // function(j) { - // return job.properties()["isDone"]; - // }, - // 10, - // done - // ); - // }, - // function(job, done) { - // job.results({}, done); - // }, - // function(results, job, done) { - // test.strictEqual(results.rows.length, 1); - // test.strictEqual(results.fields.length, 1); - // test.strictEqual(results.fields[0], "count"); - // test.strictEqual(results.rows[0][0], "1"); - // job.cancel(done); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + "Callback#Oneshot search": function(test) { + var sid = getNextId(); + var that = this; + var originalTime = ""; - // "Callback#Wait until job done": function(test) { - // this.service.search('search index=_internal | head 1000', {}, function(err, job) { - // test.ok(!err); + Async.chain([ + function(done) { + that.service.jobs().oneshotSearch('search index=_internal | head 1 | stats count', {id: sid}, done); + }, + function(results, done) { + test.ok(results); + test.ok(results.fields); + test.strictEqual(results.fields.length, 1); + test.strictEqual(results.fields[0], "count"); + test.ok(results.rows); + test.strictEqual(results.rows.length, 1); + test.strictEqual(results.rows[0].length, 1); + test.strictEqual(results.rows[0][0], "1"); - // var numReadyEvents = 0; - // var numProgressEvents = 0; - // job.track({ period: 200 }, { - // ready: function(job) { - // test.ok(job); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // numReadyEvents++; - // }, - // progress: function(job) { - // test.ok(job); + "Callback#Oneshot search with no results": function(test) { + var sid = getNextId(); + var that = this; + var originalTime = ""; - // numProgressEvents++; - // }, - // done: function(job) { - // test.ok(job); + Async.chain([ + function(done) { + var query = 'search index=history MUST_NOT_EXISTABCDEF'; + that.service.jobs().oneshotSearch(query, {id: sid}, done); + }, + function(results, done) { + test.ok(results); + test.strictEqual(results.fields.length, 0); + test.strictEqual(results.rows.length, 0); + test.ok(!results.preview); - // test.ok(numReadyEvents === 1); // all done jobs must have become ready - // test.ok(numProgressEvents >= 1); // a job that becomes ready has progress - // test.done(); - // }, - // failed: function(job) { - // test.ok(job); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // test.ok(false, "Job failed unexpectedly."); - // test.done(); - // }, - // error: function(err) { - // test.ok(err); + "Callback#Service oneshot search": function(test) { + var sid = getNextId(); + var that = this; + var namespace = {owner: "admin", app: "search"}; + var splunkVersion = 6.1; // Default to pre-6.2 version + var originalLoggerLevel = "DEBUG"; - // test.ok(false, "Error while tracking job."); - // test.done(); - // } - // }); - // }); - // }, + Async.chain([ + function(done) { + // If running on Splunk 6.2+, first set the search logger level to DEBUG + Async.chain([ + function(done1) { + that.service.serverInfo(done1); + }, + function(info, done1) { + splunkVersion = parseFloat(info.properties().version); + if (splunkVersion < 6.2) { + done(); // Exit the inner Async.chain + } + else { + done1(); + } + }, + function(done1) { + that.service.configurations({owner: "admin", app: "search"}).fetch(done1); + }, + function(confs, done1) { + try { + confs.item("limits").fetch(done1); + } + catch(e) { + done1(e); + } + }, + function(conf, done1) { + var searchInfo = conf.item("search_info"); + // Save this so it can be restored later + originalLoggerLevel = searchInfo.properties()["infocsv_log_level"]; + searchInfo.update({"infocsv_log_level": "DEBUG"}, done1); + }, + function(conf, done1) { + test.strictEqual("DEBUG", conf.properties()["infocsv_log_level"]); + done1(); + } + ], + function(err) { + test.ok(!err); + done(); + } + ); + }, + function(done) { + that.service.oneshotSearch('search index=_internal | head 1 | stats count', {id: sid}, namespace, done); + }, + function(results, done) { + test.ok(results); + test.ok(results.fields); + test.strictEqual(results.fields.length, 1); + test.strictEqual(results.fields[0], "count"); + test.ok(results.rows); + test.strictEqual(results.rows.length, 1); + test.strictEqual(results.rows[0].length, 1); + test.strictEqual(results.rows[0][0], "1"); + test.ok(results.messages[1].text.indexOf('owner="admin"')); + test.ok(results.messages[1].text.indexOf('app="search"')); - // "Callback#Wait until job failed": function(test) { - // this.service.search('search index=_internal | head bogusarg', {}, function(err, job) { - // if (err) { - // test.ok(!err); - // test.done(); - // return; - // } + done(); + }, + function(done) { + Async.chain([ + function(done1) { + if (splunkVersion < 6.2) { + done(); // Exit the inner Async.chain + } + else { + done1(); + } + }, + function(done1) { + that.service.configurations({owner: "admin", app: "search"}).fetch(done1); + }, + function(confs, done1) { + try { + confs.item("limits").fetch(done1); + } + catch(e) { + done1(e); + } + }, + function(conf, done1) { + var searchInfo = conf.item("search_info"); + // Restore the logger level from before + searchInfo.update({"infocsv_log_level": originalLoggerLevel}, done1); + }, + function(conf, done1) { + test.strictEqual(originalLoggerLevel, conf.properties()["infocsv_log_level"]); + done1(); + } + ], + function(err) { + test.ok(!err); + done(); + } + ); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // var numReadyEvents = 0; - // var numProgressEvents = 0; - // job.track({ period: 200 }, { - // ready: function(job) { - // test.ok(job); + "Callback#Service search": function(test) { + var sid = getNextId(); + var service = this.service; + var that = this; + var namespace = {owner: "admin", app: "search"}; - // numReadyEvents++; - // }, - // progress: function(job) { - // test.ok(job); + Async.chain([ + function(done) { + that.service.search('search index=_internal | head 1 | stats count', {id: sid}, namespace, done); + }, + function(job, done) { + test.strictEqual(job.sid, sid); + test.strictEqual(job.namespace, namespace); + tutils.pollUntil( + job, + function(j) { + return job.properties()["isDone"]; + }, + 10, + done + ); + }, + function(job, done) { + job.results({}, done); + }, + function(results, job, done) { + test.strictEqual(results.rows.length, 1); + test.strictEqual(results.fields.length, 1); + test.strictEqual(results.fields[0], "count"); + test.strictEqual(results.rows[0][0], "1"); + job.cancel(done); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // numProgressEvents++; - // }, - // done: function(job) { - // test.ok(job); + "Callback#Wait until job done": function(test) { + this.service.search('search index=_internal | head 1000', {}, function(err, job) { + test.ok(!err); - // test.ok(false, "Job became done unexpectedly."); - // test.done(); - // }, - // failed: function(job) { - // test.ok(job); + var numReadyEvents = 0; + var numProgressEvents = 0; + job.track({ period: 200 }, { + ready: function(job) { + test.ok(job); - // test.ok(numReadyEvents === 1); // even failed jobs become ready - // test.ok(numProgressEvents >= 1); // a job that becomes ready has progress - // test.done(); - // }, - // error: function(err) { - // test.ok(err); + numReadyEvents++; + }, + progress: function(job) { + test.ok(job); - // test.ok(false, "Error while tracking job."); - // test.done(); - // } - // }); - // }); - // }, + numProgressEvents++; + }, + done: function(job) { + test.ok(job); - // "Callback#track() with default params and one function": function(test) { - // this.service.search('search index=_internal | head 1', {}, function(err, job) { - // if (err) { - // test.ok(!err); - // test.done(); - // return; - // } + test.ok(numReadyEvents === 1); // all done jobs must have become ready + test.ok(numProgressEvents >= 1); // a job that becomes ready has progress + test.done(); + }, + failed: function(job) { + test.ok(job); - // job.track({}, function(job) { - // test.ok(job); - // test.done(); - // }); - // }); - // }, + test.ok(false, "Job failed unexpectedly."); + test.done(); + }, + error: function(err) { + test.ok(err); - // "Callback#track() should stop polling if only the ready callback is specified": function(test) { - // this.service.search('search index=_internal | head 1', {}, function(err, job) { - // if (err) { - // test.ok(!err); - // test.done(); - // return; - // } + test.ok(false, "Error while tracking job."); + test.done(); + } + }); + }); + }, - // job.track({}, { - // ready: function(job) { - // test.ok(job); - // }, + "Callback#Wait until job failed": function(test) { + this.service.search('search index=_internal | head bogusarg', {}, function(err, job) { + if (err) { + test.ok(!err); + test.done(); + return; + } - // _stoppedAfterReady: function(job) { - // test.done(); - // } - // }); - // }); - // }, + var numReadyEvents = 0; + var numProgressEvents = 0; + job.track({ period: 200 }, { + ready: function(job) { + test.ok(job); - // "Callback#track() a job that is not immediately ready": function(test) { - // /*jshint loopfunc:true */ - // var numJobs = 20; - // var numJobsLeft = numJobs; - // var gotJobNotImmediatelyReady = false; - // for (var i = 0; i < numJobs; i++) { - // this.service.search('search index=_internal | head 10000', {}, function(err, job) { - // if (err) { - // test.ok(!err); - // test.done(); - // return; - // } + numReadyEvents++; + }, + progress: function(job) { + test.ok(job); - // job.track({}, { - // _preready: function(job) { - // gotJobNotImmediatelyReady = true; - // }, - - // ready: function(job) { - // numJobsLeft--; - - // if (numJobsLeft === 0) { - // if (!gotJobNotImmediatelyReady) { - // splunkjs.Logger.error("", "WARNING: Couldn't test code path in track() where job wasn't ready immediately."); - // } - // test.done(); - // } - // } - // }); - // }); - // } - // }, + numProgressEvents++; + }, + done: function(job) { + test.ok(job); - // "Callback#Service.getJob() works": function(test) { - // var that = this; - // var sidsMatch = false; - // this.service.search('search index=_internal | head 1', {}, function(err, job){ - // if (err) { - // test.ok(!err); - // test.done(); - // return; - // } - // var sid = job.sid; - // return Async.chain([ - // function(done) { - // that.service.getJob(sid, done); - // }, - // function(innerJob, done) { - // test.strictEqual(sid, innerJob.sid); - // sidsMatch = sid === innerJob.sid; - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.ok(sidsMatch); - // test.done(); - // } - // ); - // }); - // } - // }, + test.ok(false, "Job became done unexpectedly."); + test.done(); + }, + failed: function(job) { + test.ok(job); - // "Data Model tests": { - // setUp: function(done) { - // this.service = svc; - // this.dataModels = svc.dataModels(); - // this.skip = false; - // var that = this; - // this.service.serverInfo(function(err, info) { - // if (parseInt(info.properties().version.split(".")[0], 10) < 6) { - // that.skip = true; - // splunkjs.Logger.log("Skipping data model tests..."); - // } - // done(err); - // }); - // }, + test.ok(numReadyEvents === 1); // even failed jobs become ready + test.ok(numProgressEvents >= 1); // a job that becomes ready has progress + test.done(); + }, + error: function(err) { + test.ok(err); - // "Callback#DataModels - fetch a built-in data model": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.fetch(done); - // }, - // function(dataModels, done) { - // var dm = dataModels.item("internal_audit_logs"); - // // Check for the 3 objects we expect - // test.ok(dm.objectByName("Audit")); - // test.ok(dm.objectByName("searches")); - // test.ok(dm.objectByName("modify")); - - // // Check for an object that shouldn't exist - // test.strictEqual(null, dm.objectByName(getNextId())); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + test.ok(false, "Error while tracking job."); + test.done(); + } + }); + }); + }, - // "Callback#DataModels - create & delete an empty data model": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/empty_data_model.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var name = "delete-me-" + getNextId(); + "Callback#track() with default params and one function": function(test) { + this.service.search('search index=_internal | head 1', {}, function(err, job) { + if (err) { + test.ok(!err); + test.done(); + return; + } - // var initialSize; - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.fetch(done); - // }, - // function(dataModels, done) { - // initialSize = dataModels.list().length; - // dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // that.dataModels.fetch(done); - // }, - // function(dataModels, done) { - // // Make sure we have 1 more data model than we started with - // test.strictEqual(initialSize + 1, dataModels.list().length); - // // Delete the data model we just created, by name. - // dataModels.item(name).remove(done); - // }, - // function(done) { - // that.dataModels.fetch(done); - // }, - // function(dataModels, done) { - // // Make sure we have as many data models as we started with - // test.strictEqual(initialSize, dataModels.list().length); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + job.track({}, function(job) { + test.ok(job); + test.done(); + }); + }); + }, - // "Callback#DataModels - create a data model with spaces in the name, which are swapped for -'s": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/empty_data_model.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var name = "delete-me- " + getNextId(); + "Callback#track() should stop polling if only the ready callback is specified": function(test) { + this.service.search('search index=_internal | head 1', {}, function(err, job) { + if (err) { + test.ok(!err); + test.done(); + return; + } - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // test.strictEqual(name.replace(" ", "_"), dataModel.name); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + job.track({}, { + ready: function(job) { + test.ok(job); + }, - // "Callback#DataModels - create a data model with 0 objects": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/empty_data_model.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var name = "delete-me-" + getNextId(); + _stoppedAfterReady: function(job) { + test.done(); + } + }); + }); + }, - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // // Check for 0 objects before fetch - // test.strictEqual(0, dataModel.objects.length); - // that.dataModels.fetch(done); - // }, - // function(dataModels, done) { - // // Check for 0 objects after fetch - // test.strictEqual(0, dataModels.item(name).objects.length); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + "Callback#track() a job that is not immediately ready": function(test) { + /*jshint loopfunc:true */ + var numJobs = 20; + var numJobsLeft = numJobs; + var gotJobNotImmediatelyReady = false; + for (var i = 0; i < numJobs; i++) { + this.service.search('search index=_internal | head 10000', {}, function(err, job) { + if (err) { + test.ok(!err); + test.done(); + return; + } - // "Callback#DataModels - create a data model with 1 search object": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var dataModels = this.service.dataModels(); + job.track({}, { + _preready: function(job) { + gotJobNotImmediatelyReady = true; + }, + ready: function(job) { + numJobsLeft--; - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/object_with_one_search.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var name = "delete-me-" + getNextId(); + if (numJobsLeft === 0) { + if (!gotJobNotImmediatelyReady) { + splunkjs.Logger.error("", "WARNING: Couldn't test code path in track() where job wasn't ready immediately."); + } + test.done(); + } + } + }); + }); + } + }, - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // // Check for 1 object before fetch - // test.strictEqual(1, dataModel.objects.length); - // that.dataModels.fetch(done); - // }, - // function(dataModels, done) { - // // Check for 1 object after fetch - // test.strictEqual(1, dataModels.item(name).objects.length); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + "Callback#Service.getJob() works": function(test) { + var that = this; + var sidsMatch = false; + this.service.search('search index=_internal | head 1', {}, function(err, job){ + if (err) { + test.ok(!err); + test.done(); + return; + } + var sid = job.sid; + return Async.chain([ + function(done) { + that.service.getJob(sid, done); + }, + function(innerJob, done) { + test.strictEqual(sid, innerJob.sid); + sidsMatch = sid === innerJob.sid; + done(); + } + ], + function(err) { + test.ok(!err); + test.ok(sidsMatch); + test.done(); + } + ); + }); + } + }, - // "Callback#DataModels - create a data model with 2 search objects": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/object_with_two_searches.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var name = "delete-me-" + getNextId(); + "Data Model tests": { + setUp: function(done) { + this.service = svc; + this.dataModels = svc.dataModels(); + this.skip = false; + var that = this; + this.service.serverInfo(function(err, info) { + if (parseInt(info.properties().version.split(".")[0], 10) < 6) { + that.skip = true; + splunkjs.Logger.log("Skipping data model tests..."); + } + done(err); + }); + }, - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // // Check for 2 objects before fetch - // test.strictEqual(2, dataModel.objects.length); - // that.dataModels.fetch(done); - // }, - // function(dataModels, done) { - // // Check for 2 objects after fetch - // test.strictEqual(2, dataModels.item(name).objects.length); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + "Callback#DataModels - fetch a built-in data model": function(test) { + if (this.skip) { + test.done(); + return; + } + var that = this; + Async.chain([ + function(done) { + that.dataModels.fetch(done); + }, + function(dataModels, done) { + var dm = dataModels.item("internal_audit_logs"); + // Check for the 3 objects we expect + test.ok(dm.objectByName("Audit")); + test.ok(dm.objectByName("searches")); + test.ok(dm.objectByName("modify")); + + // Check for an object that shouldn't exist + test.strictEqual(null, dm.objectByName(getNextId())); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // "Callback#DataModels - data model objects are created correctly": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/object_with_two_searches.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var name = "delete-me-" + getNextId(); + "Callback#DataModels - create & delete an empty data model": function(test) { + if (this.skip) { + test.done(); + return; + } + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/empty_data_model.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var name = "delete-me-" + getNextId(); - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // test.ok(dataModel.hasObject("search1")); - // test.ok(dataModel.hasObject("search2")); + var initialSize; + var that = this; + Async.chain([ + function(done) { + that.dataModels.fetch(done); + }, + function(dataModels, done) { + initialSize = dataModels.list().length; + dataModels.create(name, args, done); + }, + function(dataModel, done) { + that.dataModels.fetch(done); + }, + function(dataModels, done) { + // Make sure we have 1 more data model than we started with + test.strictEqual(initialSize + 1, dataModels.list().length); + // Delete the data model we just created, by name. + dataModels.item(name).remove(done); + }, + function(done) { + that.dataModels.fetch(done); + }, + function(dataModels, done) { + // Make sure we have as many data models as we started with + test.strictEqual(initialSize, dataModels.list().length); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // var search1 = dataModel.objectByName("search1"); - // test.ok(search1); - // test.strictEqual("‡Øµ‡Ø±‡Ø∞‡ØØ - search 1", search1.displayName); + "Callback#DataModels - create a data model with spaces in the name, which are swapped for -'s": function(test) { + if (this.skip) { + test.done(); + return; + } + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/empty_data_model.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var name = "delete-me- " + getNextId(); - // var search2 = dataModel.objectByName("search2"); - // test.ok(search2); - // test.strictEqual("‡Øµ‡Ø±‡Ø∞‡ØØ - search 2", search2.displayName); + var that = this; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + test.strictEqual(name.replace(" ", "_"), dataModel.name); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + "Callback#DataModels - create a data model with 0 objects": function(test) { + if (this.skip) { + test.done(); + return; + } + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/empty_data_model.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var name = "delete-me-" + getNextId(); - // "Callback#DataModels - data model handles unicode characters": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/model_with_unicode_headers.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var name = "delete-me-" + getNextId(); - - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // test.strictEqual(name, dataModel.name); - // test.strictEqual("·Ä©·öô‡Øµ", dataModel.displayName); - // test.strictEqual("‡Øµ‡Ø±‡Ø∞‡ØØ", dataModel.description); + var that = this; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + // Check for 0 objects before fetch + test.strictEqual(0, dataModel.objects.length); + that.dataModels.fetch(done); + }, + function(dataModels, done) { + // Check for 0 objects after fetch + test.strictEqual(0, dataModels.item(name).objects.length); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + "Callback#DataModels - create a data model with 1 search object": function(test) { + if (this.skip) { + test.done(); + return; + } + var dataModels = this.service.dataModels(); - // "Callback#DataModels - create data model with empty headers": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/model_with_empty_headers.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var name = "delete-me-" + getNextId(); - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // test.strictEqual(name, dataModel.name); - // test.strictEqual("", dataModel.displayName); - // test.strictEqual("", dataModel.description); + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/object_with_one_search.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var name = "delete-me-" + getNextId(); - // // Make sure we're not getting a summary of the data model - // test.strictEqual("0", dataModel.concise); + var that = this; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + // Check for 1 object before fetch + test.strictEqual(1, dataModel.objects.length); + that.dataModels.fetch(done); + }, + function(dataModels, done) { + // Check for 1 object after fetch + test.strictEqual(1, dataModels.item(name).objects.length); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + "Callback#DataModels - create a data model with 2 search objects": function(test) { + if (this.skip) { + test.done(); + return; + } + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/object_with_two_searches.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var name = "delete-me-" + getNextId(); - // "Callback#DataModels - test acceleration settings": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/data_model_with_test_objects.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var name = "delete-me-" + getNextId(); + var that = this; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + // Check for 2 objects before fetch + test.strictEqual(2, dataModel.objects.length); + that.dataModels.fetch(done); + }, + function(dataModels, done) { + // Check for 2 objects after fetch + test.strictEqual(2, dataModels.item(name).objects.length); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // dataModel.acceleration.enabled = true; - // dataModel.acceleration.earliestTime = "-2mon"; - // dataModel.acceleration.cronSchedule = "5/* * * * *"; + "Callback#DataModels - data model objects are created correctly": function(test) { + if (this.skip) { + test.done(); + return; + } + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/object_with_two_searches.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var name = "delete-me-" + getNextId(); - // test.strictEqual(true, dataModel.isAccelerated()); - // test.strictEqual(true, dataModel.acceleration.enabled); - // test.strictEqual("-2mon", dataModel.acceleration.earliestTime); - // test.strictEqual("5/* * * * *", dataModel.acceleration.cronSchedule); + var that = this; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + test.ok(dataModel.hasObject("search1")); + test.ok(dataModel.hasObject("search2")); - // dataModel.acceleration.enabled = false; - // dataModel.acceleration.earliestTime = "-1mon"; - // dataModel.acceleration.cronSchedule = "* * * * *"; + var search1 = dataModel.objectByName("search1"); + test.ok(search1); + test.strictEqual("‡Øµ‡Ø±‡Ø∞‡ØØ - search 1", search1.displayName); - // test.strictEqual(false, dataModel.isAccelerated()); - // test.strictEqual(false, dataModel.acceleration.enabled); - // test.strictEqual("-1mon", dataModel.acceleration.earliestTime); - // test.strictEqual("* * * * *", dataModel.acceleration.cronSchedule); + var search2 = dataModel.objectByName("search2"); + test.ok(search2); + test.strictEqual("‡Øµ‡Ø±‡Ø∞‡ØØ - search 2", search2.displayName); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // "Callback#DataModels - test data model object metadata": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/data_model_with_test_objects.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var name = "delete-me-" + getNextId(); + "Callback#DataModels - data model handles unicode characters": function(test) { + if (this.skip) { + test.done(); + return; + } + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/model_with_unicode_headers.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var name = "delete-me-" + getNextId(); - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // var obj = dataModel.objectByName("event1"); - // test.ok(obj); + var that = this; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + test.strictEqual(name, dataModel.name); + test.strictEqual("·Ä©·öô‡Øµ", dataModel.displayName); + test.strictEqual("‡Øµ‡Ø±‡Ø∞‡ØØ", dataModel.description); - // test.strictEqual("event1 ·Ä©·öô", obj.displayName); - // test.strictEqual("event1", obj.name); - // test.same(dataModel, obj.dataModel); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + "Callback#DataModels - create data model with empty headers": function(test) { + if (this.skip) { + test.done(); + return; + } + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/model_with_empty_headers.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var name = "delete-me-" + getNextId(); - // "Callback#DataModels - test data model object parent": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/data_model_with_test_objects.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var name = "delete-me-" + getNextId(); + var that = this; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + test.strictEqual(name, dataModel.name); + test.strictEqual("", dataModel.displayName); + test.strictEqual("", dataModel.description); - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // var obj = dataModel.objectByName("event1"); - // test.ok(obj); - // test.ok(!obj.parent()); + // Make sure we're not getting a summary of the data model + test.strictEqual("0", dataModel.concise); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // "Callback#DataModels - test data model object lineage": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/inheritance_test_data.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var name = "delete-me-" + getNextId(); + "Callback#DataModels - test acceleration settings": function(test) { + if (this.skip) { + test.done(); + return; + } + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/data_model_with_test_objects.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var name = "delete-me-" + getNextId(); - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // var obj = dataModel.objectByName("level_0"); - // test.ok(obj); - // test.strictEqual(1, obj.lineage.length); - // test.strictEqual("level_0", obj.lineage[0]); - // test.strictEqual("BaseEvent", obj.parentName); - - // obj = dataModel.objectByName("level_1"); - // test.ok(obj); - // test.strictEqual(2, obj.lineage.length); - // test.same(["level_0", "level_1"], obj.lineage); - // test.strictEqual("level_0", obj.parentName); - - // obj = dataModel.objectByName("level_2"); - // test.ok(obj); - // test.strictEqual(3, obj.lineage.length); - // test.same(["level_0", "level_1", "level_2"], obj.lineage); - // test.strictEqual("level_1", obj.parentName); - - // // Make sure there's no extra children - // test.ok(!dataModel.objectByName("level_3")); + var that = this; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + dataModel.acceleration.enabled = true; + dataModel.acceleration.earliestTime = "-2mon"; + dataModel.acceleration.cronSchedule = "5/* * * * *"; - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + test.strictEqual(true, dataModel.isAccelerated()); + test.strictEqual(true, dataModel.acceleration.enabled); + test.strictEqual("-2mon", dataModel.acceleration.earliestTime); + test.strictEqual("5/* * * * *", dataModel.acceleration.cronSchedule); - // "Callback#DataModels - test data model object fields": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/inheritance_test_data.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var name = "delete-me-" + getNextId(); + dataModel.acceleration.enabled = false; + dataModel.acceleration.earliestTime = "-1mon"; + dataModel.acceleration.cronSchedule = "* * * * *"; - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // var obj = dataModel.objectByName("level_2"); - // test.ok(obj); - - // var timeField = obj.fieldByName("_time"); - // test.ok(timeField); - // test.strictEqual("timestamp", timeField.type); - // test.ok(timeField.isTimestamp()); - // test.ok(!timeField.isNumber()); - // test.ok(!timeField.isString()); - // test.ok(!timeField.isObjectcount()); - // test.ok(!timeField.isChildcount()); - // test.ok(!timeField.isIPv4()); - // test.same(["BaseEvent"], timeField.lineage); - // test.strictEqual("_time", timeField.name); - // test.strictEqual(false, timeField.required); - // test.strictEqual(false, timeField.multivalued); - // test.strictEqual(false, timeField.hidden); - // test.strictEqual(false, timeField.editable); - // test.strictEqual(null, timeField.comment); - - // var lvl2 = obj.fieldByName("level_2"); - // test.strictEqual("level_2", lvl2.owner); - // test.same(["level_0", "level_1", "level_2"], lvl2.lineage); - // test.strictEqual("objectCount", lvl2.type); - // test.ok(!lvl2.isTimestamp()); - // test.ok(!lvl2.isNumber()); - // test.ok(!lvl2.isString()); - // test.ok(lvl2.isObjectcount()); - // test.ok(!lvl2.isChildcount()); - // test.ok(!lvl2.isIPv4()); - // test.strictEqual("level_2", lvl2.name); - // test.strictEqual("level 2", lvl2.displayName); - // test.strictEqual(false, lvl2.required); - // test.strictEqual(false, lvl2.multivalued); - // test.strictEqual(false, lvl2.hidden); - // test.strictEqual(false, lvl2.editable); - // test.strictEqual(null, lvl2.comment); + test.strictEqual(false, dataModel.isAccelerated()); + test.strictEqual(false, dataModel.acceleration.enabled); + test.strictEqual("-1mon", dataModel.acceleration.earliestTime); + test.strictEqual("* * * * *", dataModel.acceleration.cronSchedule); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // "Callback#DataModels - test data model object properties": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var name = "delete-me-" + getNextId(); + "Callback#DataModels - test data model object metadata": function(test) { + if (this.skip) { + test.done(); + return; + } + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/data_model_with_test_objects.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var name = "delete-me-" + getNextId(); - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // var obj = dataModel.objectByName("test_data"); - // test.ok(obj); - // test.strictEqual(5, obj.fieldNames().length); - // test.strictEqual(10, obj.allFieldNames().length); - // test.ok(obj.fieldByName("has_boris")); - // test.ok(obj.hasField("has_boris")); - // test.ok(obj.fieldByName("_time")); - // test.ok(obj.hasField("_time")); + var that = this; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + var obj = dataModel.objectByName("event1"); + test.ok(obj); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + test.strictEqual("event1 ·Ä©·öô", obj.displayName); + test.strictEqual("event1", obj.name); + test.same(dataModel, obj.dataModel); - // "Callback#DataModels - create local acceleration job": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/inheritance_test_data.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var name = "delete-me-" + getNextId(); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // var obj; - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // obj = dataModel.objectByName("level_2"); - // test.ok(obj); + "Callback#DataModels - test data model object parent": function(test) { + if (this.skip) { + test.done(); + return; + } + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/data_model_with_test_objects.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var name = "delete-me-" + getNextId(); - // obj.createLocalAccelerationJob(null, done); - // }, - // function(job, done) { - // test.ok(job); - - // tutils.pollUntil( - // job, - // function(j) { - // return job.properties()["isDone"]; - // }, - // 10, - // done - // ); - // }, - // function(job, done) { - // test.strictEqual("| datamodel \"" + name + "\" level_2 search | tscollect", job.properties().request.search); - // job.cancel(done); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + var that = this; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + var obj = dataModel.objectByName("event1"); + test.ok(obj); + test.ok(!obj.parent()); - // "Callback#DataModels - create local acceleration job with earliest time": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/inheritance_test_data.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var name = "delete-me-" + getNextId(); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // var obj; - // var oldNow = Date.now(); - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // obj = dataModel.objectByName("level_2"); - // test.ok(obj); - // obj.createLocalAccelerationJob("-1d", done); - // }, - // function(job, done) { - // test.ok(job); - // tutils.pollUntil( - // job, - // function(j) { - // return job.properties()["isDone"]; - // }, - // 10, - // done - // ); - // }, - // function(job, done) { - // test.strictEqual("| datamodel \"" + name + "\" level_2 search | tscollect", job.properties().request.search); - - // // Make sure the earliest time is 1 day behind - // var yesterday = new Date(Date.now() - (1000 * 60 * 60 * 24)); - // var month = (yesterday.getMonth() + 1); - // if (month <= 9) { - // month = "0" + month; - // } - // var date = yesterday.getDate(); - // if (date <= 9) { - // date = "0" + date; - // } - // var expectedDate = yesterday.getFullYear() + "-" + month + "-" + date; - // test.ok(utils.startsWith(job._state.content.earliestTime, expectedDate)); - - // job.cancel(done); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + "Callback#DataModels - test data model object lineage": function(test) { + if (this.skip) { + test.done(); + return; + } + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/inheritance_test_data.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var name = "delete-me-" + getNextId(); - // "Callback#DataModels - test data model constraints": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/data_model_with_test_objects.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var name = "delete-me-" + getNextId(); + var that = this; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + var obj = dataModel.objectByName("level_0"); + test.ok(obj); + test.strictEqual(1, obj.lineage.length); + test.strictEqual("level_0", obj.lineage[0]); + test.strictEqual("BaseEvent", obj.parentName); + + obj = dataModel.objectByName("level_1"); + test.ok(obj); + test.strictEqual(2, obj.lineage.length); + test.same(["level_0", "level_1"], obj.lineage); + test.strictEqual("level_0", obj.parentName); + + obj = dataModel.objectByName("level_2"); + test.ok(obj); + test.strictEqual(3, obj.lineage.length); + test.same(["level_0", "level_1", "level_2"], obj.lineage); + test.strictEqual("level_1", obj.parentName); + + // Make sure there's no extra children + test.ok(!dataModel.objectByName("level_3")); - // var obj; - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // obj = dataModel.objectByName("event1"); - // test.ok(obj); - // var constraints = obj.constraints; - // test.ok(constraints); - // var onlyOne = true; + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // for (var i = 0; i < constraints.length; i++) { - // var constraint = constraints[i]; - // test.ok(!!onlyOne); + "Callback#DataModels - test data model object fields": function(test) { + if (this.skip) { + test.done(); + return; + } + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/inheritance_test_data.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var name = "delete-me-" + getNextId(); - // test.strictEqual("event1", constraint.owner); - // test.strictEqual("uri=\"*.php\" OR uri=\"*.py\"\nNOT (referer=null OR referer=\"-\")", constraint.query); - // } + var that = this; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + var obj = dataModel.objectByName("level_2"); + test.ok(obj); + + var timeField = obj.fieldByName("_time"); + test.ok(timeField); + test.strictEqual("timestamp", timeField.type); + test.ok(timeField.isTimestamp()); + test.ok(!timeField.isNumber()); + test.ok(!timeField.isString()); + test.ok(!timeField.isObjectcount()); + test.ok(!timeField.isChildcount()); + test.ok(!timeField.isIPv4()); + test.same(["BaseEvent"], timeField.lineage); + test.strictEqual("_time", timeField.name); + test.strictEqual(false, timeField.required); + test.strictEqual(false, timeField.multivalued); + test.strictEqual(false, timeField.hidden); + test.strictEqual(false, timeField.editable); + test.strictEqual(null, timeField.comment); + + var lvl2 = obj.fieldByName("level_2"); + test.strictEqual("level_2", lvl2.owner); + test.same(["level_0", "level_1", "level_2"], lvl2.lineage); + test.strictEqual("objectCount", lvl2.type); + test.ok(!lvl2.isTimestamp()); + test.ok(!lvl2.isNumber()); + test.ok(!lvl2.isString()); + test.ok(lvl2.isObjectcount()); + test.ok(!lvl2.isChildcount()); + test.ok(!lvl2.isIPv4()); + test.strictEqual("level_2", lvl2.name); + test.strictEqual("level 2", lvl2.displayName); + test.strictEqual(false, lvl2.required); + test.strictEqual(false, lvl2.multivalued); + test.strictEqual(false, lvl2.hidden); + test.strictEqual(false, lvl2.editable); + test.strictEqual(null, lvl2.comment); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // "Callback#DataModels - test data model calculations, and the different types": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/data_model_with_test_objects.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var name = "delete-me-" + getNextId(); + "Callback#DataModels - test data model object properties": function(test) { + if (this.skip) { + test.done(); + return; + } + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var name = "delete-me-" + getNextId(); - // var obj; - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // obj = dataModel.objectByName("event1"); - // test.ok(obj); - - // var calculations = obj.calculations; - // test.strictEqual(4, Object.keys(calculations).length); - // test.strictEqual(4, obj.calculationIDs().length); - - // var evalCalculation = calculations["93fzsv03wa7"]; - // test.ok(evalCalculation); - // test.strictEqual("event1", evalCalculation.owner); - // test.same(["event1"], evalCalculation.lineage); - // test.strictEqual("Eval", evalCalculation.type); - // test.ok(evalCalculation.isEval()); - // test.ok(!evalCalculation.isLookup()); - // test.ok(!evalCalculation.isGeoIP()); - // test.ok(!evalCalculation.isRex()); - // test.strictEqual(null, evalCalculation.comment); - // test.strictEqual(true, evalCalculation.isEditable()); - // test.strictEqual("if(cidrmatch(\"192.0.0.0/16\", clientip), \"local\", \"other\")", evalCalculation.expression); - - // test.strictEqual(1, Object.keys(evalCalculation.outputFields).length); - // test.strictEqual(1, evalCalculation.outputFieldNames().length); - - // var field = evalCalculation.outputFields["new_field"]; - // test.ok(field); - // test.strictEqual("My New Field", field.displayName); - - // var lookupCalculation = calculations["sr3mc8o3mjr"]; - // test.ok(lookupCalculation); - // test.strictEqual("event1", lookupCalculation.owner); - // test.same(["event1"], lookupCalculation.lineage); - // test.strictEqual("Lookup", lookupCalculation.type); - // test.ok(lookupCalculation.isLookup()); - // test.ok(!lookupCalculation.isEval()); - // test.ok(!lookupCalculation.isGeoIP()); - // test.ok(!lookupCalculation.isRex()); - // test.strictEqual(null, lookupCalculation.comment); - // test.strictEqual(true, lookupCalculation.isEditable()); - // test.same({lookupField: "a_lookup_field", inputField: "host"}, lookupCalculation.inputFieldMappings); - // test.strictEqual(2, Object.keys(lookupCalculation.inputFieldMappings).length); - // test.strictEqual("a_lookup_field", lookupCalculation.inputFieldMappings.lookupField); - // test.strictEqual("host", lookupCalculation.inputFieldMappings.inputField); - // test.strictEqual("dnslookup", lookupCalculation.lookupName); - - // var regexpCalculation = calculations["a5v1k82ymic"]; - // test.ok(regexpCalculation); - // test.strictEqual("event1", regexpCalculation.owner); - // test.same(["event1"], regexpCalculation.lineage); - // test.strictEqual("Rex", regexpCalculation.type); - // test.ok(regexpCalculation.isRex()); - // test.ok(!regexpCalculation.isLookup()); - // test.ok(!regexpCalculation.isEval()); - // test.ok(!regexpCalculation.isGeoIP()); - // test.strictEqual(2, regexpCalculation.outputFieldNames().length); - // test.strictEqual("_raw", regexpCalculation.inputField); - // test.strictEqual(" From: (?.*) To: (?.*) ", regexpCalculation.expression); - - // var geoIPCalculation = calculations["pbe9bd0rp4"]; - // test.ok(geoIPCalculation); - // test.strictEqual("event1", geoIPCalculation.owner); - // test.same(["event1"], geoIPCalculation.lineage); - // test.strictEqual("GeoIP", geoIPCalculation.type); - // test.ok(geoIPCalculation.isGeoIP()); - // test.ok(!geoIPCalculation.isLookup()); - // test.ok(!geoIPCalculation.isEval()); - // test.ok(!geoIPCalculation.isRex()); - // test.strictEqual("·Ä©·öô‡Øµ comment of pbe9bd0rp4", geoIPCalculation.comment); - // test.strictEqual(5, geoIPCalculation.outputFieldNames().length); - // test.strictEqual("output_from_reverse_hostname", geoIPCalculation.inputField); + var that = this; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + var obj = dataModel.objectByName("test_data"); + test.ok(obj); + test.strictEqual(5, obj.fieldNames().length); + test.strictEqual(10, obj.allFieldNames().length); + test.ok(obj.fieldByName("has_boris")); + test.ok(obj.hasField("has_boris")); + test.ok(obj.fieldByName("_time")); + test.ok(obj.hasField("_time")); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // "Callback#DataModels - run queries": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var obj; - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.fetch(done); - // }, - // function(dataModels, done) { - // var dm = dataModels.item("internal_audit_logs"); - // obj = dm.objectByName("searches"); - // obj.startSearch({}, "", done); - // }, - // function(job, done) { - // tutils.pollUntil( - // job, - // function(j) { - // return job.properties()["isDone"]; - // }, - // 10, - // done - // ); - // }, - // function(job, done) { - // test.strictEqual("| datamodel internal_audit_logs searches search", job.properties().request.search); - // job.cancel(done); - // }, - // function(response, done) { - // obj.startSearch({status_buckets: 5, enable_lookups: false}, "| head 3", done); - // }, - // function(job, done) { - // tutils.pollUntil( - // job, - // function(j) { - // return job.properties()["isDone"]; - // }, - // 10, - // done - // ); - // }, - // function(job, done) { - // test.strictEqual("| datamodel internal_audit_logs searches search | head 3", job.properties().request.search); - // job.cancel(done); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + "Callback#DataModels - create local acceleration job": function(test) { + if (this.skip) { + test.done(); + return; + } + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/inheritance_test_data.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var name = "delete-me-" + getNextId(); - // "Callback#DataModels - baseSearch is parsed correctly": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/model_with_multiple_types.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var name = "delete-me-" + getNextId(); + var obj; + var that = this; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + obj = dataModel.objectByName("level_2"); + test.ok(obj); - // var obj; - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // obj = dataModel.objectByName("search1"); - // test.ok(obj); - // test.ok(obj instanceof splunkjs.Service.DataModelObject); - // test.strictEqual("BaseSearch", obj.parentName); - // test.ok(obj.isBaseSearch()); - // test.ok(!obj.isBaseTransaction()); - // test.strictEqual("search index=_internal | head 10", obj.baseSearch); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + obj.createLocalAccelerationJob(null, done); + }, + function(job, done) { + test.ok(job); - // "Callback#DataModels - baseTransaction is parsed correctly": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/model_with_multiple_types.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var name = "delete-me-" + getNextId(); + tutils.pollUntil( + job, + function(j) { + return job.properties()["isDone"]; + }, + 10, + done + ); + }, + function(job, done) { + test.strictEqual("| datamodel \"" + name + "\" level_2 search | tscollect", job.properties().request.search); + job.cancel(done); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // var obj; - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // obj = dataModel.objectByName("transaction1"); - // test.ok(obj); - // test.ok(obj instanceof splunkjs.Service.DataModelObject); - // test.strictEqual("BaseTransaction", obj.parentName); - // test.ok(obj.isBaseTransaction()); - // test.ok(!obj.isBaseSearch()); - // test.same(["event1"], obj.objectsToGroup); - // test.same(["host", "from"], obj.groupByFields); - // test.strictEqual("25s", obj.maxPause); - // test.strictEqual("100m", obj.maxSpan); + "Callback#DataModels - create local acceleration job with earliest time": function(test) { + if (this.skip) { + test.done(); + return; + } + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/inheritance_test_data.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var name = "delete-me-" + getNextId(); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // } - // }, + var obj; + var oldNow = Date.now(); + var that = this; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + obj = dataModel.objectByName("level_2"); + test.ok(obj); + obj.createLocalAccelerationJob("-1d", done); + }, + function(job, done) { + test.ok(job); + tutils.pollUntil( + job, + function(j) { + return job.properties()["isDone"]; + }, + 10, + done + ); + }, + function(job, done) { + test.strictEqual("| datamodel \"" + name + "\" level_2 search | tscollect", job.properties().request.search); - // "Pivot tests": { - // setUp: function(done) { - // this.service = svc; - // this.dataModels = svc.dataModels({owner: "nobody", app: "search"}); - // this.skip = false; - // var that = this; - // this.service.serverInfo(function(err, info) { - // if (parseInt(info.properties().version.split(".")[0], 10) < 6) { - // that.skip = true; - // splunkjs.Logger.log("Skipping pivot tests..."); - // } - // done(err); - // }); - // }, + // Make sure the earliest time is 1 day behind + var yesterday = new Date(Date.now() - (1000 * 60 * 60 * 24)); + var month = (yesterday.getMonth() + 1); + if (month <= 9) { + month = "0" + month; + } + var date = yesterday.getDate(); + if (date <= 9) { + date = "0" + date; + } + var expectedDate = yesterday.getFullYear() + "-" + month + "-" + date; + test.ok(utils.startsWith(job._state.content.earliestTime, expectedDate)); - // "Callback#Pivot - test constructor args": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var name = "delete-me-" + getNextId(); - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // test.ok(dataModel.objectByName("test_data")); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + job.cancel(done); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // "Callback#Pivot - test acceleration, then pivot": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var name = "delete-me-" + getNextId(); - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // dataModel.objectByName("test_data"); - // test.ok(dataModel); - - // dataModel.acceleration.enabled = true; - // dataModel.acceleration.earliestTime = "-2mon"; - // dataModel.acceleration.cronSchedule = "0 */12 * * *"; - // dataModel.update(done); - // }, - // function(dataModel, done) { - // var props = dataModel.properties(); + "Callback#DataModels - test data model constraints": function(test) { + if (this.skip) { + test.done(); + return; + } + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/data_model_with_test_objects.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var name = "delete-me-" + getNextId(); - // test.strictEqual(true, dataModel.isAccelerated()); - // test.strictEqual(true, !!dataModel.acceleration.enabled); - // test.strictEqual("-2mon", dataModel.acceleration.earliest_time); - // test.strictEqual("0 */12 * * *", dataModel.acceleration.cron_schedule); + var obj; + var that = this; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + obj = dataModel.objectByName("event1"); + test.ok(obj); + var constraints = obj.constraints; + test.ok(constraints); + var onlyOne = true; + + for (var i = 0; i < constraints.length; i++) { + var constraint = constraints[i]; + test.ok(!!onlyOne); + + test.strictEqual("event1", constraint.owner); + test.strictEqual("uri=\"*.php\" OR uri=\"*.py\"\nNOT (referer=null OR referer=\"-\")", constraint.query); + } - // var dataModelObject = dataModel.objectByName("test_data"); - // var pivotSpecification = dataModelObject.createPivotSpecification(); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // test.strictEqual(dataModelObject.dataModel.name, pivotSpecification.accelerationNamespace); + "Callback#DataModels - test data model calculations, and the different types": function(test) { + if (this.skip) { + test.done(); + return; + } + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/data_model_with_test_objects.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var name = "delete-me-" + getNextId(); - // var name1 = "delete-me-" + getNextId(); - // pivotSpecification.setAccelerationJob(name1); - // test.strictEqual("sid=" + name1, pivotSpecification.accelerationNamespace); + var obj; + var that = this; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + obj = dataModel.objectByName("event1"); + test.ok(obj); + + var calculations = obj.calculations; + test.strictEqual(4, Object.keys(calculations).length); + test.strictEqual(4, obj.calculationIDs().length); + + var evalCalculation = calculations["93fzsv03wa7"]; + test.ok(evalCalculation); + test.strictEqual("event1", evalCalculation.owner); + test.same(["event1"], evalCalculation.lineage); + test.strictEqual("Eval", evalCalculation.type); + test.ok(evalCalculation.isEval()); + test.ok(!evalCalculation.isLookup()); + test.ok(!evalCalculation.isGeoIP()); + test.ok(!evalCalculation.isRex()); + test.strictEqual(null, evalCalculation.comment); + test.strictEqual(true, evalCalculation.isEditable()); + test.strictEqual("if(cidrmatch(\"192.0.0.0/16\", clientip), \"local\", \"other\")", evalCalculation.expression); + + test.strictEqual(1, Object.keys(evalCalculation.outputFields).length); + test.strictEqual(1, evalCalculation.outputFieldNames().length); + + var field = evalCalculation.outputFields["new_field"]; + test.ok(field); + test.strictEqual("My New Field", field.displayName); + + var lookupCalculation = calculations["sr3mc8o3mjr"]; + test.ok(lookupCalculation); + test.strictEqual("event1", lookupCalculation.owner); + test.same(["event1"], lookupCalculation.lineage); + test.strictEqual("Lookup", lookupCalculation.type); + test.ok(lookupCalculation.isLookup()); + test.ok(!lookupCalculation.isEval()); + test.ok(!lookupCalculation.isGeoIP()); + test.ok(!lookupCalculation.isRex()); + test.strictEqual(null, lookupCalculation.comment); + test.strictEqual(true, lookupCalculation.isEditable()); + test.same({lookupField: "a_lookup_field", inputField: "host"}, lookupCalculation.inputFieldMappings); + test.strictEqual(2, Object.keys(lookupCalculation.inputFieldMappings).length); + test.strictEqual("a_lookup_field", lookupCalculation.inputFieldMappings.lookupField); + test.strictEqual("host", lookupCalculation.inputFieldMappings.inputField); + test.strictEqual("dnslookup", lookupCalculation.lookupName); + + var regexpCalculation = calculations["a5v1k82ymic"]; + test.ok(regexpCalculation); + test.strictEqual("event1", regexpCalculation.owner); + test.same(["event1"], regexpCalculation.lineage); + test.strictEqual("Rex", regexpCalculation.type); + test.ok(regexpCalculation.isRex()); + test.ok(!regexpCalculation.isLookup()); + test.ok(!regexpCalculation.isEval()); + test.ok(!regexpCalculation.isGeoIP()); + test.strictEqual(2, regexpCalculation.outputFieldNames().length); + test.strictEqual("_raw", regexpCalculation.inputField); + test.strictEqual(" From: (?.*) To: (?.*) ", regexpCalculation.expression); + + var geoIPCalculation = calculations["pbe9bd0rp4"]; + test.ok(geoIPCalculation); + test.strictEqual("event1", geoIPCalculation.owner); + test.same(["event1"], geoIPCalculation.lineage); + test.strictEqual("GeoIP", geoIPCalculation.type); + test.ok(geoIPCalculation.isGeoIP()); + test.ok(!geoIPCalculation.isLookup()); + test.ok(!geoIPCalculation.isEval()); + test.ok(!geoIPCalculation.isRex()); + test.strictEqual("·Ä©·öô‡Øµ comment of pbe9bd0rp4", geoIPCalculation.comment); + test.strictEqual(5, geoIPCalculation.outputFieldNames().length); + test.strictEqual("output_from_reverse_hostname", geoIPCalculation.inputField); - // var namespaceTemp = "delete-me-" + getNextId(); - // pivotSpecification.accelerationNamespace = namespaceTemp; - // test.strictEqual(namespaceTemp, pivotSpecification.accelerationNamespace); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // pivotSpecification - // .addCellValue("test_data", "Source Value", "count") - // .run(done); - // }, - // function(job, pivot, done) { - // test.ok(job); - // test.ok(pivot); - // test.notStrictEqual("FAILED", job.properties().dispatchState); - - // job.track({}, function(job) { - // test.ok(pivot.tstatsSearch); - // test.strictEqual(0, job.properties().request.search.indexOf("| tstats")); - // test.strictEqual("| tstats", job.properties().request.search.match("^\\| tstats")[0]); - // test.strictEqual(1, job.properties().request.search.match("^\\| tstats").length); - - // test.strictEqual(pivot.tstatsSearch, job.properties().request.search); - // done(null, job); - // }); - // }, - // function(job, done) { - // test.ok(job); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + "Callback#DataModels - run queries": function(test) { + if (this.skip) { + test.done(); + return; + } + var obj; + var that = this; + Async.chain([ + function(done) { + that.dataModels.fetch(done); + }, + function(dataModels, done) { + var dm = dataModels.item("internal_audit_logs"); + obj = dm.objectByName("searches"); + obj.startSearch({}, "", done); + }, + function(job, done) { + tutils.pollUntil( + job, + function(j) { + return job.properties()["isDone"]; + }, + 10, + done + ); + }, + function(job, done) { + test.strictEqual("| datamodel internal_audit_logs searches search", job.properties().request.search); + job.cancel(done); + }, + function(response, done) { + obj.startSearch({status_buckets: 5, enable_lookups: false}, "| head 3", done); + }, + function(job, done) { + tutils.pollUntil( + job, + function(j) { + return job.properties()["isDone"]; + }, + 10, + done + ); + }, + function(job, done) { + test.strictEqual("| datamodel internal_audit_logs searches search | head 3", job.properties().request.search); + job.cancel(done); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // "Callback#Pivot - test illegal filtering (all types)": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var name = "delete-me-" + getNextId(); - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // var obj = dataModel.objectByName("test_data"); - // test.ok(obj); - - // var pivotSpecification = obj.createPivotSpecification(); - - // // Boolean comparisons - // try { - // pivotSpecification.addFilter(getNextId(), "boolean", "=", true); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Cannot add filter on a nonexistent field."); - // } - // try { - // pivotSpecification.addFilter("_time", "boolean", "=", true); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Cannot add boolean filter on _time because it is of type timestamp"); - // } - - // // String comparisons - // try { - // pivotSpecification.addFilter("has_boris", "string", "contains", "abc"); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Cannot add string filter on has_boris because it is of type boolean"); - // } - // try { - // pivotSpecification.addFilter(getNextId(), "string", "contains", "abc"); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Cannot add filter on a nonexistent field."); - // } - - // // IPv4 comparisons - // try { - // pivotSpecification.addFilter("has_boris", "ipv4", "startsWith", "192.168"); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Cannot add ipv4 filter on has_boris because it is of type boolean"); - // } - // try { - // pivotSpecification.addFilter(getNextId(), "ipv4", "startsWith", "192.168"); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Cannot add filter on a nonexistent field."); - // } - - // // Number comparisons - // try { - // pivotSpecification.addFilter("has_boris", "number", "atLeast", 2.3); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Cannot add number filter on has_boris because it is of type boolean"); - // } - // try { - // pivotSpecification.addFilter(getNextId(), "number", "atLeast", 2.3); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Cannot add filter on a nonexistent field."); - // } - - // // Limit filter - // try { - // pivotSpecification.addLimitFilter("has_boris", "host", "DEFAULT", 50, "count"); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Cannot add limit filter on has_boris because it is of type boolean"); - // } - // try { - // pivotSpecification.addLimitFilter(getNextId(), "host", "DEFAULT", 50, "count"); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Cannot add limit filter on a nonexistent field."); - // } - // try { - // pivotSpecification.addLimitFilter("source", "host", "DEFAULT", 50, "sum"); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, - // "Stats function for fields of type string must be COUNT or DISTINCT_COUNT; found sum"); - // } - // try { - // pivotSpecification.addLimitFilter("epsilon", "host", "DEFAULT", 50, "duration"); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, - // "Stats function for fields of type number must be one of COUNT, DISTINCT_COUNT, SUM, or AVERAGE; found duration"); - // } - // try { - // pivotSpecification.addLimitFilter("test_data", "host", "DEFAULT", 50, "list"); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, - // "Stats function for fields of type object count must be COUNT; found list"); - // } - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + "Callback#DataModels - baseSearch is parsed correctly": function(test) { + if (this.skip) { + test.done(); + return; + } + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/model_with_multiple_types.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var name = "delete-me-" + getNextId(); - // "Callback#Pivot - test boolean filtering": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var name = "delete-me-" + getNextId(); - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // var obj = dataModel.objectByName("test_data"); - // test.ok(obj); - - // var pivotSpecification = obj.createPivotSpecification(); - // try { - // pivotSpecification.addFilter("has_boris", "boolean", "=", true); - // test.strictEqual(1, pivotSpecification.filters.length); - - // //Test the individual parts of the filter - // var filter = pivotSpecification.filters[0]; - - // test.ok(filter.hasOwnProperty("fieldName")); - // test.ok(filter.hasOwnProperty("type")); - // test.ok(filter.hasOwnProperty("rule")); - // test.ok(filter.hasOwnProperty("owner")); - - // test.strictEqual("has_boris", filter.fieldName); - // test.strictEqual("boolean", filter.type); - // test.strictEqual("=", filter.rule.comparator); - // test.strictEqual(true, filter.rule.compareTo); - // test.strictEqual("test_data", filter.owner); - // } - // catch (e) { - // test.ok(false); - // } + var obj; + var that = this; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + obj = dataModel.objectByName("search1"); + test.ok(obj); + test.ok(obj instanceof splunkjs.Service.DataModelObject); + test.strictEqual("BaseSearch", obj.parentName); + test.ok(obj.isBaseSearch()); + test.ok(!obj.isBaseTransaction()); + test.strictEqual("search index=_internal | head 10", obj.baseSearch); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + "Callback#DataModels - baseTransaction is parsed correctly": function(test) { + if (this.skip) { + test.done(); + return; + } + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/model_with_multiple_types.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var name = "delete-me-" + getNextId(); - // "Callback#Pivot - test string filtering": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var name = "delete-me-" + getNextId(); - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // var obj = dataModel.objectByName("test_data"); - // test.ok(obj); - - // var pivotSpecification = obj.createPivotSpecification(); - // try { - // pivotSpecification.addFilter("host", "string", "contains", "abc"); - // test.strictEqual(1, pivotSpecification.filters.length); - - // //Test the individual parts of the filter - // var filter = pivotSpecification.filters[0]; - - // test.ok(filter.hasOwnProperty("fieldName")); - // test.ok(filter.hasOwnProperty("type")); - // test.ok(filter.hasOwnProperty("rule")); - // test.ok(filter.hasOwnProperty("owner")); - - // test.strictEqual("host", filter.fieldName); - // test.strictEqual("string", filter.type); - // test.strictEqual("contains", filter.rule.comparator); - // test.strictEqual("abc", filter.rule.compareTo); - // test.strictEqual("BaseEvent", filter.owner); - // } - // catch (e) { - // test.ok(false); - // } + var obj; + var that = this; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + obj = dataModel.objectByName("transaction1"); + test.ok(obj); + test.ok(obj instanceof splunkjs.Service.DataModelObject); + test.strictEqual("BaseTransaction", obj.parentName); + test.ok(obj.isBaseTransaction()); + test.ok(!obj.isBaseSearch()); + test.same(["event1"], obj.objectsToGroup); + test.same(["host", "from"], obj.groupByFields); + test.strictEqual("25s", obj.maxPause); + test.strictEqual("100m", obj.maxSpan); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, - - // "Callback#Pivot - test IPv4 filtering": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var name = "delete-me-" + getNextId(); - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // var obj = dataModel.objectByName("test_data"); - // test.ok(obj); - - // var pivotSpecification = obj.createPivotSpecification(); - // try { - // pivotSpecification.addFilter("hostip", "ipv4", "startsWith", "192.168"); - // test.strictEqual(1, pivotSpecification.filters.length); - - // //Test the individual parts of the filter - // var filter = pivotSpecification.filters[0]; - - // test.ok(filter.hasOwnProperty("fieldName")); - // test.ok(filter.hasOwnProperty("type")); - // test.ok(filter.hasOwnProperty("rule")); - // test.ok(filter.hasOwnProperty("owner")); - - // test.strictEqual("hostip", filter.fieldName); - // test.strictEqual("ipv4", filter.type); - // test.strictEqual("startsWith", filter.rule.comparator); - // test.strictEqual("192.168", filter.rule.compareTo); - // test.strictEqual("test_data", filter.owner); - // } - // catch (e) { - // test.ok(false); - // } - - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + } + }, - // "Callback#Pivot - test number filtering": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var name = "delete-me-" + getNextId(); - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // var obj = dataModel.objectByName("test_data"); - // test.ok(obj); - - // var pivotSpecification = obj.createPivotSpecification(); - // try { - // pivotSpecification.addFilter("epsilon", "number", ">=", 2.3); - // test.strictEqual(1, pivotSpecification.filters.length); - - // //Test the individual parts of the filter - // var filter = pivotSpecification.filters[0]; - - // test.ok(filter.hasOwnProperty("fieldName")); - // test.ok(filter.hasOwnProperty("type")); - // test.ok(filter.hasOwnProperty("rule")); - // test.ok(filter.hasOwnProperty("owner")); - - // test.strictEqual("epsilon", filter.fieldName); - // test.strictEqual("number", filter.type); - // test.strictEqual(">=", filter.rule.comparator); - // test.strictEqual(2.3, filter.rule.compareTo); - // test.strictEqual("test_data", filter.owner); - // } - // catch (e) { - // test.ok(false); - // } + "Pivot tests": { + setUp: function(done) { + this.service = svc; + this.dataModels = svc.dataModels({owner: "nobody", app: "search"}); + this.skip = false; + var that = this; + this.service.serverInfo(function(err, info) { + if (parseInt(info.properties().version.split(".")[0], 10) < 6) { + that.skip = true; + splunkjs.Logger.log("Skipping pivot tests..."); + } + done(err); + }); + }, - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, - // "Callback#Pivot - test limit filtering": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var name = "delete-me-" + getNextId(); - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // var obj = dataModel.objectByName("test_data"); - // test.ok(obj); - - // var pivotSpecification = obj.createPivotSpecification(); - // try { - // pivotSpecification.addLimitFilter("epsilon", "host", "ASCENDING", 500, "average"); - // test.strictEqual(1, pivotSpecification.filters.length); - - // //Test the individual parts of the filter - // var filter = pivotSpecification.filters[0]; - - // test.ok(filter.hasOwnProperty("fieldName")); - // test.ok(filter.hasOwnProperty("type")); - // test.ok(filter.hasOwnProperty("owner")); - // test.ok(filter.hasOwnProperty("attributeName")); - // test.ok(filter.hasOwnProperty("attributeOwner")); - // test.ok(filter.hasOwnProperty("limitType")); - // test.ok(filter.hasOwnProperty("limitAmount")); - // test.ok(filter.hasOwnProperty("statsFn")); - - // test.strictEqual("epsilon", filter.fieldName); - // test.strictEqual("number", filter.type); - // test.strictEqual("test_data", filter.owner); - // test.strictEqual("host", filter.attributeName); - // test.strictEqual("BaseEvent", filter.attributeOwner); - // test.strictEqual("lowest", filter.limitType); - // test.strictEqual(500, filter.limitAmount); - // test.strictEqual("average", filter.statsFn); - // } - // catch (e) { - // test.ok(false); - // } + "Callback#Pivot - test constructor args": function(test) { + if (this.skip) { + test.done(); + return; + } + var name = "delete-me-" + getNextId(); + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var that = this; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + test.ok(dataModel.objectByName("test_data")); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, - // "Callback#Pivot - test row split": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var name = "delete-me-" + getNextId(); - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // var obj = dataModel.objectByName("test_data"); - // test.ok(obj); - - // var pivotSpecification = obj.createPivotSpecification(); - - // // Test error handling for row split - // try { - // pivotSpecification.addRowSplit("has_boris", "Wrong type here"); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Field was of type " + obj.fieldByName("has_boris").type + ", expected number or string."); - // } - // var field = getNextId(); - // try { - - // pivotSpecification.addRowSplit(field, "Break Me!"); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Did not find field " + field); - // } - - // // Test row split, number - // pivotSpecification.addRowSplit("epsilon", "My Label"); - // test.strictEqual(1, pivotSpecification.rows.length); - - // var row = pivotSpecification.rows[0]; - // test.ok(row.hasOwnProperty("fieldName")); - // test.ok(row.hasOwnProperty("owner")); - // test.ok(row.hasOwnProperty("type")); - // test.ok(row.hasOwnProperty("label")); - // test.ok(row.hasOwnProperty("display")); - - // test.strictEqual("epsilon", row.fieldName); - // test.strictEqual("test_data", row.owner); - // test.strictEqual("number", row.type); - // test.strictEqual("My Label", row.label); - // test.strictEqual("all", row.display); - // test.same({ - // fieldName: "epsilon", - // owner: "test_data", - // type: "number", - // label: "My Label", - // display: "all" - // }, - // row); - - // // Test row split, string - // pivotSpecification.addRowSplit("host", "My Label"); - // test.strictEqual(2, pivotSpecification.rows.length); - - // row = pivotSpecification.rows[pivotSpecification.rows.length - 1]; - // test.ok(row.hasOwnProperty("fieldName")); - // test.ok(row.hasOwnProperty("owner")); - // test.ok(row.hasOwnProperty("type")); - // test.ok(row.hasOwnProperty("label")); - // test.ok(!row.hasOwnProperty("display")); - - // test.strictEqual("host", row.fieldName); - // test.strictEqual("BaseEvent", row.owner); - // test.strictEqual("string", row.type); - // test.strictEqual("My Label", row.label); - // test.same({ - // fieldName: "host", - // owner: "BaseEvent", - // type: "string", - // label: "My Label" - // }, - // row); - - // // Test error handling on range row split - // try { - // pivotSpecification.addRangeRowSplit("has_boris", "Wrong type here", {start: 0, end: 100, step:20, limit:5}); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Field was of type " + obj.fieldByName("has_boris").type + ", expected number."); - // } - // try { - // pivotSpecification.addRangeRowSplit(field, "Break Me!", {start: 0, end: 100, step:20, limit:5}); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Did not find field " + field); - // } - - // // Test range row split - // pivotSpecification.addRangeRowSplit("epsilon", "My Label", {start: 0, end: 100, step:20, limit:5}); - // test.strictEqual(3, pivotSpecification.rows.length); - - // row = pivotSpecification.rows[pivotSpecification.rows.length - 1]; - // test.ok(row.hasOwnProperty("fieldName")); - // test.ok(row.hasOwnProperty("owner")); - // test.ok(row.hasOwnProperty("type")); - // test.ok(row.hasOwnProperty("label")); - // test.ok(row.hasOwnProperty("display")); - // test.ok(row.hasOwnProperty("ranges")); - - // test.strictEqual("epsilon", row.fieldName); - // test.strictEqual("test_data", row.owner); - // test.strictEqual("number", row.type); - // test.strictEqual("My Label", row.label); - // test.strictEqual("ranges", row.display); - - // var ranges = { - // start: 0, - // end: 100, - // size: 20, - // maxNumberOf: 5 - // }; - // test.same(ranges, row.ranges); - // test.same({ - // fieldName: "epsilon", - // owner: "test_data", - // type: "number", - // label: "My Label", - // display: "ranges", - // ranges: ranges - // }, - // row); - - // // Test error handling on boolean row split - // try { - // pivotSpecification.addBooleanRowSplit("epsilon", "Wrong type here", "t", "f"); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Field was of type " + obj.fieldByName("epsilon").type + ", expected boolean."); - // } - // try { - // pivotSpecification.addBooleanRowSplit(field, "Break Me!", "t", "f"); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Did not find field " + field); - // } - - // // Test boolean row split - // pivotSpecification.addBooleanRowSplit("has_boris", "My Label", "is_true", "is_false"); - // test.strictEqual(4, pivotSpecification.rows.length); - - // row = pivotSpecification.rows[pivotSpecification.rows.length - 1]; - // test.ok(row.hasOwnProperty("fieldName")); - // test.ok(row.hasOwnProperty("owner")); - // test.ok(row.hasOwnProperty("type")); - // test.ok(row.hasOwnProperty("label")); - // test.ok(row.hasOwnProperty("trueLabel")); - // test.ok(row.hasOwnProperty("falseLabel")); - - // test.strictEqual("has_boris", row.fieldName); - // test.strictEqual("My Label", row.label); - // test.strictEqual("test_data", row.owner); - // test.strictEqual("boolean", row.type); - // test.strictEqual("is_true", row.trueLabel); - // test.strictEqual("is_false", row.falseLabel); - // test.same({ - // fieldName: "has_boris", - // label: "My Label", - // owner: "test_data", - // type: "boolean", - // trueLabel: "is_true", - // falseLabel: "is_false" - // }, - // row); - - // // Test error handling on timestamp row split - // try { - // pivotSpecification.addTimestampRowSplit("epsilon", "Wrong type here", "some binning"); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Field was of type " + obj.fieldByName("epsilon").type + ", expected timestamp."); - // } - // try { - // pivotSpecification.addTimestampRowSplit(field, "Break Me!", "some binning"); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Did not find field " + field); - // } - // try { - // pivotSpecification.addTimestampRowSplit("_time", "some label", "Bogus binning value"); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Invalid binning Bogus binning value found. Valid values are: " + pivotSpecification._binning.join(", ")); - // } - - // // Test timestamp row split - // pivotSpecification.addTimestampRowSplit("_time", "My Label", "day"); - // test.strictEqual(5, pivotSpecification.rows.length); - - // row = pivotSpecification.rows[pivotSpecification.rows.length - 1]; - // test.ok(row.hasOwnProperty("fieldName")); - // test.ok(row.hasOwnProperty("owner")); - // test.ok(row.hasOwnProperty("type")); - // test.ok(row.hasOwnProperty("label")); - // test.ok(row.hasOwnProperty("period")); - - // test.strictEqual("_time", row.fieldName); - // test.strictEqual("My Label", row.label); - // test.strictEqual("BaseEvent", row.owner); - // test.strictEqual("timestamp", row.type); - // test.strictEqual("day", row.period); - // test.same({ - // fieldName: "_time", - // label: "My Label", - // owner: "BaseEvent", - // type: "timestamp", - // period: "day" - // }, - // row); + "Callback#Pivot - test acceleration, then pivot": function(test) { + if (this.skip) { + test.done(); + return; + } + var name = "delete-me-" + getNextId(); + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var that = this; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + dataModel.objectByName("test_data"); + test.ok(dataModel); + + dataModel.acceleration.enabled = true; + dataModel.acceleration.earliestTime = "-2mon"; + dataModel.acceleration.cronSchedule = "0 */12 * * *"; + dataModel.update(done); + }, + function(dataModel, done) { + var props = dataModel.properties(); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, - // "Callback#Pivot - test column split": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var name = "delete-me-" + getNextId(); - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // var obj = dataModel.objectByName("test_data"); - // test.ok(obj); - - // var pivotSpecification = obj.createPivotSpecification(); - - // // Test error handling for column split - // try { - // pivotSpecification.addColumnSplit("has_boris", "Wrong type here"); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Field was of type " + obj.fieldByName("has_boris").type + ", expected number or string."); - // } - // var field = getNextId(); - // try { - - // pivotSpecification.addColumnSplit(field, "Break Me!"); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Did not find field " + field); - // } - - // // Test column split, number - // pivotSpecification.addColumnSplit("epsilon"); - // test.strictEqual(1, pivotSpecification.columns.length); - - // var col = pivotSpecification.columns[pivotSpecification.columns.length - 1]; - // test.ok(col.hasOwnProperty("fieldName")); - // test.ok(col.hasOwnProperty("owner")); - // test.ok(col.hasOwnProperty("type")); - // test.ok(col.hasOwnProperty("display")); - - // test.strictEqual("epsilon", col.fieldName); - // test.strictEqual("test_data", col.owner); - // test.strictEqual("number", col.type); - // test.strictEqual("all", col.display); - // test.same({ - // fieldName: "epsilon", - // owner: "test_data", - // type: "number", - // display: "all" - // }, - // col); - - // // Test column split, string - // pivotSpecification.addColumnSplit("host"); - // test.strictEqual(2, pivotSpecification.columns.length); - - // col = pivotSpecification.columns[pivotSpecification.columns.length - 1]; - // test.ok(col.hasOwnProperty("fieldName")); - // test.ok(col.hasOwnProperty("owner")); - // test.ok(col.hasOwnProperty("type")); - // test.ok(!col.hasOwnProperty("display")); - - // test.strictEqual("host", col.fieldName); - // test.strictEqual("BaseEvent", col.owner); - // test.strictEqual("string", col.type); - // test.same({ - // fieldName: "host", - // owner: "BaseEvent", - // type: "string" - // }, - // col); + test.strictEqual(true, dataModel.isAccelerated()); + test.strictEqual(true, !!dataModel.acceleration.enabled); + test.strictEqual("-2mon", dataModel.acceleration.earliest_time); + test.strictEqual("0 */12 * * *", dataModel.acceleration.cron_schedule); - // done(); + var dataModelObject = dataModel.objectByName("test_data"); + var pivotSpecification = dataModelObject.createPivotSpecification(); - // // Test error handling for range column split - // try { - // pivotSpecification.addRangeColumnSplit("has_boris", "Wrong type here", {start: 0, end: 100, step:20, limit:5}); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Field was of type " + obj.fieldByName("has_boris").type + ", expected number."); - // } - // try { - // pivotSpecification.addRangeColumnSplit(field, {start: 0, end: 100, step:20, limit:5}); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Did not find field " + field); - // } - - // // Test range column split - // pivotSpecification.addRangeColumnSplit("epsilon", {start: 0, end: 100, step:20, limit:5}); - // test.strictEqual(3, pivotSpecification.columns.length); - - // col = pivotSpecification.columns[pivotSpecification.columns.length - 1]; - // test.ok(col.hasOwnProperty("fieldName")); - // test.ok(col.hasOwnProperty("owner")); - // test.ok(col.hasOwnProperty("type")); - // test.ok(col.hasOwnProperty("display")); - // test.ok(col.hasOwnProperty("ranges")); - - // test.strictEqual("epsilon", col.fieldName); - // test.strictEqual("test_data", col.owner); - // test.strictEqual("number", col.type); - // test.strictEqual("ranges", col.display); - // var ranges = { - // start: "0", - // end: "100", - // size: "20", - // maxNumberOf: "5" - // }; - // test.same(ranges, col.ranges); - // test.same({ - // fieldName: "epsilon", - // owner: "test_data", - // type: "number", - // display: "ranges", - // ranges: ranges - // }, - // col); - - // // Test error handling on boolean column split - // try { - // pivotSpecification.addBooleanColumnSplit("epsilon", "t", "f"); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Field was of type " + obj.fieldByName("epsilon").type + ", expected boolean."); - // } - // try { - // pivotSpecification.addBooleanColumnSplit(field, "t", "f"); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Did not find field " + field); - // } - - // // Test boolean column split - // pivotSpecification.addBooleanColumnSplit("has_boris", "is_true", "is_false"); - // test.strictEqual(4, pivotSpecification.columns.length); - - // col = pivotSpecification.columns[pivotSpecification.columns.length - 1]; - // test.ok(col.hasOwnProperty("fieldName")); - // test.ok(col.hasOwnProperty("owner")); - // test.ok(col.hasOwnProperty("type")); - // test.ok(!col.hasOwnProperty("label")); - // test.ok(col.hasOwnProperty("trueLabel")); - // test.ok(col.hasOwnProperty("falseLabel")); - - // test.strictEqual("has_boris", col.fieldName); - // test.strictEqual("test_data", col.owner); - // test.strictEqual("boolean", col.type); - // test.strictEqual("is_true", col.trueLabel); - // test.strictEqual("is_false", col.falseLabel); - // test.same({ - // fieldName: "has_boris", - // owner: "test_data", - // type: "boolean", - // trueLabel: "is_true", - // falseLabel: "is_false" - // }, - // col); - - // // Test error handling on timestamp column split - // try { - // pivotSpecification.addTimestampColumnSplit("epsilon", "Wrong type here"); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Field was of type " + obj.fieldByName("epsilon").type + ", expected timestamp."); - // } - // try { - // pivotSpecification.addTimestampColumnSplit(field, "Break Me!"); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Did not find field " + field); - // } - // try { - // pivotSpecification.addTimestampColumnSplit("_time", "Bogus binning value"); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Invalid binning Bogus binning value found. Valid values are: " + pivotSpecification._binning.join(", ")); - // } - - // // Test timestamp column split - // pivotSpecification.addTimestampColumnSplit("_time", "day"); - // test.strictEqual(5, pivotSpecification.columns.length); - - // col = pivotSpecification.columns[pivotSpecification.columns.length - 1]; - // test.ok(col.hasOwnProperty("fieldName")); - // test.ok(col.hasOwnProperty("owner")); - // test.ok(col.hasOwnProperty("type")); - // test.ok(!col.hasOwnProperty("label")); - // test.ok(col.hasOwnProperty("period")); - - // test.strictEqual("_time", col.fieldName); - // test.strictEqual("BaseEvent", col.owner); - // test.strictEqual("timestamp", col.type); - // test.strictEqual("day", col.period); - // test.same({ - // fieldName: "_time", - // owner: "BaseEvent", - // type: "timestamp", - // period: "day" - // }, - // col); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, - // "Callback#Pivot - test cell value": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var name = "delete-me-" + getNextId(); - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // var obj = dataModel.objectByName("test_data"); - // test.ok(obj); - - // var pivotSpecification = obj.createPivotSpecification(); - - // // Test error handling for cell value, string - // try { - // pivotSpecification.addCellValue("iDontExist", "Break Me!", "explosion"); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Did not find field iDontExist"); - // } - // try { - // pivotSpecification.addCellValue("source", "Wrong Stats Function", "stdev"); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Stats function on string and IPv4 fields must be one of:" + - // " list, distinct_values, first, last, count, or distinct_count; found stdev"); - // } - - // // Add cell value, string - // pivotSpecification.addCellValue("source", "Source Value", "dc"); - // test.strictEqual(1, pivotSpecification.cells.length); - - // var cell = pivotSpecification.cells[pivotSpecification.cells.length - 1]; - // test.ok(cell.hasOwnProperty("fieldName")); - // test.ok(cell.hasOwnProperty("owner")); - // test.ok(cell.hasOwnProperty("type")); - // test.ok(cell.hasOwnProperty("label")); - // test.ok(cell.hasOwnProperty("value")); - // test.ok(cell.hasOwnProperty("sparkline")); - - // test.strictEqual("source", cell.fieldName); - // test.strictEqual("BaseEvent", cell.owner); - // test.strictEqual("string", cell.type); - // test.strictEqual("Source Value", cell.label); - // test.strictEqual("dc", cell.value); - // test.strictEqual(false, cell.sparkline); - // test.same({ - // fieldName: "source", - // owner: "BaseEvent", - // type: "string", - // label: "Source Value", - // value: "dc", - // sparkline: false - // }, cell); - - // // Test error handling for cell value, IPv4 - // try { - // pivotSpecification.addCellValue("hostip", "Wrong Stats Function", "stdev"); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Stats function on string and IPv4 fields must be one of:" + - // " list, distinct_values, first, last, count, or distinct_count; found stdev"); - // } - - // // Add cell value, IPv4 - // pivotSpecification.addCellValue("hostip", "Source Value", "dc"); - // test.strictEqual(2, pivotSpecification.cells.length); - - // cell = pivotSpecification.cells[pivotSpecification.cells.length - 1]; - // test.ok(cell.hasOwnProperty("fieldName")); - // test.ok(cell.hasOwnProperty("owner")); - // test.ok(cell.hasOwnProperty("type")); - // test.ok(cell.hasOwnProperty("label")); - // test.ok(cell.hasOwnProperty("value")); - // test.ok(cell.hasOwnProperty("sparkline")); - - // test.strictEqual("hostip", cell.fieldName); - // test.strictEqual("test_data", cell.owner); - // test.strictEqual("ipv4", cell.type); - // test.strictEqual("Source Value", cell.label); - // test.strictEqual("dc", cell.value); - // test.strictEqual(false, cell.sparkline); - // test.same({ - // fieldName: "hostip", - // owner: "test_data", - // type: "ipv4", - // label: "Source Value", - // value: "dc", - // sparkline: false - // }, cell); - - // // Test error handling for cell value, boolean - // try { - // pivotSpecification.addCellValue("has_boris", "Booleans not allowed", "sum"); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Cannot use boolean valued fields as cell values."); - // } - - // // Test error handling for cell value, number - // try { - // pivotSpecification.addCellValue("epsilon", "Wrong Stats Function", "latest"); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Stats function on number field must be must be one of:" + - // " sum, count, average, max, min, stdev, list, or distinct_values; found latest"); - // } - - // // Add cell value, number - // pivotSpecification.addCellValue("epsilon", "Source Value", "average"); - // test.strictEqual(3, pivotSpecification.cells.length); - - // cell = pivotSpecification.cells[pivotSpecification.cells.length - 1]; - // test.ok(cell.hasOwnProperty("fieldName")); - // test.ok(cell.hasOwnProperty("owner")); - // test.ok(cell.hasOwnProperty("type")); - // test.ok(cell.hasOwnProperty("label")); - // test.ok(cell.hasOwnProperty("value")); - // test.ok(cell.hasOwnProperty("sparkline")); - - // test.strictEqual("epsilon", cell.fieldName); - // test.strictEqual("test_data", cell.owner); - // test.strictEqual("number", cell.type); - // test.strictEqual("Source Value", cell.label); - // test.strictEqual("average", cell.value); - // test.strictEqual(false, cell.sparkline); - // test.same({ - // fieldName: "epsilon", - // owner: "test_data", - // type: "number", - // label: "Source Value", - // value: "average", - // sparkline: false - // }, cell); - - // // Test error handling for cell value, timestamp - // try { - // pivotSpecification.addCellValue("_time", "Wrong Stats Function", "max"); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Stats function on timestamp field must be one of:" + - // " duration, earliest, latest, list, or distinct values; found max"); - // } - - // // Add cell value, timestamp - // pivotSpecification.addCellValue("_time", "Source Value", "earliest"); - // test.strictEqual(4, pivotSpecification.cells.length); - - // cell = pivotSpecification.cells[pivotSpecification.cells.length - 1]; - // test.ok(cell.hasOwnProperty("fieldName")); - // test.ok(cell.hasOwnProperty("owner")); - // test.ok(cell.hasOwnProperty("type")); - // test.ok(cell.hasOwnProperty("label")); - // test.ok(cell.hasOwnProperty("value")); - // test.ok(cell.hasOwnProperty("sparkline")); - - // test.strictEqual("_time", cell.fieldName); - // test.strictEqual("BaseEvent", cell.owner); - // test.strictEqual("timestamp", cell.type); - // test.strictEqual("Source Value", cell.label); - // test.strictEqual("earliest", cell.value); - // test.strictEqual(false, cell.sparkline); - // test.same({ - // fieldName: "_time", - // owner: "BaseEvent", - // type: "timestamp", - // label: "Source Value", - // value: "earliest", - // sparkline: false - // }, cell); - - // // Test error handling for cell value, count - // try { - // pivotSpecification.addCellValue("test_data", "Wrong Stats Function", "min"); - // test.ok(false); - // } - // catch (e) { - // test.ok(e); - // test.strictEqual(e.message, "Stats function on childcount and objectcount fields " + - // "must be count; found " + "min"); - // } - - // // Add cell value, count - // pivotSpecification.addCellValue("test_data", "Source Value", "count"); - // test.strictEqual(5, pivotSpecification.cells.length); - - // cell = pivotSpecification.cells[pivotSpecification.cells.length - 1]; - // test.ok(cell.hasOwnProperty("fieldName")); - // test.ok(cell.hasOwnProperty("owner")); - // test.ok(cell.hasOwnProperty("type")); - // test.ok(cell.hasOwnProperty("label")); - // test.ok(cell.hasOwnProperty("value")); - // test.ok(cell.hasOwnProperty("sparkline")); - - // test.strictEqual("test_data", cell.fieldName); - // test.strictEqual("test_data", cell.owner); - // test.strictEqual("objectCount", cell.type); - // test.strictEqual("Source Value", cell.label); - // test.strictEqual("count", cell.value); - // test.strictEqual(false, cell.sparkline); - // test.same({ - // fieldName: "test_data", - // owner: "test_data", - // type: "objectCount", - // label: "Source Value", - // value: "count", - // sparkline: false - // }, cell); + test.strictEqual(dataModelObject.dataModel.name, pivotSpecification.accelerationNamespace); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, - // "Callback#Pivot - test pivot throws HTTP exception": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var name = "delete-me-" + getNextId(); - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // var obj = dataModel.objectByName("test_data"); - // test.ok(obj); + var name1 = "delete-me-" + getNextId(); + pivotSpecification.setAccelerationJob(name1); + test.strictEqual("sid=" + name1, pivotSpecification.accelerationNamespace); - // obj.createPivotSpecification().pivot(done); - // }, - // function(pivot, done) { - // test.ok(false); - // } - // ], - // function(err) { - // test.ok(err); - // var expectedErr = "In handler 'datamodelpivot': Error in 'PivotReport': Must have non-empty cells or non-empty rows."; - // test.ok(utils.endsWith(err.message, expectedErr)); - // test.done(); - // } - // ); - // }, - // "Callback#Pivot - test pivot with simple namespace": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var name = "delete-me-" + getNextId(); - // var args; - // try { - // args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); - // } - // catch(err) { - // // Fail if we can't read the file, likely to occur in the browser - // test.ok(!err); - // test.done(); - // } - // var that = this; - // var obj; - // var pivotSpecification; - // var adhocjob; - // Async.chain([ - // function(done) { - // that.dataModels.create(name, args, done); - // }, - // function(dataModel, done) { - // obj = dataModel.objectByName("test_data"); - // test.ok(obj); - // obj.createLocalAccelerationJob(null, done); - // }, - // function(job, done) { - // adhocjob = job; - // test.ok(job); - // pivotSpecification = obj.createPivotSpecification(); + var namespaceTemp = "delete-me-" + getNextId(); + pivotSpecification.accelerationNamespace = namespaceTemp; + test.strictEqual(namespaceTemp, pivotSpecification.accelerationNamespace); - // pivotSpecification.addBooleanRowSplit("has_boris", "Has Boris", "meep", "hilda"); - // pivotSpecification.addCellValue("hostip", "Distinct IPs", "count"); + pivotSpecification + .addCellValue("test_data", "Source Value", "count") + .run(done); + }, + function(job, pivot, done) { + test.ok(job); + test.ok(pivot); + test.notStrictEqual("FAILED", job.properties().dispatchState); - // // Test setting a job - // pivotSpecification.setAccelerationJob(job); - // test.strictEqual("string", typeof pivotSpecification.accelerationNamespace); - // test.strictEqual("sid=" + job.sid, pivotSpecification.accelerationNamespace); + job.track({}, function(job) { + test.ok(pivot.tstatsSearch); + test.strictEqual(0, job.properties().request.search.indexOf("| tstats")); + test.strictEqual("| tstats", job.properties().request.search.match("^\\| tstats")[0]); + test.strictEqual(1, job.properties().request.search.match("^\\| tstats").length); - // // Test setting a job's SID - // pivotSpecification.setAccelerationJob(job.sid); - // test.strictEqual("string", typeof pivotSpecification.accelerationNamespace); - // test.strictEqual("sid=" + job.sid, pivotSpecification.accelerationNamespace); + test.strictEqual(pivot.tstatsSearch, job.properties().request.search); + done(null, job); + }); + }, + function(job, done) { + test.ok(job); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // pivotSpecification.pivot(done); - // }, - // function(pivot, done) { - // test.ok(pivot.tstatsSearch); - // test.ok(pivot.tstatsSearch.length > 0); - // test.strictEqual(0, pivot.tstatsSearch.indexOf("| tstats")); - // // This test won't work with utils.startsWith due to the regex escaping - // test.strictEqual("| tstats", pivot.tstatsSearch.match("^\\| tstats")[0]); - // test.strictEqual(1, pivot.tstatsSearch.match("^\\| tstats").length); - - // pivot.run(done); - // }, - // function(job, done) { - // tutils.pollUntil( - // job, - // function(j) { - // return job.properties().isDone; - // }, - // 10, - // done - // ); - // }, - // function(job, done) { - // test.ok("FAILED" !== job.properties().dispatchState); + "Callback#Pivot - test illegal filtering (all types)": function(test) { + if (this.skip) { + test.done(); + return; + } + var name = "delete-me-" + getNextId(); + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var that = this; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + var obj = dataModel.objectByName("test_data"); + test.ok(obj); - // test.strictEqual(0, job.properties().request.search.indexOf("| tstats")); - // // This test won't work with utils.startsWith due to the regex escaping - // test.strictEqual("| tstats", job.properties().request.search.match("^\\| tstats")[0]); - // test.strictEqual(1, job.properties().request.search.match("^\\| tstats").length); + var pivotSpecification = obj.createPivotSpecification(); - // adhocjob.cancel(done); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, - // "Callback#Pivot - test pivot column range split": function(test) { - // // This test is here because we had a problem with fields that were supposed to be - // // numbers being expected as strings in Splunk 6.0. This was fixed in Splunk 6.1, and accepts - // // either strings or numbers. + // Boolean comparisons + try { + pivotSpecification.addFilter(getNextId(), "boolean", "=", true); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Cannot add filter on a nonexistent field."); + } + try { + pivotSpecification.addFilter("_time", "boolean", "=", true); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Cannot add boolean filter on _time because it is of type timestamp"); + } - // if (this.skip) { - // test.done(); - // return; - // } - // var that = this; - // var search; - // Async.chain([ - // function(done) { - // that.dataModels.fetch(done); - // }, - // function(dataModels, done) { - // var dm = dataModels.item("internal_audit_logs"); - // var obj = dm.objectByName("searches"); - // var pivotSpecification = obj.createPivotSpecification(); - - // pivotSpecification.addRowSplit("user", "Executing user"); - // pivotSpecification.addRangeColumnSplit("exec_time", {start: 0, end: 12, step: 5, limit: 4}); - // pivotSpecification.addCellValue("search", "Search Query", "values"); - // pivotSpecification.pivot(done); - // }, - // function(pivot, done) { - // // If tstats is undefined, use pivotSearch - // search = pivot.tstatsSearch || pivot.pivotSearch; - // pivot.run(done); - // }, - // function(job, done) { - // tutils.pollUntil( - // job, - // function(j) { - // return job.properties().isDone; - // }, - // 10, - // done - // ); - // }, - // function(job, done) { - // test.notStrictEqual("FAILED", job.properties().dispatchState); - // // Make sure the job is run with the correct search query - // test.strictEqual(search, job.properties().request.search); - // job.cancel(done); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, - // "Callback#Pivot - test pivot with PivotSpecification.run and Job.track": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // var that = this; - // Async.chain([ - // function(done) { - // that.dataModels.fetch(done); - // }, - // function(dataModels, done) { - // var dm = dataModels.item("internal_audit_logs"); - // var obj = dm.objectByName("searches"); - // var pivotSpecification = obj.createPivotSpecification(); + // String comparisons + try { + pivotSpecification.addFilter("has_boris", "string", "contains", "abc"); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Cannot add string filter on has_boris because it is of type boolean"); + } + try { + pivotSpecification.addFilter(getNextId(), "string", "contains", "abc"); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Cannot add filter on a nonexistent field."); + } - // pivotSpecification.addRowSplit("user", "Executing user"); - // pivotSpecification.addRangeColumnSplit("exec_time", {start: 0, end: 12, step: 5, limit: 4}); - // pivotSpecification.addCellValue("search", "Search Query", "values"); + // IPv4 comparisons + try { + pivotSpecification.addFilter("has_boris", "ipv4", "startsWith", "192.168"); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Cannot add ipv4 filter on has_boris because it is of type boolean"); + } + try { + pivotSpecification.addFilter(getNextId(), "ipv4", "startsWith", "192.168"); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Cannot add filter on a nonexistent field."); + } - // pivotSpecification.run({}, done); - // }, - // function(job, pivot, done) { - // job.track({}, function(job) { - // test.strictEqual(pivot.tstatsSearch || pivot.pivotSearch, job.properties().request.search); - // done(null, job); - // }); - // }, - // function(job, done) { - // test.notStrictEqual("FAILED", job.properties().dispatchState); - // job.cancel(done); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, - // "Callback#DataModels - delete any remaining data models created by the SDK tests": function(test) { - // if (this.skip) { - // test.done(); - // return; - // } - // svc.dataModels().fetch(function(err, dataModels) { - // if (err) { - // test.ok(!err); - // } - - // var dms = dataModels.list(); - // Async.seriesEach( - // dms, - // function(datamodel, i, done) { - // // Delete any test data models that we created - // if (utils.startsWith(datamodel.name, "delete-me")) { - // datamodel.remove(done); - // } - // else { - // done(); - // } - // }, - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }); - // } - // }, - - // "App Tests": { - // setUp: function(done) { - // this.service = svc; - // done(); - // }, + // Number comparisons + try { + pivotSpecification.addFilter("has_boris", "number", "atLeast", 2.3); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Cannot add number filter on has_boris because it is of type boolean"); + } + try { + pivotSpecification.addFilter(getNextId(), "number", "atLeast", 2.3); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Cannot add filter on a nonexistent field."); + } - // "Callback#list applications": function(test) { - // var apps = this.service.apps(); - // apps.fetch(function(err, apps) { - // var appList = apps.list(); - // test.ok(appList.length > 0); - // test.done(); - // }); - // }, + // Limit filter + try { + pivotSpecification.addLimitFilter("has_boris", "host", "DEFAULT", 50, "count"); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Cannot add limit filter on has_boris because it is of type boolean"); + } + try { + pivotSpecification.addLimitFilter(getNextId(), "host", "DEFAULT", 50, "count"); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Cannot add limit filter on a nonexistent field."); + } + try { + pivotSpecification.addLimitFilter("source", "host", "DEFAULT", 50, "sum"); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, + "Stats function for fields of type string must be COUNT or DISTINCT_COUNT; found sum"); + } + try { + pivotSpecification.addLimitFilter("epsilon", "host", "DEFAULT", 50, "duration"); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, + "Stats function for fields of type number must be one of COUNT, DISTINCT_COUNT, SUM, or AVERAGE; found duration"); + } + try { + pivotSpecification.addLimitFilter("test_data", "host", "DEFAULT", 50, "list"); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, + "Stats function for fields of type object count must be COUNT; found list"); + } + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // "Callback#contains applications": function(test) { - // var apps = this.service.apps(); - // apps.fetch(function(err, apps) { - // var app = apps.item("search"); - // test.ok(app); - // test.done(); - // }); - // }, + "Callback#Pivot - test boolean filtering": function(test) { + if (this.skip) { + test.done(); + return; + } + var name = "delete-me-" + getNextId(); + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var that = this; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + var obj = dataModel.objectByName("test_data"); + test.ok(obj); + + var pivotSpecification = obj.createPivotSpecification(); + try { + pivotSpecification.addFilter("has_boris", "boolean", "=", true); + test.strictEqual(1, pivotSpecification.filters.length); + + //Test the individual parts of the filter + var filter = pivotSpecification.filters[0]; + + test.ok(filter.hasOwnProperty("fieldName")); + test.ok(filter.hasOwnProperty("type")); + test.ok(filter.hasOwnProperty("rule")); + test.ok(filter.hasOwnProperty("owner")); + + test.strictEqual("has_boris", filter.fieldName); + test.strictEqual("boolean", filter.type); + test.strictEqual("=", filter.rule.comparator); + test.strictEqual(true, filter.rule.compareTo); + test.strictEqual("test_data", filter.owner); + } + catch (e) { + test.ok(false); + } - // "Callback#create + contains app": function(test) { - // var name = "jssdk_testapp_" + getNextId(); - // var apps = this.service.apps(); - - // apps.create({name: name}, function(err, app) { - // var appName = app.name; - // apps.fetch(function(err, apps) { - // var entity = apps.item(appName); - // test.ok(entity); - // app.remove(function() { - // test.done(); - // }); - // }); - // }); - // }, + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // "Callback#create + modify app": function(test) { - // var DESCRIPTION = "TEST DESCRIPTION"; - // var VERSION = "1.1.0"; + "Callback#Pivot - test string filtering": function(test) { + if (this.skip) { + test.done(); + return; + } + var name = "delete-me-" + getNextId(); + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var that = this; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + var obj = dataModel.objectByName("test_data"); + test.ok(obj); + + var pivotSpecification = obj.createPivotSpecification(); + try { + pivotSpecification.addFilter("host", "string", "contains", "abc"); + test.strictEqual(1, pivotSpecification.filters.length); + + //Test the individual parts of the filter + var filter = pivotSpecification.filters[0]; + + test.ok(filter.hasOwnProperty("fieldName")); + test.ok(filter.hasOwnProperty("type")); + test.ok(filter.hasOwnProperty("rule")); + test.ok(filter.hasOwnProperty("owner")); + + test.strictEqual("host", filter.fieldName); + test.strictEqual("string", filter.type); + test.strictEqual("contains", filter.rule.comparator); + test.strictEqual("abc", filter.rule.compareTo); + test.strictEqual("BaseEvent", filter.owner); + } + catch (e) { + test.ok(false); + } - // var name = "jssdk_testapp_" + getNextId(); - // var apps = this.service.apps(); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // Async.chain([ - // function(callback) { - // apps.create({name: name}, callback); - // }, - // function(app, callback) { - // test.ok(app); - // test.strictEqual(app.name, name); - // var versionMatches = app.properties().version === "1.0" || - // app.properties().version == "1.0.0"; - // test.ok(versionMatches); - - // app.update({ - // description: DESCRIPTION, - // version: VERSION - // }, callback); - // }, - // function(app, callback) { - // test.ok(app); - // var properties = app.properties(); - - // test.strictEqual(properties.description, DESCRIPTION); - // test.strictEqual(properties.version, VERSION); - - // app.remove(callback); - // } - // ], function(err) { - // test.ok(!err); - // test.done(); - // }); - // }, + "Callback#Pivot - test IPv4 filtering": function(test) { + if (this.skip) { + test.done(); + return; + } + var name = "delete-me-" + getNextId(); + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var that = this; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + var obj = dataModel.objectByName("test_data"); + test.ok(obj); + + var pivotSpecification = obj.createPivotSpecification(); + try { + pivotSpecification.addFilter("hostip", "ipv4", "startsWith", "192.168"); + test.strictEqual(1, pivotSpecification.filters.length); + + //Test the individual parts of the filter + var filter = pivotSpecification.filters[0]; + + test.ok(filter.hasOwnProperty("fieldName")); + test.ok(filter.hasOwnProperty("type")); + test.ok(filter.hasOwnProperty("rule")); + test.ok(filter.hasOwnProperty("owner")); + + test.strictEqual("hostip", filter.fieldName); + test.strictEqual("ipv4", filter.type); + test.strictEqual("startsWith", filter.rule.comparator); + test.strictEqual("192.168", filter.rule.compareTo); + test.strictEqual("test_data", filter.owner); + } + catch (e) { + test.ok(false); + } - // "Callback#delete test applications": function(test) { - // var apps = this.service.apps(); - // apps.fetch(function(err, apps) { - // var appList = apps.list(); - - // Async.parallelEach( - // appList, - // function(app, idx, callback) { - // if (utils.startsWith(app.name, "jssdk_")) { - // app.remove(callback); - // } - // else { - // callback(); - // } - // }, function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }); - // }, + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // "list applications with cookies as authentication": function(test) { - // this.service.serverInfo(function (err, info) { - // // Cookie authentication was added in splunk 6.2 - // var majorVersion = parseInt(info.properties().version.split(".")[0], 10); - // var minorVersion = parseInt(info.properties().version.split(".")[1], 10); - // // Skip cookie test if Splunk older than 6.2 - // if(majorVersion < 6 || (majorVersion === 6 && minorVersion < 2)) { - // splunkjs.Logger.log("Skipping cookie test..."); - // test.done(); - // return; - // } + "Callback#Pivot - test number filtering": function(test) { + if (this.skip) { + test.done(); + return; + } + var name = "delete-me-" + getNextId(); + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var that = this; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + var obj = dataModel.objectByName("test_data"); + test.ok(obj); + + var pivotSpecification = obj.createPivotSpecification(); + try { + pivotSpecification.addFilter("epsilon", "number", ">=", 2.3); + test.strictEqual(1, pivotSpecification.filters.length); + + //Test the individual parts of the filter + var filter = pivotSpecification.filters[0]; + + test.ok(filter.hasOwnProperty("fieldName")); + test.ok(filter.hasOwnProperty("type")); + test.ok(filter.hasOwnProperty("rule")); + test.ok(filter.hasOwnProperty("owner")); + + test.strictEqual("epsilon", filter.fieldName); + test.strictEqual("number", filter.type); + test.strictEqual(">=", filter.rule.comparator); + test.strictEqual(2.3, filter.rule.compareTo); + test.strictEqual("test_data", filter.owner); + } + catch (e) { + test.ok(false); + } - // var service = new splunkjs.Service( - // { - // scheme: svc.scheme, - // host: svc.host, - // port: svc.port, - // username: svc.username, - // password: svc.password, - // version: svc.version - // }); - - // var service2 = new splunkjs.Service( - // { - // scheme: svc.scheme, - // host: svc.host, - // port: svc.port, - // version: svc.version - // }); - - // Async.chain([ - // function (done) { - // service.login(done); - // }, - // function (job, done) { - // // Save the cookie store - // var cookieStore = service.http._cookieStore; - // // Test that there are cookies - // test.ok(!utils.isEmpty(cookieStore)); - - // // Add the cookies to a service with no other authenitcation information - // service2.http._cookieStore = cookieStore; - - // var apps = service2.apps(); - // apps.fetch(done); - // }, - // function (apps, done) { - // var appList = apps.list(); - // test.ok(appList.length > 0); - // test.ok(!utils.isEmpty(service2.http._cookieStore)); - // done(); - // } - // ], - // function(err) { - // // Test that no errors were returned - // test.ok(!err); - // test.done(); - // }); - // }); - // } - // }, + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, + "Callback#Pivot - test limit filtering": function(test) { + if (this.skip) { + test.done(); + return; + } + var name = "delete-me-" + getNextId(); + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var that = this; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + var obj = dataModel.objectByName("test_data"); + test.ok(obj); + + var pivotSpecification = obj.createPivotSpecification(); + try { + pivotSpecification.addLimitFilter("epsilon", "host", "ASCENDING", 500, "average"); + test.strictEqual(1, pivotSpecification.filters.length); + + //Test the individual parts of the filter + var filter = pivotSpecification.filters[0]; + + test.ok(filter.hasOwnProperty("fieldName")); + test.ok(filter.hasOwnProperty("type")); + test.ok(filter.hasOwnProperty("owner")); + test.ok(filter.hasOwnProperty("attributeName")); + test.ok(filter.hasOwnProperty("attributeOwner")); + test.ok(filter.hasOwnProperty("limitType")); + test.ok(filter.hasOwnProperty("limitAmount")); + test.ok(filter.hasOwnProperty("statsFn")); + + test.strictEqual("epsilon", filter.fieldName); + test.strictEqual("number", filter.type); + test.strictEqual("test_data", filter.owner); + test.strictEqual("host", filter.attributeName); + test.strictEqual("BaseEvent", filter.attributeOwner); + test.strictEqual("lowest", filter.limitType); + test.strictEqual(500, filter.limitAmount); + test.strictEqual("average", filter.statsFn); + } + catch (e) { + test.ok(false); + } - // "Saved Search Tests": { - // setUp: function(done) { - // this.service = svc; - // this.loggedOutService = loggedOutSvc; - // done(); - // }, + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, + "Callback#Pivot - test row split": function(test) { + if (this.skip) { + test.done(); + return; + } + var name = "delete-me-" + getNextId(); + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var that = this; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + var obj = dataModel.objectByName("test_data"); + test.ok(obj); - // "Callback#list": function(test) { - // var searches = this.service.savedSearches(); - // searches.fetch(function(err, searches) { - // var savedSearches = searches.list(); - // test.ok(savedSearches.length > 0); + var pivotSpecification = obj.createPivotSpecification(); - // for(var i = 0; i < savedSearches.length; i++) { - // test.ok(savedSearches[i]); - // } + // Test error handling for row split + try { + pivotSpecification.addRowSplit("has_boris", "Wrong type here"); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Field was of type " + obj.fieldByName("has_boris").type + ", expected number or string."); + } + var field = getNextId(); + try { - // test.done(); - // }); - // }, + pivotSpecification.addRowSplit(field, "Break Me!"); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Did not find field " + field); + } - // "Callback#contains": function(test) { - // var searches = this.service.savedSearches(); - // searches.fetch(function(err, searches) { - // var search = searches.item("Errors in the last hour"); - // test.ok(search); + // Test row split, number + pivotSpecification.addRowSplit("epsilon", "My Label"); + test.strictEqual(1, pivotSpecification.rows.length); + + var row = pivotSpecification.rows[0]; + test.ok(row.hasOwnProperty("fieldName")); + test.ok(row.hasOwnProperty("owner")); + test.ok(row.hasOwnProperty("type")); + test.ok(row.hasOwnProperty("label")); + test.ok(row.hasOwnProperty("display")); + + test.strictEqual("epsilon", row.fieldName); + test.strictEqual("test_data", row.owner); + test.strictEqual("number", row.type); + test.strictEqual("My Label", row.label); + test.strictEqual("all", row.display); + test.same({ + fieldName: "epsilon", + owner: "test_data", + type: "number", + label: "My Label", + display: "all" + }, + row); + + // Test row split, string + pivotSpecification.addRowSplit("host", "My Label"); + test.strictEqual(2, pivotSpecification.rows.length); + + row = pivotSpecification.rows[pivotSpecification.rows.length - 1]; + test.ok(row.hasOwnProperty("fieldName")); + test.ok(row.hasOwnProperty("owner")); + test.ok(row.hasOwnProperty("type")); + test.ok(row.hasOwnProperty("label")); + test.ok(!row.hasOwnProperty("display")); + + test.strictEqual("host", row.fieldName); + test.strictEqual("BaseEvent", row.owner); + test.strictEqual("string", row.type); + test.strictEqual("My Label", row.label); + test.same({ + fieldName: "host", + owner: "BaseEvent", + type: "string", + label: "My Label" + }, + row); + + // Test error handling on range row split + try { + pivotSpecification.addRangeRowSplit("has_boris", "Wrong type here", {start: 0, end: 100, step:20, limit:5}); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Field was of type " + obj.fieldByName("has_boris").type + ", expected number."); + } + try { + pivotSpecification.addRangeRowSplit(field, "Break Me!", {start: 0, end: 100, step:20, limit:5}); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Did not find field " + field); + } - // test.done(); - // }); - // }, + // Test range row split + pivotSpecification.addRangeRowSplit("epsilon", "My Label", {start: 0, end: 100, step:20, limit:5}); + test.strictEqual(3, pivotSpecification.rows.length); + + row = pivotSpecification.rows[pivotSpecification.rows.length - 1]; + test.ok(row.hasOwnProperty("fieldName")); + test.ok(row.hasOwnProperty("owner")); + test.ok(row.hasOwnProperty("type")); + test.ok(row.hasOwnProperty("label")); + test.ok(row.hasOwnProperty("display")); + test.ok(row.hasOwnProperty("ranges")); + + test.strictEqual("epsilon", row.fieldName); + test.strictEqual("test_data", row.owner); + test.strictEqual("number", row.type); + test.strictEqual("My Label", row.label); + test.strictEqual("ranges", row.display); + + var ranges = { + start: 0, + end: 100, + size: 20, + maxNumberOf: 5 + }; + test.same(ranges, row.ranges); + test.same({ + fieldName: "epsilon", + owner: "test_data", + type: "number", + label: "My Label", + display: "ranges", + ranges: ranges + }, + row); + + // Test error handling on boolean row split + try { + pivotSpecification.addBooleanRowSplit("epsilon", "Wrong type here", "t", "f"); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Field was of type " + obj.fieldByName("epsilon").type + ", expected boolean."); + } + try { + pivotSpecification.addBooleanRowSplit(field, "Break Me!", "t", "f"); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Did not find field " + field); + } - // "Callback#suppress": function(test) { - // var searches = this.service.savedSearches(); - // searches.fetch(function(err, searches) { - // var search = searches.item("Errors in the last hour"); - // test.ok(search); + // Test boolean row split + pivotSpecification.addBooleanRowSplit("has_boris", "My Label", "is_true", "is_false"); + test.strictEqual(4, pivotSpecification.rows.length); + + row = pivotSpecification.rows[pivotSpecification.rows.length - 1]; + test.ok(row.hasOwnProperty("fieldName")); + test.ok(row.hasOwnProperty("owner")); + test.ok(row.hasOwnProperty("type")); + test.ok(row.hasOwnProperty("label")); + test.ok(row.hasOwnProperty("trueLabel")); + test.ok(row.hasOwnProperty("falseLabel")); + + test.strictEqual("has_boris", row.fieldName); + test.strictEqual("My Label", row.label); + test.strictEqual("test_data", row.owner); + test.strictEqual("boolean", row.type); + test.strictEqual("is_true", row.trueLabel); + test.strictEqual("is_false", row.falseLabel); + test.same({ + fieldName: "has_boris", + label: "My Label", + owner: "test_data", + type: "boolean", + trueLabel: "is_true", + falseLabel: "is_false" + }, + row); + + // Test error handling on timestamp row split + try { + pivotSpecification.addTimestampRowSplit("epsilon", "Wrong type here", "some binning"); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Field was of type " + obj.fieldByName("epsilon").type + ", expected timestamp."); + } + try { + pivotSpecification.addTimestampRowSplit(field, "Break Me!", "some binning"); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Did not find field " + field); + } + try { + pivotSpecification.addTimestampRowSplit("_time", "some label", "Bogus binning value"); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Invalid binning Bogus binning value found. Valid values are: " + pivotSpecification._binning.join(", ")); + } - // search.suppressInfo(function(err, info, search) { - // test.ok(!err); - // test.done(); - // }); - // }); - // }, + // Test timestamp row split + pivotSpecification.addTimestampRowSplit("_time", "My Label", "day"); + test.strictEqual(5, pivotSpecification.rows.length); + + row = pivotSpecification.rows[pivotSpecification.rows.length - 1]; + test.ok(row.hasOwnProperty("fieldName")); + test.ok(row.hasOwnProperty("owner")); + test.ok(row.hasOwnProperty("type")); + test.ok(row.hasOwnProperty("label")); + test.ok(row.hasOwnProperty("period")); + + test.strictEqual("_time", row.fieldName); + test.strictEqual("My Label", row.label); + test.strictEqual("BaseEvent", row.owner); + test.strictEqual("timestamp", row.type); + test.strictEqual("day", row.period); + test.same({ + fieldName: "_time", + label: "My Label", + owner: "BaseEvent", + type: "timestamp", + period: "day" + }, + row); - // "Callback#list limit count": function(test) { - // var searches = this.service.savedSearches(); - // searches.fetch({count: 2}, function(err, searches) { - // var savedSearches = searches.list(); - // test.strictEqual(savedSearches.length, 2); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, + "Callback#Pivot - test column split": function(test) { + if (this.skip) { + test.done(); + return; + } + var name = "delete-me-" + getNextId(); + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var that = this; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + var obj = dataModel.objectByName("test_data"); + test.ok(obj); - // for(var i = 0; i < savedSearches.length; i++) { - // test.ok(savedSearches[i]); - // } + var pivotSpecification = obj.createPivotSpecification(); - // test.done(); - // }); - // }, + // Test error handling for column split + try { + pivotSpecification.addColumnSplit("has_boris", "Wrong type here"); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Field was of type " + obj.fieldByName("has_boris").type + ", expected number or string."); + } + var field = getNextId(); + try { - // "Callback#list filter": function(test) { - // var searches = this.service.savedSearches(); - // searches.fetch({search: "Error"}, function(err, searches) { - // var savedSearches = searches.list(); - // test.ok(savedSearches.length > 0); + pivotSpecification.addColumnSplit(field, "Break Me!"); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Did not find field " + field); + } - // for(var i = 0; i < savedSearches.length; i++) { - // test.ok(savedSearches[i]); - // } + // Test column split, number + pivotSpecification.addColumnSplit("epsilon"); + test.strictEqual(1, pivotSpecification.columns.length); + + var col = pivotSpecification.columns[pivotSpecification.columns.length - 1]; + test.ok(col.hasOwnProperty("fieldName")); + test.ok(col.hasOwnProperty("owner")); + test.ok(col.hasOwnProperty("type")); + test.ok(col.hasOwnProperty("display")); + + test.strictEqual("epsilon", col.fieldName); + test.strictEqual("test_data", col.owner); + test.strictEqual("number", col.type); + test.strictEqual("all", col.display); + test.same({ + fieldName: "epsilon", + owner: "test_data", + type: "number", + display: "all" + }, + col); + + // Test column split, string + pivotSpecification.addColumnSplit("host"); + test.strictEqual(2, pivotSpecification.columns.length); + + col = pivotSpecification.columns[pivotSpecification.columns.length - 1]; + test.ok(col.hasOwnProperty("fieldName")); + test.ok(col.hasOwnProperty("owner")); + test.ok(col.hasOwnProperty("type")); + test.ok(!col.hasOwnProperty("display")); + + test.strictEqual("host", col.fieldName); + test.strictEqual("BaseEvent", col.owner); + test.strictEqual("string", col.type); + test.same({ + fieldName: "host", + owner: "BaseEvent", + type: "string" + }, + col); - // test.done(); - // }); - // }, + done(); - // "Callback#list offset": function(test) { - // var searches = this.service.savedSearches(); - // searches.fetch({offset: 2, count: 1}, function(err, searches) { - // var savedSearches = searches.list(); - // test.strictEqual(searches.paging().offset, 2); - // test.strictEqual(searches.paging().perPage, 1); - // test.strictEqual(savedSearches.length, 1); + // Test error handling for range column split + try { + pivotSpecification.addRangeColumnSplit("has_boris", "Wrong type here", {start: 0, end: 100, step:20, limit:5}); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Field was of type " + obj.fieldByName("has_boris").type + ", expected number."); + } + try { + pivotSpecification.addRangeColumnSplit(field, {start: 0, end: 100, step:20, limit:5}); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Did not find field " + field); + } - // for(var i = 0; i < savedSearches.length; i++) { - // test.ok(savedSearches[i]); - // } + // Test range column split + pivotSpecification.addRangeColumnSplit("epsilon", {start: 0, end: 100, step:20, limit:5}); + test.strictEqual(3, pivotSpecification.columns.length); + + col = pivotSpecification.columns[pivotSpecification.columns.length - 1]; + test.ok(col.hasOwnProperty("fieldName")); + test.ok(col.hasOwnProperty("owner")); + test.ok(col.hasOwnProperty("type")); + test.ok(col.hasOwnProperty("display")); + test.ok(col.hasOwnProperty("ranges")); + + test.strictEqual("epsilon", col.fieldName); + test.strictEqual("test_data", col.owner); + test.strictEqual("number", col.type); + test.strictEqual("ranges", col.display); + var ranges = { + start: "0", + end: "100", + size: "20", + maxNumberOf: "5" + }; + test.same(ranges, col.ranges); + test.same({ + fieldName: "epsilon", + owner: "test_data", + type: "number", + display: "ranges", + ranges: ranges + }, + col); + + // Test error handling on boolean column split + try { + pivotSpecification.addBooleanColumnSplit("epsilon", "t", "f"); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Field was of type " + obj.fieldByName("epsilon").type + ", expected boolean."); + } + try { + pivotSpecification.addBooleanColumnSplit(field, "t", "f"); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Did not find field " + field); + } - // test.done(); - // }); - // }, + // Test boolean column split + pivotSpecification.addBooleanColumnSplit("has_boris", "is_true", "is_false"); + test.strictEqual(4, pivotSpecification.columns.length); + + col = pivotSpecification.columns[pivotSpecification.columns.length - 1]; + test.ok(col.hasOwnProperty("fieldName")); + test.ok(col.hasOwnProperty("owner")); + test.ok(col.hasOwnProperty("type")); + test.ok(!col.hasOwnProperty("label")); + test.ok(col.hasOwnProperty("trueLabel")); + test.ok(col.hasOwnProperty("falseLabel")); + + test.strictEqual("has_boris", col.fieldName); + test.strictEqual("test_data", col.owner); + test.strictEqual("boolean", col.type); + test.strictEqual("is_true", col.trueLabel); + test.strictEqual("is_false", col.falseLabel); + test.same({ + fieldName: "has_boris", + owner: "test_data", + type: "boolean", + trueLabel: "is_true", + falseLabel: "is_false" + }, + col); + + // Test error handling on timestamp column split + try { + pivotSpecification.addTimestampColumnSplit("epsilon", "Wrong type here"); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Field was of type " + obj.fieldByName("epsilon").type + ", expected timestamp."); + } + try { + pivotSpecification.addTimestampColumnSplit(field, "Break Me!"); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Did not find field " + field); + } + try { + pivotSpecification.addTimestampColumnSplit("_time", "Bogus binning value"); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Invalid binning Bogus binning value found. Valid values are: " + pivotSpecification._binning.join(", ")); + } - // "Callback#create + modify + delete saved search": function(test) { - // var name = "jssdk_savedsearch"; - // var originalSearch = "search * | head 1"; - // var updatedSearch = "search * | head 10"; - // var updatedDescription = "description"; + // Test timestamp column split + pivotSpecification.addTimestampColumnSplit("_time", "day"); + test.strictEqual(5, pivotSpecification.columns.length); + + col = pivotSpecification.columns[pivotSpecification.columns.length - 1]; + test.ok(col.hasOwnProperty("fieldName")); + test.ok(col.hasOwnProperty("owner")); + test.ok(col.hasOwnProperty("type")); + test.ok(!col.hasOwnProperty("label")); + test.ok(col.hasOwnProperty("period")); + + test.strictEqual("_time", col.fieldName); + test.strictEqual("BaseEvent", col.owner); + test.strictEqual("timestamp", col.type); + test.strictEqual("day", col.period); + test.same({ + fieldName: "_time", + owner: "BaseEvent", + type: "timestamp", + period: "day" + }, + col); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, + "Callback#Pivot - test cell value": function(test) { + if (this.skip) { + test.done(); + return; + } + var name = "delete-me-" + getNextId(); + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var that = this; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + var obj = dataModel.objectByName("test_data"); + test.ok(obj); - // var searches = this.service.savedSearches({owner: this.service.username, app: "sdk-app-collection"}); + var pivotSpecification = obj.createPivotSpecification(); - // Async.chain([ - // function(done) { - // searches.create({search: originalSearch, name: name}, done); - // }, - // function(search, done) { - // test.ok(search); + // Test error handling for cell value, string + try { + pivotSpecification.addCellValue("iDontExist", "Break Me!", "explosion"); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Did not find field iDontExist"); + } + try { + pivotSpecification.addCellValue("source", "Wrong Stats Function", "stdev"); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Stats function on string and IPv4 fields must be one of:" + + " list, distinct_values, first, last, count, or distinct_count; found stdev"); + } - // test.strictEqual(search.name, name); - // test.strictEqual(search.properties().search, originalSearch); - // test.ok(!search.properties().description); + // Add cell value, string + pivotSpecification.addCellValue("source", "Source Value", "dc"); + test.strictEqual(1, pivotSpecification.cells.length); + + var cell = pivotSpecification.cells[pivotSpecification.cells.length - 1]; + test.ok(cell.hasOwnProperty("fieldName")); + test.ok(cell.hasOwnProperty("owner")); + test.ok(cell.hasOwnProperty("type")); + test.ok(cell.hasOwnProperty("label")); + test.ok(cell.hasOwnProperty("value")); + test.ok(cell.hasOwnProperty("sparkline")); + + test.strictEqual("source", cell.fieldName); + test.strictEqual("BaseEvent", cell.owner); + test.strictEqual("string", cell.type); + test.strictEqual("Source Value", cell.label); + test.strictEqual("dc", cell.value); + test.strictEqual(false, cell.sparkline); + test.same({ + fieldName: "source", + owner: "BaseEvent", + type: "string", + label: "Source Value", + value: "dc", + sparkline: false + }, cell); + + // Test error handling for cell value, IPv4 + try { + pivotSpecification.addCellValue("hostip", "Wrong Stats Function", "stdev"); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Stats function on string and IPv4 fields must be one of:" + + " list, distinct_values, first, last, count, or distinct_count; found stdev"); + } - // search.update({search: updatedSearch}, done); - // }, - // function(search, done) { - // test.ok(search); - // test.ok(search); + // Add cell value, IPv4 + pivotSpecification.addCellValue("hostip", "Source Value", "dc"); + test.strictEqual(2, pivotSpecification.cells.length); + + cell = pivotSpecification.cells[pivotSpecification.cells.length - 1]; + test.ok(cell.hasOwnProperty("fieldName")); + test.ok(cell.hasOwnProperty("owner")); + test.ok(cell.hasOwnProperty("type")); + test.ok(cell.hasOwnProperty("label")); + test.ok(cell.hasOwnProperty("value")); + test.ok(cell.hasOwnProperty("sparkline")); + + test.strictEqual("hostip", cell.fieldName); + test.strictEqual("test_data", cell.owner); + test.strictEqual("ipv4", cell.type); + test.strictEqual("Source Value", cell.label); + test.strictEqual("dc", cell.value); + test.strictEqual(false, cell.sparkline); + test.same({ + fieldName: "hostip", + owner: "test_data", + type: "ipv4", + label: "Source Value", + value: "dc", + sparkline: false + }, cell); + + // Test error handling for cell value, boolean + try { + pivotSpecification.addCellValue("has_boris", "Booleans not allowed", "sum"); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Cannot use boolean valued fields as cell values."); + } - // test.strictEqual(search.name, name); - // test.strictEqual(search.properties().search, updatedSearch); - // test.ok(!search.properties().description); + // Test error handling for cell value, number + try { + pivotSpecification.addCellValue("epsilon", "Wrong Stats Function", "latest"); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Stats function on number field must be must be one of:" + + " sum, count, average, max, min, stdev, list, or distinct_values; found latest"); + } - // search.update({description: updatedDescription}, done); - // }, - // function(search, done) { - // test.ok(search); - // test.ok(search); + // Add cell value, number + pivotSpecification.addCellValue("epsilon", "Source Value", "average"); + test.strictEqual(3, pivotSpecification.cells.length); + + cell = pivotSpecification.cells[pivotSpecification.cells.length - 1]; + test.ok(cell.hasOwnProperty("fieldName")); + test.ok(cell.hasOwnProperty("owner")); + test.ok(cell.hasOwnProperty("type")); + test.ok(cell.hasOwnProperty("label")); + test.ok(cell.hasOwnProperty("value")); + test.ok(cell.hasOwnProperty("sparkline")); + + test.strictEqual("epsilon", cell.fieldName); + test.strictEqual("test_data", cell.owner); + test.strictEqual("number", cell.type); + test.strictEqual("Source Value", cell.label); + test.strictEqual("average", cell.value); + test.strictEqual(false, cell.sparkline); + test.same({ + fieldName: "epsilon", + owner: "test_data", + type: "number", + label: "Source Value", + value: "average", + sparkline: false + }, cell); + + // Test error handling for cell value, timestamp + try { + pivotSpecification.addCellValue("_time", "Wrong Stats Function", "max"); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Stats function on timestamp field must be one of:" + + " duration, earliest, latest, list, or distinct values; found max"); + } - // test.strictEqual(search.name, name); - // test.strictEqual(search.properties().search, updatedSearch); - // test.strictEqual(search.properties().description, updatedDescription); + // Add cell value, timestamp + pivotSpecification.addCellValue("_time", "Source Value", "earliest"); + test.strictEqual(4, pivotSpecification.cells.length); + + cell = pivotSpecification.cells[pivotSpecification.cells.length - 1]; + test.ok(cell.hasOwnProperty("fieldName")); + test.ok(cell.hasOwnProperty("owner")); + test.ok(cell.hasOwnProperty("type")); + test.ok(cell.hasOwnProperty("label")); + test.ok(cell.hasOwnProperty("value")); + test.ok(cell.hasOwnProperty("sparkline")); + + test.strictEqual("_time", cell.fieldName); + test.strictEqual("BaseEvent", cell.owner); + test.strictEqual("timestamp", cell.type); + test.strictEqual("Source Value", cell.label); + test.strictEqual("earliest", cell.value); + test.strictEqual(false, cell.sparkline); + test.same({ + fieldName: "_time", + owner: "BaseEvent", + type: "timestamp", + label: "Source Value", + value: "earliest", + sparkline: false + }, cell); + + // Test error handling for cell value, count + try { + pivotSpecification.addCellValue("test_data", "Wrong Stats Function", "min"); + test.ok(false); + } + catch (e) { + test.ok(e); + test.strictEqual(e.message, "Stats function on childcount and objectcount fields " + + "must be count; found " + "min"); + } - // search.fetch(done); - // }, - // function(search, done) { - // // Verify that we have the required fields - // test.ok(search.fields().optional.length > 1); - // test.ok(utils.indexOf(search.fields().optional, "disabled") > -1); + // Add cell value, count + pivotSpecification.addCellValue("test_data", "Source Value", "count"); + test.strictEqual(5, pivotSpecification.cells.length); + + cell = pivotSpecification.cells[pivotSpecification.cells.length - 1]; + test.ok(cell.hasOwnProperty("fieldName")); + test.ok(cell.hasOwnProperty("owner")); + test.ok(cell.hasOwnProperty("type")); + test.ok(cell.hasOwnProperty("label")); + test.ok(cell.hasOwnProperty("value")); + test.ok(cell.hasOwnProperty("sparkline")); + + test.strictEqual("test_data", cell.fieldName); + test.strictEqual("test_data", cell.owner); + test.strictEqual("objectCount", cell.type); + test.strictEqual("Source Value", cell.label); + test.strictEqual("count", cell.value); + test.strictEqual(false, cell.sparkline); + test.same({ + fieldName: "test_data", + owner: "test_data", + type: "objectCount", + label: "Source Value", + value: "count", + sparkline: false + }, cell); - // search.remove(done); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, + "Callback#Pivot - test pivot throws HTTP exception": function(test) { + if (this.skip) { + test.done(); + return; + } + var name = "delete-me-" + getNextId(); + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var that = this; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + var obj = dataModel.objectByName("test_data"); + test.ok(obj); - // "Callback#dispatch error": function(test) { - // var name = "jssdk_savedsearch_" + getNextId(); - // var originalSearch = "search index=_internal | head 1"; - // var search = new splunkjs.Service.SavedSearch( - // this.loggedOutService, - // name, - // {owner: "nobody", app: "search"} - // ); - // search.dispatch(function(err) { - // test.ok(err); - // test.done(); - // }); - // }, + obj.createPivotSpecification().pivot(done); + }, + function(pivot, done) { + test.ok(false); + } + ], + function(err) { + test.ok(err); + var expectedErr = "In handler 'datamodelpivot': Error in 'PivotReport': Must have non-empty cells or non-empty rows."; + test.ok(utils.endsWith(err.message, expectedErr)); + test.done(); + } + ); + }, + "Callback#Pivot - test pivot with simple namespace": function(test) { + if (this.skip) { + test.done(); + return; + } + var name = "delete-me-" + getNextId(); + var args; + try { + args = JSON.parse(utils.readFile(__filename, "../data/data_model_for_pivot.json")); + } + catch(err) { + // Fail if we can't read the file, likely to occur in the browser + test.ok(!err); + test.done(); + } + var that = this; + var obj; + var pivotSpecification; + var adhocjob; + Async.chain([ + function(done) { + that.dataModels.create(name, args, done); + }, + function(dataModel, done) { + obj = dataModel.objectByName("test_data"); + test.ok(obj); + obj.createLocalAccelerationJob(null, done); + }, + function(job, done) { + adhocjob = job; + test.ok(job); + pivotSpecification = obj.createPivotSpecification(); - // "Callback#dispatch omitting optional arguments": function(test) { - // var name = "jssdk_savedsearch_" + getNextId(); - // var originalSearch = "search index=_internal | head 1"; + pivotSpecification.addBooleanRowSplit("has_boris", "Has Boris", "meep", "hilda"); + pivotSpecification.addCellValue("hostip", "Distinct IPs", "count"); - // var searches = this.service.savedSearches({owner: this.service.username, app: "sdk-app-collection"}); + // Test setting a job + pivotSpecification.setAccelerationJob(job); + test.strictEqual("string", typeof pivotSpecification.accelerationNamespace); + test.strictEqual("sid=" + job.sid, pivotSpecification.accelerationNamespace); - // Async.chain( - // [function(done) { - // searches.create({search: originalSearch, name: name}, done); - // }, - // function(search, done) { - // test.ok(search); + // Test setting a job's SID + pivotSpecification.setAccelerationJob(job.sid); + test.strictEqual("string", typeof pivotSpecification.accelerationNamespace); + test.strictEqual("sid=" + job.sid, pivotSpecification.accelerationNamespace); - // test.strictEqual(search.name, name); - // test.strictEqual(search.properties().search, originalSearch); - // test.ok(!search.properties().description); + pivotSpecification.pivot(done); + }, + function(pivot, done) { + test.ok(pivot.tstatsSearch); + test.ok(pivot.tstatsSearch.length > 0); + test.strictEqual(0, pivot.tstatsSearch.indexOf("| tstats")); + // This test won't work with utils.startsWith due to the regex escaping + test.strictEqual("| tstats", pivot.tstatsSearch.match("^\\| tstats")[0]); + test.strictEqual(1, pivot.tstatsSearch.match("^\\| tstats").length); + + pivot.run(done); + }, + function(job, done) { + tutils.pollUntil( + job, + function(j) { + return job.properties().isDone; + }, + 10, + done + ); + }, + function(job, done) { + test.ok("FAILED" !== job.properties().dispatchState); - // search.dispatch(done); - // }, - // function(job, search, done) { - // test.ok(job); - // test.ok(search); - // test.done(); - // }] - // ); - // }, + test.strictEqual(0, job.properties().request.search.indexOf("| tstats")); + // This test won't work with utils.startsWith due to the regex escaping + test.strictEqual("| tstats", job.properties().request.search.match("^\\| tstats")[0]); + test.strictEqual(1, job.properties().request.search.match("^\\| tstats").length); - // "Callback#history error": function(test) { - // var name = "jssdk_savedsearch_" + getNextId(); - // var originalSearch = "search index=_internal | head 1"; - // var search = new splunkjs.Service.SavedSearch( - // this.loggedOutService, - // name, - // {owner: "nobody", app: "search", sharing: "system"} - // ); - // search.history(function(err) { - // test.ok(err); - // test.done(); - // }); - // }, + adhocjob.cancel(done); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, + "Callback#Pivot - test pivot column range split": function(test) { + // This test is here because we had a problem with fields that were supposed to be + // numbers being expected as strings in Splunk 6.0. This was fixed in Splunk 6.1, and accepts + // either strings or numbers. - // "Callback#Update error": function(test) { - // var name = "jssdk_savedsearch_" + getNextId(); - // var originalSearch = "search index=_internal | head 1"; - // var search = new splunkjs.Service.SavedSearch( - // this.loggedOutService, - // name, - // {owner: "nobody", app: "search", sharing: "system"} - // ); - // search.update( - // {}, - // function(err) { - // test.ok(err); - // test.done(); - // }); - // }, + if (this.skip) { + test.done(); + return; + } + var that = this; + var search; + Async.chain([ + function(done) { + that.dataModels.fetch(done); + }, + function(dataModels, done) { + var dm = dataModels.item("internal_audit_logs"); + var obj = dm.objectByName("searches"); + var pivotSpecification = obj.createPivotSpecification(); + + pivotSpecification.addRowSplit("user", "Executing user"); + pivotSpecification.addRangeColumnSplit("exec_time", {start: 0, end: 12, step: 5, limit: 4}); + pivotSpecification.addCellValue("search", "Search Query", "values"); + pivotSpecification.pivot(done); + }, + function(pivot, done) { + // If tstats is undefined, use pivotSearch + search = pivot.tstatsSearch || pivot.pivotSearch; + pivot.run(done); + }, + function(job, done) { + tutils.pollUntil( + job, + function(j) { + return job.properties().isDone; + }, + 10, + done + ); + }, + function(job, done) { + test.notStrictEqual("FAILED", job.properties().dispatchState); + // Make sure the job is run with the correct search query + test.strictEqual(search, job.properties().request.search); + job.cancel(done); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, + "Callback#Pivot - test pivot with PivotSpecification.run and Job.track": function(test) { + if (this.skip) { + test.done(); + return; + } + var that = this; + Async.chain([ + function(done) { + that.dataModels.fetch(done); + }, + function(dataModels, done) { + var dm = dataModels.item("internal_audit_logs"); + var obj = dm.objectByName("searches"); + var pivotSpecification = obj.createPivotSpecification(); - // "Callback#oneshot requires search string": function(test) { - // test.throws(function() { this.service.oneshotSearch({name: "jssdk_oneshot_" + getNextId()}, function(err) {});}); - // test.done(); - // }, + pivotSpecification.addRowSplit("user", "Executing user"); + pivotSpecification.addRangeColumnSplit("exec_time", {start: 0, end: 12, step: 5, limit: 4}); + pivotSpecification.addCellValue("search", "Search Query", "values"); - // "Callback#Create + dispatch + history": function(test) { - // var name = "jssdk_savedsearch_" + getNextId(); - // var originalSearch = "search index=_internal | head 1"; - - // var searches = this.service.savedSearches({owner: this.service.username, app: "sdk-app-collection"}); - - // Async.chain( - // function(done) { - // searches.create({search: originalSearch, name: name}, done); - // }, - // function(search, done) { - // test.ok(search); - - // test.strictEqual(search.name, name); - // test.strictEqual(search.properties().search, originalSearch); - // test.ok(!search.properties().description); - - // search.dispatch({force_dispatch: false, "dispatch.buckets": 295}, done); - // }, - // function(job, search, done) { - // test.ok(job); - // test.ok(search); - - // tutils.pollUntil( - // job, - // function(j) { - // return job.properties()["isDone"]; - // }, - // 10, - // Async.augment(done, search) - // ); - // }, - // function(job, search, done) { - // test.strictEqual(job.properties().statusBuckets, 295); - // search.history(Async.augment(done, job)); - // }, - // function(jobs, search, originalJob, done) { - // test.ok(jobs); - // test.ok(jobs.length > 0); - // test.ok(search); - // test.ok(originalJob); - - // var cancel = function(job) { - // return function(cb) { - // job.cancel(cb); - // }; - // }; - - // var found = false; - // var cancellations = []; - // for(var i = 0; i < jobs.length; i++) { - // cancellations.push(cancel(jobs[i])); - // found = found || (jobs[i].sid === originalJob.sid); - // } + pivotSpecification.run({}, done); + }, + function(job, pivot, done) { + job.track({}, function(job) { + test.strictEqual(pivot.tstatsSearch || pivot.pivotSearch, job.properties().request.search); + done(null, job); + }); + }, + function(job, done) { + test.notStrictEqual("FAILED", job.properties().dispatchState); + job.cancel(done); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, + "Callback#DataModels - delete any remaining data models created by the SDK tests": function(test) { + if (this.skip) { + test.done(); + return; + } + svc.dataModels().fetch(function(err, dataModels) { + if (err) { + test.ok(!err); + } - // test.ok(found); - - // search.remove(function(err) { - // if (err) { - // done(err); - // } - // else { - // Async.parallel(cancellations, done); - // } - // }); - // }, - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + var dms = dataModels.list(); + Async.seriesEach( + dms, + function(datamodel, i, done) { + // Delete any test data models that we created + if (utils.startsWith(datamodel.name, "delete-me")) { + datamodel.remove(done); + } + else { + done(); + } + }, + function(err) { + test.ok(!err); + test.done(); + } + ); + }); + } + }, - // "Callback#job events fails": function(test) { - // var job = new splunkjs.Service.Job(this.loggedOutService, "abc", {}); - // job.events({}, function (err) { - // test.ok(err); - // test.done(); - // }); - // }, + "App Tests": { + setUp: function(done) { + this.service = svc; + done(); + }, - // "Callback#job preview fails": function(test) { - // var job = new splunkjs.Service.Job(this.loggedOutService, "abc", {}); - // job.preview({}, function(err) { - // test.ok(err); - // test.done(); - // }); - // }, + "Callback#list applications": function(test) { + var apps = this.service.apps(); + apps.fetch(function(err, apps) { + var appList = apps.list(); + test.ok(appList.length > 0); + test.done(); + }); + }, - // "Callback#job results fails": function(test) { - // var job = new splunkjs.Service.Job(this.loggedOutService, "abc", {}); - // job.results({}, function(err) { - // test.ok(err); - // test.done(); - // }); - // }, + "Callback#contains applications": function(test) { + var apps = this.service.apps(); + apps.fetch(function(err, apps) { + var app = apps.item("search"); + test.ok(app); + test.done(); + }); + }, - // "Callback#job searchlog fails": function(test) { - // var job = new splunkjs.Service.Job(this.loggedOutService, "abc", {}); - // job.searchlog(function(err) { - // test.ok(err); - // test.done(); - // }); - // }, + "Callback#create + contains app": function(test) { + var name = "jssdk_testapp_" + getNextId(); + var apps = this.service.apps(); - // "Callback#job summary fails": function(test) { - // var job = new splunkjs.Service.Job(this.loggedOutService, "abc", {}); - // job.summary({}, function(err) { - // test.ok(err); - // test.done(); - // }); - // }, + apps.create({name: name}, function(err, app) { + var appName = app.name; + apps.fetch(function(err, apps) { + var entity = apps.item(appName); + test.ok(entity); + app.remove(function() { + test.done(); + }); + }); + }); + }, - // "Callback#job timeline fails": function(test) { - // var job = new splunkjs.Service.Job(this.loggedOutService, "abc", {}); - // job.timeline({}, function(err) { - // test.ok(err); - // test.done(); - // }); - // }, + "Callback#create + modify app": function(test) { + var DESCRIPTION = "TEST DESCRIPTION"; + var VERSION = "1.1.0"; - // "Callback#delete test saved searches": function(test) { - // var searches = this.service.savedSearches({owner: this.service.username, app: "sdk-app-collection"}); - // searches.fetch(function(err, searches) { - // var searchList = searches.list(); - // Async.parallelEach( - // searchList, - // function(search, idx, callback) { - // if (utils.startsWith(search.name, "jssdk_")) { - // search.remove(callback); - // } - // else { - // callback(); - // } - // }, function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }); - // }, + var name = "jssdk_testapp_" + getNextId(); + var apps = this.service.apps(); - // "Callback#setupInfo fails": function(test) { - // var searches = new splunkjs.Service.Application(this.loggedOutService, "search"); - // searches.setupInfo(function(err, content, that) { - // test.ok(err); - // test.done(); - // }); - // }, + Async.chain([ + function(callback) { + apps.create({name: name}, callback); + }, + function(app, callback) { + test.ok(app); + test.strictEqual(app.name, name); + var versionMatches = app.properties().version === "1.0" || + app.properties().version == "1.0.0"; + test.ok(versionMatches); + + app.update({ + description: DESCRIPTION, + version: VERSION + }, callback); + }, + function(app, callback) { + test.ok(app); + var properties = app.properties(); - // "Callback#setupInfo succeeds": function(test) { - // var app = new splunkjs.Service.Application(this.service, "sdk-app-collection"); - // app.setupInfo(function(err, content, app) { - // // This error message was removed in modern versions of Splunk - // if (err) { - // test.ok(err.data.messages[0].text.match("Setup configuration file does not")); - // splunkjs.Logger.log("ERR ---", err.data.messages[0].text); - // } - // else { - // test.ok(app); - // } - // test.done(); - // }); - // }, + test.strictEqual(properties.description, DESCRIPTION); + test.strictEqual(properties.version, VERSION); - // "Callback#updateInfo": function(test) { - // var app = new splunkjs.Service.Application(this.service, "search"); - // app.updateInfo(function(err, info, app) { - // test.ok(!err); - // test.ok(app); - // test.strictEqual(app.name, 'search'); - // test.done(); - // }); - // }, + app.remove(callback); + } + ], function(err) { + test.ok(!err); + test.done(); + }); + }, - // "Callback#updateInfo failure": function(test) { - // var app = new splunkjs.Service.Application(this.loggedOutService, "sdk-app-collection"); - // app.updateInfo(function(err, info, app) { - // test.ok(err); - // test.done(); - // }); - // } - // }, + "Callback#delete test applications": function(test) { + var apps = this.service.apps(); + apps.fetch(function(err, apps) { + var appList = apps.list(); - // "Fired Alerts Tests": { - // setUp: function(done) { - // this.service = svc; - // this.loggedOutService = loggedOutSvc; + Async.parallelEach( + appList, + function(app, idx, callback) { + if (utils.startsWith(app.name, "jssdk_")) { + app.remove(callback); + } + else { + callback(); + } + }, function(err) { + test.ok(!err); + test.done(); + } + ); + }); + }, - // var indexes = this.service.indexes(); - // done(); - // }, + // "list applications with cookies as authentication": function(test) { + // this.service.serverInfo(function (err, info) { + // // Cookie authentication was added in splunk 6.2 + // var majorVersion = parseInt(info.properties().version.split(".")[0], 10); + // var minorVersion = parseInt(info.properties().version.split(".")[1], 10); + // // Skip cookie test if Splunk older than 6.2 + // if(majorVersion < 6 || (majorVersion === 6 && minorVersion < 2)) { + // splunkjs.Logger.log("Skipping cookie test..."); + // test.done(); + // return; + // } - // "Callback#create + verify emptiness + delete new alert group": function(test) { - // var searches = this.service.savedSearches({owner: this.service.username}); - - // var name = "jssdk_savedsearch_alert_" + getNextId(); - // var searchConfig = { - // "name": name, - // "search": "index=_internal | head 1", - // "alert_type": "always", - // "alert.severity": "2", - // "alert.suppress": "0", - // "alert.track": "1", - // "dispatch.earliest_time": "-1h", - // "dispatch.latest_time": "now", - // "is_scheduled": "1", - // "cron_schedule": "* * * * *" - // }; + // var service = new splunkjs.Service( + // { + // scheme: svc.scheme, + // host: svc.host, + // port: svc.port, + // username: svc.username, + // password: svc.password, + // version: svc.version + // }); + + // var service2 = new splunkjs.Service( + // { + // scheme: svc.scheme, + // host: svc.host, + // port: svc.port, + // version: svc.version + // }); + + // Async.chain([ + // function (done) { + // service.login(done); + // }, + // function (job, done) { + // // Save the cookie store + // var cookieStore = service.http._cookieStore; + // // Test that there are cookies + // test.ok(!utils.isEmpty(cookieStore)); + + // // Add the cookies to a service with no other authenitcation information + // service2.http._cookieStore = cookieStore; + + // var apps = service2.apps(); + // apps.fetch(done); + // }, + // function (apps, done) { + // var appList = apps.list(); + // test.ok(appList.length > 0); + // test.ok(!utils.isEmpty(service2.http._cookieStore)); + // done(); + // } + // ], + // function(err) { + // // Test that no errors were returned + // test.ok(!err); + // test.done(); + // }); + // }); + // } + }, - // Async.chain([ - // function(done) { - // searches.create(searchConfig, done); - // }, - // function(search, done) { - // test.ok(search); - // test.strictEqual(search.alertCount(), 0); - // search.history(done); - // }, - // function(jobs, search, done) { - // test.strictEqual(jobs.length, 0); - // test.strictEqual(search.firedAlertGroup().count(), 0); - // searches.service.firedAlertGroups().fetch( Async.augment(done, search) ); - // }, - // function(firedAlertGroups, originalSearch, done) { - // test.strictEqual(firedAlertGroups.list().indexOf(originalSearch.name), -1); - // done(null, originalSearch); - // }, - // function(originalSearch, done) { - // originalSearch.remove(done); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + "Saved Search Tests": { + setUp: function(done) { + this.service = svc; + this.loggedOutService = loggedOutSvc; + done(); + }, - // // This test is not stable, commenting it out until we figure it out - // // "Callback#alert is triggered + test firedAlert entity -- FAILS INTERMITTENTLY": function(test) { - // // var searches = this.service.savedSearches({owner: this.service.username}); - // // var indexName = "sdk-tests-alerts"; - // // var name = "jssdk_savedsearch_alert_" + getNextId(); - - // // // Real-time search config - // // var searchConfig = { - // // "name": name, - // // "search": "index="+indexName+" sourcetype=sdk-tests-alerts | head 1", - // // "alert_type": "always", - // // "alert.severity": "2", - // // "alert.suppress": "0", - // // "alert.track": "1", - // // "dispatch.earliest_time": "rt-1s", - // // "dispatch.latest_time": "rt", - // // "is_scheduled": "1", - // // "cron_schedule": "* * * * *" - // // }; - - // // Async.chain([ - // // function(done) { - // // searches.create(searchConfig, done); - // // }, - // // function(search, done) { - // // test.ok(search); - // // test.strictEqual(search.alertCount(), 0); - // // test.strictEqual(search.firedAlertGroup().count(), 0); - - // // var indexes = search.service.indexes(); - // // indexes.create(indexName, {}, function(err, index) { - // // if (err && err.status !== 409) { - // // done(new Error("Index creation failed for an unknown reason")); - // // } - // // done(null, search); - // // }); - // // }, - // // function(originalSearch, done) { - // // var indexes = originalSearch.service.indexes(); - // // indexes.fetch(function(err, indexes) { - // // if (err) { - // // done(err); - // // } - // // else { - // // var index = indexes.item(indexName); - // // test.ok(index); - // // index.enable(Async.augment(done, originalSearch)); - // // } - // // }); - // // }, - // // function(index, originalSearch, done) { - // // //Is the index enabled? - // // test.ok(!index.properties().disabled); - // // //refresh the index - // // index.fetch(Async.augment(done, originalSearch)); - // // }, - // // function(index, originalSearch, done) { - // // //Store the current event count for a later comparison - // // var eventCount = index.properties().totalEventCount; - - // // test.strictEqual(index.properties().sync, 0); - // // test.ok(!index.properties().disabled); - - // // index.fetch(Async.augment(done, originalSearch, eventCount)); - // // }, - // // function(index, originalSearch, eventCount, done) { - // // // submit an event - // // index.submitEvent( - // // "JS SDK: testing alerts", - // // { - // // sourcetype: "sdk-tests-alerts" - // // }, - // // Async.augment(done, originalSearch, eventCount) - // // ); - // // }, - // // function(result, index, originalSearch, eventCount, done) { - // // Async.sleep(1000, function(){ - // // //refresh the search - // // index.fetch(Async.augment(done, originalSearch, eventCount)); - // // }); - // // }, - // // function(index, originalSearch, eventCount, done) { - // // // Did the event get submitted - // // test.strictEqual(index.properties().totalEventCount, eventCount+1); - // // // Refresh the search - // // originalSearch.fetch(Async.augment(done, index)); - // // }, - // // function(originalSearch, index, done) { - // // splunkjs.Logger.log("\tAlert count pre-fetch", originalSearch.alertCount()); - // // var attemptNum = 1; - // // var maxAttempts = 20; - // // Async.whilst( - // // function() { - // // // When this returns false, it hits the final function in the chain - // // splunkjs.Logger.log("\tFetch attempt", attemptNum, "of", maxAttempts, "alertCount", originalSearch.alertCount()); - // // if (originalSearch.alertCount() !== 0) { - // // return false; - // // } - // // else { - // // attemptNum++; - // // return attemptNum < maxAttempts; - // // } - // // }, - // // function(callback) { - // // Async.sleep(500, function() { - // // originalSearch.fetch(callback); - // // }); - // // }, - // // function(err) { - // // splunkjs.Logger.log("Attempted fetching", attemptNum, "of", maxAttempts, "result is", originalSearch.alertCount() !== 0); - // // originalSearch.fetch(Async.augment(done, index)); - // // } - // // ); - // // }, - // // function(originalSearch, index, done) { - // // splunkjs.Logger.log("about to fetch"); - // // splunkjs.Logger.log("SavedSearch name was: " + originalSearch.name); - // // svc.firedAlertGroups({username: svc.username}).fetch(Async.augment(done, index, originalSearch)); - // // }, - // // function(firedAlertGroups, index, originalSearch, done) { - // // Async.seriesEach( - // // firedAlertGroups.list(), - // // function(firedAlertGroup, innerIndex, seriescallback) { - // // Async.chain([ - // // function(insideChainCallback) { - // // firedAlertGroup.list(insideChainCallback); - // // }, - // // function(firedAlerts, firedAlertGroup, insideChainCallback) { - // // for(var i = 0; i < firedAlerts.length; i++) { - // // var firedAlert = firedAlerts[i]; - // // firedAlert.actions(); - // // firedAlert.alertType(); - // // firedAlert.isDigestMode(); - // // firedAlert.expirationTime(); - // // firedAlert.savedSearchName(); - // // firedAlert.severity(); - // // firedAlert.sid(); - // // firedAlert.triggerTime(); - // // firedAlert.triggerTimeRendered(); - // // firedAlert.triggeredAlertCount(); - // // } - // // insideChainCallback(null); - // // } - // // ], - // // function(err) { - // // if (err) { - // // seriescallback(err); - // // } - // // seriescallback(null); - // // } - // // ); - // // }, - // // function(err) { - // // if (err) { - // // done(err, originalSearch, index); - // // } - // // done(null, originalSearch, index); - // // } - // // ); - // // }, - // // function(originalSearch, index, done) { - // // // Make sure the event count has incremented, as expected - // // test.strictEqual(originalSearch.alertCount(), 1); - // // // Remove the search, especially because it's a real-time search - // // originalSearch.remove(Async.augment(done, index)); - // // }, - // // function(index, done) { - // // Async.sleep(500, function() { - // // index.remove(done); - // // }); - // // } - // // ], - // // function(err) { - // // test.ok(!err); - // // test.done(); - // // } - // // ); - // // }, - - // "Callback#delete all alerts": function(test) { - // var namePrefix = "jssdk_savedsearch_alert_"; - // var alertList = this.service.savedSearches().list(); - - // Async.parallelEach( - // alertList, - // function(alert, idx, callback) { - // if (utils.startsWith(alert.name, namePrefix)) { - // splunkjs.Logger.log("ALERT ---", alert.name); - // alert.remove(callback); - // } - // else { - // callback(); - // } - // }, function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // } - // }, + "Callback#list": function(test) { + var searches = this.service.savedSearches(); + searches.fetch(function(err, searches) { + var savedSearches = searches.list(); + test.ok(savedSearches.length > 0); - // "Properties Tests": { - // setUp: function(done) { - // this.service = svc; - // done(); - // }, + for(var i = 0; i < savedSearches.length; i++) { + test.ok(savedSearches[i]); + } - // "Callback#list": function(test) { - // var that = this; - // var namespace = {owner: "admin", app: "search"}; + test.done(); + }); + }, - // Async.chain([ - // function(done) { - // that.service.configurations(namespace).fetch(done); - // }, - // function(props, done) { - // var files = props.list(); - // test.ok(files.length > 0); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // }); - // }, + "Callback#contains": function(test) { + var searches = this.service.savedSearches(); + searches.fetch(function(err, searches) { + var search = searches.item("Errors in the last hour"); + test.ok(search); - // "Callback#item": function(test) { - // var that = this; - // var namespace = {owner: "admin", app: "search"}; + test.done(); + }); + }, - // Async.chain([ - // function(done) { that.service.configurations(namespace).fetch(done); }, - // function(props, done) { - // var file = props.item("web"); - // test.ok(file); - // file.fetch(done); - // }, - // function(file, done) { - // test.strictEqual(file.name, "web"); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // }); - // }, + "Callback#suppress": function(test) { + var searches = this.service.savedSearches(); + searches.fetch(function(err, searches) { + var search = searches.item("Errors in the last hour"); + test.ok(search); - // "Callback#contains stanza": function(test) { - // var that = this; - // var namespace = {owner: "admin", app: "search"}; + search.suppressInfo(function(err, info, search) { + test.ok(!err); + test.done(); + }); + }); + }, - // Async.chain([ - // function(done) { that.service.configurations(namespace).fetch(done); }, - // function(props, done) { - // var file = props.item("web"); - // test.ok(file); - // file.fetch(done); - // }, - // function(file, done) { - // test.strictEqual(file.name, "web"); - // var stanza = file.item("settings"); - // test.ok(stanza); - // stanza.fetch(done); - // }, - // function(stanza, done) { - // test.ok(stanza.properties().hasOwnProperty("httpport")); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // }); - // }, + "Callback#list limit count": function(test) { + var searches = this.service.savedSearches(); + searches.fetch({count: 2}, function(err, searches) { + var savedSearches = searches.list(); + test.strictEqual(savedSearches.length, 2); - // "Callback#create file + create stanza + update stanza": function(test) { - // var that = this; - // var fileName = "jssdk_file_" + getNextId(); - // var value = "barfoo_" + getNextId(); - // var namespace = {owner: "admin", app: "search"}; + for(var i = 0; i < savedSearches.length; i++) { + test.ok(savedSearches[i]); + } - // Async.chain([ - // function(done) { - // var properties = that.service.configurations(namespace); - // properties.fetch(done); - // }, - // function(properties, done) { - // properties.create(fileName, done); - // }, - // function(file, done) { - // file.create("stanza", done); - // }, - // function(stanza, done) { - // stanza.update({"jssdk_foobar": value}, done); - // }, - // function(stanza, done) { - // test.strictEqual(stanza.properties()["jssdk_foobar"], value); - // done(); - // }, - // function(done) { - // var file = new splunkjs.Service.ConfigurationFile(svc, fileName); - // file.fetch(done); - // }, - // function(file, done) { - // var stanza = file.item("stanza"); - // test.ok(stanza); - // stanza.remove(done); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // }); - // } - // }, + test.done(); + }); + }, - // "Configuration Tests": { - // setUp: function(done) { - // this.service = svc; - // done(); - // }, + "Callback#list filter": function(test) { + var searches = this.service.savedSearches(); + searches.fetch({search: "Error"}, function(err, searches) { + var savedSearches = searches.list(); + test.ok(savedSearches.length > 0); - // "Callback#list": function(test) { - // var that = this; - // var namespace = {owner: "admin", app: "search"}; + for(var i = 0; i < savedSearches.length; i++) { + test.ok(savedSearches[i]); + } - // Async.chain([ - // function(done) { that.service.configurations(namespace).fetch(done); }, - // function(props, done) { - // var files = props.list(); - // test.ok(files.length > 0); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // }); - // }, + test.done(); + }); + }, - // "Callback#contains": function(test) { - // var that = this; - // var namespace = {owner: "admin", app: "search"}; + "Callback#list offset": function(test) { + var searches = this.service.savedSearches(); + searches.fetch({offset: 2, count: 1}, function(err, searches) { + var savedSearches = searches.list(); + test.strictEqual(searches.paging().offset, 2); + test.strictEqual(searches.paging().perPage, 1); + test.strictEqual(savedSearches.length, 1); - // Async.chain([ - // function(done) { that.service.configurations(namespace).fetch(done); }, - // function(props, done) { - // var file = props.item("web"); - // test.ok(file); - // file.fetch(done); - // }, - // function(file, done) { - // test.strictEqual(file.name, "web"); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // }); - // }, + for(var i = 0; i < savedSearches.length; i++) { + test.ok(savedSearches[i]); + } - // "Callback#contains stanza": function(test) { - // var that = this; - // var namespace = {owner: "admin", app: "search"}; + test.done(); + }); + }, - // Async.chain([ - // function(done) { that.service.configurations(namespace).fetch(done); }, - // function(props, done) { - // var file = props.item("web"); - // test.ok(file); - // file.fetch(done); - // }, - // function(file, done) { - // test.strictEqual(file.name, "web"); - - // var stanza = file.item("settings"); - // test.ok(stanza); - // stanza.fetch(done); - // }, - // function(stanza, done) { - // test.ok(stanza.properties().hasOwnProperty("httpport")); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // }); - // }, + "Callback#create + modify + delete saved search": function(test) { + var name = "jssdk_savedsearch"; + var originalSearch = "search * | head 1"; + var updatedSearch = "search * | head 10"; + var updatedDescription = "description"; - // "Callback#configurations init": function(test) { - // test.throws(function() { - // var confs = new splunkjs.Service.Configurations( - // this.service, - // {owner: "-", app: "-", sharing: "system"} - // ); - // }); - // test.done(); - // }, + var searches = this.service.savedSearches({owner: this.service.username, app: "sdk-app-collection"}); - // "Callback#create file + create stanza + update stanza": function(test) { - // var that = this; - // var namespace = {owner: "nobody", app: "system"}; - // var fileName = "jssdk_file_" + getNextId(); - // var value = "barfoo_" + getNextId(); + Async.chain([ + function(done) { + searches.create({search: originalSearch, name: name}, done); + }, + function(search, done) { + test.ok(search); - // Async.chain([ - // function(done) { - // var configs = svc.configurations(namespace); - // configs.fetch(done); - // }, - // function(configs, done) { - // configs.create({__conf: fileName}, done); - // }, - // function(file, done) { - // if (file.item("stanza")) { - // file.item("stanza").remove(); - // } - // file.create("stanza", done); - // }, - // function(stanza, done) { - // stanza.update({"jssdk_foobar": value}, done); - // }, - // function(stanza, done) { - // test.strictEqual(stanza.properties()["jssdk_foobar"], value); - // done(); - // }, - // function(done) { - // var file = new splunkjs.Service.ConfigurationFile(svc, fileName); - // file.fetch(done); - // }, - // function(file, done) { - // var stanza = file.item("stanza"); - // test.ok(stanza); - // stanza.remove(done); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // }); - // }, + test.strictEqual(search.name, name); + test.strictEqual(search.properties().search, originalSearch); + test.ok(!search.properties().description); - // "Callback#can get default stanza": function(test) { - // var that = this; - // var namespace = {owner: "admin", app: "search"}; + search.update({search: updatedSearch}, done); + }, + function(search, done) { + test.ok(search); + test.ok(search); - // Async.chain([ - // function(done) { that.service.configurations(namespace).fetch(done); }, - // function(props, done) { - // var file = props.item("savedsearches"); - // test.strictEqual(namespace, file.namespace); - // test.ok(file); - // file.fetch(done); - // }, - // function(file, done) { - // test.strictEqual(namespace, file.namespace); - // file.getDefaultStanza().fetch(done); - // }, - // function(stanza, done) { - // test.strictEqual(stanza.name, "default"); - // test.strictEqual(namespace, stanza.namespace); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // }); - // }, + test.strictEqual(search.name, name); + test.strictEqual(search.properties().search, updatedSearch); + test.ok(!search.properties().description); - // "Callback#updating default stanza is noop": function(test) { - // var that = this; - // var namespace = {owner: "admin", app: "search"}; - // var backup = null; - // var invalid = "this won't work"; + search.update({description: updatedDescription}, done); + }, + function(search, done) { + test.ok(search); + test.ok(search); - // Async.chain([ - // function(done) { that.service.configurations(namespace).fetch(done); }, - // function(props, done) { - // var file = props.item("savedsearches"); - // test.strictEqual(namespace, file.namespace); - // test.ok(file); - // file.fetch(done); - // }, - // function(file, done) { - // test.strictEqual(namespace, file.namespace); - // file.getDefaultStanza().fetch(done); - // }, - // function(stanza, done) { - // test.ok(stanza._properties.hasOwnProperty("max_concurrent")); - // test.strictEqual(namespace, stanza.namespace); - // backup = stanza._properties.max_concurrent; - // stanza.update({"max_concurrent": invalid}, done); - // }, - // function(stanza, done) { - // test.ok(stanza.properties().hasOwnProperty("max_concurrent")); - // test.strictEqual(stanza.properties()["max_concurrent"], backup); - // test.notStrictEqual(stanza.properties()["max_concurrent"], invalid); - // stanza.fetch(done); - // }, - // function(stanza, done) { - // test.ok(stanza.properties().hasOwnProperty("max_concurrent")); - // test.strictEqual(stanza.properties()["max_concurrent"], backup); - // test.notStrictEqual(stanza.properties()["max_concurrent"], invalid); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // }); - // } - // }, + test.strictEqual(search.name, name); + test.strictEqual(search.properties().search, updatedSearch); + test.strictEqual(search.properties().description, updatedDescription); - // "Storage Passwords Tests": { - // setUp: function(done) { - // this.service = svc; - // done(); - // }, + search.fetch(done); + }, + function(search, done) { + // Verify that we have the required fields + test.ok(search.fields().optional.length > 1); + test.ok(utils.indexOf(search.fields().optional, "disabled") > -1); - // "Callback#Create": function(test) { - // var startcount = -1; - // var name = "delete-me-" + getNextId(); - // var realm = "delete-me-" + getNextId(); - // var that = this; - // Async.chain([ - // function(done) { - // that.service.storagePasswords().fetch(done); - // }, - // function(storagePasswords, done) { - // startcount = storagePasswords.list().length; - // storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); - // }, - // function(storagePassword, done) { - // test.strictEqual(name, storagePassword.properties().username); - // test.strictEqual(realm + ":" + name + ":", storagePassword.name); - // test.strictEqual("changed!", storagePassword.properties().clear_password); - // test.strictEqual(realm, storagePassword.properties().realm); - // that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); - // }, - // function(storagePasswords, storagePassword, done) { - // test.strictEqual(startcount + 1, storagePasswords.list().length); - // storagePassword.remove(done); - // }, - // function(done) { - // that.service.storagePasswords().fetch(done); - // }, - // function(storagePasswords, done) { - // test.strictEqual(startcount, storagePasswords.list().length); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + search.remove(done); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // "Callback#Create with backslashes": function(test) { - // var startcount = -1; - // var name = "\\delete-me-" + getNextId(); - // var realm = "\\delete-me-" + getNextId(); - // var that = this; - // Async.chain([ - // function(done) { - // that.service.storagePasswords().fetch(done); - // }, - // function(storagePasswords, done) { - // startcount = storagePasswords.list().length; - // storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); - // }, - // function(storagePassword, done) { - // test.strictEqual(name, storagePassword.properties().username); - // test.strictEqual("\\" + realm + ":\\" + name + ":", storagePassword.name); - // test.strictEqual("changed!", storagePassword.properties().clear_password); - // test.strictEqual(realm, storagePassword.properties().realm); - // that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); - // }, - // function(storagePasswords, storagePassword, done) { - // test.strictEqual(startcount + 1, storagePasswords.list().length); - // storagePassword.remove(done); - // }, - // function(done) { - // that.service.storagePasswords().fetch(done); - // }, - // function(storagePasswords, done) { - // test.strictEqual(startcount, storagePasswords.list().length); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + "Callback#dispatch error": function(test) { + var name = "jssdk_savedsearch_" + getNextId(); + var originalSearch = "search index=_internal | head 1"; + var search = new splunkjs.Service.SavedSearch( + this.loggedOutService, + name, + {owner: "nobody", app: "search"} + ); + search.dispatch(function(err) { + test.ok(err); + test.done(); + }); + }, - // "Callback#Create with slashes": function(test) { - // var startcount = -1; - // var name = "/delete-me-" + getNextId(); - // var realm = "/delete-me-" + getNextId(); - // var that = this; - // Async.chain([ - // function(done) { - // that.service.storagePasswords().fetch(done); - // }, - // function(storagePasswords, done) { - // startcount = storagePasswords.list().length; - // storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); - // }, - // function(storagePassword, done) { - // test.strictEqual(name, storagePassword.properties().username); - // test.strictEqual(realm + ":" + name + ":", storagePassword.name); - // test.strictEqual("changed!", storagePassword.properties().clear_password); - // test.strictEqual(realm, storagePassword.properties().realm); - // that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); - // }, - // function(storagePasswords, storagePassword, done) { - // test.strictEqual(startcount + 1, storagePasswords.list().length); - // storagePassword.remove(done); - // }, - // function(done) { - // that.service.storagePasswords().fetch(done); - // }, - // function(storagePasswords, done) { - // test.strictEqual(startcount, storagePasswords.list().length); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + "Callback#dispatch omitting optional arguments": function(test) { + var name = "jssdk_savedsearch_" + getNextId(); + var originalSearch = "search index=_internal | head 1"; - // "Callback#Create without realm": function(test) { - // var startcount = -1; - // var name = "delete-me-" + getNextId(); - // var that = this; - // Async.chain([ - // function(done) { - // that.service.storagePasswords().fetch(done); - // }, - // function(storagePasswords, done) { - // startcount = storagePasswords.list().length; - // storagePasswords.create({name: name, password: "changed!"}, done); - // }, - // function(storagePassword, done) { - // test.strictEqual(name, storagePassword.properties().username); - // test.strictEqual(":" + name + ":", storagePassword.name); - // test.strictEqual("changed!", storagePassword.properties().clear_password); - // test.strictEqual("", storagePassword.properties().realm); - // that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); - // }, - // function(storagePasswords, storagePassword, done) { - // test.strictEqual(startcount + 1, storagePasswords.list().length); - // storagePassword.remove(done); - // }, - // function(done) { - // that.service.storagePasswords().fetch(done); - // }, - // function(storagePasswords, done) { - // test.strictEqual(startcount, storagePasswords.list().length); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + var searches = this.service.savedSearches({owner: this.service.username, app: "sdk-app-collection"}); - // "Callback#Create should fail without user, or realm": function(test) { - // var that = this; - // Async.chain([ - // function(done) { - // that.service.storagePasswords().fetch(done); - // }, - // function(storagePasswords, done) { - // storagePasswords.create({name: null, password: "changed!"}, done); - // } - // ], - // function(err) { - // test.ok(err); - // test.done(); - // } - // ); - // }, + Async.chain( + [function(done) { + searches.create({search: originalSearch, name: name}, done); + }, + function(search, done) { + test.ok(search); - // "Callback#Create should fail without password": function(test) { - // var that = this; - // Async.chain([ - // function(done) { - // that.service.storagePasswords().fetch(done); - // }, - // function(storagePasswords, done) { - // storagePasswords.create({name: "something", password: null}, done); - // } - // ], - // function(err) { - // test.ok(err); - // test.done(); - // } - // ); - // }, + test.strictEqual(search.name, name); + test.strictEqual(search.properties().search, originalSearch); + test.ok(!search.properties().description); - // "Callback#Create should fail without user, realm, or password": function(test) { - // var that = this; - // Async.chain([ - // function(done) { - // that.service.storagePasswords().fetch(done); - // }, - // function(storagePasswords, done) { - // storagePasswords.create({name: null, password: null}, done); - // } - // ], - // function(err) { - // test.ok(err); - // test.done(); - // } - // ); - // }, + search.dispatch(done); + }, + function(job, search, done) { + test.ok(job); + test.ok(search); + test.done(); + }] + ); + }, + + "Callback#history error": function(test) { + var name = "jssdk_savedsearch_" + getNextId(); + var originalSearch = "search index=_internal | head 1"; + var search = new splunkjs.Service.SavedSearch( + this.loggedOutService, + name, + {owner: "nobody", app: "search", sharing: "system"} + ); + search.history(function(err) { + test.ok(err); + test.done(); + }); + }, + + "Callback#Update error": function(test) { + var name = "jssdk_savedsearch_" + getNextId(); + var originalSearch = "search index=_internal | head 1"; + var search = new splunkjs.Service.SavedSearch( + this.loggedOutService, + name, + {owner: "nobody", app: "search", sharing: "system"} + ); + search.update( + {}, + function(err) { + test.ok(err); + test.done(); + }); + }, + + "Callback#oneshot requires search string": function(test) { + test.throws(function() { this.service.oneshotSearch({name: "jssdk_oneshot_" + getNextId()}, function(err) {});}); + test.done(); + }, + + "Callback#Create + dispatch + history": function(test) { + var name = "jssdk_savedsearch_" + getNextId(); + var originalSearch = "search index=_internal | head 1"; + + var searches = this.service.savedSearches({owner: this.service.username, app: "sdk-app-collection"}); + + Async.chain( + function(done) { + searches.create({search: originalSearch, name: name}, done); + }, + function(search, done) { + test.ok(search); + + test.strictEqual(search.name, name); + test.strictEqual(search.properties().search, originalSearch); + test.ok(!search.properties().description); + + search.dispatch({force_dispatch: false, "dispatch.buckets": 295}, done); + }, + function(job, search, done) { + test.ok(job); + test.ok(search); + + tutils.pollUntil( + job, + function(j) { + return job.properties()["isDone"]; + }, + 10, + Async.augment(done, search) + ); + }, + function(job, search, done) { + test.strictEqual(job.properties().statusBuckets, 295); + search.history(Async.augment(done, job)); + }, + function(jobs, search, originalJob, done) { + test.ok(jobs); + test.ok(jobs.length > 0); + test.ok(search); + test.ok(originalJob); + + var cancel = function(job) { + return function(cb) { + job.cancel(cb); + }; + }; + + var found = false; + var cancellations = []; + for(var i = 0; i < jobs.length; i++) { + cancellations.push(cancel(jobs[i])); + found = found || (jobs[i].sid === originalJob.sid); + } + + test.ok(found); + + search.remove(function(err) { + if (err) { + done(err); + } + else { + Async.parallel(cancellations, done); + } + }); + }, + function(err) { + test.ok(!err); + test.done(); + } + ); + }, + + "Callback#job events fails": function(test) { + var job = new splunkjs.Service.Job(this.loggedOutService, "abc", {}); + job.events({}, function (err) { + test.ok(err); + test.done(); + }); + }, + + "Callback#job preview fails": function(test) { + var job = new splunkjs.Service.Job(this.loggedOutService, "abc", {}); + job.preview({}, function(err) { + test.ok(err); + test.done(); + }); + }, + + "Callback#job results fails": function(test) { + var job = new splunkjs.Service.Job(this.loggedOutService, "abc", {}); + job.results({}, function(err) { + test.ok(err); + test.done(); + }); + }, + + "Callback#job searchlog fails": function(test) { + var job = new splunkjs.Service.Job(this.loggedOutService, "abc", {}); + job.searchlog(function(err) { + test.ok(err); + test.done(); + }); + }, + + "Callback#job summary fails": function(test) { + var job = new splunkjs.Service.Job(this.loggedOutService, "abc", {}); + job.summary({}, function(err) { + test.ok(err); + test.done(); + }); + }, + + "Callback#job timeline fails": function(test) { + var job = new splunkjs.Service.Job(this.loggedOutService, "abc", {}); + job.timeline({}, function(err) { + test.ok(err); + test.done(); + }); + }, + + "Callback#delete test saved searches": function(test) { + var searches = this.service.savedSearches({owner: this.service.username, app: "sdk-app-collection"}); + searches.fetch(function(err, searches) { + var searchList = searches.list(); + Async.parallelEach( + searchList, + function(search, idx, callback) { + if (utils.startsWith(search.name, "jssdk_")) { + search.remove(callback); + } + else { + callback(); + } + }, function(err) { + test.ok(!err); + test.done(); + } + ); + }); + }, + + "Callback#setupInfo fails": function(test) { + var searches = new splunkjs.Service.Application(this.loggedOutService, "search"); + searches.setupInfo(function(err, content, that) { + test.ok(err); + test.done(); + }); + }, + + "Callback#setupInfo succeeds": function(test) { + var app = new splunkjs.Service.Application(this.service, "sdk-app-collection"); + app.setupInfo(function(err, content, app) { + // This error message was removed in modern versions of Splunk + if (err) { + test.ok(err.data.messages[0].text.match("Setup configuration file does not")); + splunkjs.Logger.log("ERR ---", err.data.messages[0].text); + } + else { + test.ok(app); + } + test.done(); + }); + }, + + "Callback#updateInfo": function(test) { + var app = new splunkjs.Service.Application(this.service, "search"); + app.updateInfo(function(err, info, app) { + test.ok(!err); + test.ok(app); + test.strictEqual(app.name, 'search'); + test.done(); + }); + }, + + "Callback#updateInfo failure": function(test) { + var app = new splunkjs.Service.Application(this.loggedOutService, "sdk-app-collection"); + app.updateInfo(function(err, info, app) { + test.ok(err); + test.done(); + }); + } + }, + + "Fired Alerts Tests": { + setUp: function(done) { + this.service = svc; + this.loggedOutService = loggedOutSvc; + + var indexes = this.service.indexes(); + done(); + }, + + "Callback#create + verify emptiness + delete new alert group": function(test) { + var searches = this.service.savedSearches({owner: this.service.username}); + + var name = "jssdk_savedsearch_alert_" + getNextId(); + var searchConfig = { + "name": name, + "search": "index=_internal | head 1", + "alert_type": "always", + "alert.severity": "2", + "alert.suppress": "0", + "alert.track": "1", + "dispatch.earliest_time": "-1h", + "dispatch.latest_time": "now", + "is_scheduled": "1", + "cron_schedule": "* * * * *" + }; + + Async.chain([ + function(done) { + searches.create(searchConfig, done); + }, + function(search, done) { + test.ok(search); + test.strictEqual(search.alertCount(), 0); + search.history(done); + }, + function(jobs, search, done) { + test.strictEqual(jobs.length, 0); + test.strictEqual(search.firedAlertGroup().count(), 0); + searches.service.firedAlertGroups().fetch( Async.augment(done, search) ); + }, + function(firedAlertGroups, originalSearch, done) { + test.strictEqual(firedAlertGroups.list().indexOf(originalSearch.name), -1); + done(null, originalSearch); + }, + function(originalSearch, done) { + originalSearch.remove(done); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, + + // This test is not stable, commenting it out until we figure it out + // "Callback#alert is triggered + test firedAlert entity -- FAILS INTERMITTENTLY": function(test) { + // var searches = this.service.savedSearches({owner: this.service.username}); + // var indexName = "sdk-tests-alerts"; + // var name = "jssdk_savedsearch_alert_" + getNextId(); + + // // Real-time search config + // var searchConfig = { + // "name": name, + // "search": "index="+indexName+" sourcetype=sdk-tests-alerts | head 1", + // "alert_type": "always", + // "alert.severity": "2", + // "alert.suppress": "0", + // "alert.track": "1", + // "dispatch.earliest_time": "rt-1s", + // "dispatch.latest_time": "rt", + // "is_scheduled": "1", + // "cron_schedule": "* * * * *" + // }; + + // Async.chain([ + // function(done) { + // searches.create(searchConfig, done); + // }, + // function(search, done) { + // test.ok(search); + // test.strictEqual(search.alertCount(), 0); + // test.strictEqual(search.firedAlertGroup().count(), 0); + + // var indexes = search.service.indexes(); + // indexes.create(indexName, {}, function(err, index) { + // if (err && err.status !== 409) { + // done(new Error("Index creation failed for an unknown reason")); + // } + // done(null, search); + // }); + // }, + // function(originalSearch, done) { + // var indexes = originalSearch.service.indexes(); + // indexes.fetch(function(err, indexes) { + // if (err) { + // done(err); + // } + // else { + // var index = indexes.item(indexName); + // test.ok(index); + // index.enable(Async.augment(done, originalSearch)); + // } + // }); + // }, + // function(index, originalSearch, done) { + // //Is the index enabled? + // test.ok(!index.properties().disabled); + // //refresh the index + // index.fetch(Async.augment(done, originalSearch)); + // }, + // function(index, originalSearch, done) { + // //Store the current event count for a later comparison + // var eventCount = index.properties().totalEventCount; + + // test.strictEqual(index.properties().sync, 0); + // test.ok(!index.properties().disabled); + + // index.fetch(Async.augment(done, originalSearch, eventCount)); + // }, + // function(index, originalSearch, eventCount, done) { + // // submit an event + // index.submitEvent( + // "JS SDK: testing alerts", + // { + // sourcetype: "sdk-tests-alerts" + // }, + // Async.augment(done, originalSearch, eventCount) + // ); + // }, + // function(result, index, originalSearch, eventCount, done) { + // Async.sleep(1000, function(){ + // //refresh the search + // index.fetch(Async.augment(done, originalSearch, eventCount)); + // }); + // }, + // function(index, originalSearch, eventCount, done) { + // // Did the event get submitted + // test.strictEqual(index.properties().totalEventCount, eventCount+1); + // // Refresh the search + // originalSearch.fetch(Async.augment(done, index)); + // }, + // function(originalSearch, index, done) { + // splunkjs.Logger.log("\tAlert count pre-fetch", originalSearch.alertCount()); + // var attemptNum = 1; + // var maxAttempts = 20; + // Async.whilst( + // function() { + // // When this returns false, it hits the final function in the chain + // splunkjs.Logger.log("\tFetch attempt", attemptNum, "of", maxAttempts, "alertCount", originalSearch.alertCount()); + // if (originalSearch.alertCount() !== 0) { + // return false; + // } + // else { + // attemptNum++; + // return attemptNum < maxAttempts; + // } + // }, + // function(callback) { + // Async.sleep(500, function() { + // originalSearch.fetch(callback); + // }); + // }, + // function(err) { + // splunkjs.Logger.log("Attempted fetching", attemptNum, "of", maxAttempts, "result is", originalSearch.alertCount() !== 0); + // originalSearch.fetch(Async.augment(done, index)); + // } + // ); + // }, + // function(originalSearch, index, done) { + // splunkjs.Logger.log("about to fetch"); + // splunkjs.Logger.log("SavedSearch name was: " + originalSearch.name); + // svc.firedAlertGroups({username: svc.username}).fetch(Async.augment(done, index, originalSearch)); + // }, + // function(firedAlertGroups, index, originalSearch, done) { + // Async.seriesEach( + // firedAlertGroups.list(), + // function(firedAlertGroup, innerIndex, seriescallback) { + // Async.chain([ + // function(insideChainCallback) { + // firedAlertGroup.list(insideChainCallback); + // }, + // function(firedAlerts, firedAlertGroup, insideChainCallback) { + // for(var i = 0; i < firedAlerts.length; i++) { + // var firedAlert = firedAlerts[i]; + // firedAlert.actions(); + // firedAlert.alertType(); + // firedAlert.isDigestMode(); + // firedAlert.expirationTime(); + // firedAlert.savedSearchName(); + // firedAlert.severity(); + // firedAlert.sid(); + // firedAlert.triggerTime(); + // firedAlert.triggerTimeRendered(); + // firedAlert.triggeredAlertCount(); + // } + // insideChainCallback(null); + // } + // ], + // function(err) { + // if (err) { + // seriescallback(err); + // } + // seriescallback(null); + // } + // ); + // }, + // function(err) { + // if (err) { + // done(err, originalSearch, index); + // } + // done(null, originalSearch, index); + // } + // ); + // }, + // function(originalSearch, index, done) { + // // Make sure the event count has incremented, as expected + // test.strictEqual(originalSearch.alertCount(), 1); + // // Remove the search, especially because it's a real-time search + // originalSearch.remove(Async.augment(done, index)); + // }, + // function(index, done) { + // Async.sleep(500, function() { + // index.remove(done); + // }); + // } + // ], + // function(err) { + // test.ok(!err); + // test.done(); + // } + // ); + // }, + + "Callback#delete all alerts": function(test) { + var namePrefix = "jssdk_savedsearch_alert_"; + var alertList = this.service.savedSearches().list(); + + Async.parallelEach( + alertList, + function(alert, idx, callback) { + if (utils.startsWith(alert.name, namePrefix)) { + splunkjs.Logger.log("ALERT ---", alert.name); + alert.remove(callback); + } + else { + callback(); + } + }, function(err) { + test.ok(!err); + test.done(); + } + ); + } + }, + + "Properties Tests": { + setUp: function(done) { + this.service = svc; + done(); + }, + + "Callback#list": function(test) { + var that = this; + var namespace = {owner: "admin", app: "search"}; + + Async.chain([ + function(done) { + that.service.configurations(namespace).fetch(done); + }, + function(props, done) { + var files = props.list(); + test.ok(files.length > 0); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + }); + }, + + "Callback#item": function(test) { + var that = this; + var namespace = {owner: "admin", app: "search"}; + + Async.chain([ + function(done) { that.service.configurations(namespace).fetch(done); }, + function(props, done) { + var file = props.item("web"); + test.ok(file); + file.fetch(done); + }, + function(file, done) { + test.strictEqual(file.name, "web"); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + }); + }, + + "Callback#contains stanza": function(test) { + var that = this; + var namespace = {owner: "admin", app: "search"}; + + Async.chain([ + function(done) { that.service.configurations(namespace).fetch(done); }, + function(props, done) { + var file = props.item("web"); + test.ok(file); + file.fetch(done); + }, + function(file, done) { + test.strictEqual(file.name, "web"); + var stanza = file.item("settings"); + test.ok(stanza); + stanza.fetch(done); + }, + function(stanza, done) { + test.ok(stanza.properties().hasOwnProperty("httpport")); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + }); + }, + + "Callback#create file + create stanza + update stanza": function(test) { + var that = this; + var fileName = "jssdk_file_" + getNextId(); + var value = "barfoo_" + getNextId(); + var namespace = {owner: "admin", app: "search"}; + + Async.chain([ + function(done) { + var properties = that.service.configurations(namespace); + properties.fetch(done); + }, + function(properties, done) { + properties.create(fileName, done); + }, + function(file, done) { + file.create("stanza", done); + }, + function(stanza, done) { + stanza.update({"jssdk_foobar": value}, done); + }, + function(stanza, done) { + test.strictEqual(stanza.properties()["jssdk_foobar"], value); + done(); + }, + function(done) { + var file = new splunkjs.Service.ConfigurationFile(svc, fileName); + file.fetch(done); + }, + function(file, done) { + var stanza = file.item("stanza"); + test.ok(stanza); + stanza.remove(done); + } + ], + function(err) { + test.ok(!err); + test.done(); + }); + } + }, + + "Configuration Tests": { + setUp: function(done) { + this.service = svc; + done(); + }, + + "Callback#list": function(test) { + var that = this; + var namespace = {owner: "admin", app: "search"}; + + Async.chain([ + function(done) { that.service.configurations(namespace).fetch(done); }, + function(props, done) { + var files = props.list(); + test.ok(files.length > 0); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + }); + }, + + "Callback#contains": function(test) { + var that = this; + var namespace = {owner: "admin", app: "search"}; + + Async.chain([ + function(done) { that.service.configurations(namespace).fetch(done); }, + function(props, done) { + var file = props.item("web"); + test.ok(file); + file.fetch(done); + }, + function(file, done) { + test.strictEqual(file.name, "web"); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + }); + }, + + "Callback#contains stanza": function(test) { + var that = this; + var namespace = {owner: "admin", app: "search"}; + + Async.chain([ + function(done) { that.service.configurations(namespace).fetch(done); }, + function(props, done) { + var file = props.item("web"); + test.ok(file); + file.fetch(done); + }, + function(file, done) { + test.strictEqual(file.name, "web"); + + var stanza = file.item("settings"); + test.ok(stanza); + stanza.fetch(done); + }, + function(stanza, done) { + test.ok(stanza.properties().hasOwnProperty("httpport")); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + }); + }, + + "Callback#configurations init": function(test) { + test.throws(function() { + var confs = new splunkjs.Service.Configurations( + this.service, + {owner: "-", app: "-", sharing: "system"} + ); + }); + test.done(); + }, + + "Callback#create file + create stanza + update stanza": function(test) { + var that = this; + var namespace = {owner: "nobody", app: "system"}; + var fileName = "jssdk_file_" + getNextId(); + var value = "barfoo_" + getNextId(); + + Async.chain([ + function(done) { + var configs = svc.configurations(namespace); + configs.fetch(done); + }, + function(configs, done) { + configs.create({__conf: fileName}, done); + }, + function(file, done) { + if (file.item("stanza")) { + file.item("stanza").remove(); + } + file.create("stanza", done); + }, + function(stanza, done) { + stanza.update({"jssdk_foobar": value}, done); + }, + function(stanza, done) { + test.strictEqual(stanza.properties()["jssdk_foobar"], value); + done(); + }, + function(done) { + var file = new splunkjs.Service.ConfigurationFile(svc, fileName); + file.fetch(done); + }, + function(file, done) { + var stanza = file.item("stanza"); + test.ok(stanza); + stanza.remove(done); + } + ], + function(err) { + test.ok(!err); + test.done(); + }); + }, + + "Callback#can get default stanza": function(test) { + var that = this; + var namespace = {owner: "admin", app: "search"}; + + Async.chain([ + function(done) { that.service.configurations(namespace).fetch(done); }, + function(props, done) { + var file = props.item("savedsearches"); + test.strictEqual(namespace, file.namespace); + test.ok(file); + file.fetch(done); + }, + function(file, done) { + test.strictEqual(namespace, file.namespace); + file.getDefaultStanza().fetch(done); + }, + function(stanza, done) { + test.strictEqual(stanza.name, "default"); + test.strictEqual(namespace, stanza.namespace); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + }); + }, + + "Callback#updating default stanza is noop": function(test) { + var that = this; + var namespace = {owner: "admin", app: "search"}; + var backup = null; + var invalid = "this won't work"; + + Async.chain([ + function(done) { that.service.configurations(namespace).fetch(done); }, + function(props, done) { + var file = props.item("savedsearches"); + test.strictEqual(namespace, file.namespace); + test.ok(file); + file.fetch(done); + }, + function(file, done) { + test.strictEqual(namespace, file.namespace); + file.getDefaultStanza().fetch(done); + }, + function(stanza, done) { + test.ok(stanza._properties.hasOwnProperty("max_concurrent")); + test.strictEqual(namespace, stanza.namespace); + backup = stanza._properties.max_concurrent; + stanza.update({"max_concurrent": invalid}, done); + }, + function(stanza, done) { + test.ok(stanza.properties().hasOwnProperty("max_concurrent")); + test.strictEqual(stanza.properties()["max_concurrent"], backup); + test.notStrictEqual(stanza.properties()["max_concurrent"], invalid); + stanza.fetch(done); + }, + function(stanza, done) { + test.ok(stanza.properties().hasOwnProperty("max_concurrent")); + test.strictEqual(stanza.properties()["max_concurrent"], backup); + test.notStrictEqual(stanza.properties()["max_concurrent"], invalid); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + }); + } + }, + + "Storage Passwords Tests": { + setUp: function(done) { + this.service = svc; + done(); + }, + + "Callback#Create": function(test) { + var startcount = -1; + var name = "delete-me-" + getNextId(); + var realm = "delete-me-" + getNextId(); + var that = this; + Async.chain([ + function(done) { + that.service.storagePasswords().fetch(done); + }, + function(storagePasswords, done) { + startcount = storagePasswords.list().length; + storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); + }, + function(storagePassword, done) { + test.strictEqual(name, storagePassword.properties().username); + test.strictEqual(realm + ":" + name + ":", storagePassword.name); + test.strictEqual("changed!", storagePassword.properties().clear_password); + test.strictEqual(realm, storagePassword.properties().realm); + that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); + }, + function(storagePasswords, storagePassword, done) { + test.strictEqual(startcount + 1, storagePasswords.list().length); + storagePassword.remove(done); + }, + function(done) { + that.service.storagePasswords().fetch(done); + }, + function(storagePasswords, done) { + test.strictEqual(startcount, storagePasswords.list().length); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, + + "Callback#Create with backslashes": function(test) { + var startcount = -1; + var name = "\\delete-me-" + getNextId(); + var realm = "\\delete-me-" + getNextId(); + var that = this; + Async.chain([ + function(done) { + that.service.storagePasswords().fetch(done); + }, + function(storagePasswords, done) { + startcount = storagePasswords.list().length; + storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); + }, + function(storagePassword, done) { + test.strictEqual(name, storagePassword.properties().username); + test.strictEqual("\\" + realm + ":\\" + name + ":", storagePassword.name); + test.strictEqual("changed!", storagePassword.properties().clear_password); + test.strictEqual(realm, storagePassword.properties().realm); + that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); + }, + function(storagePasswords, storagePassword, done) { + test.strictEqual(startcount + 1, storagePasswords.list().length); + storagePassword.remove(done); + }, + function(done) { + that.service.storagePasswords().fetch(done); + }, + function(storagePasswords, done) { + test.strictEqual(startcount, storagePasswords.list().length); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, + + "Callback#Create with slashes": function(test) { + var startcount = -1; + var name = "/delete-me-" + getNextId(); + var realm = "/delete-me-" + getNextId(); + var that = this; + Async.chain([ + function(done) { + that.service.storagePasswords().fetch(done); + }, + function(storagePasswords, done) { + startcount = storagePasswords.list().length; + storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); + }, + function(storagePassword, done) { + test.strictEqual(name, storagePassword.properties().username); + test.strictEqual(realm + ":" + name + ":", storagePassword.name); + test.strictEqual("changed!", storagePassword.properties().clear_password); + test.strictEqual(realm, storagePassword.properties().realm); + that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); + }, + function(storagePasswords, storagePassword, done) { + test.strictEqual(startcount + 1, storagePasswords.list().length); + storagePassword.remove(done); + }, + function(done) { + that.service.storagePasswords().fetch(done); + }, + function(storagePasswords, done) { + test.strictEqual(startcount, storagePasswords.list().length); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, + + "Callback#Create without realm": function(test) { + var startcount = -1; + var name = "delete-me-" + getNextId(); + var that = this; + Async.chain([ + function(done) { + that.service.storagePasswords().fetch(done); + }, + function(storagePasswords, done) { + startcount = storagePasswords.list().length; + storagePasswords.create({name: name, password: "changed!"}, done); + }, + function(storagePassword, done) { + test.strictEqual(name, storagePassword.properties().username); + test.strictEqual(":" + name + ":", storagePassword.name); + test.strictEqual("changed!", storagePassword.properties().clear_password); + test.strictEqual("", storagePassword.properties().realm); + that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); + }, + function(storagePasswords, storagePassword, done) { + test.strictEqual(startcount + 1, storagePasswords.list().length); + storagePassword.remove(done); + }, + function(done) { + that.service.storagePasswords().fetch(done); + }, + function(storagePasswords, done) { + test.strictEqual(startcount, storagePasswords.list().length); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, + + "Callback#Create should fail without user, or realm": function(test) { + var that = this; + Async.chain([ + function(done) { + that.service.storagePasswords().fetch(done); + }, + function(storagePasswords, done) { + storagePasswords.create({name: null, password: "changed!"}, done); + } + ], + function(err) { + test.ok(err); + test.done(); + } + ); + }, + + "Callback#Create should fail without password": function(test) { + var that = this; + Async.chain([ + function(done) { + that.service.storagePasswords().fetch(done); + }, + function(storagePasswords, done) { + storagePasswords.create({name: "something", password: null}, done); + } + ], + function(err) { + test.ok(err); + test.done(); + } + ); + }, + + "Callback#Create should fail without user, realm, or password": function(test) { + var that = this; + Async.chain([ + function(done) { + that.service.storagePasswords().fetch(done); + }, + function(storagePasswords, done) { + storagePasswords.create({name: null, password: null}, done); + } + ], + function(err) { + test.ok(err); + test.done(); + } + ); + }, + + "Callback#Create with colons": function(test) { + var startcount = -1; + var name = ":delete-me-" + getNextId(); + var realm = ":delete-me-" + getNextId(); + var that = this; + Async.chain([ + function(done) { + that.service.storagePasswords().fetch(done); + }, + function(storagePasswords, done) { + startcount = storagePasswords.list().length; + storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); + }, + function(storagePassword, done) { + test.strictEqual(name, storagePassword.properties().username); + test.strictEqual("\\" + realm + ":\\" + name + ":", storagePassword.name); + test.strictEqual("changed!", storagePassword.properties().clear_password); + test.strictEqual(realm, storagePassword.properties().realm); + that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); + }, + function(storagePasswords, storagePassword, done) { + test.strictEqual(startcount + 1, storagePasswords.list().length); + storagePassword.remove(done); + }, + function(done) { + that.service.storagePasswords().fetch(done); + }, + function(storagePasswords, done) { + test.strictEqual(startcount, storagePasswords.list().length); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, + + "Callback#Create crazy": function(test) { + var startcount = -1; + var name = "delete-me-" + getNextId(); + var realm = "delete-me-" + getNextId(); + var that = this; + Async.chain([ + function(done) { + that.service.storagePasswords().fetch(done); + }, + function(storagePasswords, done) { + startcount = storagePasswords.list().length; + storagePasswords.create({ + name: name + ":end!@#$%^&*()_+{}:|<>?", + realm: ":start::!@#$%^&*()_+{}:|<>?" + realm, + password: "changed!"}, + done); + }, + function(storagePassword, done) { + test.strictEqual(name + ":end!@#$%^&*()_+{}:|<>?", storagePassword.properties().username); + test.strictEqual("\\:start\\:\\:!@#$%^&*()_+{}\\:|<>?" + realm + ":" + name + "\\:end!@#$%^&*()_+{}\\:|<>?:", storagePassword.name); + test.strictEqual("changed!", storagePassword.properties().clear_password); + test.strictEqual(":start::!@#$%^&*()_+{}:|<>?" + realm, storagePassword.properties().realm); + that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); + }, + function(storagePasswords, storagePassword, done) { + test.strictEqual(startcount + 1, storagePasswords.list().length); + storagePassword.remove(done); + }, + function(done) { + that.service.storagePasswords().fetch(done); + }, + function(storagePasswords, done) { + test.strictEqual(startcount, storagePasswords.list().length); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, + + "Callback#Create with unicode chars": function(test) { + var startcount = -1; + var name = "delete-me-" + getNextId(); + var realm = "delete-me-" + getNextId(); + var that = this; + Async.chain([ + function(done) { + that.service.storagePasswords().fetch(done); + }, + function(storagePasswords, done) { + startcount = storagePasswords.list().length; + storagePasswords.create({ + name: name + ":end!@#$%^&*()_+{}:|<>?쎼 and 쎶 and <&> für", + realm: ":start::!@#$%^&*()_+{}:|<>?" + encodeURIComponent("쎼 and 쎶 and <&> für") + realm, + password: decodeURIComponent(encodeURIComponent("쎼 and 쎶 and <&> für"))}, + done); + }, + function(storagePassword, done) { + test.strictEqual(name + ":end!@#$%^&*()_+{}:|<>?쎼 and 쎶 and <&> für", storagePassword.properties().username); + test.strictEqual("\\:start\\:\\:!@#$%^&*()_+{}\\:|<>?" + encodeURIComponent("쎼 and 쎶 and <&> für") + realm + ":" + name + "\\:end!@#$%^&*()_+{}\\:|<>?쎼 and 쎶 and <&> für:", storagePassword.name); + test.strictEqual(decodeURIComponent(encodeURIComponent("쎼 and 쎶 and <&> für")), storagePassword.properties().clear_password); + test.strictEqual(":start::!@#$%^&*()_+{}:|<>?" + encodeURIComponent("쎼 and 쎶 and <&> für") + realm, storagePassword.properties().realm); + that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); + }, + function(storagePasswords, storagePassword, done) { + test.strictEqual(startcount + 1, storagePasswords.list().length); + storagePassword.remove(done); + }, + function(done) { + that.service.storagePasswords().fetch(done); + }, + function(storagePasswords, done) { + test.strictEqual(startcount, storagePasswords.list().length); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, + + "Callback#Read": function(test) { + var startcount = -1; + var name = "delete-me-" + getNextId(); + var realm = "delete-me-" + getNextId(); + var that = this; + Async.chain([ + function(done) { + that.service.storagePasswords().fetch(done); + }, + function(storagePasswords, done) { + startcount = storagePasswords.list().length; + storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); + }, + function(storagePassword, done) { + test.strictEqual(name, storagePassword.properties().username); + test.strictEqual(realm + ":" + name + ":", storagePassword.name); + test.strictEqual("changed!", storagePassword.properties().clear_password); + test.strictEqual(realm, storagePassword.properties().realm); + that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); + }, + function(storagePasswords, storagePassword, done) { + try { + test.ok(!!storagePasswords.item(realm + ":" + name + ":")); + } + catch (e) { + test.ok(false); + } - // "Callback#Create with colons": function(test) { - // var startcount = -1; - // var name = ":delete-me-" + getNextId(); - // var realm = ":delete-me-" + getNextId(); - // var that = this; - // Async.chain([ - // function(done) { - // that.service.storagePasswords().fetch(done); - // }, - // function(storagePasswords, done) { - // startcount = storagePasswords.list().length; - // storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); - // }, - // function(storagePassword, done) { - // test.strictEqual(name, storagePassword.properties().username); - // test.strictEqual("\\" + realm + ":\\" + name + ":", storagePassword.name); - // test.strictEqual("changed!", storagePassword.properties().clear_password); - // test.strictEqual(realm, storagePassword.properties().realm); - // that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); - // }, - // function(storagePasswords, storagePassword, done) { - // test.strictEqual(startcount + 1, storagePasswords.list().length); - // storagePassword.remove(done); - // }, - // function(done) { - // that.service.storagePasswords().fetch(done); - // }, - // function(storagePasswords, done) { - // test.strictEqual(startcount, storagePasswords.list().length); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + var list = storagePasswords.list(); + var found = false; - // "Callback#Create crazy": function(test) { - // var startcount = -1; - // var name = "delete-me-" + getNextId(); - // var realm = "delete-me-" + getNextId(); - // var that = this; - // Async.chain([ - // function(done) { - // that.service.storagePasswords().fetch(done); - // }, - // function(storagePasswords, done) { - // startcount = storagePasswords.list().length; - // storagePasswords.create({ - // name: name + ":end!@#$%^&*()_+{}:|<>?", - // realm: ":start::!@#$%^&*()_+{}:|<>?" + realm, - // password: "changed!"}, - // done); - // }, - // function(storagePassword, done) { - // test.strictEqual(name + ":end!@#$%^&*()_+{}:|<>?", storagePassword.properties().username); - // test.strictEqual("\\:start\\:\\:!@#$%^&*()_+{}\\:|<>?" + realm + ":" + name + "\\:end!@#$%^&*()_+{}\\:|<>?:", storagePassword.name); - // test.strictEqual("changed!", storagePassword.properties().clear_password); - // test.strictEqual(":start::!@#$%^&*()_+{}:|<>?" + realm, storagePassword.properties().realm); - // that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); - // }, - // function(storagePasswords, storagePassword, done) { - // test.strictEqual(startcount + 1, storagePasswords.list().length); - // storagePassword.remove(done); - // }, - // function(done) { - // that.service.storagePasswords().fetch(done); - // }, - // function(storagePasswords, done) { - // test.strictEqual(startcount, storagePasswords.list().length); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + test.strictEqual(startcount + 1, list.length); + for (var i = 0; i < list.length; i ++) { + if (realm + ":" + name + ":" === list[i].name) { + found = true; + } + } + test.ok(found); - // "Callback#Create with unicode chars": function(test) { - // var startcount = -1; - // var name = "delete-me-" + getNextId(); - // var realm = "delete-me-" + getNextId(); - // var that = this; - // Async.chain([ - // function(done) { - // that.service.storagePasswords().fetch(done); - // }, - // function(storagePasswords, done) { - // startcount = storagePasswords.list().length; - // storagePasswords.create({ - // name: name + ":end!@#$%^&*()_+{}:|<>?쎼 and 쎶 and <&> für", - // realm: ":start::!@#$%^&*()_+{}:|<>?" + encodeURIComponent("쎼 and 쎶 and <&> für") + realm, - // password: decodeURIComponent(encodeURIComponent("쎼 and 쎶 and <&> für"))}, - // done); - // }, - // function(storagePassword, done) { - // test.strictEqual(name + ":end!@#$%^&*()_+{}:|<>?쎼 and 쎶 and <&> für", storagePassword.properties().username); - // test.strictEqual("\\:start\\:\\:!@#$%^&*()_+{}\\:|<>?" + encodeURIComponent("쎼 and 쎶 and <&> für") + realm + ":" + name + "\\:end!@#$%^&*()_+{}\\:|<>?쎼 and 쎶 and <&> für:", storagePassword.name); - // test.strictEqual(decodeURIComponent(encodeURIComponent("쎼 and 쎶 and <&> für")), storagePassword.properties().clear_password); - // test.strictEqual(":start::!@#$%^&*()_+{}:|<>?" + encodeURIComponent("쎼 and 쎶 and <&> für") + realm, storagePassword.properties().realm); - // that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); - // }, - // function(storagePasswords, storagePassword, done) { - // test.strictEqual(startcount + 1, storagePasswords.list().length); - // storagePassword.remove(done); - // }, - // function(done) { - // that.service.storagePasswords().fetch(done); - // }, - // function(storagePasswords, done) { - // test.strictEqual(startcount, storagePasswords.list().length); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + storagePassword.remove(done); + }, + function(done) { + that.service.storagePasswords().fetch(done); + }, + function(storagePasswords, done) { + test.strictEqual(startcount, storagePasswords.list().length); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // "Callback#Read": function(test) { - // var startcount = -1; - // var name = "delete-me-" + getNextId(); - // var realm = "delete-me-" + getNextId(); - // var that = this; - // Async.chain([ - // function(done) { - // that.service.storagePasswords().fetch(done); - // }, - // function(storagePasswords, done) { - // startcount = storagePasswords.list().length; - // storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); - // }, - // function(storagePassword, done) { - // test.strictEqual(name, storagePassword.properties().username); - // test.strictEqual(realm + ":" + name + ":", storagePassword.name); - // test.strictEqual("changed!", storagePassword.properties().clear_password); - // test.strictEqual(realm, storagePassword.properties().realm); - // that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); - // }, - // function(storagePasswords, storagePassword, done) { - // try { - // test.ok(!!storagePasswords.item(realm + ":" + name + ":")); - // } - // catch (e) { - // test.ok(false); - // } - - // var list = storagePasswords.list(); - // var found = false; - - // test.strictEqual(startcount + 1, list.length); - // for (var i = 0; i < list.length; i ++) { - // if (realm + ":" + name + ":" === list[i].name) { - // found = true; - // } - // } - // test.ok(found); - - // storagePassword.remove(done); - // }, - // function(done) { - // that.service.storagePasswords().fetch(done); - // }, - // function(storagePasswords, done) { - // test.strictEqual(startcount, storagePasswords.list().length); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + "Callback#Read with slashes": function(test) { + var startcount = -1; + var name = "/delete-me-" + getNextId(); + var realm = "/delete-me-" + getNextId(); + var that = this; + Async.chain([ + function(done) { + that.service.storagePasswords().fetch(done); + }, + function(storagePasswords, done) { + startcount = storagePasswords.list().length; + storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); + }, + function(storagePassword, done) { + test.strictEqual(name, storagePassword.properties().username); + test.strictEqual(realm + ":" + name + ":", storagePassword.name); + test.strictEqual("changed!", storagePassword.properties().clear_password); + test.strictEqual(realm, storagePassword.properties().realm); + that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); + }, + function(storagePasswords, storagePassword, done) { + try { + test.ok(!!storagePasswords.item(realm + ":" + name + ":")); + } + catch (e) { + test.ok(false); + } - // "Callback#Read with slashes": function(test) { - // var startcount = -1; - // var name = "/delete-me-" + getNextId(); - // var realm = "/delete-me-" + getNextId(); - // var that = this; - // Async.chain([ - // function(done) { - // that.service.storagePasswords().fetch(done); - // }, - // function(storagePasswords, done) { - // startcount = storagePasswords.list().length; - // storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); - // }, - // function(storagePassword, done) { - // test.strictEqual(name, storagePassword.properties().username); - // test.strictEqual(realm + ":" + name + ":", storagePassword.name); - // test.strictEqual("changed!", storagePassword.properties().clear_password); - // test.strictEqual(realm, storagePassword.properties().realm); - // that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); - // }, - // function(storagePasswords, storagePassword, done) { - // try { - // test.ok(!!storagePasswords.item(realm + ":" + name + ":")); - // } - // catch (e) { - // test.ok(false); - // } - - // var list = storagePasswords.list(); - // var found = false; - - // test.strictEqual(startcount + 1, list.length); - // for (var i = 0; i < list.length; i ++) { - // if (realm + ":" + name + ":" === list[i].name) { - // found = true; - // } - // } - // test.ok(found); - - // storagePassword.remove(done); - // }, - // function(done) { - // that.service.storagePasswords().fetch(done); - // }, - // function(storagePasswords, done) { - // test.strictEqual(startcount, storagePasswords.list().length); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + var list = storagePasswords.list(); + var found = false; - // "Callback#Update": function(test) { - // var startcount = -1; - // var name = "delete-me-" + getNextId(); - // var realm = "delete-me-" + getNextId(); - // var that = this; - // Async.chain([ - // function(done) { - // that.service.storagePasswords().fetch(done); - // }, - // function(storagePasswords, done) { - // startcount = storagePasswords.list().length; - // storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); - // }, - // function(storagePassword, done) { - // test.strictEqual(name, storagePassword.properties().username); - // test.strictEqual(realm + ":" + name + ":", storagePassword.name); - // test.strictEqual("changed!", storagePassword.properties().clear_password); - // test.strictEqual(realm, storagePassword.properties().realm); - // that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); - // }, - // function(storagePasswords, storagePassword, done) { - // test.strictEqual(startcount + 1, storagePasswords.list().length); - // storagePassword.update({password: "changed"}, done); - // }, - // function(storagePassword, done) { - // test.strictEqual(name, storagePassword.properties().username); - // test.strictEqual(realm + ":" + name + ":", storagePassword.name); - // test.strictEqual("changed", storagePassword.properties().clear_password); - // test.strictEqual(realm, storagePassword.properties().realm); - // that.service.storagePasswords().fetch(done); - // }, - // function(storagePasswords, done) { - // var list = storagePasswords.list(); - // var found = false; - // var index = -1; - - // test.strictEqual(startcount + 1, list.length); - // for (var i = 0; i < list.length; i ++) { - // if (realm + ":" + name + ":" === list[i].name) { - // found = true; - // index = i; - // test.strictEqual(name, list[i].properties().username); - // test.strictEqual(realm + ":" + name + ":", list[i].name); - // test.strictEqual("changed", list[i].properties().clear_password); - // test.strictEqual(realm, list[i].properties().realm); - // } - // } - // test.ok(found); - - // if (!found) { - // done(new Error("Didn't find the created password")); - // } - // else { - // list[index].remove(done); - // } - // }, - // function(done) { - // that.service.storagePasswords().fetch(done); - // }, - // function(storagePasswords, done) { - // test.strictEqual(startcount, storagePasswords.list().length); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + test.strictEqual(startcount + 1, list.length); + for (var i = 0; i < list.length; i ++) { + if (realm + ":" + name + ":" === list[i].name) { + found = true; + } + } + test.ok(found); - // "Callback#Delete": function(test) { - // var startcount = -1; - // var name = "delete-me-" + getNextId(); - // var realm = "delete-me-" + getNextId(); - // var that = this; - // Async.chain([ - // function(done) { - // that.service.storagePasswords().fetch(done); - // }, - // function(storagePasswords, done) { - // startcount = storagePasswords.list().length; - // storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); - // }, - // function(storagePassword, done) { - // test.strictEqual(name, storagePassword.properties().username); - // test.strictEqual(realm + ":" + name + ":", storagePassword.name); - // test.strictEqual("changed!", storagePassword.properties().clear_password); - // test.strictEqual(realm, storagePassword.properties().realm); - // that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); - // }, - // function(storagePasswords, storagePassword, done) { - // test.strictEqual(startcount + 1, storagePasswords.list().length); - // storagePassword.remove(done); - // }, - // function(done) { - // that.service.storagePasswords().fetch(done); - // }, - // function(storagePasswords, done) { - // test.strictEqual(startcount, storagePasswords.list().length); - // storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); - // }, - // function(storagePassword, done) { - // test.strictEqual(name, storagePassword.properties().username); - // that.service.storagePasswords().fetch(done); - // }, - // function(storagePasswords, done) { - // test.strictEqual(startcount + 1, storagePasswords.list().length); - // var list = storagePasswords.list(); - // var found = false; - // var index = -1; - - // test.strictEqual(startcount + 1, list.length); - // for (var i = 0; i < list.length; i ++) { - // if (realm + ":" + name + ":" === list[i].name) { - // found = true; - // index = i; - // test.strictEqual(name, list[i].properties().username); - // test.strictEqual(realm + ":" + name + ":", list[i].name); - // test.strictEqual("changed!", list[i].properties().clear_password); - // test.strictEqual(realm, list[i].properties().realm); - // } - // } - // test.ok(found); - - // if (!found) { - // done(new Error("Didn't find the created password")); - // } - // else { - // list[index].remove(done); - // } - // }, - // function(done) { - // that.service.storagePasswords().fetch(done); - // }, - // function(storagePasswords, done) { - // test.strictEqual(startcount, storagePasswords.list().length); - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // } - // }, + storagePassword.remove(done); + }, + function(done) { + that.service.storagePasswords().fetch(done); + }, + function(storagePasswords, done) { + test.strictEqual(startcount, storagePasswords.list().length); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // "Index Tests": { - // setUp: function(done) { - // this.service = svc; - // this.loggedOutService = loggedOutSvc; - - // // Create the index for everyone to use - // var name = this.indexName = "sdk-tests"; - // var indexes = this.service.indexes(); - // indexes.create(name, {}, function(err, index) { - // if (err && err.status !== 409) { - // throw new Error("Index creation failed for an unknown reason"); - // } + "Callback#Update": function(test) { + var startcount = -1; + var name = "delete-me-" + getNextId(); + var realm = "delete-me-" + getNextId(); + var that = this; + Async.chain([ + function(done) { + that.service.storagePasswords().fetch(done); + }, + function(storagePasswords, done) { + startcount = storagePasswords.list().length; + storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); + }, + function(storagePassword, done) { + test.strictEqual(name, storagePassword.properties().username); + test.strictEqual(realm + ":" + name + ":", storagePassword.name); + test.strictEqual("changed!", storagePassword.properties().clear_password); + test.strictEqual(realm, storagePassword.properties().realm); + that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); + }, + function(storagePasswords, storagePassword, done) { + test.strictEqual(startcount + 1, storagePasswords.list().length); + storagePassword.update({password: "changed"}, done); + }, + function(storagePassword, done) { + test.strictEqual(name, storagePassword.properties().username); + test.strictEqual(realm + ":" + name + ":", storagePassword.name); + test.strictEqual("changed", storagePassword.properties().clear_password); + test.strictEqual(realm, storagePassword.properties().realm); + that.service.storagePasswords().fetch(done); + }, + function(storagePasswords, done) { + var list = storagePasswords.list(); + var found = false; + var index = -1; + + test.strictEqual(startcount + 1, list.length); + for (var i = 0; i < list.length; i ++) { + if (realm + ":" + name + ":" === list[i].name) { + found = true; + index = i; + test.strictEqual(name, list[i].properties().username); + test.strictEqual(realm + ":" + name + ":", list[i].name); + test.strictEqual("changed", list[i].properties().clear_password); + test.strictEqual(realm, list[i].properties().realm); + } + } + test.ok(found); - // done(); - // }); - // }, + if (!found) { + done(new Error("Didn't find the created password")); + } + else { + list[index].remove(done); + } + }, + function(done) { + that.service.storagePasswords().fetch(done); + }, + function(storagePasswords, done) { + test.strictEqual(startcount, storagePasswords.list().length); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, + + "Callback#Delete": function(test) { + var startcount = -1; + var name = "delete-me-" + getNextId(); + var realm = "delete-me-" + getNextId(); + var that = this; + Async.chain([ + function(done) { + that.service.storagePasswords().fetch(done); + }, + function(storagePasswords, done) { + startcount = storagePasswords.list().length; + storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); + }, + function(storagePassword, done) { + test.strictEqual(name, storagePassword.properties().username); + test.strictEqual(realm + ":" + name + ":", storagePassword.name); + test.strictEqual("changed!", storagePassword.properties().clear_password); + test.strictEqual(realm, storagePassword.properties().realm); + that.service.storagePasswords().fetch(Async.augment(done, storagePassword)); + }, + function(storagePasswords, storagePassword, done) { + test.strictEqual(startcount + 1, storagePasswords.list().length); + storagePassword.remove(done); + }, + function(done) { + that.service.storagePasswords().fetch(done); + }, + function(storagePasswords, done) { + test.strictEqual(startcount, storagePasswords.list().length); + storagePasswords.create({name: name, realm: realm, password: "changed!"}, done); + }, + function(storagePassword, done) { + test.strictEqual(name, storagePassword.properties().username); + that.service.storagePasswords().fetch(done); + }, + function(storagePasswords, done) { + test.strictEqual(startcount + 1, storagePasswords.list().length); + var list = storagePasswords.list(); + var found = false; + var index = -1; + + test.strictEqual(startcount + 1, list.length); + for (var i = 0; i < list.length; i ++) { + if (realm + ":" + name + ":" === list[i].name) { + found = true; + index = i; + test.strictEqual(name, list[i].properties().username); + test.strictEqual(realm + ":" + name + ":", list[i].name); + test.strictEqual("changed!", list[i].properties().clear_password); + test.strictEqual(realm, list[i].properties().realm); + } + } + test.ok(found); - // "Callback#remove index fails on Splunk 4.x": function(test) { - // var original_version = this.service.version; - // this.service.version = "4.0"; + if (!found) { + done(new Error("Didn't find the created password")); + } + else { + list[index].remove(done); + } + }, + function(done) { + that.service.storagePasswords().fetch(done); + }, + function(storagePasswords, done) { + test.strictEqual(startcount, storagePasswords.list().length); + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + } + }, - // var index = this.service.indexes().item(this.indexName); - // test.throws(function() { index.remove(function(err) {}); }); + "Index Tests": { + setUp: function(done) { + this.service = svc; + this.loggedOutService = loggedOutSvc; + + // Create the index for everyone to use + var name = this.indexName = "sdk-tests"; + var indexes = this.service.indexes(); + indexes.create(name, {}, function(err, index) { + if (err && err.status !== 409) { + throw new Error("Index creation failed for an unknown reason"); + } - // this.service.version = original_version; - // test.done(); - // }, + done(); + }); + }, + + "Callback#remove index fails on Splunk 4.x": function(test) { + var original_version = this.service.version; + this.service.version = "4.0"; + + var index = this.service.indexes().item(this.indexName); + test.throws(function() { index.remove(function(err) {}); }); + + this.service.version = original_version; + test.done(); + }, + + "Callback#remove index": function(test) { + var indexes = this.service.indexes(); + + // Must generate a private index because an index cannot + // be recreated with the same name as a deleted index + // for a certain period of time after the deletion. + var salt = Math.floor(Math.random() * 65536); + var myIndexName = this.indexName + '-' + salt; + + if (this.service.versionCompare("5.0") < 0) { + splunkjs.Logger.info("", "Must be running Splunk 5.0+ for this test to work."); + test.done(); + return; + } + + Async.chain([ + function(callback) { + indexes.create(myIndexName, {}, callback); + }, + function(index, callback) { + index.remove(callback); + }, + function(callback) { + var numTriesLeft = 50; + var delayPerTry = 100; // ms + + Async.whilst( + function() { return indexes.item(myIndexName) && ((numTriesLeft--) > 0); }, + function(iterDone) { + Async.sleep(delayPerTry, function() { indexes.fetch(iterDone); }); + }, + function(err) { + if (err) { + callback(err); + } + else { + callback(numTriesLeft <= 0 ? "Timed out" : null); + } + } + ); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, + + "Callback#list indexes": function(test) { + var indexes = this.service.indexes(); + indexes.fetch(function(err, indexes) { + var indexList = indexes.list(); + test.ok(indexList.length > 0); + test.done(); + }); + }, + + "Callback#contains index": function(test) { + var indexes = this.service.indexes(); + var indexName = this.indexName; + + indexes.fetch(function(err, indexes) { + var index = indexes.item(indexName); + test.ok(index); + test.done(); + }); + }, - // "Callback#remove index": function(test) { - // var indexes = this.service.indexes(); + "Callback#modify index": function(test) { - // // Must generate a private index because an index cannot - // // be recreated with the same name as a deleted index - // // for a certain period of time after the deletion. - // var salt = Math.floor(Math.random() * 65536); - // var myIndexName = this.indexName + '-' + salt; + var name = this.indexName; + var indexes = this.service.indexes(); + var originalSyncMeta = false; - // if (this.service.versionCompare("5.0") < 0) { - // splunkjs.Logger.info("", "Must be running Splunk 5.0+ for this test to work."); - // test.done(); - // return; - // } + Async.chain([ + function(callback) { + indexes.fetch(callback); + }, + function(indexes, callback) { + var index = indexes.item(name); + test.ok(index); + + originalSyncMeta = index.properties().syncMeta; + index.update({ + syncMeta: !originalSyncMeta + }, callback); + }, + function(index, callback) { + test.ok(index); + var properties = index.properties(); - // Async.chain([ - // function(callback) { - // indexes.create(myIndexName, {}, callback); - // }, - // function(index, callback) { - // index.remove(callback); - // }, - // function(callback) { - // var numTriesLeft = 50; - // var delayPerTry = 100; // ms - - // Async.whilst( - // function() { return indexes.item(myIndexName) && ((numTriesLeft--) > 0); }, - // function(iterDone) { - // Async.sleep(delayPerTry, function() { indexes.fetch(iterDone); }); - // }, - // function(err) { - // if (err) { - // callback(err); - // } - // else { - // callback(numTriesLeft <= 0 ? "Timed out" : null); - // } - // } - // ); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + test.strictEqual(!originalSyncMeta, properties.syncMeta); - // "Callback#list indexes": function(test) { - // var indexes = this.service.indexes(); - // indexes.fetch(function(err, indexes) { - // var indexList = indexes.list(); - // test.ok(indexList.length > 0); - // test.done(); - // }); - // }, + index.update({ + syncMeta: !properties.syncMeta + }, callback); + }, + function(index, callback) { + test.ok(index); + var properties = index.properties(); - // "Callback#contains index": function(test) { - // var indexes = this.service.indexes(); - // var indexName = this.indexName; + test.strictEqual(originalSyncMeta, properties.syncMeta); + callback(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // indexes.fetch(function(err, indexes) { - // var index = indexes.item(indexName); - // test.ok(index); - // test.done(); - // }); - // }, + "Callback#Enable+disable index": function(test) { - // "Callback#modify index": function(test) { + var name = this.indexName; + var indexes = this.service.indexes(); - // var name = this.indexName; - // var indexes = this.service.indexes(); - // var originalSyncMeta = false; + Async.chain([ + function(callback) { + indexes.fetch(callback); + }, + function(indexes, callback) { + var index = indexes.item(name); + test.ok(index); - // Async.chain([ - // function(callback) { - // indexes.fetch(callback); - // }, - // function(indexes, callback) { - // var index = indexes.item(name); - // test.ok(index); - - // originalSyncMeta = index.properties().syncMeta; - // index.update({ - // syncMeta: !originalSyncMeta - // }, callback); - // }, - // function(index, callback) { - // test.ok(index); - // var properties = index.properties(); + index.disable(callback); + }, + function(index, callback) { + test.ok(index); + index.fetch(callback); + }, + function(index, callback) { + test.ok(index); + test.ok(index.properties().disabled); - // test.strictEqual(!originalSyncMeta, properties.syncMeta); + index.enable(callback); + }, + function(index, callback) { + test.ok(index); + index.fetch(callback); + }, + function(index, callback) { + test.ok(index); + test.ok(!index.properties().disabled); - // index.update({ - // syncMeta: !properties.syncMeta - // }, callback); - // }, - // function(index, callback) { - // test.ok(index); - // var properties = index.properties(); + callback(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // test.strictEqual(originalSyncMeta, properties.syncMeta); - // callback(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + "Callback#Service submit event": function(test) { + var message = "Hello World -- " + getNextId(); + var sourcetype = "sdk-tests"; - // "Callback#Enable+disable index": function(test) { + var service = this.service; + var indexName = this.indexName; + Async.chain( + function(done) { + service.log(message, {sourcetype: sourcetype, index: indexName}, done); + }, + function(eventInfo, done) { + test.ok(eventInfo); + test.strictEqual(eventInfo.sourcetype, sourcetype); + test.strictEqual(eventInfo.bytes, message.length); + test.strictEqual(eventInfo.index, indexName); + + // We could poll to make sure the index has eaten up the event, + // but unfortunately this can take an unbounded amount of time. + // As such, since we got a good response, we'll just be done with it. + done(); + }, + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // var name = this.indexName; - // var indexes = this.service.indexes(); + "Callback#Service submit event, omitting optional arguments": function(test) { + var message = "Hello World -- " + getNextId(); + var sourcetype = "sdk-tests"; - // Async.chain([ - // function(callback) { - // indexes.fetch(callback); - // }, - // function(indexes, callback) { - // var index = indexes.item(name); - // test.ok(index); + var service = this.service; + var indexName = this.indexName; + Async.chain( + function(done) { + service.log(message, done); + }, + function(eventInfo, done) { + test.ok(eventInfo); + test.strictEqual(eventInfo.bytes, message.length); - // index.disable(callback); - // }, - // function(index, callback) { - // test.ok(index); - // index.fetch(callback); - // }, - // function(index, callback) { - // test.ok(index); - // test.ok(index.properties().disabled); + // We could poll to make sure the index has eaten up the event, + // but unfortunately this can take an unbounded amount of time. + // As such, since we got a good response, we'll just be done with it. + done(); + }, + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // index.enable(callback); - // }, - // function(index, callback) { - // test.ok(index); - // index.fetch(callback); - // }, - // function(index, callback) { - // test.ok(index); - // test.ok(!index.properties().disabled); + "Callback#Service submit events with multi-byte chars": function(test) { + var service = this.service; + var messages = [ + "Ummelner Straße 6", + "Ümmelner Straße 6", + "Iԉtérԉátíòлåɭìƶåtiòл", + "Intérnâtì߀лàɭíƶɑtïòл", + "ãϻét dòner turƙëy ѵ߀lù", + "ptãte ìԉ rëρrèhënԁérit ", + "ϻ߀lɭit fìɭèt ϻìǥnoԉ ɭäb߀ríѕ", + " êӽ cɦùck cüpïᏧåtåt Ꮷèѕëruлt. ", + "D߀ɭor ѵélít ìrurè, sèᏧ ѕhòr", + "t riƅѕ c߀ɰ ɭãnԁյàéɢêr drúmst", + "ícƙ. Minïm ƃàɭl tip ѕհòrt rìƃѕ,", + " ïԁ aɭïqúìρ ѕɦànƙ ρ߀rcɦéttɑ. Pìǥ", + " hãm ɦòck ìлcídíԁùԉt séԁ cüpïϻ ", + "ƙèviл láborê. Et taiɭ ѕtriρ", + " steák út üllãϻc߀ rump d߀ɭore.", + "٩(͡๏̯͡๏)۶ ٩(-̮̮̃•̃).", + "Lɑƅòré ƃrësãòlá d߀лèr ѕâlámí ", + "cíllûm ìn ѕɯìлe ϻêàtɭ߀àf dûìs ", + "ρãncettä ƅrìsƙét ԁèsêrûлt áútè", + " յòɰɭ. Lɑbòrìѕ ƙìêɭ", + "básá ԁòlòré fatƃɑck ƅêéf. Pɑѕtr", + "ämì piɢ ѕհàлƙ ùɭɭamcò ѕaû", + "ѕäǥë sɦànƙlë.", + " Cúpím ɭäƃorum drumstïcƙ jerkϒ veli", + " pïcåԉɦɑ ƙíéɭƅãsa. Alïqû", + "iρ írürë cûpíϻ, äɭìɋuâ ǥròûлd ", + "roúлᏧ toԉgüè ρàrìãtùr ", + "briѕkèt ԉostruᏧ cûɭpɑ", + " ìd còлѕèqûât làƅ߀rìs." + ]; + + var counter = 0; + Async.seriesMap( + messages, + function(val, idx, done) { + counter++; + service.log(val, done); + }, + function(err, vals) { + test.ok(!err); + test.strictEqual(counter, messages.length); - // callback(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + // Verify that the full byte-length was sent for each message + for (var m in messages) { + test.notStrictEqual(messages[m].length, vals[m].bytes); + try { + test.strictEqual(Buffer.byteLength(messages[m]), vals[m].bytes); + } + catch (err) { + // Assume Buffer isn't defined, we're probably in the browser + test.strictEqual(decodeURI(encodeURIComponent(messages[m])).length, vals[m].bytes); + } + } - // "Callback#Service submit event": function(test) { - // var message = "Hello World -- " + getNextId(); - // var sourcetype = "sdk-tests"; - - // var service = this.service; - // var indexName = this.indexName; - // Async.chain( - // function(done) { - // service.log(message, {sourcetype: sourcetype, index: indexName}, done); - // }, - // function(eventInfo, done) { - // test.ok(eventInfo); - // test.strictEqual(eventInfo.sourcetype, sourcetype); - // test.strictEqual(eventInfo.bytes, message.length); - // test.strictEqual(eventInfo.index, indexName); - - // // We could poll to make sure the index has eaten up the event, - // // but unfortunately this can take an unbounded amount of time. - // // As such, since we got a good response, we'll just be done with it. - // done(); - // }, - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + test.done(); + } + ); + }, - // "Callback#Service submit event, omitting optional arguments": function(test) { - // var message = "Hello World -- " + getNextId(); - // var sourcetype = "sdk-tests"; - - // var service = this.service; - // var indexName = this.indexName; - // Async.chain( - // function(done) { - // service.log(message, done); - // }, - // function(eventInfo, done) { - // test.ok(eventInfo); - // test.strictEqual(eventInfo.bytes, message.length); - - // // We could poll to make sure the index has eaten up the event, - // // but unfortunately this can take an unbounded amount of time. - // // As such, since we got a good response, we'll just be done with it. - // done(); - // }, - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + "Callback#Service submit event, failure": function(test) { + var message = "Hello World -- " + getNextId(); + var sourcetype = "sdk-tests"; - // "Callback#Service submit events with multi-byte chars": function(test) { - // var service = this.service; - // var messages = [ - // "Ummelner Straße 6", - // "Ümmelner Straße 6", - // "Iԉtérԉátíòлåɭìƶåtiòл", - // "Intérnâtì߀лàɭíƶɑtïòл", - // "ãϻét dòner turƙëy ѵ߀lù", - // "ptãte ìԉ rëρrèhënԁérit ", - // "ϻ߀lɭit fìɭèt ϻìǥnoԉ ɭäb߀ríѕ", - // " êӽ cɦùck cüpïᏧåtåt Ꮷèѕëruлt. ", - // "D߀ɭor ѵélít ìrurè, sèᏧ ѕhòr", - // "t riƅѕ c߀ɰ ɭãnԁյàéɢêr drúmst", - // "ícƙ. Minïm ƃàɭl tip ѕհòrt rìƃѕ,", - // " ïԁ aɭïqúìρ ѕɦànƙ ρ߀rcɦéttɑ. Pìǥ", - // " hãm ɦòck ìлcídíԁùԉt séԁ cüpïϻ ", - // "ƙèviл láborê. Et taiɭ ѕtriρ", - // " steák út üllãϻc߀ rump d߀ɭore.", - // "٩(͡๏̯͡๏)۶ ٩(-̮̮̃•̃).", - // "Lɑƅòré ƃrësãòlá d߀лèr ѕâlámí ", - // "cíllûm ìn ѕɯìлe ϻêàtɭ߀àf dûìs ", - // "ρãncettä ƅrìsƙét ԁèsêrûлt áútè", - // " յòɰɭ. Lɑbòrìѕ ƙìêɭ", - // "básá ԁòlòré fatƃɑck ƅêéf. Pɑѕtr", - // "ämì piɢ ѕհàлƙ ùɭɭamcò ѕaû", - // "ѕäǥë sɦànƙlë.", - // " Cúpím ɭäƃorum drumstïcƙ jerkϒ veli", - // " pïcåԉɦɑ ƙíéɭƅãsa. Alïqû", - // "iρ írürë cûpíϻ, äɭìɋuâ ǥròûлd ", - // "roúлᏧ toԉgüè ρàrìãtùr ", - // "briѕkèt ԉostruᏧ cûɭpɑ", - // " ìd còлѕèqûât làƅ߀rìs." - // ]; - - // var counter = 0; - // Async.seriesMap( - // messages, - // function(val, idx, done) { - // counter++; - // service.log(val, done); - // }, - // function(err, vals) { - // test.ok(!err); - // test.strictEqual(counter, messages.length); - - // // Verify that the full byte-length was sent for each message - // for (var m in messages) { - // test.notStrictEqual(messages[m].length, vals[m].bytes); - // try { - // test.strictEqual(Buffer.byteLength(messages[m]), vals[m].bytes); - // } - // catch (err) { - // // Assume Buffer isn't defined, we're probably in the browser - // test.strictEqual(decodeURI(encodeURIComponent(messages[m])).length, vals[m].bytes); - // } - // } + var service = this.loggedOutService; + var indexName = this.indexName; + Async.chain( + function(done) { + test.ok(service); + service.log(message, done); + }, + function(err) { + test.ok(err); + test.done(); + } + ); + }, - // test.done(); - // } - // ); - // }, + "Callback#remove throws an error": function(test) { + var index = this.service.indexes().item("_internal"); + test.throws(function() { + index.remove(); + }); + test.done(); + }, - // "Callback#Service submit event, failure": function(test) { - // var message = "Hello World -- " + getNextId(); - // var sourcetype = "sdk-tests"; - - // var service = this.loggedOutService; - // var indexName = this.indexName; - // Async.chain( - // function(done) { - // test.ok(service); - // service.log(message, done); - // }, - // function(err) { - // test.ok(err); - // test.done(); - // } - // ); - // }, + "Callback#create an index with alternate argument format": function(test) { + var indexes = this.service.indexes(); + indexes.create( + {name: "_internal"}, + function(err, newIndex) { + test.ok(err.data.messages[0].text.match("name=_internal already exists")); + test.done(); + } + ); + }, - // "Callback#remove throws an error": function(test) { - // var index = this.service.indexes().item("_internal"); - // test.throws(function() { - // index.remove(); - // }); - // test.done(); - // }, + "Callback#Index submit event with omitted optional arguments": function(test) { + var message = "Hello world -- " + getNextId(); - // "Callback#create an index with alternate argument format": function(test) { - // var indexes = this.service.indexes(); - // indexes.create( - // {name: "_internal"}, - // function(err, newIndex) { - // test.ok(err.data.messages[0].text.match("name=_internal already exists")); - // test.done(); - // } - // ); - // }, + var indexName = this.indexName; + var indexes = this.service.indexes(); - // "Callback#Index submit event with omitted optional arguments": function(test) { - // var message = "Hello world -- " + getNextId(); + Async.chain( + [ + function(done) { + indexes.fetch(done); + }, + function(indexes, done) { + var index = indexes.item(indexName); + test.ok(index); + test.strictEqual(index.name, indexName); + index.submitEvent(message, done); + }, + function(eventInfo, index, done) { + test.ok(eventInfo); + test.strictEqual(eventInfo.bytes, message.length); + test.strictEqual(eventInfo.index, indexName); + + // We could poll to make sure the index has eaten up the event, + // but unfortunately this can take an unbounded amount of time. + // As such, since we got a good response, we'll just be done with it. + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // var indexName = this.indexName; - // var indexes = this.service.indexes(); + "Callback#Index submit event": function(test) { + var message = "Hello World -- " + getNextId(); + var sourcetype = "sdk-tests"; - // Async.chain( - // [ - // function(done) { - // indexes.fetch(done); - // }, - // function(indexes, done) { - // var index = indexes.item(indexName); - // test.ok(index); - // test.strictEqual(index.name, indexName); - // index.submitEvent(message, done); - // }, - // function(eventInfo, index, done) { - // test.ok(eventInfo); - // test.strictEqual(eventInfo.bytes, message.length); - // test.strictEqual(eventInfo.index, indexName); - - // // We could poll to make sure the index has eaten up the event, - // // but unfortunately this can take an unbounded amount of time. - // // As such, since we got a good response, we'll just be done with it. - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + var indexName = this.indexName; + var indexes = this.service.indexes(); + Async.chain([ + function(done) { + indexes.fetch(done); + }, + function(indexes, done) { + var index = indexes.item(indexName); + test.ok(index); + test.strictEqual(index.name, indexName); + index.submitEvent(message, {sourcetype: sourcetype}, done); + }, + function(eventInfo, index, done) { + test.ok(eventInfo); + test.strictEqual(eventInfo.sourcetype, sourcetype); + test.strictEqual(eventInfo.bytes, message.length); + test.strictEqual(eventInfo.index, indexName); + + // We could poll to make sure the index has eaten up the event, + // but unfortunately this can take an unbounded amount of time. + // As such, since we got a good response, we'll just be done with it. + done(); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + } + }, - // "Callback#Index submit event": function(test) { - // var message = "Hello World -- " + getNextId(); - // var sourcetype = "sdk-tests"; + "User Tests": { + setUp: function(done) { + this.service = svc; + this.loggedOutService = loggedOutSvc; + done(); + }, - // var indexName = this.indexName; - // var indexes = this.service.indexes(); - // Async.chain([ - // function(done) { - // indexes.fetch(done); - // }, - // function(indexes, done) { - // var index = indexes.item(indexName); - // test.ok(index); - // test.strictEqual(index.name, indexName); - // index.submitEvent(message, {sourcetype: sourcetype}, done); - // }, - // function(eventInfo, index, done) { - // test.ok(eventInfo); - // test.strictEqual(eventInfo.sourcetype, sourcetype); - // test.strictEqual(eventInfo.bytes, message.length); - // test.strictEqual(eventInfo.index, indexName); - - // // We could poll to make sure the index has eaten up the event, - // // but unfortunately this can take an unbounded amount of time. - // // As such, since we got a good response, we'll just be done with it. - // done(); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // } - // }, + tearDown: function(done) { + this.service.logout(done); + }, - // "User Tests": { - // setUp: function(done) { - // this.service = svc; - // this.loggedOutService = loggedOutSvc; - // done(); - // }, + "Callback#Current user": function(test) { + var service = this.service; - // tearDown: function(done) { - // this.service.logout(done); - // }, + service.currentUser(function(err, user) { + test.ok(!err); + test.ok(user); + test.strictEqual(user.name, service.username); + test.done(); + }); + }, - // "Callback#Current user": function(test) { - // var service = this.service; + "Callback#Current user fails": function(test) { + var service = this.loggedOutService; - // service.currentUser(function(err, user) { - // test.ok(!err); - // test.ok(user); - // test.strictEqual(user.name, service.username); - // test.done(); - // }); - // }, + service.currentUser(function(err, user) { + test.ok(err); + test.done(); + }); + }, - // "Callback#Current user fails": function(test) { - // var service = this.loggedOutService; + "Callback#List users": function(test) { + var service = this.service; - // service.currentUser(function(err, user) { - // test.ok(err); - // test.done(); - // }); - // }, + service.users().fetch(function(err, users) { + var userList = users.list(); + test.ok(!err); + test.ok(users); - // "Callback#List users": function(test) { - // var service = this.service; + test.ok(userList); + test.ok(userList.length > 0); + test.done(); + }); + }, - // service.users().fetch(function(err, users) { - // var userList = users.list(); - // test.ok(!err); - // test.ok(users); + "Callback#create user failure": function(test) { + this.loggedOutService.users().create( + {name: "jssdk_testuser", password: "abc", roles: "user"}, + function(err, response) { + test.ok(err); + test.done(); + } + ); + }, - // test.ok(userList); - // test.ok(userList.length > 0); - // test.done(); - // }); - // }, + "Callback#Create + update + delete user": function(test) { + var service = this.service; + var name = "jssdk_testuser"; - // "Callback#create user failure": function(test) { - // this.loggedOutService.users().create( - // {name: "jssdk_testuser", password: "abc", roles: "user"}, - // function(err, response) { - // test.ok(err); - // test.done(); - // } - // ); - // }, + Async.chain([ + function(done) { + service.users().create({name: "jssdk_testuser", password: "abc", roles: "user"}, done); + }, + function(user, done) { + test.ok(user); + test.strictEqual(user.name, name); + test.strictEqual(user.properties().roles.length, 1); + test.strictEqual(user.properties().roles[0], "user"); - // "Callback#Create + update + delete user": function(test) { - // var service = this.service; - // var name = "jssdk_testuser"; + user.update({realname: "JS SDK", roles: ["admin", "user"]}, done); + }, + function(user, done) { + test.ok(user); + test.strictEqual(user.properties().realname, "JS SDK"); + test.strictEqual(user.properties().roles.length, 2); + test.strictEqual(user.properties().roles[0], "admin"); + test.strictEqual(user.properties().roles[1], "user"); + + user.remove(done); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // Async.chain([ - // function(done) { - // service.users().create({name: "jssdk_testuser", password: "abc", roles: "user"}, done); - // }, - // function(user, done) { - // test.ok(user); - // test.strictEqual(user.name, name); - // test.strictEqual(user.properties().roles.length, 1); - // test.strictEqual(user.properties().roles[0], "user"); + "Callback#Roles": function(test) { + var service = this.service; + var name = "jssdk_testuser_" + getNextId(); - // user.update({realname: "JS SDK", roles: ["admin", "user"]}, done); - // }, - // function(user, done) { - // test.ok(user); - // test.strictEqual(user.properties().realname, "JS SDK"); - // test.strictEqual(user.properties().roles.length, 2); - // test.strictEqual(user.properties().roles[0], "admin"); - // test.strictEqual(user.properties().roles[1], "user"); - - // user.remove(done); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + Async.chain([ + function(done) { + service.users().create({name: name, password: "abc", roles: "user"}, done); + }, + function(user, done) { + test.ok(user); + test.strictEqual(user.name, name); + test.strictEqual(user.properties().roles.length, 1); + test.strictEqual(user.properties().roles[0], "user"); - // "Callback#Roles": function(test) { - // var service = this.service; - // var name = "jssdk_testuser_" + getNextId(); + user.update({roles: ["admin", "user"]}, done); + }, + function(user, done) { + test.ok(user); + test.strictEqual(user.properties().roles.length, 2); + test.strictEqual(user.properties().roles[0], "admin"); + test.strictEqual(user.properties().roles[1], "user"); - // Async.chain([ - // function(done) { - // service.users().create({name: name, password: "abc", roles: "user"}, done); - // }, - // function(user, done) { - // test.ok(user); - // test.strictEqual(user.name, name); - // test.strictEqual(user.properties().roles.length, 1); - // test.strictEqual(user.properties().roles[0], "user"); + user.update({roles: "user"}, done); + }, + function(user, done) { + test.ok(user); + test.strictEqual(user.properties().roles.length, 1); + test.strictEqual(user.properties().roles[0], "user"); - // user.update({roles: ["admin", "user"]}, done); - // }, - // function(user, done) { - // test.ok(user); - // test.strictEqual(user.properties().roles.length, 2); - // test.strictEqual(user.properties().roles[0], "admin"); - // test.strictEqual(user.properties().roles[1], "user"); + user.update({roles: "__unknown__"}, done); + } + ], + function(err) { + test.ok(err); + test.strictEqual(err.status, 400); + test.done(); + } + ); + }, - // user.update({roles: "user"}, done); - // }, - // function(user, done) { - // test.ok(user); - // test.strictEqual(user.properties().roles.length, 1); - // test.strictEqual(user.properties().roles[0], "user"); + "Callback#Passwords": function(test) { + var service = this.service; + var newService = null; + var name = "jssdk_testuser_" + getNextId(); - // user.update({roles: "__unknown__"}, done); - // } - // ], - // function(err) { - // test.ok(err); - // test.strictEqual(err.status, 400); - // test.done(); - // } - // ); - // }, + Async.chain([ + function(done) { + service.users().create({name: name, password: "abc", roles: "user"}, done); + }, + function(user, done) { + test.ok(user); + test.strictEqual(user.name, name); + test.strictEqual(user.properties().roles.length, 1); + test.strictEqual(user.properties().roles[0], "user"); + + newService = new splunkjs.Service(service.http, { + username: name, + password: "abc", + host: service.host, + port: service.port, + scheme: service.scheme, + version: service.version + }); - // "Callback#Passwords": function(test) { - // var service = this.service; - // var newService = null; - // var name = "jssdk_testuser_" + getNextId(); + newService.login(Async.augment(done, user)); + }, + function(success, user, done) { + test.ok(success); + test.ok(user); - // Async.chain([ - // function(done) { - // service.users().create({name: name, password: "abc", roles: "user"}, done); - // }, - // function(user, done) { - // test.ok(user); - // test.strictEqual(user.name, name); - // test.strictEqual(user.properties().roles.length, 1); - // test.strictEqual(user.properties().roles[0], "user"); - - // newService = new splunkjs.Service(service.http, { - // username: name, - // password: "abc", - // host: service.host, - // port: service.port, - // scheme: service.scheme, - // version: service.version - // }); - - // newService.login(Async.augment(done, user)); - // }, - // function(success, user, done) { - // test.ok(success); - // test.ok(user); + user.update({password: "abc2"}, done); + }, + function(user, done) { + newService.login(function(err, success) { + test.ok(err); + test.ok(!success); - // user.update({password: "abc2"}, done); - // }, - // function(user, done) { - // newService.login(function(err, success) { - // test.ok(err); - // test.ok(!success); + user.update({password: "abc"}, done); + }); + }, + function(user, done) { + test.ok(user); + newService.login(done); + } + ], + function(err) { + test.ok(!err); + test.done(); + } + ); + }, - // user.update({password: "abc"}, done); - // }); - // }, - // function(user, done) { - // test.ok(user); - // newService.login(done); - // } - // ], - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }, + "Callback#delete test users": function(test) { + var users = this.service.users(); + users.fetch(function(err, users) { + var userList = users.list(); - // "Callback#delete test users": function(test) { - // var users = this.service.users(); - // users.fetch(function(err, users) { - // var userList = users.list(); - - // Async.parallelEach( - // userList, - // function(user, idx, callback) { - // if (utils.startsWith(user.name, "jssdk_")) { - // user.remove(callback); - // } - // else { - // callback(); - // } - // }, function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // }); - // } - // }, + Async.parallelEach( + userList, + function(user, idx, callback) { + if (utils.startsWith(user.name, "jssdk_")) { + user.remove(callback); + } + else { + callback(); + } + }, function(err) { + test.ok(!err); + test.done(); + } + ); + }); + } + }, - // "Server Info Tests": { - // setUp: function(done) { - // this.service = svc; - // done(); - // }, + "Server Info Tests": { + setUp: function(done) { + this.service = svc; + done(); + }, - // "Callback#Basic": function(test) { - // var service = this.service; + "Callback#Basic": function(test) { + var service = this.service; - // service.serverInfo(function(err, info) { - // test.ok(!err); - // test.ok(info); - // test.strictEqual(info.name, "server-info"); - // test.ok(info.properties().hasOwnProperty("version")); - // test.ok(info.properties().hasOwnProperty("serverName")); - // test.ok(info.properties().hasOwnProperty("os_version")); + service.serverInfo(function(err, info) { + test.ok(!err); + test.ok(info); + test.strictEqual(info.name, "server-info"); + test.ok(info.properties().hasOwnProperty("version")); + test.ok(info.properties().hasOwnProperty("serverName")); + test.ok(info.properties().hasOwnProperty("os_version")); - // test.done(); - // }); - // } - // }, + test.done(); + }); + } + }, "View Tests": { setUp: function(done) { @@ -22292,252 +22292,252 @@ exports.setup = function(svc, loggedOutSvc) { } }, - // "Parser Tests": { - // setUp: function(done) { - // this.service = svc; - // done(); - // }, + "Parser Tests": { + setUp: function(done) { + this.service = svc; + done(); + }, - // "Callback#Basic parse": function(test) { - // var service = this.service; + "Callback#Basic parse": function(test) { + var service = this.service; - // service.parse("search index=_internal | head 1", function(err, parse) { - // test.ok(!err); - // test.ok(parse); - // test.ok(parse.commands.length > 0); - // test.done(); - // }); - // }, + service.parse("search index=_internal | head 1", function(err, parse) { + test.ok(!err); + test.ok(parse); + test.ok(parse.commands.length > 0); + test.done(); + }); + }, - // "Callback#Parse error": function(test) { - // var service = this.service; + "Callback#Parse error": function(test) { + var service = this.service; - // service.parse("ABCXYZ", function(err, parse) { - // test.ok(err); - // test.strictEqual(err.status, 400); - // test.done(); - // }); - // } - // }, + service.parse("ABCXYZ", function(err, parse) { + test.ok(err); + test.strictEqual(err.status, 400); + test.done(); + }); + } + }, - // "Typeahead Tests": { - // setUp: function(done) { - // this.service = svc; - // this.loggedOutService = loggedOutSvc; - // done(); - // }, + "Typeahead Tests": { + setUp: function(done) { + this.service = svc; + this.loggedOutService = loggedOutSvc; + done(); + }, - // "Callback#Typeahead failure": function(test) { - // var service = this.loggedOutService; - // service.typeahead("index=", 1, function(err, options) { - // test.ok(err); - // test.done(); - // }); - // }, + "Callback#Typeahead failure": function(test) { + var service = this.loggedOutService; + service.typeahead("index=", 1, function(err, options) { + test.ok(err); + test.done(); + }); + }, - // "Callback#Basic typeahead": function(test) { - // var service = this.service; + "Callback#Basic typeahead": function(test) { + var service = this.service; - // service.typeahead("index=", 1, function(err, options) { - // test.ok(!err); - // test.ok(options); - // test.strictEqual(options.length, 1); - // test.ok(options[0]); - // test.done(); - // }); - // }, + service.typeahead("index=", 1, function(err, options) { + test.ok(!err); + test.ok(options); + test.strictEqual(options.length, 1); + test.ok(options[0]); + test.done(); + }); + }, - // "Typeahead with omitted optional arguments": function(test) { - // var service = this.service; - // service.typeahead("index=", function(err, options) { - // test.ok(!err); - // test.ok(options); - // test.done(); - // }); - // } - // }, + "Typeahead with omitted optional arguments": function(test) { + var service = this.service; + service.typeahead("index=", function(err, options) { + test.ok(!err); + test.ok(options); + test.done(); + }); + } + }, - // "Endpoint Tests": { - // setUp: function(done) { - // this.service = svc; - // done(); - // }, + "Endpoint Tests": { + setUp: function(done) { + this.service = svc; + done(); + }, - // "Throws on null arguments to init": function(test) { - // var service = this.service; - // test.throws(function() { - // var endpoint = new splunkjs.Service.Endpoint(null, "a/b"); - // }); - // test.throws(function() { - // var endpoint = new splunkjs.Service.Endpoint(service, null); - // }); - // test.done(); - // }, + "Throws on null arguments to init": function(test) { + var service = this.service; + test.throws(function() { + var endpoint = new splunkjs.Service.Endpoint(null, "a/b"); + }); + test.throws(function() { + var endpoint = new splunkjs.Service.Endpoint(service, null); + }); + test.done(); + }, - // "Endpoint delete on a relative path": function(test) { - // var service = this.service; - // var endpoint = new splunkjs.Service.Endpoint(service, "/search/jobs/12345"); - // endpoint.del("search/jobs/12345", {}, function() { test.done();}); - // }, + "Endpoint delete on a relative path": function(test) { + var service = this.service; + var endpoint = new splunkjs.Service.Endpoint(service, "/search/jobs/12345"); + endpoint.del("search/jobs/12345", {}, function() { test.done();}); + }, - // "Methods of Resource to be overridden": function(test) { - // var service = this.service; - // var resource = new splunkjs.Service.Resource(service, "/search/jobs/12345"); - // test.throws(function() { resource.path(); }); - // test.throws(function() { resource.fetch(); }); - // test.ok(splunkjs.Utils.isEmpty(resource.state())); - // test.done(); - // } - // }, + "Methods of Resource to be overridden": function(test) { + var service = this.service; + var resource = new splunkjs.Service.Resource(service, "/search/jobs/12345"); + test.throws(function() { resource.path(); }); + test.throws(function() { resource.fetch(); }); + test.ok(splunkjs.Utils.isEmpty(resource.state())); + test.done(); + } + }, - // "Entity tests": { - // setUp: function(done) { - // this.service = svc; - // this.loggedOutService = loggedOutSvc; - // done(); - // }, + "Entity tests": { + setUp: function(done) { + this.service = svc; + this.loggedOutService = loggedOutSvc; + done(); + }, - // "Accessors function properly": function(test) { - // var entity = new splunkjs.Service.Entity( - // this.service, - // "/search/jobs/12345", - // {owner: "boris", app: "factory", sharing: "app"} - // ); - // entity._load( - // {acl: {owner: "boris", app: "factory", sharing: "app"}, - // links: {link1: 35}, - // published: "meep", - // author: "Hilda"} - // ); - // test.ok(entity.acl().owner === "boris"); - // test.ok(entity.acl().app === "factory"); - // test.ok(entity.acl().sharing === "app"); - // test.ok(entity.links().link1 === 35); - // test.strictEqual(entity.author(), "Hilda"); - // test.strictEqual(entity.published(), "meep"); - // test.done(); - // }, + "Accessors function properly": function(test) { + var entity = new splunkjs.Service.Entity( + this.service, + "/search/jobs/12345", + {owner: "boris", app: "factory", sharing: "app"} + ); + entity._load( + {acl: {owner: "boris", app: "factory", sharing: "app"}, + links: {link1: 35}, + published: "meep", + author: "Hilda"} + ); + test.ok(entity.acl().owner === "boris"); + test.ok(entity.acl().app === "factory"); + test.ok(entity.acl().sharing === "app"); + test.ok(entity.links().link1 === 35); + test.strictEqual(entity.author(), "Hilda"); + test.strictEqual(entity.published(), "meep"); + test.done(); + }, - // "Refresh throws error correctly": function(test) { - // var entity = new splunkjs.Service.Entity(this.loggedOutService, "/search/jobs/12345", {owner: "boris", app: "factory", sharing: "app"}); - // entity.fetch({}, function(err) { test.ok(err); test.done();}); - // }, + "Refresh throws error correctly": function(test) { + var entity = new splunkjs.Service.Entity(this.loggedOutService, "/search/jobs/12345", {owner: "boris", app: "factory", sharing: "app"}); + entity.fetch({}, function(err) { test.ok(err); test.done();}); + }, - // "Cannot update name of entity": function(test) { - // var entity = new splunkjs.Service.Entity(this.service, "/search/jobs/12345", {owner: "boris", app: "factory", sharing: "app"}); - // test.throws(function() { entity.update({name: "asdf"});}); - // test.done(); - // }, + "Cannot update name of entity": function(test) { + var entity = new splunkjs.Service.Entity(this.service, "/search/jobs/12345", {owner: "boris", app: "factory", sharing: "app"}); + test.throws(function() { entity.update({name: "asdf"});}); + test.done(); + }, - // "Disable throws error correctly": function(test) { - // var entity = new splunkjs.Service.Entity( - // this.loggedOutService, - // "/search/jobs/12345", - // {owner: "boris", app: "factory", sharing: "app"} - // ); - // entity.disable(function(err) { test.ok(err); test.done();}); - // }, + "Disable throws error correctly": function(test) { + var entity = new splunkjs.Service.Entity( + this.loggedOutService, + "/search/jobs/12345", + {owner: "boris", app: "factory", sharing: "app"} + ); + entity.disable(function(err) { test.ok(err); test.done();}); + }, - // "Enable throws error correctly": function(test) { - // var entity = new splunkjs.Service.Entity( - // this.loggedOutService, - // "/search/jobs/12345", - // {owner: "boris", app: "factory", sharing: "app"} - // ); - // entity.enable(function(err) { test.ok(err); test.done();}); - // }, + "Enable throws error correctly": function(test) { + var entity = new splunkjs.Service.Entity( + this.loggedOutService, + "/search/jobs/12345", + {owner: "boris", app: "factory", sharing: "app"} + ); + entity.enable(function(err) { test.ok(err); test.done();}); + }, - // "Does reload work?": function(test) { - // var idx = new splunkjs.Service.Index( - // this.service, - // "data/indexes/sdk-test", - // { - // owner: "admin", - // app: "search", - // sharing: "app" - // } - // ); - // var name = "jssdk_testapp_" + getNextId(); - // var apps = this.service.apps(); + "Does reload work?": function(test) { + var idx = new splunkjs.Service.Index( + this.service, + "data/indexes/sdk-test", + { + owner: "admin", + app: "search", + sharing: "app" + } + ); + var name = "jssdk_testapp_" + getNextId(); + var apps = this.service.apps(); - // var that = this; - // Async.chain( - // function(done) { - // apps.create({name: name}, done); - // }, - // function(app, done) { - // app.reload(function(err) { - // test.ok(!err); - // done(null, app); - // }); - // }, - // function(app, done) { - // var app2 = new splunkjs.Service.Application(that.loggedOutService, app.name); - // app2.reload(function(err) { - // test.ok(err); - // done(null, app); - // }); - // }, - // function(app, done) { - // app.remove(done); - // }, - // function(err) { - // test.ok(!err); - // test.done(); - // } - // ); - // } - // }, + var that = this; + Async.chain( + function(done) { + apps.create({name: name}, done); + }, + function(app, done) { + app.reload(function(err) { + test.ok(!err); + done(null, app); + }); + }, + function(app, done) { + var app2 = new splunkjs.Service.Application(that.loggedOutService, app.name); + app2.reload(function(err) { + test.ok(err); + done(null, app); + }); + }, + function(app, done) { + app.remove(done); + }, + function(err) { + test.ok(!err); + test.done(); + } + ); + } + }, - // "Collection tests": { - // setUp: function(done) { - // this.service = svc; - // this.loggedOutService = loggedOutSvc; - // done(); - // }, + "Collection tests": { + setUp: function(done) { + this.service = svc; + this.loggedOutService = loggedOutSvc; + done(); + }, - // "Methods to be overridden throw": function(test) { - // var coll = new splunkjs.Service.Collection( - // this.service, - // "/data/indexes", - // {owner: "admin", - // app: "search", - // sharing: "app"} - // ); - // test.throws(function() { - // coll.instantiateEntity({}); - // }); - // test.done(); - // }, + "Methods to be overridden throw": function(test) { + var coll = new splunkjs.Service.Collection( + this.service, + "/data/indexes", + {owner: "admin", + app: "search", + sharing: "app"} + ); + test.throws(function() { + coll.instantiateEntity({}); + }); + test.done(); + }, - // "Accessors work": function(test) { - // var coll = new splunkjs.Service.Collection( - // this.service, - // "/data/indexes", - // {owner: "admin", - // app: "search", - // sharing: "app"} - // ); - // coll._load({links: "Hilda", updated: true}); - // test.strictEqual(coll.links(), "Hilda"); - // test.ok(coll.updated()); - // test.done(); - // }, + "Accessors work": function(test) { + var coll = new splunkjs.Service.Collection( + this.service, + "/data/indexes", + {owner: "admin", + app: "search", + sharing: "app"} + ); + coll._load({links: "Hilda", updated: true}); + test.strictEqual(coll.links(), "Hilda"); + test.ok(coll.updated()); + test.done(); + }, - // "Contains throws without a good id": function(test) { - // var coll = new splunkjs.Service.Collection( - // this.service, - // "/data/indexes", - // { - // owner: "admin", - // app: "search", - // sharing: "app" - // } - // ); - // test.throws(function() { coll.item(null);}); - // test.done(); - // } - // } + "Contains throws without a good id": function(test) { + var coll = new splunkjs.Service.Collection( + this.service, + "/data/indexes", + { + owner: "admin", + app: "search", + sharing: "app" + } + ); + test.throws(function() { coll.item(null);}); + test.done(); + } + } }; return suite; }; @@ -25488,10 +25488,10 @@ require.define("/browser.test.entry.js", function (require, module, exports, __d // include it. window.SplunkTest = { - // Utils : require('../../tests/test_utils'), - // Async : require('../../tests/test_async'), - // Http : require('../../tests/test_http'), - // Context : require('../../tests/test_context'), + Utils : require('../../tests/test_utils'), + Async : require('../../tests/test_async'), + Http : require('../../tests/test_http'), + Context : require('../../tests/test_context'), Service : require('../../tests/test_service'), Examples : require('../../tests/test_examples') }; diff --git a/node_modules/.bin/needle b/node_modules/.bin/needle new file mode 120000 index 000000000..828096942 --- /dev/null +++ b/node_modules/.bin/needle @@ -0,0 +1 @@ +../needle/bin/needle \ No newline at end of file diff --git a/node_modules/dotenv/CHANGELOG.md b/node_modules/dotenv/CHANGELOG.md new file mode 100644 index 000000000..1b3893d9d --- /dev/null +++ b/node_modules/dotenv/CHANGELOG.md @@ -0,0 +1,210 @@ +# Changelog + +All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. + +## [10.0.0](https://github.com/motdotla/dotenv/compare/v9.0.2...v10.0.0) (2021-05-20) + +### Added + +- Add generic support to parse function +- Allow for import "dotenv/config.js" +- Add support to resolve home directory in path via ~ + +## [9.0.2](https://github.com/motdotla/dotenv/compare/v9.0.1...v9.0.2) (2021-05-10) + +### Changed + +- Support windows newlines with debug mode + +## [9.0.1](https://github.com/motdotla/dotenv/compare/v9.0.0...v9.0.1) (2021-05-08) + +### Changed + +- Updates to README + +## [9.0.0](https://github.com/motdotla/dotenv/compare/v8.6.0...v9.0.0) (2021-05-05) + +### Changed + +- _Breaking:_ drop support for Node v8 + +## [8.6.0](https://github.com/motdotla/dotenv/compare/v8.5.1...v8.6.0) (2021-05-05) + +### Added + +- define package.json in exports + +## [8.5.1](https://github.com/motdotla/dotenv/compare/v8.5.0...v8.5.1) (2021-05-05) + +### Changed + +- updated dev dependencies via npm audit + +## [8.5.0](https://github.com/motdotla/dotenv/compare/v8.4.0...v8.5.0) (2021-05-05) + +### Added + +- allow for `import "dotenv/config"` + +## [8.4.0](https://github.com/motdotla/dotenv/compare/v8.3.0...v8.4.0) (2021-05-05) + +### Changed + +- point to exact types file to work with VS Code + +## [8.3.0](https://github.com/motdotla/dotenv/compare/v8.2.0...v8.3.0) (2021-05-05) + +### Changed + +- _Breaking:_ drop support for Node v8 (mistake to be released as minor bump. later bumped to 9.0.0. see above.) + +## [8.2.0](https://github.com/motdotla/dotenv/compare/v8.1.0...v8.2.0) (2019-10-16) + +### Added + +- TypeScript types + +## [8.1.0](https://github.com/motdotla/dotenv/compare/v8.0.0...v8.1.0) (2019-08-18) + +### Changed + +- _Breaking:_ drop support for Node v6 ([#392](https://github.com/motdotla/dotenv/issues/392)) + +# [8.0.0](https://github.com/motdotla/dotenv/compare/v7.0.0...v8.0.0) (2019-05-02) + +### Changed + +- _Breaking:_ drop support for Node v6 ([#302](https://github.com/motdotla/dotenv/issues/392)) + +## [7.0.0] - 2019-03-12 + +### Fixed + +- Fix removing unbalanced quotes ([#376](https://github.com/motdotla/dotenv/pull/376)) + +### Removed + +- Removed `load` alias for `config` for consistency throughout code and documentation. + +## [6.2.0] - 2018-12-03 + +### Added + +- Support preload configuration via environment variables ([#351](https://github.com/motdotla/dotenv/issues/351)) + +## [6.1.0] - 2018-10-08 + +### Added + +- `debug` option for `config` and `parse` methods will turn on logging + +## [6.0.0] - 2018-06-02 + +### Changed + +- _Breaking:_ drop support for Node v4 ([#304](https://github.com/motdotla/dotenv/pull/304)) + +## [5.0.0] - 2018-01-29 + +### Added + +- Testing against Node v8 and v9 +- Documentation on trim behavior of values +- Documentation on how to use with `import` + +### Changed + +- _Breaking_: default `path` is now `path.resolve(process.cwd(), '.env')` +- _Breaking_: does not write over keys already in `process.env` if the key has a falsy value +- using `const` and `let` instead of `var` + +### Removed + +- Testing against Node v7 + +## [4.0.0] - 2016-12-23 + +### Changed + +- Return Object with parsed content or error instead of false ([#165](https://github.com/motdotla/dotenv/pull/165)). + +### Removed + +- `verbose` option removed in favor of returning result. + +## [3.0.0] - 2016-12-20 + +### Added + +- `verbose` option will log any error messages. Off by default. +- parses email addresses correctly +- allow importing config method directly in ES6 + +### Changed + +- Suppress error messages by default ([#154](https://github.com/motdotla/dotenv/pull/154)) +- Ignoring more files for NPM to make package download smaller + +### Fixed + +- False positive test due to case-sensitive variable ([#124](https://github.com/motdotla/dotenv/pull/124)) + +### Removed + +- `silent` option removed in favor of `verbose` + +## [2.0.0] - 2016-01-20 + +### Added + +- CHANGELOG to ["make it easier for users and contributors to see precisely what notable changes have been made between each release"](http://keepachangelog.com/). Linked to from README +- LICENSE to be more explicit about what was defined in `package.json`. Linked to from README +- Testing nodejs v4 on travis-ci +- added examples of how to use dotenv in different ways +- return parsed object on success rather than boolean true + +### Changed + +- README has shorter description not referencing ruby gem since we don't have or want feature parity + +### Removed + +- Variable expansion and escaping so environment variables are encouraged to be fully orthogonal + +## [1.2.0] - 2015-06-20 + +### Added + +- Preload hook to require dotenv without including it in your code + +### Changed + +- clarified license to be "BSD-2-Clause" in `package.json` + +### Fixed + +- retain spaces in string vars + +## [1.1.0] - 2015-03-31 + +### Added + +- Silent option to silence `console.log` when `.env` missing + +## [1.0.0] - 2015-03-13 + +### Removed + +- support for multiple `.env` files. should always use one `.env` file for the current environment + +[7.0.0]: https://github.com/motdotla/dotenv/compare/v6.2.0...v7.0.0 +[6.2.0]: https://github.com/motdotla/dotenv/compare/v6.1.0...v6.2.0 +[6.1.0]: https://github.com/motdotla/dotenv/compare/v6.0.0...v6.1.0 +[6.0.0]: https://github.com/motdotla/dotenv/compare/v5.0.0...v6.0.0 +[5.0.0]: https://github.com/motdotla/dotenv/compare/v4.0.0...v5.0.0 +[4.0.0]: https://github.com/motdotla/dotenv/compare/v3.0.0...v4.0.0 +[3.0.0]: https://github.com/motdotla/dotenv/compare/v2.0.0...v3.0.0 +[2.0.0]: https://github.com/motdotla/dotenv/compare/v1.2.0...v2.0.0 +[1.2.0]: https://github.com/motdotla/dotenv/compare/v1.1.0...v1.2.0 +[1.1.0]: https://github.com/motdotla/dotenv/compare/v1.0.0...v1.1.0 +[1.0.0]: https://github.com/motdotla/dotenv/compare/v0.4.0...v1.0.0 diff --git a/node_modules/dotenv/LICENSE b/node_modules/dotenv/LICENSE new file mode 100644 index 000000000..c430ad8bd --- /dev/null +++ b/node_modules/dotenv/LICENSE @@ -0,0 +1,23 @@ +Copyright (c) 2015, Scott Motte +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/node_modules/dotenv/README.md b/node_modules/dotenv/README.md new file mode 100644 index 000000000..92c5b57c4 --- /dev/null +++ b/node_modules/dotenv/README.md @@ -0,0 +1,275 @@ +

    +Announcement 📣
    From the makers that brought you Dotenv, introducing Dotenv Sync.
    Sync your .env files between machines, environments, and team members.
    Join the early access list. 🕶 +

    + +# dotenv + +dotenv + +Dotenv is a zero-dependency module that loads environment variables from a `.env` file into [`process.env`](https://nodejs.org/docs/latest/api/process.html#process_process_env). Storing configuration in the environment separate from code is based on [The Twelve-Factor App](http://12factor.net/config) methodology. + +[![BuildStatus](https://img.shields.io/travis/motdotla/dotenv/master.svg?style=flat-square)](https://travis-ci.org/motdotla/dotenv) +[![Build status](https://ci.appveyor.com/api/projects/status/github/motdotla/dotenv?svg=true)](https://ci.appveyor.com/project/motdotla/dotenv/branch/master) +[![NPM version](https://img.shields.io/npm/v/dotenv.svg?style=flat-square)](https://www.npmjs.com/package/dotenv) +[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard) +[![Coverage Status](https://img.shields.io/coveralls/motdotla/dotenv/master.svg?style=flat-square)](https://coveralls.io/github/motdotla/dotenv?branch=coverall-intergration) +[![LICENSE](https://img.shields.io/github/license/motdotla/dotenv.svg)](LICENSE) +[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org) + +## Install + +```bash +# with npm +npm install dotenv + +# or with Yarn +yarn add dotenv +``` + +## Usage + +As early as possible in your application, require and configure dotenv. + +```javascript +require('dotenv').config() +``` + +Create a `.env` file in the root directory of your project. Add +environment-specific variables on new lines in the form of `NAME=VALUE`. +For example: + +```dosini +DB_HOST=localhost +DB_USER=root +DB_PASS=s1mpl3 +``` + +`process.env` now has the keys and values you defined in your `.env` file. + +```javascript +const db = require('db') +db.connect({ + host: process.env.DB_HOST, + username: process.env.DB_USER, + password: process.env.DB_PASS +}) +``` + +### Preload + +You can use the `--require` (`-r`) [command line option](https://nodejs.org/api/cli.html#cli_r_require_module) to preload dotenv. By doing this, you do not need to require and load dotenv in your application code. This is the preferred approach when using `import` instead of `require`. + +```bash +$ node -r dotenv/config your_script.js +``` + +The configuration options below are supported as command line arguments in the format `dotenv_config_