signal-desktop/ts/test-mock/backups/backups_test.ts

244 lines
6.8 KiB
TypeScript
Raw Normal View History

2024-03-15 14:20:33 +00:00
// Copyright 2023 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import createDebug from 'debug';
import Long from 'long';
2024-05-07 16:47:46 +00:00
import { Proto, StorageState } from '@signalapp/mock-server';
2024-03-15 14:20:33 +00:00
2024-05-07 16:47:46 +00:00
import { generateStoryDistributionId } from '../../types/StoryDistributionId';
import { MY_STORY_ID } from '../../types/Stories';
import { uuidToBytes } from '../../util/uuidToBytes';
2024-03-15 14:20:33 +00:00
import * as durations from '../../util/durations';
import type { App } from '../playwright';
import { Bootstrap } from '../bootstrap';
export const debug = createDebug('mock:test:backups');
2024-05-07 16:47:46 +00:00
const IdentifierType = Proto.ManifestRecord.Identifier.Type;
const DISTRIBUTION1 = generateStoryDistributionId();
2024-03-15 14:20:33 +00:00
describe('backups', function (this: Mocha.Suite) {
this.timeout(100 * durations.MINUTE);
let bootstrap: Bootstrap;
let app: App;
beforeEach(async () => {
bootstrap = new Bootstrap();
await bootstrap.init();
2024-04-15 20:54:21 +00:00
let state = StorageState.getEmpty();
const { phone, contacts } = bootstrap;
const [friend, pinned] = contacts;
state = state.updateAccount({
profileKey: phone.profileKey.serialize(),
e164: phone.device.number,
givenName: phone.profileName,
readReceipts: true,
hasCompletedUsernameOnboarding: true,
});
state = state.addContact(friend, {
identityKey: friend.publicKey.serialize(),
profileKey: friend.profileKey.serialize(),
});
state = state.addContact(pinned, {
identityKey: pinned.publicKey.serialize(),
profileKey: pinned.profileKey.serialize(),
2024-07-15 20:58:55 +00:00
whitelisted: true,
2024-04-15 20:54:21 +00:00
});
state = state.pin(pinned);
2024-05-07 16:47:46 +00:00
// Create empty My Story
state = state.addRecord({
type: IdentifierType.STORY_DISTRIBUTION_LIST,
record: {
storyDistributionList: {
allowsReplies: true,
identifier: uuidToBytes(MY_STORY_ID),
isBlockList: true,
name: MY_STORY_ID,
recipientServiceIds: [pinned.device.aci],
},
},
});
state = state.addRecord({
type: IdentifierType.STORY_DISTRIBUTION_LIST,
record: {
storyDistributionList: {
allowsReplies: true,
identifier: uuidToBytes(DISTRIBUTION1),
isBlockList: false,
name: 'friend',
recipientServiceIds: [friend.device.aci],
},
},
});
2024-04-15 20:54:21 +00:00
await phone.setStorageState(state);
2024-03-15 14:20:33 +00:00
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('exports and imports backup', async function () {
const { contacts, phone, desktop, server } = bootstrap;
2024-04-15 20:54:21 +00:00
const [friend, pinned] = contacts;
{
2024-07-15 20:58:55 +00:00
debug('wait for storage service sync to finish');
2024-04-15 20:54:21 +00:00
const window = await app.getWindow();
const leftPane = window.locator('#LeftPane');
2024-07-15 20:58:55 +00:00
const contact = leftPane.locator(
`[data-testid="${pinned.device.aci}"] >> "${pinned.profileName}"`
);
await contact.click();
debug('setting bubble color');
const conversationStack = window.locator('.Inbox__conversation-stack');
await conversationStack
.locator('button.module-ConversationHeader__button--more')
.click();
await window
.locator('.react-contextmenu-item >> "Chat settings"')
.click();
await conversationStack
.locator('.ConversationDetails__chat-color')
.click();
await conversationStack
.locator('.ChatColorPicker__bubble--infrared')
.click();
const backButton = conversationStack.locator(
'.ConversationPanel__header__back-button'
);
// Go back from colors
await backButton.first().click();
// Go back from settings
await backButton.last().click();
2024-04-15 20:54:21 +00:00
}
2024-03-15 14:20:33 +00:00
for (let i = 0; i < 5; i += 1) {
2024-07-15 20:58:55 +00:00
// eslint-disable-next-line no-await-in-loop
await server.send(
desktop,
// eslint-disable-next-line no-await-in-loop
await phone.encryptSyncSent(desktop, `to pinned ${i}`, {
timestamp: bootstrap.getTimestamp(),
destinationServiceId: pinned.device.aci,
})
);
2024-03-15 14:20:33 +00:00
const theirTimestamp = bootstrap.getTimestamp();
// eslint-disable-next-line no-await-in-loop
await friend.sendText(desktop, `msg ${i}`, {
timestamp: theirTimestamp,
});
const ourTimestamp = bootstrap.getTimestamp();
// eslint-disable-next-line no-await-in-loop
await server.send(
desktop,
// eslint-disable-next-line no-await-in-loop
await phone.encryptSyncSent(desktop, `respond ${i}`, {
timestamp: ourTimestamp,
destinationServiceId: friend.device.aci,
})
);
const reactionTimestamp = bootstrap.getTimestamp();
// eslint-disable-next-line no-await-in-loop
await friend.sendRaw(
desktop,
{
dataMessage: {
timestamp: Long.fromNumber(reactionTimestamp),
reaction: {
emoji: '👍',
targetAuthorAci: desktop.aci,
targetTimestamp: Long.fromNumber(ourTimestamp),
},
},
},
{
timestamp: reactionTimestamp,
}
);
}
const backupPath = bootstrap.getBackupPath('backup.bin');
await app.exportBackupToDisk(backupPath);
2024-03-15 14:20:33 +00:00
const comparator = await bootstrap.createScreenshotComparator(
app,
async (window, snapshot) => {
const leftPane = window.locator('#LeftPane');
2024-07-15 20:58:55 +00:00
const pinnedElem = leftPane.locator(
`[data-testid="${pinned.toContact().aci}"] >> "to pinned 4"`
);
debug('Waiting for messages to pinned contact to come through');
await pinnedElem.click();
2024-03-15 14:20:33 +00:00
const contactElem = leftPane.locator(
`[data-testid="${friend.toContact().aci}"] >> "respond 4"`
);
2024-07-15 20:58:55 +00:00
debug('Waiting for messages to regular contact to come through');
2024-03-15 14:20:33 +00:00
await contactElem.waitFor();
2024-07-15 20:58:55 +00:00
await snapshot('styled bubbles');
2024-03-15 14:20:33 +00:00
debug('Going into the conversation');
await contactElem.click();
await window
.locator('.ConversationView .module-message >> "respond 4"')
.waitFor();
await snapshot('conversation');
2024-05-07 16:47:46 +00:00
debug('Switching to stories nav tab');
await window.getByTestId('NavTabsItem--Stories').click();
debug('Opening story privacy');
await window.locator('.StoriesTab__MoreActionsIcon').click();
await window.getByRole('button', { name: 'Story Privacy' }).click();
await snapshot('story privacy');
2024-03-15 14:20:33 +00:00
},
this.test
);
await app.close();
// Restart
await bootstrap.eraseStorage();
2024-03-15 14:20:33 +00:00
app = await bootstrap.link({
ciBackupPath: backupPath,
});
await comparator(app);
});
});