2013-12-16 19:00:21 +01:00
|
|
|
(function (root, factory) {
|
2018-01-04 12:41:03 +01:00
|
|
|
define(["jquery", "jasmine", "mock", "converse-core", "test-utils"], factory);
|
2017-07-11 10:41:11 +02:00
|
|
|
} (this, function ($, jasmine, mock, converse, test_utils) {
|
2016-12-20 10:30:20 +01:00
|
|
|
var Strophe = converse.env.Strophe;
|
|
|
|
var b64_sha1 = converse.env.b64_sha1;
|
2018-02-08 17:06:53 +01:00
|
|
|
var $pres = converse.env.$pres;
|
|
|
|
var _ = converse.env._;
|
2015-02-01 16:15:34 +01:00
|
|
|
|
2018-02-07 13:12:43 +01:00
|
|
|
describe("A chatbox with an active OTR session", function() {
|
|
|
|
|
|
|
|
it("will not show the spoiler toolbar button",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
|
|
|
test_utils.createContacts(_converse, 'current');
|
|
|
|
var contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
|
2018-02-08 17:06:53 +01:00
|
|
|
|
|
|
|
// XXX: We need to send a presence from the contact, so that we
|
|
|
|
// have a resource, that resource is then queried to see
|
|
|
|
// whether Strophe.NS.SPOILER is supported, in which case
|
|
|
|
// the spoiler button will appear.
|
|
|
|
var presence = $pres({
|
|
|
|
'from': contact_jid+'/phone',
|
|
|
|
'to': 'dummy@localhost'
|
|
|
|
});
|
|
|
|
_converse.connection._dataRecv(test_utils.createRequest(presence));
|
2018-02-07 13:12:43 +01:00
|
|
|
test_utils.openChatBoxFor(_converse, contact_jid);
|
|
|
|
|
2018-02-08 17:06:53 +01:00
|
|
|
test_utils.waitUntilDiscoConfirmed(_converse, contact_jid+'/phone', [], [Strophe.NS.SPOILER]).then(function () {
|
|
|
|
var spoiler_toggle;
|
|
|
|
var view = _converse.chatboxviews.get(contact_jid);
|
|
|
|
spyOn(view, 'addSpoilerButton').and.callThrough();
|
|
|
|
view.model.set('otr_status', 1);
|
|
|
|
|
|
|
|
test_utils.waitUntil(function () {
|
|
|
|
return _.isNull(view.el.querySelector('.toggle-compose-spoiler'));
|
|
|
|
}).then(function () {
|
|
|
|
spoiler_toggle = view.el.querySelector('.toggle-compose-spoiler');
|
|
|
|
expect(spoiler_toggle).toBe(null);
|
2018-02-07 13:12:43 +01:00
|
|
|
|
2018-02-08 17:06:53 +01:00
|
|
|
view.model.set('otr_status', 3);
|
2018-02-07 13:12:43 +01:00
|
|
|
|
2018-02-08 17:06:53 +01:00
|
|
|
return test_utils.waitUntil(function () {
|
|
|
|
return !_.isNull(view.el.querySelector('.toggle-compose-spoiler'));
|
|
|
|
});
|
|
|
|
}).then(function () {
|
|
|
|
spoiler_toggle = view.el.querySelector('.toggle-compose-spoiler');
|
|
|
|
expect(spoiler_toggle).not.toBe(null);
|
2018-02-07 13:12:43 +01:00
|
|
|
|
2018-02-08 17:06:53 +01:00
|
|
|
view.model.set('otr_status', 2);
|
|
|
|
return test_utils.waitUntil(function () {
|
|
|
|
return _.isNull(view.el.querySelector('.toggle-compose-spoiler'));
|
|
|
|
});
|
|
|
|
}).then(function () {
|
|
|
|
spoiler_toggle = view.el.querySelector('.toggle-compose-spoiler');
|
|
|
|
expect(spoiler_toggle).toBe(null);
|
2018-02-07 13:12:43 +01:00
|
|
|
|
2018-02-08 17:06:53 +01:00
|
|
|
view.model.set('otr_status', 4);
|
|
|
|
return test_utils.waitUntil(function () {
|
|
|
|
return !_.isNull(view.el.querySelector('.toggle-compose-spoiler'));
|
|
|
|
});
|
|
|
|
}).then(function () {
|
|
|
|
spoiler_toggle = view.el.querySelector('.toggle-compose-spoiler');
|
|
|
|
expect(spoiler_toggle).not.toBe(null);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2018-02-07 13:12:43 +01:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("The OTR module", function() {
|
2013-12-18 15:30:19 +01:00
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("will add processing hints to sent out encrypted <message> stanzas",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
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);
|
2018-04-16 14:22:27 +02:00
|
|
|
var stanza = chatview.model.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
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
2016-11-03 11:01:09 +01:00
|
|
|
}));
|
2016-05-30 18:20:23 +02:00
|
|
|
|
|
|
|
describe("An OTR Chat Message", function () {
|
|
|
|
|
2017-07-11 10:41:11 +02:00
|
|
|
it("will not be carbon copied when it's sent out",
|
|
|
|
mock.initConverseWithPromises(
|
|
|
|
null, ['rosterGroupsFetched'], {},
|
|
|
|
function (done, _converse) {
|
|
|
|
|
2016-11-03 11:01:09 +01:00
|
|
|
test_utils.openControlBox();
|
2016-12-20 10:30:20 +01:00
|
|
|
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
|
2018-04-16 14:22:27 +02:00
|
|
|
chatbox.sendMessage(new _converse.Message({'message': msgtext}));
|
2017-04-05 11:01:31 +02:00
|
|
|
var $sent = $(_converse.connection.send.calls.argsFor(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
|
2017-07-11 10:41:11 +02:00
|
|
|
done();
|
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
|
|
|
}));
|