Use async/await instead of promise callbacks

This commit is contained in:
JC Brand 2018-10-15 23:18:06 +02:00
parent e181aaf99b
commit 439d13d311

View File

@ -37,10 +37,9 @@
).pop(); ).pop();
} }
function initializedOMEMO (_converse) { async function initializedOMEMO (_converse) {
return test_utils.waitUntil(() => deviceListFetched(_converse, _converse.bare_jid)) let iq_stanza = await test_utils.waitUntil(() => deviceListFetched(_converse, _converse.bare_jid));
.then(iq_stanza => { let stanza = $iq({
const stanza = $iq({
'from': _converse.bare_jid, 'from': _converse.bare_jid,
'id': iq_stanza.nodeTree.getAttribute('id'), 'id': iq_stanza.nodeTree.getAttribute('id'),
'to': _converse.bare_jid, 'to': _converse.bare_jid,
@ -51,24 +50,23 @@
.c('list', {'xmlns': "eu.siacs.conversations.axolotl"}) .c('list', {'xmlns': "eu.siacs.conversations.axolotl"})
.c('device', {'id': '482886413b977930064a5888b92134fe'}); .c('device', {'id': '482886413b977930064a5888b92134fe'});
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
return test_utils.waitUntil(() => ownDeviceHasBeenPublished(_converse)) iq_stanza = await test_utils.waitUntil(() => ownDeviceHasBeenPublished(_converse))
}).then(iq_stanza => {
const stanza = $iq({ stanza = $iq({
'from': _converse.bare_jid, 'from': _converse.bare_jid,
'id': iq_stanza.nodeTree.getAttribute('id'), 'id': iq_stanza.nodeTree.getAttribute('id'),
'to': _converse.bare_jid, 'to': _converse.bare_jid,
'type': 'result'}); 'type': 'result'});
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
return test_utils.waitUntil(() => bundleHasBeenPublished(_converse)) iq_stanza = await test_utils.waitUntil(() => bundleHasBeenPublished(_converse))
}).then(iq_stanza => {
const stanza = $iq({ stanza = $iq({
'from': _converse.bare_jid, 'from': _converse.bare_jid,
'id': iq_stanza.nodeTree.getAttribute('id'), 'id': iq_stanza.nodeTree.getAttribute('id'),
'to': _converse.bare_jid, 'to': _converse.bare_jid,
'type': 'result'}); 'type': 'result'});
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
return _converse.api.waitUntil('OMEMOInitialized'); await _converse.api.waitUntil('OMEMOInitialized');
});
} }
@ -77,41 +75,33 @@
it("adds methods for encrypting and decrypting messages via AES GCM", it("adds methods for encrypting and decrypting messages via AES GCM",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
function (done, _converse) { async function (done, _converse) {
const message = 'This message will be encrypted' const message = 'This message will be encrypted'
let view;
test_utils.createContacts(_converse, 'current', 1); test_utils.createContacts(_converse, 'current', 1);
_converse.emit('rosterContactsFetched'); _converse.emit('rosterContactsFetched');
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
test_utils.openChatBoxFor(_converse, contact_jid) const view = await test_utils.openChatBoxFor(_converse, contact_jid);
.then((v) => { const payload = await view.model.encryptMessage(message);
view = v; const result = await view.model.decryptMessage(payload);
return view.model.encryptMessage(message);
}).then(payload => {
return view.model.decryptMessage(payload);
}).then(result => {
expect(result).toBe(message); expect(result).toBe(message);
done(); done();
});
})); }));
it("enables encrypted messages to be sent and received", it("enables encrypted messages to be sent and received",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
function (done, _converse) { async function (done, _converse) {
let view, sent_stanza; let sent_stanza;
test_utils.createContacts(_converse, 'current', 1); test_utils.createContacts(_converse, 'current', 1);
_converse.emit('rosterContactsFetched'); _converse.emit('rosterContactsFetched');
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
await test_utils.waitUntil(() => initializedOMEMO(_converse));
return test_utils.waitUntil(() => initializedOMEMO(_converse)) await test_utils.openChatBoxFor(_converse, contact_jid);
.then(() => test_utils.openChatBoxFor(_converse, contact_jid)) let iq_stanza = await test_utils.waitUntil(() => deviceListFetched(_converse, contact_jid));
.then(() => test_utils.waitUntil(() => deviceListFetched(_converse, contact_jid))) let stanza = $iq({
.then(iq_stanza => {
const stanza = $iq({
'from': contact_jid, 'from': contact_jid,
'id': iq_stanza.nodeTree.getAttribute('id'), 'id': iq_stanza.nodeTree.getAttribute('id'),
'to': _converse.connection.jid, 'to': _converse.connection.jid,
@ -122,12 +112,11 @@
.c('list', {'xmlns': "eu.siacs.conversations.axolotl"}) .c('list', {'xmlns': "eu.siacs.conversations.axolotl"})
.c('device', {'id': '555'}); .c('device', {'id': '555'});
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
return test_utils.waitUntil(() => _converse.omemo_store); await test_utils.waitUntil(() => _converse.omemo_store);
}).then(() => {
const devicelist = _converse.devicelists.get({'jid': contact_jid}); const devicelist = _converse.devicelists.get({'jid': contact_jid});
expect(devicelist.devices.length).toBe(1); expect(devicelist.devices.length).toBe(1);
view = _converse.chatboxviews.get(contact_jid); const view = _converse.chatboxviews.get(contact_jid);
view.model.set('omemo_active', true); view.model.set('omemo_active', true);
const textarea = view.el.querySelector('.chat-textarea'); const textarea = view.el.querySelector('.chat-textarea');
@ -137,9 +126,8 @@
preventDefault: _.noop, preventDefault: _.noop,
keyCode: 13 // Enter keyCode: 13 // Enter
}); });
return test_utils.waitUntil(() => bundleFetched(_converse, contact_jid, '555')); iq_stanza = await test_utils.waitUntil(() => bundleFetched(_converse, contact_jid, '555'));
}).then(iq_stanza => { stanza = $iq({
const stanza = $iq({
'from': contact_jid, 'from': contact_jid,
'id': iq_stanza.nodeTree.getAttribute('id'), 'id': iq_stanza.nodeTree.getAttribute('id'),
'to': _converse.bare_jid, 'to': _converse.bare_jid,
@ -157,10 +145,8 @@
.c('preKeyPublic', {'preKeyId': '2'}).t(btoa('1002')).up() .c('preKeyPublic', {'preKeyId': '2'}).t(btoa('1002')).up()
.c('preKeyPublic', {'preKeyId': '3'}).t(btoa('1003')); .c('preKeyPublic', {'preKeyId': '3'}).t(btoa('1003'));
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
iq_stanza = await test_utils.waitUntil(() => bundleFetched(_converse, _converse.bare_jid, '482886413b977930064a5888b92134fe'));
return test_utils.waitUntil(() => bundleFetched(_converse, _converse.bare_jid, '482886413b977930064a5888b92134fe')); stanza = $iq({
}).then(iq_stanza => {
const stanza = $iq({
'from': _converse.bare_jid, 'from': _converse.bare_jid,
'id': iq_stanza.nodeTree.getAttribute('id'), 'id': iq_stanza.nodeTree.getAttribute('id'),
'to': _converse.bare_jid, 'to': _converse.bare_jid,
@ -180,8 +166,7 @@
spyOn(_converse.connection, 'send').and.callFake(stanza => { sent_stanza = stanza }); spyOn(_converse.connection, 'send').and.callFake(stanza => { sent_stanza = stanza });
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
return test_utils.waitUntil(() => sent_stanza); await test_utils.waitUntil(() => sent_stanza);
}).then(() => {
expect(sent_stanza.toLocaleString()).toBe( expect(sent_stanza.toLocaleString()).toBe(
`<message from="dummy@localhost/resource" id="${sent_stanza.nodeTree.getAttribute("id")}" `+ `<message from="dummy@localhost/resource" id="${sent_stanza.nodeTree.getAttribute("id")}" `+
`to="max.frankfurter@localhost" `+ `to="max.frankfurter@localhost" `+
@ -197,17 +182,12 @@
`</encrypted>`+ `</encrypted>`+
`<store xmlns="urn:xmpp:hints"/>`+ `<store xmlns="urn:xmpp:hints"/>`+
`</message>`); `</message>`);
// Test reception of an encrypted message // Test reception of an encrypted message
return view.model.encryptMessage('This is an encrypted message from the contact') const obj = await view.model.encryptMessage('This is an encrypted message from the contact')
}).then(obj => {
// XXX: Normally the key will be encrypted via libsignal. // XXX: Normally the key will be encrypted via libsignal.
// However, we're mocking libsignal in the tests, so we include // However, we're mocking libsignal in the tests, so we include
// it as plaintext in the message. // it as plaintext in the message.
stanza = $msg({
// u.stringToArrayBuffer(atob(u.arrayBufferToBase64(obj.key_and_tag)));
// u.stringToArrayBuffer(u.arrayBufferToString(obj.key_and_tag));
const stanza = $msg({
'from': contact_jid, 'from': contact_jid,
'to': _converse.connection.jid, 'to': _converse.connection.jid,
'type': 'chat', 'type': 'chat',
@ -220,21 +200,19 @@
.up().up() .up().up()
.c('payload').t(obj.payload); .c('payload').t(obj.payload);
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
return test_utils.waitUntil(() => view.model.messages.length > 1); await test_utils.waitUntil(() => view.model.messages.length > 1);
}).then(() => {
expect(view.model.messages.length).toBe(2); expect(view.model.messages.length).toBe(2);
const last_msg = view.model.messages.at(1); const last_msg = view.model.messages.at(1);
expect(view.el.querySelectorAll('.chat-msg__body')[1].textContent.trim()) expect(view.el.querySelectorAll('.chat-msg__body')[1].textContent.trim())
.toBe('This is an encrypted message from the contact'); .toBe('This is an encrypted message from the contact');
done(); done();
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL))
})); }));
it("can receive a PreKeySignalMessage", it("can receive a PreKeySignalMessage",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
function (done, _converse) { async function (done, _converse) {
_converse.NUM_PREKEYS = 5; // Restrict to 5, otherwise the resulting stanza is too large to easily test _converse.NUM_PREKEYS = 5; // Restrict to 5, otherwise the resulting stanza is too large to easily test
let view, sent_stanza; let view, sent_stanza;
@ -242,13 +220,12 @@
_converse.emit('rosterContactsFetched'); _converse.emit('rosterContactsFetched');
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
return test_utils.waitUntil(() => initializedOMEMO(_converse)) await test_utils.waitUntil(() => initializedOMEMO(_converse));
.then(() => _converse.ChatBox.prototype.encryptMessage('This is an encrypted message from the contact')) const obj = await _converse.ChatBox.prototype.encryptMessage('This is an encrypted message from the contact');
.then(obj => {
// XXX: Normally the key will be encrypted via libsignal. // XXX: Normally the key will be encrypted via libsignal.
// However, we're mocking libsignal in the tests, so we include // However, we're mocking libsignal in the tests, so we include
// it as plaintext in the message. // it as plaintext in the message.
const stanza = $msg({ let stanza = $msg({
'from': contact_jid, 'from': contact_jid,
'to': _converse.connection.jid, 'to': _converse.connection.jid,
'type': 'chat', 'type': 'chat',
@ -274,10 +251,9 @@
return generateMissingPreKeys.apply(_converse.omemo_store, arguments); return generateMissingPreKeys.apply(_converse.omemo_store, arguments);
}); });
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
return test_utils.waitUntil(() => _converse.chatboxviews.get(contact_jid)) let iq_stanza = await test_utils.waitUntil(() => _converse.chatboxviews.get(contact_jid));
}).then(iq_stanza => deviceListFetched(_converse, contact_jid)) iq_stanza = await deviceListFetched(_converse, contact_jid);
.then(iq_stanza => { stanza = $iq({
const stanza = $iq({
'from': contact_jid, 'from': contact_jid,
'id': iq_stanza.nodeTree.getAttribute('id'), 'id': iq_stanza.nodeTree.getAttribute('id'),
'to': _converse.connection.jid, 'to': _converse.connection.jid,
@ -293,9 +269,8 @@
// stanzas. // stanzas.
_converse.connection.IQ_stanzas = []; _converse.connection.IQ_stanzas = [];
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
return test_utils.waitUntil(() => _converse.omemo_store); await test_utils.waitUntil(() => _converse.omemo_store);
}).then(() => test_utils.waitUntil(() => bundleHasBeenPublished(_converse))) iq_stanza = await test_utils.waitUntil(() => bundleHasBeenPublished(_converse));
.then(iq_stanza => {
expect(iq_stanza.toLocaleString()).toBe( expect(iq_stanza.toLocaleString()).toBe(
`<iq from="dummy@localhost" id="${iq_stanza.nodeTree.getAttribute("id")}" type="set" xmlns="jabber:client">`+ `<iq from="dummy@localhost" id="${iq_stanza.nodeTree.getAttribute("id")}" type="set" xmlns="jabber:client">`+
`<pubsub xmlns="http://jabber.org/protocol/pubsub">`+ `<pubsub xmlns="http://jabber.org/protocol/pubsub">`+
@ -321,21 +296,19 @@
expect(own_device.get('bundle').prekeys.length).toBe(5); expect(own_device.get('bundle').prekeys.length).toBe(5);
expect(_converse.omemo_store.generateMissingPreKeys).toHaveBeenCalled(); expect(_converse.omemo_store.generateMissingPreKeys).toHaveBeenCalled();
done(); done();
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL))
})); }));
it("updates device lists based on PEP messages", it("updates device lists based on PEP messages",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {'allow_non_roster_messaging': true}, null, ['rosterGroupsFetched'], {'allow_non_roster_messaging': true},
function (done, _converse) { async function (done, _converse) {
test_utils.createContacts(_converse, 'current', 1); test_utils.createContacts(_converse, 'current', 1);
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
// Wait until own devices are fetched // Wait until own devices are fetched
test_utils.waitUntil(() => deviceListFetched(_converse, _converse.bare_jid)) let iq_stanza = await test_utils.waitUntil(() => deviceListFetched(_converse, _converse.bare_jid));
.then(iq_stanza => {
expect(iq_stanza.toLocaleString()).toBe( expect(iq_stanza.toLocaleString()).toBe(
`<iq from="dummy@localhost" id="${iq_stanza.nodeTree.getAttribute("id")}" to="dummy@localhost" type="get" xmlns="jabber:client">`+ `<iq from="dummy@localhost" id="${iq_stanza.nodeTree.getAttribute("id")}" to="dummy@localhost" type="get" xmlns="jabber:client">`+
`<pubsub xmlns="http://jabber.org/protocol/pubsub">`+ `<pubsub xmlns="http://jabber.org/protocol/pubsub">`+
@ -343,7 +316,7 @@
`</pubsub>`+ `</pubsub>`+
`</iq>`); `</iq>`);
const stanza = $iq({ let stanza = $iq({
'from': _converse.bare_jid, 'from': _converse.bare_jid,
'id': iq_stanza.nodeTree.getAttribute('id'), 'id': iq_stanza.nodeTree.getAttribute('id'),
'to': _converse.bare_jid, 'to': _converse.bare_jid,
@ -354,33 +327,31 @@
.c('list', {'xmlns': "eu.siacs.conversations.axolotl"}) .c('list', {'xmlns': "eu.siacs.conversations.axolotl"})
.c('device', {'id': '555'}); .c('device', {'id': '555'});
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
return test_utils.waitUntil(() => _converse.omemo_store); await test_utils.waitUntil(() => _converse.omemo_store);
}).then(() => {
expect(_converse.chatboxes.length).toBe(1); expect(_converse.chatboxes.length).toBe(1);
expect(_converse.devicelists.length).toBe(1); expect(_converse.devicelists.length).toBe(1);
const devicelist = _converse.devicelists.get(_converse.bare_jid); const devicelist = _converse.devicelists.get(_converse.bare_jid);
expect(devicelist.devices.length).toBe(2); expect(devicelist.devices.length).toBe(2);
expect(devicelist.devices.at(0).get('id')).toBe('555'); expect(devicelist.devices.at(0).get('id')).toBe('555');
expect(devicelist.devices.at(1).get('id')).toBe('123456789'); expect(devicelist.devices.at(1).get('id')).toBe('123456789');
return test_utils.waitUntil(() => ownDeviceHasBeenPublished(_converse)); iq_stanza = await test_utils.waitUntil(() => ownDeviceHasBeenPublished(_converse));
}).then(iq_stanza => { stanza = $iq({
const stanza = $iq({
'from': _converse.bare_jid, 'from': _converse.bare_jid,
'id': iq_stanza.nodeTree.getAttribute('id'), 'id': iq_stanza.nodeTree.getAttribute('id'),
'to': _converse.bare_jid, 'to': _converse.bare_jid,
'type': 'result'}); 'type': 'result'});
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
return test_utils.waitUntil(() => bundleHasBeenPublished(_converse)); iq_stanza = await test_utils.waitUntil(() => bundleHasBeenPublished(_converse));
}).then(iq_stanza => {
const stanza = $iq({ stanza = $iq({
'from': _converse.bare_jid, 'from': _converse.bare_jid,
'id': iq_stanza.nodeTree.getAttribute('id'), 'id': iq_stanza.nodeTree.getAttribute('id'),
'to': _converse.bare_jid, 'to': _converse.bare_jid,
'type': 'result'}); 'type': 'result'});
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
return _converse.api.waitUntil('OMEMOInitialized'); await _converse.api.waitUntil('OMEMOInitialized');
}).then(() => {
let stanza = $msg({ stanza = $msg({
'from': contact_jid, 'from': contact_jid,
'to': _converse.bare_jid, 'to': _converse.bare_jid,
'type': 'headline', 'type': 'headline',
@ -450,8 +421,7 @@
.c('device', {'id': '444'}) .c('device', {'id': '444'})
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
return test_utils.waitUntil(() => ownDeviceHasBeenPublished(_converse)); iq_stanza = await test_utils.waitUntil(() => ownDeviceHasBeenPublished(_converse));
}).then(iq_stanza => {
// Check that our own device is added again, but that removed // Check that our own device is added again, but that removed
// devices are not added. // devices are not added.
expect(iq_stanza.toLocaleString()).toBe( expect(iq_stanza.toLocaleString()).toBe(
@ -468,26 +438,23 @@
`</pubsub>`+ `</pubsub>`+
`</iq>`); `</iq>`);
expect(_converse.devicelists.length).toBe(2); expect(_converse.devicelists.length).toBe(2);
const devices = _converse.devicelists.get(_converse.bare_jid).devices; devices = _converse.devicelists.get(_converse.bare_jid).devices;
// The device id for this device (123456789) was also generated and added to the list, // The device id for this device (123456789) was also generated and added to the list,
// which is why we have 2 devices now. // which is why we have 2 devices now.
expect(devices.length).toBe(2); expect(devices.length).toBe(2);
expect(_.map(devices.models, 'attributes.id').sort().join()).toBe('123456789,444'); expect(_.map(devices.models, 'attributes.id').sort().join()).toBe('123456789,444');
done(); done();
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL))
})); }));
it("updates device bundles based on PEP messages", it("updates device bundles based on PEP messages",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { async function (done, _converse) {
test_utils.createContacts(_converse, 'current'); test_utils.createContacts(_converse, 'current');
const contact_jid = mock.cur_names[3].replace(/ /g,'.').toLowerCase() + '@localhost'; const contact_jid = mock.cur_names[3].replace(/ /g,'.').toLowerCase() + '@localhost';
let iq_stanza = await test_utils.waitUntil(() => deviceListFetched(_converse, _converse.bare_jid));
test_utils.waitUntil(() => deviceListFetched(_converse, _converse.bare_jid))
.then(iq_stanza => {
expect(iq_stanza.toLocaleString()).toBe( expect(iq_stanza.toLocaleString()).toBe(
`<iq from="dummy@localhost" id="${iq_stanza.nodeTree.getAttribute("id")}" to="dummy@localhost" type="get" xmlns="jabber:client">`+ `<iq from="dummy@localhost" id="${iq_stanza.nodeTree.getAttribute("id")}" to="dummy@localhost" type="get" xmlns="jabber:client">`+
`<pubsub xmlns="http://jabber.org/protocol/pubsub">`+ `<pubsub xmlns="http://jabber.org/protocol/pubsub">`+
@ -495,7 +462,7 @@
`</pubsub>`+ `</pubsub>`+
`</iq>`); `</iq>`);
const stanza = $iq({ let stanza = $iq({
'from': contact_jid, 'from': contact_jid,
'id': iq_stanza.nodeTree.getAttribute('id'), 'id': iq_stanza.nodeTree.getAttribute('id'),
'to': _converse.bare_jid, 'to': _converse.bare_jid,
@ -506,32 +473,28 @@
.c('list', {'xmlns': "eu.siacs.conversations.axolotl"}) .c('list', {'xmlns': "eu.siacs.conversations.axolotl"})
.c('device', {'id': '555'}); .c('device', {'id': '555'});
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
return test_utils.waitUntil(() => _converse.omemo_store); await await test_utils.waitUntil(() => _converse.omemo_store);
}).then(() => {
expect(_converse.devicelists.length).toBe(1); expect(_converse.devicelists.length).toBe(1);
const devicelist = _converse.devicelists.get(_converse.bare_jid); let devicelist = _converse.devicelists.get(_converse.bare_jid);
expect(devicelist.devices.length).toBe(2); expect(devicelist.devices.length).toBe(2);
expect(devicelist.devices.at(0).get('id')).toBe('555'); expect(devicelist.devices.at(0).get('id')).toBe('555');
expect(devicelist.devices.at(1).get('id')).toBe('123456789'); expect(devicelist.devices.at(1).get('id')).toBe('123456789');
return test_utils.waitUntil(() => ownDeviceHasBeenPublished(_converse)); iq_stanza = await test_utils.waitUntil(() => ownDeviceHasBeenPublished(_converse));
}).then(iq_stanza => { stanza = $iq({
const stanza = $iq({
'from': _converse.bare_jid, 'from': _converse.bare_jid,
'id': iq_stanza.nodeTree.getAttribute('id'), 'id': iq_stanza.nodeTree.getAttribute('id'),
'to': _converse.bare_jid, 'to': _converse.bare_jid,
'type': 'result'}); 'type': 'result'});
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
return test_utils.waitUntil(() => bundleHasBeenPublished(_converse)); iq_stanza = await test_utils.waitUntil(() => bundleHasBeenPublished(_converse));
}).then(iq_stanza => { stanza = $iq({
const stanza = $iq({
'from': _converse.bare_jid, 'from': _converse.bare_jid,
'id': iq_stanza.nodeTree.getAttribute('id'), 'id': iq_stanza.nodeTree.getAttribute('id'),
'to': _converse.bare_jid, 'to': _converse.bare_jid,
'type': 'result'}); 'type': 'result'});
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
return _converse.api.waitUntil('OMEMOInitialized'); await _converse.api.waitUntil('OMEMOInitialized');
}).then(() => { stanza = $msg({
let stanza = $msg({
'from': contact_jid, 'from': contact_jid,
'to': _converse.bare_jid, 'to': _converse.bare_jid,
'type': 'headline', 'type': 'headline',
@ -550,7 +513,7 @@
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
expect(_converse.devicelists.length).toBe(2); expect(_converse.devicelists.length).toBe(2);
let devicelist = _converse.devicelists.get(contact_jid); devicelist = _converse.devicelists.get(contact_jid);
expect(devicelist.devices.length).toBe(1); expect(devicelist.devices.length).toBe(1);
let device = devicelist.devices.at(0); let device = devicelist.devices.at(0);
expect(device.get('bundle').identity_key).toBe('3333'); expect(device.get('bundle').identity_key).toBe('3333');
@ -626,23 +589,20 @@
expect(device.get('bundle').prekeys[1].id).toBe(3002); expect(device.get('bundle').prekeys[1].id).toBe(3002);
expect(device.get('bundle').prekeys[2].id).toBe(3003); expect(device.get('bundle').prekeys[2].id).toBe(3003);
done(); done();
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL))
})); }));
it("publishes a bundle with which an encrypted session can be created", it("publishes a bundle with which an encrypted session can be created",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
function (done, _converse) { async function (done, _converse) {
_converse.NUM_PREKEYS = 2; // Restrict to 2, otherwise the resulting stanza is too large to easily test _converse.NUM_PREKEYS = 2; // Restrict to 2, otherwise the resulting stanza is too large to easily test
test_utils.createContacts(_converse, 'current', 1); test_utils.createContacts(_converse, 'current', 1);
_converse.emit('rosterContactsFetched'); _converse.emit('rosterContactsFetched');
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
let iq_stanza = await test_utils.waitUntil(() => deviceListFetched(_converse, _converse.bare_jid));
test_utils.waitUntil(() => deviceListFetched(_converse, _converse.bare_jid)) let stanza = $iq({
.then(iq_stanza => {
const stanza = $iq({
'from': contact_jid, 'from': contact_jid,
'id': iq_stanza.nodeTree.getAttribute('id'), 'id': iq_stanza.nodeTree.getAttribute('id'),
'to': _converse.bare_jid, 'to': _converse.bare_jid,
@ -654,19 +614,16 @@
.c('device', {'id': '482886413b977930064a5888b92134fe'}); .c('device', {'id': '482886413b977930064a5888b92134fe'});
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
expect(_converse.devicelists.length).toBe(1); expect(_converse.devicelists.length).toBe(1);
return test_utils.openChatBoxFor(_converse, contact_jid); await test_utils.openChatBoxFor(_converse, contact_jid);
iq_stanza = await ownDeviceHasBeenPublished(_converse);
}).then(() => ownDeviceHasBeenPublished(_converse)) stanza = $iq({
.then(iq_stanza => {
const stanza = $iq({
'from': _converse.bare_jid, 'from': _converse.bare_jid,
'id': iq_stanza.nodeTree.getAttribute('id'), 'id': iq_stanza.nodeTree.getAttribute('id'),
'to': _converse.bare_jid, 'to': _converse.bare_jid,
'type': 'result'}); 'type': 'result'});
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
return test_utils.waitUntil(() => bundleHasBeenPublished(_converse)); iq_stanza = await test_utils.waitUntil(() => bundleHasBeenPublished(_converse));
}).then(iq_stanza => {
expect(iq_stanza.toLocaleString()).toBe( expect(iq_stanza.toLocaleString()).toBe(
`<iq from="dummy@localhost" id="${iq_stanza.nodeTree.getAttribute("id")}" type="set" xmlns="jabber:client">`+ `<iq from="dummy@localhost" id="${iq_stanza.nodeTree.getAttribute("id")}" type="set" xmlns="jabber:client">`+
`<pubsub xmlns="http://jabber.org/protocol/pubsub">`+ `<pubsub xmlns="http://jabber.org/protocol/pubsub">`+
@ -686,29 +643,27 @@
`</pubsub>`+ `</pubsub>`+
`</iq>`) `</iq>`)
const stanza = $iq({ stanza = $iq({
'from': _converse.bare_jid, 'from': _converse.bare_jid,
'id': iq_stanza.nodeTree.getAttribute('id'), 'id': iq_stanza.nodeTree.getAttribute('id'),
'to': _converse.bare_jid, 'to': _converse.bare_jid,
'type': 'result'}); 'type': 'result'});
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
return _converse.api.waitUntil('OMEMOInitialized'); await _converse.api.waitUntil('OMEMOInitialized');
}).then(done).catch(_.partial(console.error, _)); done();
})); }));
it("adds a toolbar button for starting an encrypted chat session", it("adds a toolbar button for starting an encrypted chat session",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
function (done, _converse) { async function (done, _converse) {
let modal;
test_utils.createContacts(_converse, 'current', 1); test_utils.createContacts(_converse, 'current', 1);
_converse.emit('rosterContactsFetched'); _converse.emit('rosterContactsFetched');
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
test_utils.waitUntil(() => deviceListFetched(_converse, _converse.bare_jid)) let iq_stanza = await test_utils.waitUntil(() => deviceListFetched(_converse, _converse.bare_jid));
.then(iq_stanza => {
expect(iq_stanza.toLocaleString()).toBe( expect(iq_stanza.toLocaleString()).toBe(
`<iq from="dummy@localhost" id="${iq_stanza.nodeTree.getAttribute("id")}" to="dummy@localhost" type="get" xmlns="jabber:client">`+ `<iq from="dummy@localhost" id="${iq_stanza.nodeTree.getAttribute("id")}" to="dummy@localhost" type="get" xmlns="jabber:client">`+
`<pubsub xmlns="http://jabber.org/protocol/pubsub">`+ `<pubsub xmlns="http://jabber.org/protocol/pubsub">`+
@ -716,7 +671,7 @@
`</pubsub>`+ `</pubsub>`+
`</iq>`); `</iq>`);
const stanza = $iq({ let stanza = $iq({
'from': _converse.bare_jid, 'from': _converse.bare_jid,
'id': iq_stanza.nodeTree.getAttribute('id'), 'id': iq_stanza.nodeTree.getAttribute('id'),
'to': _converse.bare_jid, 'to': _converse.bare_jid,
@ -727,16 +682,14 @@
.c('list', {'xmlns': "eu.siacs.conversations.axolotl"}) .c('list', {'xmlns': "eu.siacs.conversations.axolotl"})
.c('device', {'id': '482886413b977930064a5888b92134fe'}); .c('device', {'id': '482886413b977930064a5888b92134fe'});
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
return test_utils.waitUntil(() => _converse.omemo_store); await test_utils.waitUntil(() => _converse.omemo_store);
}).then(() => {
expect(_converse.devicelists.length).toBe(1); expect(_converse.devicelists.length).toBe(1);
const devicelist = _converse.devicelists.get(_converse.bare_jid); let devicelist = _converse.devicelists.get(_converse.bare_jid);
expect(devicelist.devices.length).toBe(2); expect(devicelist.devices.length).toBe(2);
expect(devicelist.devices.at(0).get('id')).toBe('482886413b977930064a5888b92134fe'); expect(devicelist.devices.at(0).get('id')).toBe('482886413b977930064a5888b92134fe');
expect(devicelist.devices.at(1).get('id')).toBe('123456789'); expect(devicelist.devices.at(1).get('id')).toBe('123456789');
// Check that own device was published // Check that own device was published
return test_utils.waitUntil(() => ownDeviceHasBeenPublished(_converse)); iq_stanza = await test_utils.waitUntil(() => ownDeviceHasBeenPublished(_converse));
}).then(iq_stanza => {
expect(iq_stanza.toLocaleString()).toBe( expect(iq_stanza.toLocaleString()).toBe(
`<iq from="dummy@localhost" id="${iq_stanza.nodeTree.getAttribute(`id`)}" type="set" xmlns="jabber:client">`+ `<iq from="dummy@localhost" id="${iq_stanza.nodeTree.getAttribute(`id`)}" type="set" xmlns="jabber:client">`+
`<pubsub xmlns="http://jabber.org/protocol/pubsub">`+ `<pubsub xmlns="http://jabber.org/protocol/pubsub">`+
@ -751,15 +704,14 @@
`</pubsub>`+ `</pubsub>`+
`</iq>`); `</iq>`);
const stanza = $iq({ stanza = $iq({
'from': _converse.bare_jid, 'from': _converse.bare_jid,
'id': iq_stanza.nodeTree.getAttribute('id'), 'id': iq_stanza.nodeTree.getAttribute('id'),
'to': _converse.bare_jid, 'to': _converse.bare_jid,
'type': 'result'}); 'type': 'result'});
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
return test_utils.waitUntil(() => _.get(bundleHasBeenPublished(_converse), 'nodeTree')); const iq_el = await test_utils.waitUntil(() => _.get(bundleHasBeenPublished(_converse), 'nodeTree'));
}).then(iq_el => {
expect(iq_el.getAttributeNames().sort().join()).toBe(["from", "type", "xmlns", "id"].sort().join()); expect(iq_el.getAttributeNames().sort().join()).toBe(["from", "type", "xmlns", "id"].sort().join());
expect(iq_el.querySelector('prekeys').childNodes.length).toBe(100); expect(iq_el.querySelector('prekeys').childNodes.length).toBe(100);
@ -770,18 +722,15 @@
expect(iq_el.querySelectorAll('signedPreKeySignature').length).toBe(1); expect(iq_el.querySelectorAll('signedPreKeySignature').length).toBe(1);
expect(iq_el.querySelectorAll('identityKey').length).toBe(1); expect(iq_el.querySelectorAll('identityKey').length).toBe(1);
const stanza = $iq({ stanza = $iq({
'from': _converse.bare_jid, 'from': _converse.bare_jid,
'id': iq_el.getAttribute('id'), 'id': iq_el.getAttribute('id'),
'to': _converse.bare_jid, 'to': _converse.bare_jid,
'type': 'result'}); 'type': 'result'});
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
return _converse.api.waitUntil('OMEMOInitialized', 1000); await _converse.api.waitUntil('OMEMOInitialized', 1000);
}).then(() => { await test_utils.openChatBoxFor(_converse, contact_jid);
return test_utils.openChatBoxFor(_converse, contact_jid); iq_stanza = await test_utils.waitUntil(() => deviceListFetched(_converse, contact_jid));
}).then(() => {
return test_utils.waitUntil(() => deviceListFetched(_converse, contact_jid));
}).then(iq_stanza => {
expect(iq_stanza.toLocaleString()).toBe( expect(iq_stanza.toLocaleString()).toBe(
`<iq from="dummy@localhost" id="${iq_stanza.nodeTree.getAttribute("id")}" to="${contact_jid}" type="get" xmlns="jabber:client">`+ `<iq from="dummy@localhost" id="${iq_stanza.nodeTree.getAttribute("id")}" to="${contact_jid}" type="get" xmlns="jabber:client">`+
`<pubsub xmlns="http://jabber.org/protocol/pubsub">`+ `<pubsub xmlns="http://jabber.org/protocol/pubsub">`+
@ -789,7 +738,7 @@
`</pubsub>`+ `</pubsub>`+
`</iq>`); `</iq>`);
const stanza = $iq({ stanza = $iq({
'from': contact_jid, 'from': contact_jid,
'id': iq_stanza.nodeTree.getAttribute('id'), 'id': iq_stanza.nodeTree.getAttribute('id'),
'to': _converse.bare_jid, 'to': _converse.bare_jid,
@ -803,22 +752,20 @@
.c('device', {'id': '4e30f35051b7b8b42abe083742187228'}).up() .c('device', {'id': '4e30f35051b7b8b42abe083742187228'}).up()
.c('device', {'id': 'ae890ac52d0df67ed7cfdf51b644e901'}); .c('device', {'id': 'ae890ac52d0df67ed7cfdf51b644e901'});
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
const devicelist = _converse.devicelists.get(contact_jid); devicelist = _converse.devicelists.get(contact_jid);
return test_utils.waitUntil(() => devicelist.devices.length); await test_utils.waitUntil(() => devicelist.devices.length);
}).then(() => {
expect(_converse.devicelists.length).toBe(2); expect(_converse.devicelists.length).toBe(2);
const devicelist = _converse.devicelists.get(contact_jid); devicelist = _converse.devicelists.get(contact_jid);
expect(devicelist.devices.length).toBe(4); expect(devicelist.devices.length).toBe(4);
expect(devicelist.devices.at(0).get('id')).toBe('368866411b877c30064a5f62b917cffe'); expect(devicelist.devices.at(0).get('id')).toBe('368866411b877c30064a5f62b917cffe');
expect(devicelist.devices.at(1).get('id')).toBe('3300659945416e274474e469a1f0154c'); expect(devicelist.devices.at(1).get('id')).toBe('3300659945416e274474e469a1f0154c');
expect(devicelist.devices.at(2).get('id')).toBe('4e30f35051b7b8b42abe083742187228'); expect(devicelist.devices.at(2).get('id')).toBe('4e30f35051b7b8b42abe083742187228');
expect(devicelist.devices.at(3).get('id')).toBe('ae890ac52d0df67ed7cfdf51b644e901'); expect(devicelist.devices.at(3).get('id')).toBe('ae890ac52d0df67ed7cfdf51b644e901');
return test_utils.waitUntil(() => _converse.chatboxviews.get(contact_jid).el.querySelector('.chat-toolbar')); await test_utils.waitUntil(() => _converse.chatboxviews.get(contact_jid).el.querySelector('.chat-toolbar'));
}).then(() => {
const view = _converse.chatboxviews.get(contact_jid); const view = _converse.chatboxviews.get(contact_jid);
const toolbar = view.el.querySelector('.chat-toolbar'); const toolbar = view.el.querySelector('.chat-toolbar');
expect(view.model.get('omemo_active')).toBe(undefined); expect(view.model.get('omemo_active')).toBe(undefined);
const toggle = toolbar.querySelector('.toggle-omemo'); let toggle = toolbar.querySelector('.toggle-omemo');
expect(_.isNull(toggle)).toBe(false); expect(_.isNull(toggle)).toBe(false);
expect(u.hasClass('fa-unlock', toggle)).toBe(true); expect(u.hasClass('fa-unlock', toggle)).toBe(true);
expect(u.hasClass('fa-lock', toggle)).toBe(false); expect(u.hasClass('fa-lock', toggle)).toBe(false);
@ -829,11 +776,8 @@
expect(view.toggleOMEMO).toHaveBeenCalled(); expect(view.toggleOMEMO).toHaveBeenCalled();
expect(view.model.get('omemo_active')).toBe(true); expect(view.model.get('omemo_active')).toBe(true);
return test_utils.waitUntil(() => u.hasClass('fa-lock', toolbar.querySelector('.toggle-omemo'))); await test_utils.waitUntil(() => u.hasClass('fa-lock', toolbar.querySelector('.toggle-omemo')));
}).then(() => { toggle = toolbar.querySelector('.toggle-omemo');
const view = _converse.chatboxviews.get(contact_jid);
const toolbar = view.el.querySelector('.chat-toolbar');
const toggle = toolbar.querySelector('.toggle-omemo');
expect(u.hasClass('fa-unlock', toggle)).toBe(false); expect(u.hasClass('fa-unlock', toggle)).toBe(false);
expect(u.hasClass('fa-lock', toggle)).toBe(true); expect(u.hasClass('fa-lock', toggle)).toBe(true);
@ -845,38 +789,32 @@
keyCode: 13 keyCode: 13
}); });
done(); done();
}).catch(_.partial(console.error, _));
})); }));
it("shows OMEMO device fingerprints in the user details modal", it("shows OMEMO device fingerprints in the user details modal",
mock.initConverseWithPromises( mock.initConverseWithPromises(
null, ['rosterGroupsFetched', 'chatBoxesFetched'], {}, null, ['rosterGroupsFetched', 'chatBoxesFetched'], {},
function (done, _converse) { async function (done, _converse) {
let modal;
test_utils.createContacts(_converse, 'current', 1); test_utils.createContacts(_converse, 'current', 1);
_converse.emit('rosterContactsFetched'); _converse.emit('rosterContactsFetched');
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost'; const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@localhost';
test_utils.openChatBoxFor(_converse, contact_jid) await test_utils.openChatBoxFor(_converse, contact_jid)
.then(() => {
// We simply emit, to avoid doing all the setup work // We simply emit, to avoid doing all the setup work
_converse.emit('OMEMOInitialized'); _converse.emit('OMEMOInitialized');
const view = _converse.chatboxviews.get(contact_jid); const view = _converse.chatboxviews.get(contact_jid);
const show_modal_button = view.el.querySelector('.show-user-details-modal'); const show_modal_button = view.el.querySelector('.show-user-details-modal');
show_modal_button.click(); show_modal_button.click();
modal = view.user_details_modal; const modal = view.user_details_modal;
await test_utils.waitUntil(() => u.isVisible(modal.el), 1000);
return test_utils.waitUntil(() => u.isVisible(modal.el), 1000); let iq_stanza = await test_utils.waitUntil(() => deviceListFetched(_converse, contact_jid));
}).then(() => test_utils.waitUntil(() => deviceListFetched(_converse, contact_jid)))
.then(iq_stanza => {
expect(iq_stanza.toLocaleString()).toBe( expect(iq_stanza.toLocaleString()).toBe(
`<iq from="dummy@localhost" id="${iq_stanza.nodeTree.getAttribute("id")}" to="max.frankfurter@localhost" type="get" xmlns="jabber:client">`+ `<iq from="dummy@localhost" id="${iq_stanza.nodeTree.getAttribute("id")}" to="max.frankfurter@localhost" type="get" xmlns="jabber:client">`+
`<pubsub xmlns="http://jabber.org/protocol/pubsub"><items node="eu.siacs.conversations.axolotl.devicelist"/></pubsub>`+ `<pubsub xmlns="http://jabber.org/protocol/pubsub"><items node="eu.siacs.conversations.axolotl.devicelist"/></pubsub>`+
`</iq>`); `</iq>`);
let stanza = $iq({
const stanza = $iq({
'from': contact_jid, 'from': contact_jid,
'id': iq_stanza.nodeTree.getAttribute('id'), 'id': iq_stanza.nodeTree.getAttribute('id'),
'to': _converse.bare_jid, 'to': _converse.bare_jid,
@ -887,18 +825,15 @@
.c('list', {'xmlns': "eu.siacs.conversations.axolotl"}) .c('list', {'xmlns': "eu.siacs.conversations.axolotl"})
.c('device', {'id': '555'}); .c('device', {'id': '555'});
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
await test_utils.waitUntil(() => u.isVisible(modal.el), 1000);
return test_utils.waitUntil(() => u.isVisible(modal.el), 1000); iq_stanza = await test_utils.waitUntil(() => bundleFetched(_converse, contact_jid, '555'));
}).then(() => test_utils.waitUntil(() => bundleFetched(_converse, contact_jid, '555')))
.then(iq_stanza => {
expect(iq_stanza.toLocaleString()).toBe( expect(iq_stanza.toLocaleString()).toBe(
`<iq from="dummy@localhost" id="${iq_stanza.nodeTree.getAttribute("id")}" to="max.frankfurter@localhost" type="get" xmlns="jabber:client">`+ `<iq from="dummy@localhost" id="${iq_stanza.nodeTree.getAttribute("id")}" to="max.frankfurter@localhost" type="get" xmlns="jabber:client">`+
`<pubsub xmlns="http://jabber.org/protocol/pubsub">`+ `<pubsub xmlns="http://jabber.org/protocol/pubsub">`+
`<items node="eu.siacs.conversations.axolotl.bundles:555"/>`+ `<items node="eu.siacs.conversations.axolotl.bundles:555"/>`+
`</pubsub>`+ `</pubsub>`+
`</iq>`); `</iq>`);
stanza = $iq({
const stanza = $iq({
'from': contact_jid, 'from': contact_jid,
'id': iq_stanza.nodeTree.getAttribute('id'), 'id': iq_stanza.nodeTree.getAttribute('id'),
'to': _converse.bare_jid, 'to': _converse.bare_jid,
@ -917,18 +852,12 @@
.c('preKeyPublic', {'preKeyId': '3'}).t(btoa('1003')); .c('preKeyPublic', {'preKeyId': '3'}).t(btoa('1003'));
_converse.connection._dataRecv(test_utils.createRequest(stanza)); _converse.connection._dataRecv(test_utils.createRequest(stanza));
const view = _converse.chatboxviews.get(contact_jid); await test_utils.waitUntil(() => modal.el.querySelectorAll('.fingerprints .fingerprint').length);
const modal = view.user_details_modal;
return test_utils.waitUntil(() => modal.el.querySelectorAll('.fingerprints .fingerprint').length);
}).then(() => {
const view = _converse.chatboxviews.get(contact_jid);
const modal = view.user_details_modal;
expect(modal.el.querySelectorAll('.fingerprints .fingerprint').length).toBe(1); expect(modal.el.querySelectorAll('.fingerprints .fingerprint').length).toBe(1);
const el = modal.el.querySelector('.fingerprints .fingerprint'); const el = modal.el.querySelector('.fingerprints .fingerprint');
expect(el.textContent.trim()).toBe( expect(el.textContent.trim()).toBe(
u.formatFingerprint(u.arrayBufferToHex(u.base64ToArrayBuffer('BQmHEOHjsYm3w5M8VqxAtqJmLCi7CaxxsdZz6G0YpuMI'))) u.formatFingerprint(u.arrayBufferToHex(u.base64ToArrayBuffer('BQmHEOHjsYm3w5M8VqxAtqJmLCi7CaxxsdZz6G0YpuMI')))
); );
expect(modal.el.querySelectorAll('input[type="radio"]').length).toBe(2); expect(modal.el.querySelectorAll('input[type="radio"]').length).toBe(2);
const devicelist = _converse.devicelists.get(contact_jid); const devicelist = _converse.devicelists.get(contact_jid);
@ -952,7 +881,6 @@
trusted_radio.click(); trusted_radio.click();
expect(devicelist.devices.get('555').get('trusted')).toBe(1); expect(devicelist.devices.get('555').get('trusted')).toBe(1);
done(); done();
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL))
})); }));
}); });