2022-07-28 16:35:29 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2023-08-16 20:54:39 +00:00
|
|
|
import { ServiceIdKind } from '@signalapp/mock-server';
|
2022-07-28 16:35:29 +00:00
|
|
|
import createDebug from 'debug';
|
|
|
|
|
|
|
|
import * as durations from '../../util/durations';
|
|
|
|
import { Bootstrap } from '../bootstrap';
|
|
|
|
import type { App } from '../bootstrap';
|
|
|
|
|
|
|
|
export const debug = createDebug('mock:test:change-number');
|
|
|
|
|
2023-10-11 19:06:43 +00:00
|
|
|
describe('pnp/change number', function (this: Mocha.Suite) {
|
2022-07-28 16:35:29 +00:00
|
|
|
this.timeout(durations.MINUTE);
|
2023-09-19 17:02:37 +00:00
|
|
|
this.retries(4);
|
2022-07-28 16:35:29 +00:00
|
|
|
|
|
|
|
let bootstrap: Bootstrap;
|
|
|
|
let app: App;
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
bootstrap = new Bootstrap();
|
|
|
|
await bootstrap.init();
|
|
|
|
app = await bootstrap.link();
|
|
|
|
});
|
|
|
|
|
2023-10-11 19:06:43 +00:00
|
|
|
afterEach(async function (this: Mocha.Context) {
|
2023-07-14 16:53:20 +00:00
|
|
|
await bootstrap.maybeSaveLogs(this.currentTest, app);
|
2022-07-28 16:35:29 +00:00
|
|
|
await app.close();
|
|
|
|
await bootstrap.teardown();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should accept sync message and update keys', async () => {
|
|
|
|
const { server, phone, desktop, contacts } = bootstrap;
|
|
|
|
|
|
|
|
const [first] = contacts;
|
|
|
|
|
|
|
|
const window = await app.getWindow();
|
|
|
|
|
2023-07-26 22:23:32 +00:00
|
|
|
const leftPane = window.locator('#LeftPane');
|
2022-07-28 16:35:29 +00:00
|
|
|
|
|
|
|
debug('prepare a message for original PNI');
|
|
|
|
const messageBefore = await first.encryptText(desktop, 'Before', {
|
2023-08-16 20:54:39 +00:00
|
|
|
serviceIdKind: ServiceIdKind.PNI,
|
2022-07-28 16:35:29 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
debug('preparing change number');
|
|
|
|
const changeNumber = await phone.prepareChangeNumber();
|
|
|
|
|
2023-08-16 20:54:39 +00:00
|
|
|
const newKey = await desktop.popSingleUseKey(ServiceIdKind.PNI);
|
|
|
|
await first.addSingleUseKey(desktop, newKey, ServiceIdKind.PNI);
|
2022-07-28 16:35:29 +00:00
|
|
|
|
|
|
|
debug('prepare a message for updated PNI');
|
|
|
|
const messageAfter = await first.encryptText(desktop, 'After', {
|
2023-08-16 20:54:39 +00:00
|
|
|
serviceIdKind: ServiceIdKind.PNI,
|
2022-07-28 16:35:29 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
debug('sending all messages');
|
|
|
|
await Promise.all([
|
|
|
|
server.send(desktop, messageBefore),
|
|
|
|
phone.sendChangeNumber(changeNumber),
|
|
|
|
server.send(desktop, messageAfter),
|
|
|
|
]);
|
|
|
|
|
|
|
|
debug('opening conversation with the first contact');
|
2023-08-16 20:54:39 +00:00
|
|
|
await leftPane.locator(`[data-testid="${first.toContact().aci}"]`).click();
|
2022-07-28 16:35:29 +00:00
|
|
|
|
|
|
|
debug('done');
|
|
|
|
});
|
|
|
|
});
|