Commit 114e46df authored by JC Brand's avatar JC Brand

Fix broken test and refactor slightly. updates #497

parent b80a77a2
...@@ -73204,31 +73204,6 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_ ...@@ -73204,31 +73204,6 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
const TRUSTED = 1; const TRUSTED = 1;
const UNTRUSTED = -1; const UNTRUSTED = -1;
function getDevicesForContact(_converse, jid) {
return new Promise((resolve, reject) => {
_converse.api.waitUntil('OMEMOInitialized').then(() => {
let devicelist = _converse.devicelists.get(jid);
if (_.isNil(devicelist)) {
devicelist = _converse.devicelists.create({
'jid': jid
});
}
devicelist.fetchDevices().then(() => resolve(devicelist.devices));
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
});
}
function contactHasOMEMOSupport(_converse, jid) {
/* Checks whether the contact advertises any OMEMO-compatible devices. */
return new Promise((resolve, reject) => {
getDevicesForContact(_converse, jid).then(devices => {
resolve(devices.length > 0);
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
});
}
function parseBundle(bundle_el) { function parseBundle(bundle_el) {
/* Given an XML element representing a user's OMEMO bundle, parse it /* Given an XML element representing a user's OMEMO bundle, parse it
* and return a map. * and return a map.
...@@ -73266,9 +73241,8 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_ ...@@ -73266,9 +73241,8 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
getBundlesAndBuildSessions() { getBundlesAndBuildSessions() {
const _converse = this.__super__._converse; const _converse = this.__super__._converse;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
getDevicesForContact(this.get('jid')).then(devices => { _converse.getDevicesForContact(this.get('jid')).then(devices => {
const promises = _.map(devices, device => device.getBundle()); const promises = devices.map(device => device.getBundle());
Promise.all(promises).then(() => { Promise.all(promises).then(() => {
this.buildSessions(devices).then(() => resolve(devices)).catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR)); this.buildSessions(devices).then(() => resolve(devices)).catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR)); }).catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
...@@ -73361,7 +73335,8 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_ ...@@ -73361,7 +73335,8 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
renderOMEMOToolbarButton() { renderOMEMOToolbarButton() {
const _converse = this.__super__._converse, const _converse = this.__super__._converse,
__ = _converse.__; __ = _converse.__;
contactHasOMEMOSupport(_converse, this.model.get('jid')).then(support => {
_converse.contactHasOMEMOSupport(this.model.get('jid')).then(support => {
if (support) { if (support) {
const icon = this.el.querySelector('.toggle-omemo'), const icon = this.el.querySelector('.toggle-omemo'),
html = tpl_toolbar_omemo(_.extend(this.model.toJSON(), { html = tpl_toolbar_omemo(_.extend(this.model.toJSON(), {
...@@ -73398,6 +73373,29 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_ ...@@ -73398,6 +73373,29 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
_converse.NUM_PREKEYS = 100; // Set here so that tests can override _converse.NUM_PREKEYS = 100; // Set here so that tests can override
_converse.getDevicesForContact = function (jid) {
return new Promise((resolve, reject) => {
_converse.api.waitUntil('OMEMOInitialized').then(() => {
let devicelist = _converse.devicelists.get(jid);
if (_.isNil(devicelist)) {
devicelist = _converse.devicelists.create({
'jid': jid
});
}
devicelist.fetchDevices().then(() => resolve(devicelist.devices));
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
});
};
_converse.contactHasOMEMOSupport = function (jid) {
/* Checks whether the contact advertises any OMEMO-compatible devices. */
return new Promise((resolve, reject) => {
_converse.getDevicesForContact(jid).then(devices => resolve(devices.length > 0)).catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
});
};
function generateDeviceID() { function generateDeviceID() {
/* Generates a device ID, making sure that it's unique */ /* Generates a device ID, making sure that it's unique */
const existing_ids = _converse.devicelists.get(_converse.bare_jid).devices.pluck('id'); const existing_ids = _converse.devicelists.get(_converse.bare_jid).devices.pluck('id');
...@@ -73741,7 +73739,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_ ...@@ -73741,7 +73739,7 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
'signedPreKeyId': signed_prekey.keyId 'signedPreKeyId': signed_prekey.keyId
}).t(u.arrayBufferToBase64(signed_prekey.keyPair.pubKey)).up().c('signedPreKeySignature').t(u.arrayBufferToBase64(signed_prekey.signature)).up().c('identityKey').t(u.arrayBufferToBase64(store.get('identity_keypair').pubKey)).up().c('prekeys'); }).t(u.arrayBufferToBase64(signed_prekey.keyPair.pubKey)).up().c('signedPreKeySignature').t(u.arrayBufferToBase64(signed_prekey.signature)).up().c('identityKey').t(u.arrayBufferToBase64(store.get('identity_keypair').pubKey)).up().c('prekeys');
_.forEach(store.get('prekeys'), prekey => { _.forEach(store.get('prekeys').slice(0, _converse.NUM_PREKEYS), prekey => {
stanza.c('preKeyPublic', { stanza.c('preKeyPublic', {
'preKeyId': prekey.keyId 'preKeyId': prekey.keyId
}).t(u.arrayBufferToBase64(prekey.keyPair.pubKey)).up(); }).t(u.arrayBufferToBase64(prekey.keyPair.pubKey)).up();
...@@ -326,6 +326,8 @@ ...@@ -326,6 +326,8 @@
null, ['rosterGroupsFetched'], {}, null, ['rosterGroupsFetched'], {},
function (done, _converse) { function (done, _converse) {
_converse.NUM_PREKEYS = 2; // Restrict to 2, otherwise the resulting stanza is too large to easily test
let iq_stanza; let iq_stanza;
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';
...@@ -339,8 +341,6 @@ ...@@ -339,8 +341,6 @@
return node; return node;
}).length; }).length;
}).then(function () { }).then(function () {
_converse.NUM_PREKEYS = 2; // Restrict to 2, otherwise the resulting stanza is too large to easily test
const stanza = $iq({ const stanza = $iq({
'from': contact_jid, 'from': contact_jid,
'id': iq_stanza.getAttribute('id'), 'id': iq_stanza.getAttribute('id'),
......
...@@ -27,28 +27,6 @@ ...@@ -27,28 +27,6 @@
const UNTRUSTED = -1; const UNTRUSTED = -1;
function getDevicesForContact (_converse, jid) {
return new Promise((resolve, reject) => {
_converse.api.waitUntil('OMEMOInitialized').then(() => {
let devicelist = _converse.devicelists.get(jid);
if (_.isNil(devicelist)) {
devicelist = _converse.devicelists.create({'jid': jid});
}
devicelist.fetchDevices().then(() => resolve(devicelist.devices));
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
});
}
function contactHasOMEMOSupport (_converse, jid) {
/* Checks whether the contact advertises any OMEMO-compatible devices. */
return new Promise((resolve, reject) => {
getDevicesForContact(_converse, jid).then((devices) => {
resolve(devices.length > 0)
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
});
}
function parseBundle (bundle_el) { function parseBundle (bundle_el) {
/* Given an XML element representing a user's OMEMO bundle, parse it /* Given an XML element representing a user's OMEMO bundle, parse it
* and return a map. * and return a map.
...@@ -92,9 +70,9 @@ ...@@ -92,9 +70,9 @@
getBundlesAndBuildSessions () { getBundlesAndBuildSessions () {
const { _converse } = this.__super__; const { _converse } = this.__super__;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
getDevicesForContact(this.get('jid')) _converse.getDevicesForContact(this.get('jid'))
.then((devices) => { .then((devices) => {
const promises = _.map(devices, (device) => device.getBundle()); const promises = devices.map((device) => device.getBundle());
Promise.all(promises).then(() => { Promise.all(promises).then(() => {
this.buildSessions(devices) this.buildSessions(devices)
.then(() => resolve(devices)) .then(() => resolve(devices))
...@@ -185,7 +163,7 @@ ...@@ -185,7 +163,7 @@
renderOMEMOToolbarButton () { renderOMEMOToolbarButton () {
const { _converse } = this.__super__, const { _converse } = this.__super__,
{ __ } = _converse; { __ } = _converse;
contactHasOMEMOSupport(_converse, this.model.get('jid')).then((support) => { _converse.contactHasOMEMOSupport(this.model.get('jid')).then((support) => {
if (support) { if (support) {
const icon = this.el.querySelector('.toggle-omemo'), const icon = this.el.querySelector('.toggle-omemo'),
html = tpl_toolbar_omemo(_.extend(this.model.toJSON(), {'__': __})); html = tpl_toolbar_omemo(_.extend(this.model.toJSON(), {'__': __}));
...@@ -217,6 +195,29 @@ ...@@ -217,6 +195,29 @@
_converse.NUM_PREKEYS = 100; // Set here so that tests can override _converse.NUM_PREKEYS = 100; // Set here so that tests can override
_converse.getDevicesForContact = function (jid) {
return new Promise((resolve, reject) => {
_converse.api.waitUntil('OMEMOInitialized').then(() => {
let devicelist = _converse.devicelists.get(jid);
if (_.isNil(devicelist)) {
devicelist = _converse.devicelists.create({'jid': jid});
}
devicelist.fetchDevices().then(() => resolve(devicelist.devices));
}).catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
});
}
_converse.contactHasOMEMOSupport = function (jid) {
/* Checks whether the contact advertises any OMEMO-compatible devices. */
return new Promise((resolve, reject) => {
_converse.getDevicesForContact(jid)
.then((devices) => resolve(devices.length > 0))
.catch(_.partial(_converse.log, _, Strophe.LogLevel.ERROR));
});
}
function generateDeviceID () { function generateDeviceID () {
/* Generates a device ID, making sure that it's unique */ /* Generates a device ID, making sure that it's unique */
const existing_ids = _converse.devicelists.get(_converse.bare_jid).devices.pluck('id'); const existing_ids = _converse.devicelists.get(_converse.bare_jid).devices.pluck('id');
...@@ -535,7 +536,7 @@ ...@@ -535,7 +536,7 @@
.t(u.arrayBufferToBase64(store.get('identity_keypair').pubKey)).up() .t(u.arrayBufferToBase64(store.get('identity_keypair').pubKey)).up()
.c('prekeys'); .c('prekeys');
_.forEach( _.forEach(
store.get('prekeys'), store.get('prekeys').slice(0, _converse.NUM_PREKEYS),
(prekey) => { (prekey) => {
stanza.c('preKeyPublic', {'preKeyId': prekey.keyId}) stanza.c('preKeyPublic', {'preKeyId': prekey.keyId})
.t(u.arrayBufferToBase64(prekey.keyPair.pubKey)).up(); .t(u.arrayBufferToBase64(prekey.keyPair.pubKey)).up();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment