Add identity key conflict tests
This commit is contained in:
parent
c05be725b3
commit
17e515f886
4 changed files with 64 additions and 2 deletions
|
@ -259,7 +259,7 @@
|
|||
publicKey = convertToArrayBuffer(publicKey);
|
||||
}
|
||||
var number = textsecure.utils.unencodeNumber(identifier)[0];
|
||||
return new Promise(function(resolve) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var identityKey = new IdentityKey({id: number});
|
||||
identityKey.fetch().always(function() {
|
||||
var oldpublicKey = identityKey.get('publicKey');
|
||||
|
@ -271,7 +271,7 @@
|
|||
if (equalArrayBuffers(oldpublicKey, publicKey)) {
|
||||
resolve();
|
||||
} else {
|
||||
throw new Error("Attempted to overwrite a different identity key");
|
||||
reject(new Error("Attempted to overwrite a different identity key"));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
50
libtextsecure/test/device_storage_test.js
Normal file
50
libtextsecure/test/device_storage_test.js
Normal file
|
@ -0,0 +1,50 @@
|
|||
/* vim: ts=4:sw=4
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
describe('Device storage', function() {
|
||||
before(function() { localStorage.clear(); });
|
||||
var store = textsecure.storage.axolotl;
|
||||
var identifier = '+5558675309';
|
||||
var another_identifier = '+5555590210';
|
||||
var identityKey = {
|
||||
pubKey: textsecure.crypto.getRandomBytes(33),
|
||||
privKey: textsecure.crypto.getRandomBytes(32),
|
||||
};
|
||||
var testKey = {
|
||||
pubKey: textsecure.crypto.getRandomBytes(33),
|
||||
privKey: textsecure.crypto.getRandomBytes(32),
|
||||
};
|
||||
describe('saveKeysToDeviceObject', function() {
|
||||
it('rejects if the identity key changes', function(done) {
|
||||
return textsecure.storage.devices.saveKeysToDeviceObject({
|
||||
identityKey: identityKey.pubKey,
|
||||
encodedNumber: identifier + '.1'
|
||||
}).then(function() {
|
||||
textsecure.storage.devices.saveKeysToDeviceObject({
|
||||
identityKey: testKey.pubKey,
|
||||
encodedNumber: identifier + '.1'
|
||||
}).then(function() {
|
||||
done(new Error('Allowed to overwrite identity key'));
|
||||
}).catch(function(e) {
|
||||
assert.strictEqual(e.message, 'Identity key changed');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -52,6 +52,7 @@
|
|||
<script type="text/javascript" src="helpers_test.js"></script>
|
||||
<script type="text/javascript" src="websocket-resources_test.js"></script>
|
||||
<script type="text/javascript" src="storage_test.js"></script>
|
||||
<script type="text/javascript" src="device_storage_test.js"></script>
|
||||
<script type="text/javascript" src="contacts_parser_test.js"></script>
|
||||
<script type="text/javascript" src="generate_keys_test.js"></script>
|
||||
<script type="text/javascript" src="websocket_test.js"></script>
|
||||
|
|
|
@ -50,6 +50,17 @@ describe("AxolotlStore", function() {
|
|||
});
|
||||
}).then(done,done);
|
||||
});
|
||||
it('rejects on key change', function(done) {
|
||||
var newIdentity = textsecure.crypto.getRandomBytes(33);
|
||||
store.putIdentityKey(identifier, testKey.pubKey).then(function() {
|
||||
store.putIdentityKey(identifier, newIdentity).then(function() {
|
||||
done(new Error('Allowed to overwrite identity key'));
|
||||
}).catch(function(e) {
|
||||
assert(e instanceof Error);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
it('stores prekeys', function(done) {
|
||||
store.putPreKey(1, testKey).then(function() {
|
||||
return store.getPreKey(1).then(function(key) {
|
||||
|
|
Loading…
Reference in a new issue