diff --git a/js/models/conversations.js b/js/models/conversations.js index 6fe724ead..636ed3b2f 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -857,25 +857,18 @@ validateNumber() { if (!this.id) return 'Invalid ID'; + if (!this.isPrivate()) return null; - if (this.isPrivate()) { - // Check if it's hex - const isHex = this.id.replace(/[\s]*/g, '').match(/^[0-9a-fA-F]+$/); - if (!isHex) return 'Invalid Hex ID'; - - // Check if it has a valid length - if (this.id.length !== 33 * 2) { - // 33 bytes in hex - this.set({ id: this.id }); - return 'Invalid ID Length'; - } + // Check if it's hex + const isHex = this.id.replace(/[\s]*/g, '').match(/^[0-9a-fA-F]+$/); + if (!isHex) return 'Invalid Hex ID'; - // Check if the id is prefixed by 05 - if (!/^05/.test(this.id)) { - return 'Invalid Pubkey Format'; - } - } + // Check if the pubkey length is 33 and leading with 05 or of length 32 + const len = this.id.length; + if ((len !== 33 * 2 || !/^05/.test(this.id)) && len !== 32 * 2) + return 'Invalid Pubkey Format'; + this.set({ id: this.id }); return null; }, diff --git a/js/signal_protocol_store.js b/js/signal_protocol_store.js index 94a5f2224..b13fc3ed5 100644 --- a/js/signal_protocol_store.js +++ b/js/signal_protocol_store.js @@ -161,14 +161,12 @@ return undefined; }, async getLocalRegistrationId() { - return 1; - - // const item = await window.Signal.Data.getItemById('registrationId'); - // if (item) { - // return item.value; - // } + const item = await window.Signal.Data.getItemById('registrationId'); + if (item) { + return item.value; + } - // return undefined; + return 1; }, /* Returns a prekeypair object or undefined */ diff --git a/test/backup_test.js b/test/backup_test.js index 2ac94cea9..16b52721d 100644 --- a/test/backup_test.js +++ b/test/backup_test.js @@ -366,12 +366,12 @@ describe('Backup', () => { (message.contact || []).map(async contact => { return contact && contact.avatar && contact.avatar.avatar ? Object.assign({}, contact, { - avatar: Object.assign({}, contact.avatar, { - avatar: await wrappedLoadAttachment( - contact.avatar.avatar - ), - }), - }) + avatar: Object.assign({}, contact.avatar, { + avatar: await wrappedLoadAttachment( + contact.avatar.avatar + ), + }), + }) : contact; }) ), diff --git a/test/index.html b/test/index.html index fdf60a6cc..b03374a61 100644 --- a/test/index.html +++ b/test/index.html @@ -329,6 +329,16 @@ {{/action }} + + @@ -387,6 +398,7 @@ + diff --git a/test/models/conversations_test.js b/test/models/conversations_test.js index fed0ed267..62190fec7 100644 --- a/test/models/conversations_test.js +++ b/test/models/conversations_test.js @@ -1,4 +1,4 @@ -/* global storage, textsecure, Whisper */ +/* global textsecure, Whisper */ 'use strict'; @@ -29,7 +29,7 @@ describe('ConversationCollection', () => { }); describe('Conversation', () => { - const attributes = { type: 'private', id: '771d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab' }; + const attributes = { type: 'private', id: '051d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab' }; before(async () => { const convo = new Whisper.ConversationCollection().add(attributes); await window.Signal.Data.saveConversation(convo.attributes, { @@ -50,7 +50,7 @@ describe('Conversation', () => { after(clearDatabase); it('sorts its contacts in an intl-friendly way', () => { - const convo = new Whisper.Conversation({ id: '771d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab' }); + const convo = new Whisper.Conversation({ id: '051d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab' }); convo.contactCollection.add( new Whisper.Conversation({ name: 'C', @@ -72,9 +72,9 @@ describe('Conversation', () => { assert.strictEqual(convo.contactCollection.at('2').get('name'), 'C'); }); - it('contains its own messages', async function() { - var convo = new Whisper.ConversationCollection().add({ - id: '771d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab', + it('contains its own messages', async () => { + const convo = new Whisper.ConversationCollection().add({ + id: '051d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab', }); await convo.fetchMessages(); assert.notEqual(convo.messageCollection.length, 0); @@ -82,7 +82,7 @@ describe('Conversation', () => { it('contains only its own messages', async () => { const convo = new Whisper.ConversationCollection().add({ - id: '6eb56f06737d0966239e70d431d4dfd9e57c1e7dddacaf61907fcbc14295e424fd', + id: '052d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab', }); await convo.fetchMessages(); assert.strictEqual(convo.messageCollection.length, 0); @@ -100,7 +100,7 @@ describe('Conversation', () => { it('has a title', () => { const convos = new Whisper.ConversationCollection(); let convo = convos.add(attributes); - assert.equal(convo.getTitle(), '771d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab'); + assert.equal(convo.getTitle(), '051d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab'); convo = convos.add({ type: '' }); assert.equal(convo.getTitle(), 'Unknown group'); @@ -112,7 +112,7 @@ describe('Conversation', () => { it('returns the number', () => { const convos = new Whisper.ConversationCollection(); let convo = convos.add(attributes); - assert.equal(convo.getNumber(), '771d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab'); + assert.equal(convo.getNumber(), '051d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab'); convo = convos.add({ type: '' }); assert.equal(convo.getNumber(), ''); @@ -125,19 +125,21 @@ describe('Conversation', () => { assert.property(avatar, 'color'); }); - describe('when set to private', function() { - it('correctly validates hex numbers', function() { - const regularId = new Whisper.Conversation({ type: 'private', id: '771d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab' }); + describe('when set to private', () => { + it('correctly validates hex numbers', () => { + const regularId = new Whisper.Conversation({ type: 'private', id: '051d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab' }); const invalidId = new Whisper.Conversation({ type: 'private', id: 'j71d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab' }); assert.ok(regularId.isValid()); assert.notOk(invalidId.isValid()); }); - it('correctly validates length', function() { - const regularId = new Whisper.Conversation({ type: 'private', id: '771d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab' }); + it('correctly validates length', () => { + const regularId33 = new Whisper.Conversation({ type: 'private', id: '051d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab' }); + const regularId32 = new Whisper.Conversation({ type: 'private', id: '1d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab' }); const shortId = new Whisper.Conversation({ type: 'private', id: '771d11d' }); const longId = new Whisper.Conversation({ type: 'private', id: '771d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94abaa' }); - assert.ok(regularId.isValid()); + assert.ok(regularId33.isValid()); + assert.ok(regularId32.isValid()); assert.notOk(shortId.isValid()); assert.notOk(longId.isValid()); }); @@ -146,6 +148,8 @@ describe('Conversation', () => { describe('Conversation search', () => { let convo; + before(clearDatabase); + beforeEach(async () => { convo = new Whisper.ConversationCollection().add({ id: '771d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab', @@ -169,14 +173,13 @@ describe('Conversation', () => { }) ); } - it('matches by partial keys', function() { + it('matches by partial keys', () => { return testSearch([ '1', - '771', - '1e', - '56d9bfc3d74115c3322', - '6d9bfc3d74115c33225a632321b509ac17a13fdeac71165d', - '771d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab' + 'd11', + 'fc3d74115c33225', + 'd01e56d9bfc3d74115c33225a632321b509ac17a13fde', + '1d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab', ]); }); // TODO: Re-enable once we have nickanme functionality diff --git a/test/modules/startup_test.js b/test/modules/startup_test.js index b4e201523..508495bde 100644 --- a/test/modules/startup_test.js +++ b/test/modules/startup_test.js @@ -52,7 +52,7 @@ describe('Startup', () => { it('should be skipped if this is the primary device', async () => { const ourNumber = '+15551234567'; const deviceId = '1'; - const sendRequestConfigurationSyncMessage = () => {}; + const sendRequestConfigurationSyncMessage = () => { }; const storage = {}; const prepareForSend = () => ({ wrap: promise => promise, @@ -78,7 +78,7 @@ describe('Startup', () => { it('should be skipped if user has previously synced', async () => { const ourNumber = '+15551234567'; const deviceId = '2'; - const sendRequestConfigurationSyncMessage = () => {}; + const sendRequestConfigurationSyncMessage = () => { }; const storage = { get(name) { if (name !== 'read-receipt-configuration-sync') { diff --git a/test/modules/types/message_test.js b/test/modules/types/message_test.js index 40f258570..98af1e77f 100644 --- a/test/modules/types/message_test.js +++ b/test/modules/types/message_test.js @@ -23,7 +23,7 @@ describe('Message', () => { body: 'Imagine there is no heaven…', schemaVersion: 2, }; - const writeExistingAttachmentData = () => {}; + const writeExistingAttachmentData = () => { }; const actual = await Message.createAttachmentDataWriter({ writeExistingAttachmentData, @@ -43,7 +43,7 @@ describe('Message', () => { schemaVersion: 4, attachments: [], }; - const writeExistingAttachmentData = () => {}; + const writeExistingAttachmentData = () => { }; const actual = await Message.createAttachmentDataWriter({ writeExistingAttachmentData, @@ -432,7 +432,7 @@ describe('Message', () => { describe('_withSchemaVersion', () => { it('should require a version number', () => { - const toVersionX = () => {}; + const toVersionX = () => { }; assert.throws( () => Message._withSchemaVersion({ schemaVersion: toVersionX, upgrade: 2 }), diff --git a/test/storage_test.js b/test/storage_test.js index ab4f847cf..f127591f4 100644 --- a/test/storage_test.js +++ b/test/storage_test.js @@ -19,9 +19,10 @@ describe('SignalProtocolStore', () => { privKey: libsignal.crypto.getRandomBytes(32), }; - storage.put('registrationId', 1337); - storage.put('identityKey', identityKey); - storage.fetch().then(done, done); + storage.put('registrationId', 1337) + .then(() => storage.put('identityKey', identityKey)) + .then(() => storage.fetch()) + .then(done, done); }); describe('getLocalRegistrationId', () => { diff --git a/test/views/inbox_view_test.js b/test/views/inbox_view_test.js index abc076139..5bcd0445c 100644 --- a/test/views/inbox_view_test.js +++ b/test/views/inbox_view_test.js @@ -1,11 +1,17 @@ -/* global ConversationController, textsecure, Whisper */ +/* global storage, libsignal, ConversationController, textsecure, Whisper */ describe('InboxView', () => { let inboxView; let conversation; + let identityKey; before(async () => { ConversationController.reset(); + identityKey = { + pubKey: libsignal.crypto.getRandomBytes(33), + privKey: libsignal.crypto.getRandomBytes(32), + }; + storage.put('identityKey', identityKey); await ConversationController.load(); await ConversationController.getOrCreateAndWait( textsecure.storage.user.getNumber(), @@ -14,7 +20,7 @@ describe('InboxView', () => { inboxView = new Whisper.InboxView({ model: {}, window, - initialLoadComplete() {}, + initialLoadComplete() { }, }).render(); conversation = new Whisper.Conversation({ diff --git a/test/views/network_status_view_test.js b/test/views/network_status_view_test.js index a3daa7883..29c56112e 100644 --- a/test/views/network_status_view_test.js +++ b/test/views/network_status_view_test.js @@ -174,7 +174,7 @@ describe('NetworkStatusView', () => { /Attempting reconnect/ ); }); - it('should be reset by changing the socketStatus to CONNECTING', () => {}); + it('should be reset by changing the socketStatus to CONNECTING', () => { }); }); }); }); diff --git a/ts/test/types/Attachment_test.ts b/ts/test/types/Attachment_test.ts index a7d251697..17fba5d7d 100644 --- a/ts/test/types/Attachment_test.ts +++ b/ts/test/types/Attachment_test.ts @@ -1,4 +1,5 @@ import { assert } from 'chai'; +import moment from 'moment'; import * as Attachment from '../../types/Attachment'; import * as MIME from '../../types/MIME'; @@ -44,7 +45,7 @@ describe('Attachment', () => { data: stringToArrayBuffer('foo'), contentType: MIME.VIDEO_QUICKTIME, }; - const timestamp = new Date(new Date(0).getTimezoneOffset() * 60 * 1000); + const timestamp = new Date(-moment().utcOffset() * 60 * 1000); const actual = Attachment.getSuggestedFilename({ attachment, timestamp,