Add test for call link storage

This commit is contained in:
ayumi-signal 2024-10-25 13:31:30 -07:00 committed by GitHub
parent 9c918e4d62
commit 83f42f3100
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 259 additions and 31 deletions

View file

@ -0,0 +1,138 @@
// Copyright 2024 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { assert } from 'chai';
import Long from 'long';
import { Proto, StorageState } from '@signalapp/mock-server';
import * as durations from '../../util/durations';
import type { App } from './fixtures';
import { Bootstrap, debug, getCallLinkRecordPredicate } from './fixtures';
import { createCallLink } from '../helpers';
import { uuidToBytes } from '../../util/uuidToBytes';
import { MY_STORY_ID } from '../../types/Stories';
const IdentifierType = Proto.ManifestRecord.Identifier.Type;
describe('storage service', function (this: Mocha.Suite) {
this.timeout(durations.MINUTE);
let bootstrap: Bootstrap;
let app: App;
beforeEach(async () => {
bootstrap = new Bootstrap({ contactCount: 0 });
await bootstrap.init();
const { phone } = bootstrap;
let state = StorageState.getEmpty();
state = state.updateAccount({
profileKey: phone.profileKey.serialize(),
e164: phone.device.number,
givenName: phone.profileName,
});
// Add 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: [],
},
},
});
await phone.setStorageState(state);
app = await bootstrap.link();
});
afterEach(async function (this: Mocha.Context) {
if (!bootstrap) {
return;
}
await bootstrap.maybeSaveLogs(this.currentTest, app);
if (app) {
await app.close();
}
await bootstrap.teardown();
});
it('should save created call links and restore on relink', async () => {
const { phone } = bootstrap;
let state;
const window = await app.getWindow();
state = await phone.expectStorageState('initial state');
debug('Creating call link');
const roomId = await createCallLink(window, { name: 'Fun link' });
assert.exists(roomId, 'Call link roomId should exist');
debug('Waiting for storage update');
state = await phone.waitForStorageState({ after: state });
const record = state.findRecord(getCallLinkRecordPredicate(roomId));
assert.ok(record, 'Saves call link record with matching roomId');
const deletedAt = Long.fromValue(
record.record.callLink?.deletedAtTimestampMs ?? 0
).toNumber();
assert.notOk(deletedAt, 'deletedAt falsey');
debug('Creating link then deleting it');
const roomIdDelete = await createCallLink(window, {
name: 'Link to delete',
});
assert.exists(roomIdDelete, 'Call link roomId should exist');
debug('Waiting for storage update');
state = await phone.waitForStorageState({ after: state });
const recordToDelete = state.findRecord(
getCallLinkRecordPredicate(roomIdDelete)
);
assert.ok(recordToDelete, 'Saves call link record with matching roomId');
const deletedAtBeforeDelete = Long.fromValue(
recordToDelete.record.callLink?.deletedAtTimestampMs ?? 0
).toNumber();
assert.notOk(deletedAtBeforeDelete, 'deletedAt falsey');
debug('Deleting call link');
const callLinkItem = await window.getByText('Link to delete');
await callLinkItem.click();
const callLinkDetails = await window.locator(
'.CallsTab__ConversationCallDetails'
);
await callLinkDetails.waitFor();
const deleteButton = await window.getByText('Delete link');
await deleteButton.click();
const confirmModal = await window.getByTestId(
'ConfirmationDialog.CallLinkDetails__DeleteLinkModal'
);
await confirmModal.waitFor();
const deleteConfirm = await window
.locator('.module-Button')
.getByText('Delete');
await deleteConfirm.click();
debug('Waiting for storage update');
state = await phone.waitForStorageState({ after: state });
const recordAfterDelete = state.findRecord(
getCallLinkRecordPredicate(roomIdDelete)
);
assert.ok(recordAfterDelete, 'Call link record still present');
const deletedAtAfterDelete = Long.fromValue(
recordAfterDelete.record.callLink?.deletedAtTimestampMs ?? 0
).toNumber();
assert.ok(deletedAtAfterDelete, 'deletedAt present');
});
});

View file

@ -12,12 +12,14 @@ import { StorageState, Proto } from '@signalapp/mock-server';
import path from 'path';
import fs from 'fs/promises';
import { range } from 'lodash';
import { CallLinkRootKey } from '@signalapp/ringrtc';
import { App } from '../playwright';
import { Bootstrap } from '../bootstrap';
import type { BootstrapOptions } from '../bootstrap';
import { MY_STORY_ID } from '../../types/Stories';
import { uuidToBytes } from '../../util/uuidToBytes';
import { artAddStickersRoute } from '../../util/signalRoutes';
import { getRoomIdFromRootKey } from '../../util/callLinksRingrtc';
export const debug = createDebug('mock:test:storage');
@ -206,3 +208,17 @@ export async function storeStickerPacks(
})
);
}
export function getCallLinkRecordPredicate(
roomId: string
): (record: StorageStateRecord) => boolean {
return ({ type, record }: StorageStateRecord): boolean => {
const rootKeyBytes = record.callLink?.rootKey;
if (type !== IdentifierType.CALL_LINK || rootKeyBytes == null) {
return false;
}
const recordRootKey = CallLinkRootKey.fromBytes(Buffer.from(rootKeyBytes));
const recordRoomId = getRoomIdFromRootKey(recordRootKey);
return roomId === recordRoomId;
};
}