Created
April 3, 2013 17:19
-
-
Save jrgm/5303230 to your computer and use it in GitHub Desktop.
send a test blob.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
/* This Source Code Form is subject to the terms of the Mozilla Public | |
* License, v. 2.0. If a copy of the MPL was not distributed with this | |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | |
var client = require('../lib/wsapi_client.js'); | |
var optimist = require('optimist'); | |
var path = require('path'); | |
var urlparse = require('urlparse'); | |
var util = require('util'); | |
const USAGE = 'Send a single KPI blob to a webhead'; | |
const OPTIONS = { | |
h: { | |
describe: 'display this usage message' | |
}, | |
u: { | |
describe: 'which url endpoint to test', | |
'default': 'https://login.anosrep.org' | |
}, | |
}; | |
var event_stream = [ | |
["window.dom_loading",972], | |
["window.channel_established",2720], | |
["screen.rp_info",2721], | |
["xhr_complete.GET/wsapi/session_context",2723,294], | |
["screen.authenticate",3032],["user.can_interact",3053], | |
["xhr_complete.POST/wsapi/interaction_data",3025,271], | |
["xhr_complete.GET/wsapi/address_info",8656,603], | |
["authenticate.enter_password",9548], | |
["authenticate.enter_password",9554], | |
["authenticate.enter_password",9560], | |
["authenticate.password_submitted",15381], | |
["xhr_complete.POST/wsapi/authenticate_user",15381,1545], | |
["xhr_complete.GET/wsapi/list_emails",16930,255], | |
["authenticate.password_success",17195], | |
["screen.is_this_your_computer",17199], | |
["xhr_complete.POST/wsapi/prolong_session",19812,245], | |
["generate_assertion",20064], | |
["screen.generate_assertion",20065], | |
["xhr_complete.POST/wsapi/cert_key",20140,3580], | |
["assertion_generated",23761], | |
["window.unload",1337] | |
]; | |
function blob(now) { | |
// sets timestamp to `now`; the rest is static. | |
if (!now) now = Date.now(); | |
var data = { | |
data: { | |
"event_stream": event_stream, | |
"sample_rate":1, | |
"timestamp": now, | |
"lang":"en", | |
"new_account":false, | |
"screen_size":{"width":1680,"height":1050}, | |
"number_emails":1, | |
"number_sites_signed_in":1, | |
"number_sites_remembered":1, | |
"orphaned":false, | |
"user_agent":{"os":"Macintosh","browser":"kpi-test","version":1} | |
} | |
}; | |
return data; | |
} | |
function processOptions() { | |
function optionError(message) { | |
console.log('\n** ERROR: ', message, '\n'); | |
//argv.showHelp(); | |
process.exit(1); | |
} | |
argv = optimist | |
.usage('\n' + USAGE + '\n\nUsage: $0 [options]') | |
.options(OPTIONS) | |
.wrap(80); | |
args = argv.argv; | |
if (args.h) { | |
argv.showHelp(); | |
process.exit(1); | |
} | |
// check for valid url | |
try { | |
urlparse(args.u).validate(); | |
} catch(e) { | |
optionError(args.u + " is not a valid url: " + e.toString()); | |
} | |
} | |
exports.startFunc = function(cfg, cb) { | |
client.post(cfg, '/wsapi/interaction_data', {}, blob(), function(err, r) { | |
if (err) { | |
cb(err); | |
} else if (!r || r.code !== 200) { | |
cb("for interaction_data post response code is not 200: " + (r ? r.code : "no response")); | |
} else if (r.body !== '{"success":true}' ){ | |
cb("interaction_data post not successful"); | |
} else { | |
cb(null, r); | |
} | |
}); | |
}; | |
if (require.main === module) { | |
processOptions(); | |
console.log('Posting to', args.u); | |
var cfg = { browserid: args.u }; | |
exports.startFunc(cfg, function (err, r) { | |
if (err) return console.log('error: ', err); | |
console.log('Blob was posted ok to /wsapi/interaction_data'); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment