Better sync between convo and protocol stores
This commit is contained in:
parent
442cc43b94
commit
fbf91a4d79
10 changed files with 195 additions and 14 deletions
|
@ -211,7 +211,7 @@
|
|||
"@formatjs/intl": "2.6.7",
|
||||
"@indutny/rezip-electron": "1.3.1",
|
||||
"@mixer/parallel-prettier": "2.0.3",
|
||||
"@signalapp/mock-server": "6.4.3",
|
||||
"@signalapp/mock-server": "6.5.0",
|
||||
"@storybook/addon-a11y": "7.4.5",
|
||||
"@storybook/addon-actions": "7.4.5",
|
||||
"@storybook/addon-controls": "7.4.5",
|
||||
|
|
6
ts/CI.ts
6
ts/CI.ts
|
@ -34,6 +34,7 @@ export type CIType = {
|
|||
) => unknown;
|
||||
openSignalRoute(url: string): Promise<void>;
|
||||
exportBackupToDisk(path: string): Promise<void>;
|
||||
unlink: () => void;
|
||||
};
|
||||
|
||||
export type GetCIOptionsType = Readonly<{
|
||||
|
@ -162,6 +163,10 @@ export function getCI({ deviceName, backupData }: GetCIOptionsType): CIType {
|
|||
await backupsService.exportToDisk(path);
|
||||
}
|
||||
|
||||
function unlink() {
|
||||
window.Whisper.events.trigger('unlinkAndDisconnect');
|
||||
}
|
||||
|
||||
return {
|
||||
deviceName,
|
||||
backupData,
|
||||
|
@ -173,5 +178,6 @@ export function getCI({ deviceName, backupData }: GetCIOptionsType): CIType {
|
|||
waitForEvent,
|
||||
openSignalRoute,
|
||||
exportBackupToDisk,
|
||||
unlink,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -2708,7 +2708,16 @@ export class SignalProtocolStore extends EventEmitter {
|
|||
}
|
||||
|
||||
async removeAllConfiguration(): Promise<void> {
|
||||
// Conversations. These properties are not present in redux.
|
||||
window.getConversations().forEach(conversation => {
|
||||
conversation.unset('storageID');
|
||||
conversation.unset('needsStorageServiceSync');
|
||||
conversation.unset('storageUnknownFields');
|
||||
conversation.unset('senderKeyInfo');
|
||||
});
|
||||
|
||||
await window.Signal.Data.removeAllConfiguration();
|
||||
|
||||
await this.hydrateCaches();
|
||||
|
||||
window.storage.reset();
|
||||
|
|
|
@ -3015,11 +3015,6 @@ export async function startApp(): Promise<void> {
|
|||
try {
|
||||
log.info('unlinkAndDisconnect: removing configuration');
|
||||
|
||||
// First, make changes to conversations in memory
|
||||
window.getConversations().forEach(conversation => {
|
||||
conversation.unset('senderKeyInfo');
|
||||
});
|
||||
|
||||
// We use username for integrity check
|
||||
const ourConversation =
|
||||
window.ConversationController.getOurConversation();
|
||||
|
|
|
@ -6372,7 +6372,6 @@ async function removeAllConfiguration(): Promise<void> {
|
|||
DELETE FROM backup_cdn_object_metadata;
|
||||
DELETE FROM groupSendCombinedEndorsement;
|
||||
DELETE FROM groupSendMemberEndorsement;
|
||||
DELETE FROM identityKeys;
|
||||
DELETE FROM jobs;
|
||||
DELETE FROM kyberPreKeys;
|
||||
DELETE FROM preKeys;
|
||||
|
@ -6401,7 +6400,16 @@ async function removeAllConfiguration(): Promise<void> {
|
|||
|
||||
db.exec(
|
||||
`
|
||||
UPDATE conversations SET json = json_remove(json, '$.senderKeyInfo');
|
||||
UPDATE conversations
|
||||
SET
|
||||
json = json_remove(
|
||||
json,
|
||||
'$.senderKeyInfo',
|
||||
'$.storageID',
|
||||
'$.needsStorageServiceSync',
|
||||
'$.storageUnknownFields'
|
||||
);
|
||||
|
||||
UPDATE storyDistributions SET senderKeyInfoJson = NULL;
|
||||
`
|
||||
);
|
||||
|
|
|
@ -191,7 +191,7 @@ describe('backups', function (this: Mocha.Suite) {
|
|||
await app.close();
|
||||
|
||||
// Restart
|
||||
await bootstrap.unlink();
|
||||
await bootstrap.eraseStorage();
|
||||
app = await bootstrap.link({
|
||||
ciBackupPath: backupPath,
|
||||
});
|
||||
|
|
|
@ -266,7 +266,7 @@ export class Bootstrap {
|
|||
return path.join(this.backupPath, fileName);
|
||||
}
|
||||
|
||||
public unlink(): Promise<void> {
|
||||
public eraseStorage(): Promise<void> {
|
||||
return this.resetAppStorage();
|
||||
}
|
||||
|
||||
|
@ -304,6 +304,18 @@ export class Bootstrap {
|
|||
|
||||
const app = await this.startApp(extraConfig);
|
||||
|
||||
const window = await app.getWindow();
|
||||
const qrCode = window.locator(
|
||||
'.module-InstallScreenQrCodeNotScannedStep__qr-code__code'
|
||||
);
|
||||
const relinkButton = window.locator('.LeftPaneDialog__icon--relink');
|
||||
await qrCode.or(relinkButton).waitFor();
|
||||
if (await relinkButton.isVisible()) {
|
||||
debug('unlinked, clicking left pane button');
|
||||
await relinkButton.click();
|
||||
await qrCode.waitFor();
|
||||
}
|
||||
|
||||
const provision = await this.server.waitForProvision();
|
||||
|
||||
const provisionURL = await app.waitForProvisionURL();
|
||||
|
|
146
ts/test-mock/messaging/relink_test.ts
Normal file
146
ts/test-mock/messaging/relink_test.ts
Normal file
|
@ -0,0 +1,146 @@
|
|||
// Copyright 2023 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import createDebug from 'debug';
|
||||
import { Proto, StorageState } from '@signalapp/mock-server';
|
||||
|
||||
import * as durations from '../../util/durations';
|
||||
import type { App } from '../playwright';
|
||||
import { Bootstrap } from '../bootstrap';
|
||||
import { expectSystemMessages } from '../helpers';
|
||||
|
||||
export const debug = createDebug('mock:test:stories');
|
||||
|
||||
describe('messaging/relink', function (this: Mocha.Suite) {
|
||||
this.timeout(durations.MINUTE);
|
||||
|
||||
let bootstrap: Bootstrap;
|
||||
let app: App;
|
||||
|
||||
beforeEach(async () => {
|
||||
bootstrap = new Bootstrap();
|
||||
await bootstrap.init();
|
||||
|
||||
const {
|
||||
phone,
|
||||
contacts: [first, second, third],
|
||||
} = bootstrap;
|
||||
|
||||
let state = StorageState.getEmpty();
|
||||
|
||||
state = state.updateAccount({
|
||||
profileKey: phone.profileKey.serialize(),
|
||||
e164: phone.device.number,
|
||||
givenName: phone.profileName,
|
||||
hasSetMyStoriesPrivacy: true,
|
||||
});
|
||||
|
||||
state = state.addContact(first, {
|
||||
serviceE164: first.device.number,
|
||||
profileKey: first.profileKey.serialize(),
|
||||
givenName: first.profileName,
|
||||
|
||||
// Intentionally incorrect identity key!
|
||||
identityKey: third.publicKey.serialize(),
|
||||
});
|
||||
|
||||
state = state.addContact(second, {
|
||||
serviceE164: second.device.number,
|
||||
identityKey: second.publicKey.serialize(),
|
||||
profileKey: second.profileKey.serialize(),
|
||||
givenName: second.profileName,
|
||||
identityState: Proto.ContactRecord.IdentityState.VERIFIED,
|
||||
});
|
||||
|
||||
state = state.pin(first);
|
||||
|
||||
await phone.setStorageState(state);
|
||||
app = await bootstrap.link();
|
||||
});
|
||||
|
||||
afterEach(async function (this: Mocha.Context) {
|
||||
if (!bootstrap) {
|
||||
return;
|
||||
}
|
||||
|
||||
await bootstrap.maybeSaveLogs(this.currentTest, app);
|
||||
await app.close();
|
||||
await bootstrap.teardown();
|
||||
});
|
||||
|
||||
it('updates pin state on relink', async () => {
|
||||
const {
|
||||
phone,
|
||||
desktop,
|
||||
contacts: [first, second],
|
||||
} = bootstrap;
|
||||
|
||||
{
|
||||
const window = await app.getWindow();
|
||||
|
||||
const leftPane = window.locator('#LeftPane');
|
||||
|
||||
debug('waiting for pinned contact');
|
||||
await leftPane
|
||||
.locator(
|
||||
`[data-testid="${first.device.aci}"] >> "${first.profileName}"`
|
||||
)
|
||||
.waitFor();
|
||||
|
||||
await app.unlink();
|
||||
await phone.unlink(desktop);
|
||||
await app.close();
|
||||
|
||||
debug('change pinned contact, identity key');
|
||||
let state = await phone.expectStorageState('after link');
|
||||
|
||||
// Fix identity key
|
||||
state = state.updateContact(first, {
|
||||
identityKey: first.publicKey.serialize(),
|
||||
});
|
||||
|
||||
state = state.unpin(first);
|
||||
state = state.pin(second);
|
||||
|
||||
await phone.setStorageState(state);
|
||||
}
|
||||
|
||||
debug('relinking');
|
||||
app = await bootstrap.link();
|
||||
|
||||
{
|
||||
const window = await app.getWindow();
|
||||
|
||||
const leftPane = window.locator('#LeftPane');
|
||||
debug('waiting for different pinned contact');
|
||||
await leftPane
|
||||
.locator(
|
||||
`[data-testid="${second.device.aci}"] >> "${second.profileName}"`
|
||||
)
|
||||
.click();
|
||||
|
||||
await expectSystemMessages(window, [
|
||||
/You marked your Safety Number with .* as verified from another device/,
|
||||
]);
|
||||
|
||||
debug('change pinned contact again');
|
||||
let state = await phone.expectStorageState('after relink');
|
||||
state = state.unpin(second);
|
||||
state = state.pin(first);
|
||||
|
||||
await phone.setStorageState(state);
|
||||
await phone.sendFetchStorage({
|
||||
timestamp: bootstrap.getTimestamp(),
|
||||
});
|
||||
|
||||
debug('open old pinned contact');
|
||||
await leftPane
|
||||
.locator(
|
||||
`[data-testid="${first.device.aci}"] >> "${first.profileName}"`
|
||||
)
|
||||
.click();
|
||||
|
||||
await expectSystemMessages(window, [/Safety Number has changed/]);
|
||||
}
|
||||
});
|
||||
});
|
|
@ -175,6 +175,11 @@ export class App extends EventEmitter {
|
|||
);
|
||||
}
|
||||
|
||||
public async unlink(): Promise<void> {
|
||||
const window = await this.getWindow();
|
||||
return window.evaluate('window.SignalCI.unlink()');
|
||||
}
|
||||
|
||||
// EventEmitter types
|
||||
|
||||
public override on(type: 'close', callback: () => void): this;
|
||||
|
|
|
@ -4001,10 +4001,10 @@
|
|||
type-fest "^3.5.0"
|
||||
uuid "^8.3.0"
|
||||
|
||||
"@signalapp/mock-server@6.4.3":
|
||||
version "6.4.3"
|
||||
resolved "https://registry.yarnpkg.com/@signalapp/mock-server/-/mock-server-6.4.3.tgz#5672fb2c0123998ece49b68232debb07715c55a9"
|
||||
integrity sha512-6EnR4o349f+BO7fTCfkMzOYSzJcyhGvS7JExmp7YmKWQ+/YI5dgVQfsThw9uy/GUNDtfbVzUjMkPKI2kdDm2eA==
|
||||
"@signalapp/mock-server@6.5.0":
|
||||
version "6.5.0"
|
||||
resolved "https://registry.yarnpkg.com/@signalapp/mock-server/-/mock-server-6.5.0.tgz#0fa420ff2d7386770b3c8dfe6f57be425816a130"
|
||||
integrity sha512-QuEYX9EFFaPIvQzGlHkgfrnpnhs+Q8jOwk2UuE+5txJNXezrQnq1nRFChG+M/XAv0aSbc7thiq8iBxwpN2F2EA==
|
||||
dependencies:
|
||||
"@signalapp/libsignal-client" "^0.45.0"
|
||||
debug "^4.3.2"
|
||||
|
|
Loading…
Reference in a new issue