2023-05-12 18:20:10 +00:00
|
|
|
// Copyright 2023 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import type { PrimaryDevice } from '@signalapp/mock-server';
|
2023-11-07 21:31:59 +00:00
|
|
|
import { Proto } from '@signalapp/mock-server';
|
2023-05-12 18:20:10 +00:00
|
|
|
import createDebug from 'debug';
|
|
|
|
import Long from 'long';
|
|
|
|
import type { Page } from 'playwright';
|
|
|
|
import assert from 'assert';
|
|
|
|
import * as durations from '../../util/durations';
|
|
|
|
import type { App } from '../playwright';
|
|
|
|
import { Bootstrap } from '../bootstrap';
|
|
|
|
|
|
|
|
export const debug = createDebug('mock:test:edit');
|
|
|
|
|
2023-10-11 19:06:43 +00:00
|
|
|
describe('unknown contacts', function (this: Mocha.Suite) {
|
2023-05-12 18:20:10 +00:00
|
|
|
this.timeout(durations.MINUTE);
|
|
|
|
|
|
|
|
let bootstrap: Bootstrap;
|
|
|
|
let app: App;
|
|
|
|
let page: Page;
|
|
|
|
let unknownContact: PrimaryDevice;
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
2023-10-14 01:14:46 +00:00
|
|
|
bootstrap = new Bootstrap({ contactCount: 1, unknownContactCount: 1 });
|
2023-05-12 18:20:10 +00:00
|
|
|
await bootstrap.init();
|
|
|
|
app = await bootstrap.link();
|
|
|
|
page = await app.getWindow();
|
|
|
|
|
2023-10-14 01:14:46 +00:00
|
|
|
const { unknownContacts } = bootstrap;
|
|
|
|
[unknownContact] = unknownContacts;
|
2023-05-12 18:20:10 +00:00
|
|
|
});
|
|
|
|
|
2023-10-11 19:06:43 +00:00
|
|
|
afterEach(async function (this: Mocha.Context) {
|
2023-05-12 18:20:10 +00:00
|
|
|
if (!bootstrap) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-14 16:53:20 +00:00
|
|
|
await bootstrap.maybeSaveLogs(this.currentTest, app);
|
2023-05-12 18:20:10 +00:00
|
|
|
await app.close();
|
|
|
|
await bootstrap.teardown();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('blocks incoming calls from unknown contacts & shows message request', async () => {
|
|
|
|
const { desktop } = bootstrap;
|
|
|
|
|
|
|
|
debug('sending calling offer message');
|
|
|
|
await unknownContact.sendRaw(desktop, {
|
|
|
|
callingMessage: {
|
|
|
|
offer: {
|
|
|
|
callId: new Long(Math.floor(Math.random() * 1e10)),
|
2023-11-07 21:31:59 +00:00
|
|
|
type: Proto.CallingMessage.Offer.Type.OFFER_AUDIO_CALL,
|
|
|
|
opaque: new Uint8Array(0),
|
2023-05-12 18:20:10 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
debug('opening conversation');
|
2023-07-26 22:23:32 +00:00
|
|
|
const leftPane = page.locator('#LeftPane');
|
2023-05-12 18:20:10 +00:00
|
|
|
|
|
|
|
const conversationListItem = leftPane.getByRole('button', {
|
|
|
|
name: 'Chat with Unknown contact',
|
|
|
|
});
|
|
|
|
await conversationListItem.getByText('Message Request').click();
|
|
|
|
|
2023-07-26 22:23:32 +00:00
|
|
|
const conversationStack = page.locator('.Inbox__conversation-stack');
|
2023-05-12 18:20:10 +00:00
|
|
|
await conversationStack.getByText('Missed voice call').waitFor();
|
|
|
|
|
|
|
|
debug('accepting message request');
|
|
|
|
await page.getByText('message you and share your name').waitFor();
|
|
|
|
await page.getByRole('button', { name: 'Accept' }).click();
|
|
|
|
assert.strictEqual(
|
|
|
|
await page.getByText('message you and share your name').count(),
|
|
|
|
0
|
|
|
|
);
|
|
|
|
});
|
2024-02-14 20:19:08 +00:00
|
|
|
|
|
|
|
it('blocks incoming calls from unknown contacts & shows message request', async () => {
|
|
|
|
const { desktop } = bootstrap;
|
|
|
|
|
|
|
|
debug('sending calling offer message');
|
|
|
|
await unknownContact.sendRaw(desktop, {
|
|
|
|
callingMessage: {
|
|
|
|
offer: {
|
|
|
|
callId: new Long(Math.floor(Math.random() * 1e10)),
|
|
|
|
type: Proto.CallingMessage.Offer.Type.OFFER_AUDIO_CALL,
|
|
|
|
opaque: new Uint8Array(0),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
debug('opening conversation');
|
|
|
|
const leftPane = page.locator('#LeftPane');
|
|
|
|
|
|
|
|
const conversationListItem = leftPane.getByRole('button', {
|
|
|
|
name: 'Chat with Unknown contact',
|
|
|
|
});
|
|
|
|
await conversationListItem.getByText('Message Request').click();
|
|
|
|
|
|
|
|
const conversationStack = page.locator('.Inbox__conversation-stack');
|
|
|
|
await conversationStack.getByText('Missed voice call').waitFor();
|
|
|
|
|
|
|
|
debug('accepting message request');
|
|
|
|
await page.getByText('message you and share your name').waitFor();
|
|
|
|
await page.getByRole('button', { name: 'Accept' }).click();
|
|
|
|
assert.strictEqual(
|
|
|
|
await page.getByText('message you and share your name').count(),
|
|
|
|
0
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('syncs message request state', async () => {
|
|
|
|
const { phone, desktop } = bootstrap;
|
|
|
|
|
|
|
|
debug('sending regular text message');
|
|
|
|
await unknownContact.sendText(desktop, 'hello');
|
|
|
|
|
|
|
|
debug('opening conversation');
|
|
|
|
const leftPane = page.locator('#LeftPane');
|
|
|
|
|
|
|
|
const conversationListItem = leftPane.getByRole('button', {
|
|
|
|
name: 'Chat with Unknown contact',
|
|
|
|
});
|
|
|
|
await conversationListItem.getByText('Message Request').click();
|
|
|
|
|
|
|
|
debug('sending message request sync');
|
|
|
|
await phone.sendRaw(desktop, {
|
|
|
|
syncMessage: {
|
|
|
|
messageRequestResponse: {
|
|
|
|
type: Proto.SyncMessage.MessageRequestResponse.Type.ACCEPT,
|
|
|
|
threadAci: unknownContact.device.aci,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
debug('verifying that compose is now visible');
|
|
|
|
const composeArea = page.locator(
|
|
|
|
'.composition-area-wrapper, .Inbox__conversation .ConversationView'
|
|
|
|
);
|
|
|
|
const input = composeArea.locator('[data-testid=CompositionInput]');
|
|
|
|
await input.waitFor();
|
|
|
|
});
|
2023-05-12 18:20:10 +00:00
|
|
|
});
|