Test new setVerified behavior
// FREEBIE
This commit is contained in:
parent
4f2f622598
commit
044e1560e0
1 changed files with 50 additions and 8 deletions
|
@ -284,16 +284,58 @@ describe("SignalProtocolStore", function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('setVerified', function() {
|
describe('setVerified', function() {
|
||||||
var record = new IdentityKeyRecord({id: identifier});
|
var record;
|
||||||
function fetchRecord() {
|
function saveRecordDefault() {
|
||||||
return new Promise(function(resolve) {
|
record = new IdentityKeyRecord({
|
||||||
record.fetch().then(resolve);
|
id : identifier,
|
||||||
|
publicKey : testKey.pubKey,
|
||||||
|
firstUse : true,
|
||||||
|
timestamp : Date.now(),
|
||||||
|
verified : store.VerifiedStatus.DEFAULT,
|
||||||
|
nonblockingApproval : false
|
||||||
|
});
|
||||||
|
return new Promise(function(resolve, reject) {
|
||||||
|
record.save().then(resolve, reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
it ('updates the verified status', function(done) {
|
function fetchRecord() {
|
||||||
store.setVerified(identifier, store.VerifiedStatus.UNVERIFIED).then(fetchRecord).then(function() {
|
return new Promise(function(resolve, reject) {
|
||||||
assert.strictEqual(record.get('verified'), store.VerifiedStatus.UNVERIFIED);
|
record.fetch().then(resolve, reject);
|
||||||
}).then(done, done);
|
});
|
||||||
|
}
|
||||||
|
describe('with no public key argument', function() {
|
||||||
|
before(saveRecordDefault);
|
||||||
|
it ('updates the verified status', function() {
|
||||||
|
return store.setVerified(
|
||||||
|
identifier, store.VerifiedStatus.VERIFIED
|
||||||
|
).then(fetchRecord).then(function() {
|
||||||
|
assert.strictEqual(record.get('verified'), store.VerifiedStatus.VERIFIED);
|
||||||
|
assertEqualArrayBuffers(record.get('publicKey'), testKey.pubKey);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('with the current public key', function() {
|
||||||
|
before(saveRecordDefault);
|
||||||
|
it ('updates the verified status', function() {
|
||||||
|
return store.setVerified(
|
||||||
|
identifier, store.VerifiedStatus.VERIFIED, testKey.pubKey
|
||||||
|
).then(fetchRecord).then(function() {
|
||||||
|
assert.strictEqual(record.get('verified'), store.VerifiedStatus.VERIFIED);
|
||||||
|
assertEqualArrayBuffers(record.get('publicKey'), testKey.pubKey);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('with a mismatching public key', function() {
|
||||||
|
var newIdentity = libsignal.crypto.getRandomBytes(33);
|
||||||
|
before(saveRecordDefault);
|
||||||
|
it ('does not change the record.', function() {
|
||||||
|
return store.setVerified(
|
||||||
|
identifier, store.VerifiedStatus.VERIFIED, newIdentity
|
||||||
|
).then(fetchRecord).then(function() {
|
||||||
|
assert.strictEqual(record.get('verified'), store.VerifiedStatus.DEFAULT);
|
||||||
|
assertEqualArrayBuffers(record.get('publicKey'), testKey.pubKey);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('getVerified', function() {
|
describe('getVerified', function() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue