2013-12-16 19:00:21 +01:00
|
|
|
(function (root, factory) {
|
2016-11-30 13:18:58 +01:00
|
|
|
define(["mock", "converse-api", "test_utils"], factory);
|
2016-12-20 10:30:20 +01:00
|
|
|
} (this, function (mock, converse, test_utils) {
|
|
|
|
var $ = converse.env.jQuery;
|
|
|
|
var Strophe = converse.env.Strophe;
|
|
|
|
var b64_sha1 = converse.env.b64_sha1;
|
2015-02-01 16:15:34 +01:00
|
|
|
|
2016-04-13 17:11:04 +02:00
|
|
|
return describe("The OTR module", function() {
|
2013-12-18 15:30:19 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("can store a session passphrase in session storage", mock.initConverse(function (_converse) {
|
2014-02-12 01:02:45 +01:00
|
|
|
// With no prebind, the user's XMPP password is used and nothing is
|
|
|
|
// stored in session storage.
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
var auth = _converse.authentication;
|
|
|
|
var pass = _converse.connection.pass;
|
|
|
|
_converse.authentication = "manual";
|
|
|
|
_converse.connection.pass = 's3cr3t!';
|
|
|
|
expect(_converse.otr.getSessionPassphrase()).toBe(_converse.connection.pass);
|
2014-02-12 01:02:45 +01:00
|
|
|
|
|
|
|
// With prebind, a random passphrase is generated and stored in
|
|
|
|
// session storage.
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.authentication = "prebind";
|
|
|
|
var pp = _converse.otr.getSessionPassphrase();
|
|
|
|
expect(pp).not.toBe(_converse.connection.pass);
|
|
|
|
expect(pp).toBe(window.sessionStorage[b64_sha1(_converse.connection.jid)]);
|
2014-02-12 01:02:45 +01:00
|
|
|
|
|
|
|
// Clean up
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.authentication = auth;
|
|
|
|
_converse.connection.pass = pass;
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("will add processing hints to sent out encrypted <message> stanzas", mock.initConverse(function (_converse) {
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-05-30 18:20:23 +02:00
|
|
|
|
|
|
|
var UNVERIFIED = 1, UNENCRYPTED = 0;
|
|
|
|
var contact_name = mock.cur_names[0];
|
|
|
|
var contact_jid = contact_name.replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
var chatview = _converse.chatboxviews.get(contact_jid);
|
2016-05-30 18:20:23 +02:00
|
|
|
chatview.model.set('otr_status', UNVERIFIED);
|
2016-12-20 10:30:20 +01:00
|
|
|
var stanza = chatview.createMessageStanza(new _converse.Message({ message: 'hello world'}));
|
2016-05-30 18:20:23 +02:00
|
|
|
var $hints = $(stanza.nodeTree).find('[xmlns="'+Strophe.NS.HINTS+'"]');
|
|
|
|
expect($hints.length).toBe(3);
|
|
|
|
expect($hints.get(0).tagName).toBe('no-store');
|
|
|
|
expect($hints.get(1).tagName).toBe('no-permanent-store');
|
|
|
|
expect($hints.get(2).tagName).toBe('no-copy');
|
|
|
|
chatview.model.set('otr_status', UNENCRYPTED); // Reset again to UNENCRYPTED
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2016-05-30 18:20:23 +02:00
|
|
|
|
|
|
|
describe("An OTR Chat Message", function () {
|
|
|
|
|
2016-12-20 10:30:20 +01:00
|
|
|
it("will not be carbon copied when it's sent out", mock.initConverse(function (_converse) {
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
test_utils.openContactsPanel(_converse);
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
2016-11-03 11:01:09 +01:00
|
|
|
|
2016-05-30 18:20:23 +02:00
|
|
|
var msgtext = "?OTR,1,3,?OTR:AAIDAAAAAAEAAAABAAAAwCQ8HKsag0y0DGKsneo0kzKu1ua5L93M4UKTkCf1I2kbm2RgS5kIxDTxrTj3wVRB+H5Si86E1fKtuBgsDf/bKkGTM0h/49vh5lOD9HkE8cnSrFEn5GN,";
|
|
|
|
var sender_jid = mock.cur_names[3].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2016-12-20 10:30:20 +01:00
|
|
|
_converse.api.chats.open(sender_jid);
|
|
|
|
var chatbox = _converse.chatboxes.get(sender_jid);
|
|
|
|
spyOn(_converse.connection, 'send');
|
2016-05-30 18:20:23 +02:00
|
|
|
chatbox.set('otr_status', 1); // Set OTR status to UNVERIFIED, to mock an encrypted session
|
2016-12-20 10:30:20 +01:00
|
|
|
chatbox.trigger('sendMessage', new _converse.Message({ message: msgtext }));
|
|
|
|
var $sent = $(_converse.connection.send.argsForCall[0][0].tree());
|
2016-05-30 18:20:23 +02:00
|
|
|
expect($sent.find('body').siblings('private').length).toBe(1);
|
|
|
|
expect($sent.find('private').length).toBe(1);
|
|
|
|
expect($sent.find('private').attr('xmlns')).toBe('urn:xmpp:carbons:2');
|
|
|
|
chatbox.set('otr_status', 0); // Reset again to UNENCRYPTED
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2016-05-30 18:20:23 +02:00
|
|
|
});
|
2016-04-13 17:11:04 +02:00
|
|
|
});
|
2013-12-16 19:00:21 +01:00
|
|
|
}));
|