Fixed test again after rebase, reworked some logic in the conversation validateNumber function to correctly reflect what libsignal thinks is valid

pull/73/head
Beaudan 7 years ago
parent eb7a0dbb3a
commit 13db2d666f

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

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

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

@ -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',
@ -74,7 +74,7 @@ describe('Conversation', () => {
it('contains its own messages', async () => { it('contains its own messages', async () => {
const 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(), '');
@ -127,17 +127,19 @@ describe('Conversation', () => {
describe('when set to private', () => { describe('when set to private', () => {
it('correctly validates hex numbers', () => { 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', () => { 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());
}); });
@ -174,11 +176,10 @@ describe('Conversation', () => {
it('matches by partial keys', () => { 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

Loading…
Cancel
Save