Merge pull request #73 from BeaudanBrown/tests

Tests
pull/74/head
Beaudan Campbell-Brown 7 years ago committed by GitHub
commit 2836bd6dd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -857,25 +857,18 @@
validateNumber() { validateNumber() {
if (!this.id) return 'Invalid ID'; if (!this.id) return 'Invalid ID';
if (!this.isPrivate()) return null;
if (this.isPrivate()) { // Check if it's hex
// Check if it's hex const isHex = this.id.replace(/[\s]*/g, '').match(/^[0-9a-fA-F]+$/);
const isHex = this.id.replace(/[\s]*/g, '').match(/^[0-9a-fA-F]+$/); if (!isHex) return 'Invalid Hex ID';
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 the id is prefixed by 05 // Check if the pubkey length is 33 and leading with 05 or of length 32
if (!/^05/.test(this.id)) { const len = this.id.length;
return 'Invalid Pubkey Format'; if ((len !== 33 * 2 || !/^05/.test(this.id)) && len !== 32 * 2)
} return 'Invalid Pubkey Format';
}
this.set({ id: this.id });
return null; return null;
}, },

@ -161,14 +161,12 @@
return undefined; return undefined;
}, },
async getLocalRegistrationId() { async getLocalRegistrationId() {
return 1; const item = await window.Signal.Data.getItemById('registrationId');
if (item) {
// const item = await window.Signal.Data.getItemById('registrationId'); return item.value;
// if (item) { }
// return item.value;
// }
// return undefined; return 1;
}, },
/* Returns a prekeypair object or undefined */ /* Returns a prekeypair object or undefined */

@ -366,12 +366,12 @@ describe('Backup', () => {
(message.contact || []).map(async contact => { (message.contact || []).map(async contact => {
return contact && contact.avatar && contact.avatar.avatar return contact && contact.avatar && contact.avatar.avatar
? Object.assign({}, contact, { ? Object.assign({}, contact, {
avatar: Object.assign({}, contact.avatar, { avatar: Object.assign({}, contact.avatar, {
avatar: await wrappedLoadAttachment( avatar: await wrappedLoadAttachment(
contact.avatar.avatar contact.avatar.avatar
), ),
}), }),
}) })
: contact; : contact;
}) })
), ),

@ -329,6 +329,16 @@
</div> </div>
{{/action }} {{/action }}
</script> </script>
<script type='text/x-tmpl-mustache' id='main-header-placeholder'>
<div class='main-header-title-wrapper'>
<div class='main-header-content-toggle'/>
</div>
<div class='main-header-content-wrapper'>
{{ #items }}
<div role='button' id='{{ id }}'>{{ text }}</div>
{{ /items }}
</div>
</script>
<script type='text/x-tmpl-mustache' id='file-view'> <script type='text/x-tmpl-mustache' id='file-view'>
<div class='icon'></div> <div class='icon'></div>
<div class='text'> <div class='text'>
@ -352,6 +362,7 @@
<script type="text/javascript" src="../js/libtextsecure.js" data-cover></script> <script type="text/javascript" src="../js/libtextsecure.js" data-cover></script>
<script type="text/javascript" src="../js/libphonenumber-util.js"></script> <script type="text/javascript" src="../js/libphonenumber-util.js"></script>
<script type='text/javascript' src='../js/models/profile.js' data-cover></script>
<script type="text/javascript" src="../js/models/messages.js" data-cover></script> <script type="text/javascript" src="../js/models/messages.js" data-cover></script>
<script type="text/javascript" src="../js/models/conversations.js" data-cover></script> <script type="text/javascript" src="../js/models/conversations.js" data-cover></script>
<script type="text/javascript" src="../js/models/blockedNumbers.js" data-cover></script> <script type="text/javascript" src="../js/models/blockedNumbers.js" data-cover></script>
@ -387,6 +398,7 @@
<script type='text/javascript' src='../js/views/conversation_view.js' data-cover></script> <script type='text/javascript' src='../js/views/conversation_view.js' data-cover></script>
<script type='text/javascript' src='../js/views/conversation_search_view.js' data-cover></script> <script type='text/javascript' src='../js/views/conversation_search_view.js' data-cover></script>
<script type='text/javascript' src='../js/views/hint_view.js' data-cover></script> <script type='text/javascript' src='../js/views/hint_view.js' data-cover></script>
<script type='text/javascript' src='../js/views/main_header_view.js' data-cover></script>
<script type='text/javascript' src='../js/views/inbox_view.js' data-cover></script> <script type='text/javascript' src='../js/views/inbox_view.js' data-cover></script>
<script type='text/javascript' src='../js/views/network_status_view.js'></script> <script type='text/javascript' src='../js/views/network_status_view.js'></script>
<script type='text/javascript' src='../js/views/confirmation_dialog_view.js' data-cover></script> <script type='text/javascript' src='../js/views/confirmation_dialog_view.js' data-cover></script>

@ -1,4 +1,4 @@
/* global storage, textsecure, Whisper */ /* global textsecure, Whisper */
'use strict'; 'use strict';
@ -29,7 +29,7 @@ describe('ConversationCollection', () => {
}); });
describe('Conversation', () => { describe('Conversation', () => {
const attributes = { type: 'private', id: '771d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab' }; const attributes = { type: 'private', id: '051d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab' };
before(async () => { before(async () => {
const convo = new Whisper.ConversationCollection().add(attributes); const convo = new Whisper.ConversationCollection().add(attributes);
await window.Signal.Data.saveConversation(convo.attributes, { await window.Signal.Data.saveConversation(convo.attributes, {
@ -50,7 +50,7 @@ describe('Conversation', () => {
after(clearDatabase); after(clearDatabase);
it('sorts its contacts in an intl-friendly way', () => { 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( convo.contactCollection.add(
new Whisper.Conversation({ new Whisper.Conversation({
name: 'C', name: 'C',
@ -72,9 +72,9 @@ describe('Conversation', () => {
assert.strictEqual(convo.contactCollection.at('2').get('name'), 'C'); assert.strictEqual(convo.contactCollection.at('2').get('name'), 'C');
}); });
it('contains its own messages', async function() { it('contains its own messages', async () => {
var convo = new Whisper.ConversationCollection().add({ const convo = new Whisper.ConversationCollection().add({
id: '771d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab', id: '051d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab',
}); });
await convo.fetchMessages(); await convo.fetchMessages();
assert.notEqual(convo.messageCollection.length, 0); assert.notEqual(convo.messageCollection.length, 0);
@ -82,7 +82,7 @@ describe('Conversation', () => {
it('contains only its own messages', async () => { it('contains only its own messages', async () => {
const convo = new Whisper.ConversationCollection().add({ const convo = new Whisper.ConversationCollection().add({
id: '6eb56f06737d0966239e70d431d4dfd9e57c1e7dddacaf61907fcbc14295e424fd', id: '052d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab',
}); });
await convo.fetchMessages(); await convo.fetchMessages();
assert.strictEqual(convo.messageCollection.length, 0); assert.strictEqual(convo.messageCollection.length, 0);
@ -100,7 +100,7 @@ describe('Conversation', () => {
it('has a title', () => { it('has a title', () => {
const convos = new Whisper.ConversationCollection(); const convos = new Whisper.ConversationCollection();
let convo = convos.add(attributes); let convo = convos.add(attributes);
assert.equal(convo.getTitle(), '771d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab'); assert.equal(convo.getTitle(), '051d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab');
convo = convos.add({ type: '' }); convo = convos.add({ type: '' });
assert.equal(convo.getTitle(), 'Unknown group'); assert.equal(convo.getTitle(), 'Unknown group');
@ -112,7 +112,7 @@ describe('Conversation', () => {
it('returns the number', () => { it('returns the number', () => {
const convos = new Whisper.ConversationCollection(); const convos = new Whisper.ConversationCollection();
let convo = convos.add(attributes); let convo = convos.add(attributes);
assert.equal(convo.getNumber(), '771d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab'); assert.equal(convo.getNumber(), '051d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab');
convo = convos.add({ type: '' }); convo = convos.add({ type: '' });
assert.equal(convo.getNumber(), ''); assert.equal(convo.getNumber(), '');
@ -125,19 +125,21 @@ describe('Conversation', () => {
assert.property(avatar, 'color'); assert.property(avatar, 'color');
}); });
describe('when set to private', function() { describe('when set to private', () => {
it('correctly validates hex numbers', function() { it('correctly validates hex numbers', () => {
const regularId = new Whisper.Conversation({ type: 'private', id: '771d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab' }); const regularId = new Whisper.Conversation({ type: 'private', id: '051d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab' });
const invalidId = new Whisper.Conversation({ type: 'private', id: 'j71d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab' }); const invalidId = new Whisper.Conversation({ type: 'private', id: 'j71d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab' });
assert.ok(regularId.isValid()); assert.ok(regularId.isValid());
assert.notOk(invalidId.isValid()); assert.notOk(invalidId.isValid());
}); });
it('correctly validates length', function() { it('correctly validates length', () => {
const regularId = new Whisper.Conversation({ type: 'private', id: '771d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab' }); 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 shortId = new Whisper.Conversation({ type: 'private', id: '771d11d' });
const longId = new Whisper.Conversation({ type: 'private', id: '771d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94abaa' }); 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(shortId.isValid());
assert.notOk(longId.isValid()); assert.notOk(longId.isValid());
}); });
@ -146,6 +148,8 @@ describe('Conversation', () => {
describe('Conversation search', () => { describe('Conversation search', () => {
let convo; let convo;
before(clearDatabase);
beforeEach(async () => { beforeEach(async () => {
convo = new Whisper.ConversationCollection().add({ convo = new Whisper.ConversationCollection().add({
id: '771d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab', id: '771d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab',
@ -169,14 +173,13 @@ describe('Conversation', () => {
}) })
); );
} }
it('matches by partial keys', function() { it('matches by partial keys', () => {
return testSearch([ return testSearch([
'1', '1',
'771', 'd11',
'1e', 'fc3d74115c33225',
'56d9bfc3d74115c3322', 'd01e56d9bfc3d74115c33225a632321b509ac17a13fde',
'6d9bfc3d74115c33225a632321b509ac17a13fdeac71165d', '1d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab',
'771d11d01e56d9bfc3d74115c33225a632321b509ac17a13fdeac71165d09b94ab'
]); ]);
}); });
// TODO: Re-enable once we have nickanme functionality // TODO: Re-enable once we have nickanme functionality

@ -52,7 +52,7 @@ describe('Startup', () => {
it('should be skipped if this is the primary device', async () => { it('should be skipped if this is the primary device', async () => {
const ourNumber = '+15551234567'; const ourNumber = '+15551234567';
const deviceId = '1'; const deviceId = '1';
const sendRequestConfigurationSyncMessage = () => {}; const sendRequestConfigurationSyncMessage = () => { };
const storage = {}; const storage = {};
const prepareForSend = () => ({ const prepareForSend = () => ({
wrap: promise => promise, wrap: promise => promise,
@ -78,7 +78,7 @@ describe('Startup', () => {
it('should be skipped if user has previously synced', async () => { it('should be skipped if user has previously synced', async () => {
const ourNumber = '+15551234567'; const ourNumber = '+15551234567';
const deviceId = '2'; const deviceId = '2';
const sendRequestConfigurationSyncMessage = () => {}; const sendRequestConfigurationSyncMessage = () => { };
const storage = { const storage = {
get(name) { get(name) {
if (name !== 'read-receipt-configuration-sync') { if (name !== 'read-receipt-configuration-sync') {

@ -23,7 +23,7 @@ describe('Message', () => {
body: 'Imagine there is no heaven…', body: 'Imagine there is no heaven…',
schemaVersion: 2, schemaVersion: 2,
}; };
const writeExistingAttachmentData = () => {}; const writeExistingAttachmentData = () => { };
const actual = await Message.createAttachmentDataWriter({ const actual = await Message.createAttachmentDataWriter({
writeExistingAttachmentData, writeExistingAttachmentData,
@ -43,7 +43,7 @@ describe('Message', () => {
schemaVersion: 4, schemaVersion: 4,
attachments: [], attachments: [],
}; };
const writeExistingAttachmentData = () => {}; const writeExistingAttachmentData = () => { };
const actual = await Message.createAttachmentDataWriter({ const actual = await Message.createAttachmentDataWriter({
writeExistingAttachmentData, writeExistingAttachmentData,
@ -432,7 +432,7 @@ describe('Message', () => {
describe('_withSchemaVersion', () => { describe('_withSchemaVersion', () => {
it('should require a version number', () => { it('should require a version number', () => {
const toVersionX = () => {}; const toVersionX = () => { };
assert.throws( assert.throws(
() => () =>
Message._withSchemaVersion({ schemaVersion: toVersionX, upgrade: 2 }), Message._withSchemaVersion({ schemaVersion: toVersionX, upgrade: 2 }),

@ -19,9 +19,10 @@ describe('SignalProtocolStore', () => {
privKey: libsignal.crypto.getRandomBytes(32), privKey: libsignal.crypto.getRandomBytes(32),
}; };
storage.put('registrationId', 1337); storage.put('registrationId', 1337)
storage.put('identityKey', identityKey); .then(() => storage.put('identityKey', identityKey))
storage.fetch().then(done, done); .then(() => storage.fetch())
.then(done, done);
}); });
describe('getLocalRegistrationId', () => { describe('getLocalRegistrationId', () => {

@ -1,11 +1,17 @@
/* global ConversationController, textsecure, Whisper */ /* global storage, libsignal, ConversationController, textsecure, Whisper */
describe('InboxView', () => { describe('InboxView', () => {
let inboxView; let inboxView;
let conversation; let conversation;
let identityKey;
before(async () => { before(async () => {
ConversationController.reset(); ConversationController.reset();
identityKey = {
pubKey: libsignal.crypto.getRandomBytes(33),
privKey: libsignal.crypto.getRandomBytes(32),
};
storage.put('identityKey', identityKey);
await ConversationController.load(); await ConversationController.load();
await ConversationController.getOrCreateAndWait( await ConversationController.getOrCreateAndWait(
textsecure.storage.user.getNumber(), textsecure.storage.user.getNumber(),
@ -14,7 +20,7 @@ describe('InboxView', () => {
inboxView = new Whisper.InboxView({ inboxView = new Whisper.InboxView({
model: {}, model: {},
window, window,
initialLoadComplete() {}, initialLoadComplete() { },
}).render(); }).render();
conversation = new Whisper.Conversation({ conversation = new Whisper.Conversation({

@ -174,7 +174,7 @@ describe('NetworkStatusView', () => {
/Attempting reconnect/ /Attempting reconnect/
); );
}); });
it('should be reset by changing the socketStatus to CONNECTING', () => {}); it('should be reset by changing the socketStatus to CONNECTING', () => { });
}); });
}); });
}); });

@ -1,4 +1,5 @@
import { assert } from 'chai'; import { assert } from 'chai';
import moment from 'moment';
import * as Attachment from '../../types/Attachment'; import * as Attachment from '../../types/Attachment';
import * as MIME from '../../types/MIME'; import * as MIME from '../../types/MIME';
@ -44,7 +45,7 @@ describe('Attachment', () => {
data: stringToArrayBuffer('foo'), data: stringToArrayBuffer('foo'),
contentType: MIME.VIDEO_QUICKTIME, 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({ const actual = Attachment.getSuggestedFilename({
attachment, attachment,
timestamp, timestamp,

Loading…
Cancel
Save