Merge pull request #73 from BeaudanBrown/tests

Tests
pull/74/head
Beaudan Campbell-Brown 6 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() {
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;
},

@ -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 */

@ -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;
})
),

@ -329,6 +329,16 @@
</div>
{{/action }}
</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'>
<div class='icon'></div>
<div class='text'>
@ -352,6 +362,7 @@
<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/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/conversations.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_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/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/network_status_view.js'></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';
@ -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

@ -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') {

@ -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 }),

@ -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', () => {

@ -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({

@ -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', () => { });
});
});
});

@ -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,

Loading…
Cancel
Save