Fix flakey mock test
This commit is contained in:
parent
703a82c818
commit
9ce0746f5b
4 changed files with 185 additions and 139 deletions
|
@ -241,6 +241,8 @@ export class SignalProtocolStore extends EventEmitter {
|
||||||
|
|
||||||
sessionQueues = new Map<SessionIdType, PQueue>();
|
sessionQueues = new Map<SessionIdType, PQueue>();
|
||||||
|
|
||||||
|
private readonly identityQueues = new Map<UUIDStringType, PQueue>();
|
||||||
|
|
||||||
private currentZone?: Zone;
|
private currentZone?: Zone;
|
||||||
|
|
||||||
private currentZoneDepth = 0;
|
private currentZoneDepth = 0;
|
||||||
|
@ -730,6 +732,27 @@ export class SignalProtocolStore extends EventEmitter {
|
||||||
return freshQueue;
|
return freshQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Identity Queue
|
||||||
|
|
||||||
|
private _createIdentityQueue(): PQueue {
|
||||||
|
return new PQueue({
|
||||||
|
concurrency: 1,
|
||||||
|
timeout: MINUTE * 30,
|
||||||
|
throwOnTimeout: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private _getIdentityQueue(uuid: UUID): PQueue {
|
||||||
|
const cachedQueue = this.identityQueues.get(uuid.toString());
|
||||||
|
if (cachedQueue) {
|
||||||
|
return cachedQueue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const freshQueue = this._createIdentityQueue();
|
||||||
|
this.identityQueues.set(uuid.toString(), freshQueue);
|
||||||
|
return freshQueue;
|
||||||
|
}
|
||||||
|
|
||||||
// Sessions
|
// Sessions
|
||||||
|
|
||||||
// Re-entrant session transaction routine. Only one session transaction could
|
// Re-entrant session transaction routine. Only one session transaction could
|
||||||
|
@ -1686,15 +1709,17 @@ export class SignalProtocolStore extends EventEmitter {
|
||||||
nonblockingApproval = false;
|
nonblockingApproval = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return this._getIdentityQueue(encodedAddress.uuid).add(async () => {
|
||||||
const identityRecord = await this.getOrMigrateIdentityRecord(
|
const identityRecord = await this.getOrMigrateIdentityRecord(
|
||||||
encodedAddress.uuid
|
encodedAddress.uuid
|
||||||
);
|
);
|
||||||
|
|
||||||
const id = encodedAddress.uuid.toString();
|
const id = encodedAddress.uuid.toString();
|
||||||
|
const logId = `saveIdentity(${id})`;
|
||||||
|
|
||||||
if (!identityRecord || !identityRecord.publicKey) {
|
if (!identityRecord || !identityRecord.publicKey) {
|
||||||
// Lookup failed, or the current key was removed, so save this one.
|
// Lookup failed, or the current key was removed, so save this one.
|
||||||
log.info('saveIdentity: Saving new identity...');
|
log.info(`${logId}: Saving new identity...`);
|
||||||
await this._saveIdentityKey({
|
await this._saveIdentityKey({
|
||||||
id,
|
id,
|
||||||
publicKey,
|
publicKey,
|
||||||
|
@ -1720,11 +1745,11 @@ export class SignalProtocolStore extends EventEmitter {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isOurIdentifier && identityKeyChanged) {
|
if (isOurIdentifier && identityKeyChanged) {
|
||||||
log.warn('saveIdentity: ignoring identity for ourselves');
|
log.warn(`${logId}: ignoring identity for ourselves`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info('saveIdentity: Replacing existing identity...');
|
log.info(`${logId}: Replacing existing identity...`);
|
||||||
const previousStatus = identityRecord.verified;
|
const previousStatus = identityRecord.verified;
|
||||||
let verifiedStatus;
|
let verifiedStatus;
|
||||||
if (
|
if (
|
||||||
|
@ -1751,7 +1776,7 @@ export class SignalProtocolStore extends EventEmitter {
|
||||||
this.emit('keychange', encodedAddress.uuid, 'saveIdentity - change');
|
this.emit('keychange', encodedAddress.uuid, 'saveIdentity - change');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error(
|
log.error(
|
||||||
'saveIdentity: error triggering keychange:',
|
`${logId}: error triggering keychange:`,
|
||||||
Errors.toLogFormat(error)
|
Errors.toLogFormat(error)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1765,7 +1790,7 @@ export class SignalProtocolStore extends EventEmitter {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (this.isNonBlockingApprovalRequired(identityRecord)) {
|
if (this.isNonBlockingApprovalRequired(identityRecord)) {
|
||||||
log.info('saveIdentity: Setting approval status...');
|
log.info(`${logId}: Setting approval status...`);
|
||||||
|
|
||||||
identityRecord.nonblockingApproval = nonblockingApproval;
|
identityRecord.nonblockingApproval = nonblockingApproval;
|
||||||
await this._saveIdentityKey(identityRecord);
|
await this._saveIdentityKey(identityRecord);
|
||||||
|
@ -1774,6 +1799,7 @@ export class SignalProtocolStore extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/signalapp/Signal-Android/blob/fc3db538bcaa38dc149712a483d3032c9c1f3998/app/src/main/java/org/thoughtcrime/securesms/crypto/storage/SignalBaseIdentityKeyStore.java#L257
|
// https://github.com/signalapp/Signal-Android/blob/fc3db538bcaa38dc149712a483d3032c9c1f3998/app/src/main/java/org/thoughtcrime/securesms/crypto/storage/SignalBaseIdentityKeyStore.java#L257
|
||||||
|
@ -1790,6 +1816,15 @@ export class SignalProtocolStore extends EventEmitter {
|
||||||
async saveIdentityWithAttributes(
|
async saveIdentityWithAttributes(
|
||||||
uuid: UUID,
|
uuid: UUID,
|
||||||
attributes: Partial<IdentityKeyType>
|
attributes: Partial<IdentityKeyType>
|
||||||
|
): Promise<void> {
|
||||||
|
return this._getIdentityQueue(uuid).add(async () => {
|
||||||
|
return this.saveIdentityWithAttributesOnQueue(uuid, attributes);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private async saveIdentityWithAttributesOnQueue(
|
||||||
|
uuid: UUID,
|
||||||
|
attributes: Partial<IdentityKeyType>
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
throw new Error('saveIdentityWithAttributes: uuid was undefined/null');
|
throw new Error('saveIdentityWithAttributes: uuid was undefined/null');
|
||||||
|
@ -1823,6 +1858,7 @@ export class SignalProtocolStore extends EventEmitter {
|
||||||
throw new Error('setApproval: Invalid approval status');
|
throw new Error('setApproval: Invalid approval status');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return this._getIdentityQueue(uuid).add(async () => {
|
||||||
const identityRecord = await this.getOrMigrateIdentityRecord(uuid);
|
const identityRecord = await this.getOrMigrateIdentityRecord(uuid);
|
||||||
|
|
||||||
if (!identityRecord) {
|
if (!identityRecord) {
|
||||||
|
@ -1831,6 +1867,7 @@ export class SignalProtocolStore extends EventEmitter {
|
||||||
|
|
||||||
identityRecord.nonblockingApproval = nonblockingApproval;
|
identityRecord.nonblockingApproval = nonblockingApproval;
|
||||||
await this._saveIdentityKey(identityRecord);
|
await this._saveIdentityKey(identityRecord);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/signalapp/Signal-Android/blob/fc3db538bcaa38dc149712a483d3032c9c1f3998/app/src/main/java/org/thoughtcrime/securesms/crypto/storage/SignalBaseIdentityKeyStore.java#L215
|
// https://github.com/signalapp/Signal-Android/blob/fc3db538bcaa38dc149712a483d3032c9c1f3998/app/src/main/java/org/thoughtcrime/securesms/crypto/storage/SignalBaseIdentityKeyStore.java#L215
|
||||||
|
@ -1847,10 +1884,13 @@ export class SignalProtocolStore extends EventEmitter {
|
||||||
throw new Error('setVerified: Invalid verified status');
|
throw new Error('setVerified: Invalid verified status');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return this._getIdentityQueue(uuid).add(async () => {
|
||||||
const identityRecord = await this.getOrMigrateIdentityRecord(uuid);
|
const identityRecord = await this.getOrMigrateIdentityRecord(uuid);
|
||||||
|
|
||||||
if (!identityRecord) {
|
if (!identityRecord) {
|
||||||
throw new Error(`setVerified: No identity record for ${uuid.toString()}`);
|
throw new Error(
|
||||||
|
`setVerified: No identity record for ${uuid.toString()}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (validateIdentityKey(identityRecord)) {
|
if (validateIdentityKey(identityRecord)) {
|
||||||
|
@ -1860,6 +1900,7 @@ export class SignalProtocolStore extends EventEmitter {
|
||||||
verified: verifiedStatus,
|
verified: verifiedStatus,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getVerified(uuid: UUID): Promise<number> {
|
async getVerified(uuid: UUID): Promise<number> {
|
||||||
|
@ -1922,6 +1963,7 @@ export class SignalProtocolStore extends EventEmitter {
|
||||||
`Invalid verified status: ${verifiedStatus}`
|
`Invalid verified status: ${verifiedStatus}`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return this._getIdentityQueue(uuid).add(async () => {
|
||||||
const identityRecord = await this.getOrMigrateIdentityRecord(uuid);
|
const identityRecord = await this.getOrMigrateIdentityRecord(uuid);
|
||||||
const hadEntry = identityRecord !== undefined;
|
const hadEntry = identityRecord !== undefined;
|
||||||
const keyMatches = Boolean(
|
const keyMatches = Boolean(
|
||||||
|
@ -1932,7 +1974,7 @@ export class SignalProtocolStore extends EventEmitter {
|
||||||
keyMatches && verifiedStatus === identityRecord?.verified;
|
keyMatches && verifiedStatus === identityRecord?.verified;
|
||||||
|
|
||||||
if (!keyMatches || !statusMatches) {
|
if (!keyMatches || !statusMatches) {
|
||||||
await this.saveIdentityWithAttributes(uuid, {
|
await this.saveIdentityWithAttributesOnQueue(uuid, {
|
||||||
publicKey,
|
publicKey,
|
||||||
verified: verifiedStatus,
|
verified: verifiedStatus,
|
||||||
firstUse: !hadEntry,
|
firstUse: !hadEntry,
|
||||||
|
@ -1970,6 +2012,7 @@ export class SignalProtocolStore extends EventEmitter {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
isUntrusted(uuid: UUID, timestampThreshold = TIMESTAMP_THRESHOLD): boolean {
|
isUntrusted(uuid: UUID, timestampThreshold = TIMESTAMP_THRESHOLD): boolean {
|
||||||
|
|
|
@ -1032,7 +1032,9 @@ export class ConversationModel extends window.Backbone
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.get('removalStage') === undefined) {
|
if (this.get('removalStage') === undefined) {
|
||||||
|
if (!viaStorageServiceSync) {
|
||||||
log.warn(`${logId}: not removed`);
|
log.warn(`${logId}: not removed`);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -584,6 +584,7 @@ export async function updateIdentityKey(
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
if (changed) {
|
if (changed) {
|
||||||
|
log.info(`updateIdentityKey(${uuid.toString()}): changed`);
|
||||||
// save identity will close all sessions except for .1, so we
|
// save identity will close all sessions except for .1, so we
|
||||||
// must close that one manually.
|
// must close that one manually.
|
||||||
const ourUuid = window.textsecure.storage.user.getCheckedUuid();
|
const ourUuid = window.textsecure.storage.user.getCheckedUuid();
|
||||||
|
|
|
@ -192,7 +192,7 @@ describe('pnp/accept gv2 invite', function needsName() {
|
||||||
debug('Checking final notification');
|
debug('Checking final notification');
|
||||||
await window
|
await window
|
||||||
.locator(
|
.locator(
|
||||||
'text=You accepted an invitation to the group from ' +
|
'.SystemMessage >> text=You accepted an invitation to the group from ' +
|
||||||
`${second.profileName}.`
|
`${second.profileName}.`
|
||||||
)
|
)
|
||||||
.waitFor();
|
.waitFor();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue