2022-09-19 22:08:55 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { assert } from 'chai';
|
|
|
|
import createDebug from 'debug';
|
|
|
|
import { Proto, StorageState } from '@signalapp/mock-server';
|
|
|
|
|
|
|
|
import * as durations from '../../util/durations';
|
|
|
|
import { uuidToBytes } from '../../util/uuidToBytes';
|
2022-11-10 15:51:39 +00:00
|
|
|
import { MY_STORY_ID } from '../../types/Stories';
|
2022-09-19 22:08:55 +00:00
|
|
|
import { Bootstrap } from '../bootstrap';
|
|
|
|
import type { App } from '../bootstrap';
|
|
|
|
|
|
|
|
export const debug = createDebug('mock:test:rate-limit');
|
|
|
|
|
|
|
|
const IdentifierType = Proto.ManifestRecord.Identifier.Type;
|
|
|
|
|
2022-10-07 17:02:08 +00:00
|
|
|
describe('story/no-sender-key', function needsName() {
|
2022-09-19 22:08:55 +00:00
|
|
|
this.timeout(durations.MINUTE);
|
2023-09-19 17:02:37 +00:00
|
|
|
this.retries(4);
|
2022-09-19 22:08:55 +00:00
|
|
|
|
|
|
|
let bootstrap: Bootstrap;
|
|
|
|
let app: App;
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
bootstrap = new Bootstrap({
|
|
|
|
contactCount: 0,
|
|
|
|
contactsWithoutProfileKey: 40,
|
|
|
|
});
|
|
|
|
await bootstrap.init();
|
|
|
|
|
|
|
|
const { phone } = bootstrap;
|
|
|
|
|
|
|
|
let state = StorageState.getEmpty();
|
|
|
|
|
|
|
|
state = state.updateAccount({
|
|
|
|
profileKey: phone.profileKey.serialize(),
|
|
|
|
e164: phone.device.number,
|
|
|
|
givenName: phone.profileName,
|
|
|
|
hasSetMyStoriesPrivacy: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
state = state.addRecord({
|
|
|
|
type: IdentifierType.STORY_DISTRIBUTION_LIST,
|
|
|
|
record: {
|
|
|
|
storyDistributionList: {
|
|
|
|
allowsReplies: true,
|
2022-11-10 15:51:39 +00:00
|
|
|
identifier: uuidToBytes(MY_STORY_ID),
|
2022-09-19 22:08:55 +00:00
|
|
|
isBlockList: true,
|
2022-11-10 15:51:39 +00:00
|
|
|
name: MY_STORY_ID,
|
2023-08-16 20:54:39 +00:00
|
|
|
recipientServiceIds: [],
|
2022-09-19 22:08:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2022-12-21 18:41:48 +00:00
|
|
|
await phone.setStorageState(state);
|
2022-09-19 22:08:55 +00:00
|
|
|
|
|
|
|
app = await bootstrap.link();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(async function after() {
|
2023-07-14 16:53:20 +00:00
|
|
|
await bootstrap.maybeSaveLogs(this.currentTest, app);
|
2022-09-19 22:08:55 +00:00
|
|
|
await app.close();
|
|
|
|
await bootstrap.teardown();
|
|
|
|
});
|
|
|
|
|
2022-10-07 17:02:08 +00:00
|
|
|
it('should successfully send story', async () => {
|
2022-09-19 22:08:55 +00:00
|
|
|
const {
|
|
|
|
server,
|
|
|
|
contactsWithoutProfileKey: contacts,
|
|
|
|
phone,
|
|
|
|
desktop,
|
|
|
|
} = bootstrap;
|
|
|
|
|
|
|
|
for (const contact of contacts) {
|
2023-08-16 20:54:39 +00:00
|
|
|
server.rateLimit({ source: desktop.aci, target: contact.device.aci });
|
2022-09-19 22:08:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const window = await app.getWindow();
|
|
|
|
|
|
|
|
debug('Posting a new story');
|
|
|
|
{
|
|
|
|
const storiesPane = window.locator('.Stories');
|
2023-08-09 00:53:06 +00:00
|
|
|
const storiesCreator = window.locator('.StoryCreator');
|
2022-09-19 22:08:55 +00:00
|
|
|
|
2023-08-09 00:53:06 +00:00
|
|
|
await window.getByTestId('NavTabsItem--Stories').click();
|
2022-09-19 22:08:55 +00:00
|
|
|
|
|
|
|
await storiesPane
|
|
|
|
.locator('button.Stories__pane__add-story__button')
|
|
|
|
.click();
|
|
|
|
await storiesPane
|
|
|
|
.locator(
|
|
|
|
'.ContextMenu__popper .Stories__pane__add-story__option--title ' +
|
|
|
|
'>> "Text story"'
|
|
|
|
)
|
|
|
|
.click();
|
|
|
|
|
|
|
|
debug('Focusing textarea');
|
2023-09-08 16:36:18 +00:00
|
|
|
await storiesCreator.locator('.TextAttachment__story').click();
|
2022-09-19 22:08:55 +00:00
|
|
|
|
|
|
|
debug('Entering text');
|
2023-08-09 00:53:06 +00:00
|
|
|
await storiesCreator
|
|
|
|
.locator('.TextAttachment__text__textarea')
|
2023-09-08 16:36:18 +00:00
|
|
|
.type('123');
|
2022-09-19 22:08:55 +00:00
|
|
|
|
|
|
|
debug('Clicking "Next"');
|
2023-08-09 00:53:06 +00:00
|
|
|
await storiesCreator
|
2022-09-19 22:08:55 +00:00
|
|
|
.locator('.StoryCreator__toolbar button >> "Next"')
|
|
|
|
.click();
|
|
|
|
|
2022-10-27 23:01:26 +00:00
|
|
|
debug('Selecting "My Story"');
|
2022-09-19 22:08:55 +00:00
|
|
|
await window
|
2022-10-27 23:01:26 +00:00
|
|
|
.locator('.SendStoryModal__distribution-list__name >> "My Story"')
|
2022-09-19 22:08:55 +00:00
|
|
|
.click();
|
|
|
|
|
|
|
|
debug('Hitting Send');
|
|
|
|
await window.locator('button.SendStoryModal__send').click();
|
|
|
|
}
|
|
|
|
|
|
|
|
debug('Verifying that all contacts received story');
|
|
|
|
await Promise.all(
|
|
|
|
contacts.map(async contact => {
|
|
|
|
const { storyMessage } = await contact.waitForStory();
|
|
|
|
assert.isTrue(
|
|
|
|
phone.profileKey
|
|
|
|
.serialize()
|
|
|
|
.equals(storyMessage.profileKey ?? new Uint8Array(0))
|
|
|
|
);
|
|
|
|
assert.strictEqual(storyMessage.textAttachment?.text, '123');
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|