@wireapp/core 17.31.0 → 17.31.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/package.json +9 -9
- package/src/main/Account.js.map +0 -1
- package/src/main/Account.test.browser.js +0 -114
- package/src/main/Account.test.node.d.ts +0 -1
- package/src/main/Account.test.node.js +0 -214
- package/src/main/Account.test.node.js.map +0 -1
- package/src/main/Account.test.node.ts +0 -236
- package/src/main/Account.ts +0 -401
- package/src/main/CoreError.js.map +0 -1
- package/src/main/CoreError.ts +0 -30
- package/src/main/auth/LoginSanitizer.js.map +0 -1
- package/src/main/auth/LoginSanitizer.test.node.d.ts +0 -1
- package/src/main/auth/LoginSanitizer.test.node.js +0 -56
- package/src/main/auth/LoginSanitizer.test.node.js.map +0 -1
- package/src/main/auth/LoginSanitizer.test.node.ts +0 -68
- package/src/main/auth/LoginSanitizer.ts +0 -44
- package/src/main/auth/index.js.map +0 -1
- package/src/main/auth/index.ts +0 -20
- package/src/main/broadcast/AvailabilityType.js.map +0 -1
- package/src/main/broadcast/AvailabilityType.ts +0 -22
- package/src/main/broadcast/BroadcastService.js.map +0 -1
- package/src/main/broadcast/BroadcastService.ts +0 -66
- package/src/main/broadcast/index.js.map +0 -1
- package/src/main/broadcast/index.ts +0 -21
- package/src/main/client/ClientBackendRepository.js.map +0 -1
- package/src/main/client/ClientBackendRepository.ts +0 -33
- package/src/main/client/ClientDatabaseRepository.js.map +0 -1
- package/src/main/client/ClientDatabaseRepository.ts +0 -130
- package/src/main/client/ClientInfo.js.map +0 -1
- package/src/main/client/ClientInfo.ts +0 -28
- package/src/main/client/ClientService.js.map +0 -1
- package/src/main/client/ClientService.ts +0 -116
- package/src/main/client/index.js.map +0 -1
- package/src/main/client/index.ts +0 -23
- package/src/main/connection/ConnectionService.js.map +0 -1
- package/src/main/connection/ConnectionService.ts +0 -49
- package/src/main/connection/index.js.map +0 -1
- package/src/main/connection/index.ts +0 -20
- package/src/main/conversation/AbortReason.js.map +0 -1
- package/src/main/conversation/AbortReason.ts +0 -22
- package/src/main/conversation/AssetService.js.map +0 -1
- package/src/main/conversation/AssetService.test.node.d.ts +0 -1
- package/src/main/conversation/AssetService.test.node.js +0 -61
- package/src/main/conversation/AssetService.test.node.js.map +0 -1
- package/src/main/conversation/AssetService.test.node.ts +0 -65
- package/src/main/conversation/AssetService.ts +0 -60
- package/src/main/conversation/AssetTransferState.js.map +0 -1
- package/src/main/conversation/AssetTransferState.ts +0 -23
- package/src/main/conversation/ClientActionType.js.map +0 -1
- package/src/main/conversation/ClientActionType.ts +0 -20
- package/src/main/conversation/ConversationMapper.js.map +0 -1
- package/src/main/conversation/ConversationMapper.test.node.d.ts +0 -1
- package/src/main/conversation/ConversationMapper.test.node.js +0 -111
- package/src/main/conversation/ConversationMapper.test.node.js.map +0 -1
- package/src/main/conversation/ConversationMapper.test.node.ts +0 -154
- package/src/main/conversation/ConversationMapper.ts +0 -56
- package/src/main/conversation/ConversationService.js.map +0 -1
- package/src/main/conversation/ConversationService.test.node.d.ts +0 -1
- package/src/main/conversation/ConversationService.test.node.js +0 -344
- package/src/main/conversation/ConversationService.test.node.js.map +0 -1
- package/src/main/conversation/ConversationService.test.node.ts +0 -416
- package/src/main/conversation/ConversationService.ts +0 -1024
- package/src/main/conversation/GenericMessageType.js.map +0 -1
- package/src/main/conversation/GenericMessageType.ts +0 -44
- package/src/main/conversation/MessageTimer.js.map +0 -1
- package/src/main/conversation/MessageTimer.test.node.d.ts +0 -1
- package/src/main/conversation/MessageTimer.test.node.js +0 -88
- package/src/main/conversation/MessageTimer.test.node.js.map +0 -1
- package/src/main/conversation/MessageTimer.test.node.ts +0 -103
- package/src/main/conversation/MessageTimer.ts +0 -56
- package/src/main/conversation/ReactionType.js.map +0 -1
- package/src/main/conversation/ReactionType.ts +0 -23
- package/src/main/conversation/content/AssetContent.js.map +0 -1
- package/src/main/conversation/content/AssetContent.ts +0 -71
- package/src/main/conversation/content/ButtonActionConfirmationContent.js.map +0 -1
- package/src/main/conversation/content/ButtonActionConfirmationContent.ts +0 -21
- package/src/main/conversation/content/ButtonActionContent.js.map +0 -1
- package/src/main/conversation/content/ButtonActionContent.ts +0 -21
- package/src/main/conversation/content/CallingContent.js.map +0 -1
- package/src/main/conversation/content/CallingContent.ts +0 -20
- package/src/main/conversation/content/ClearedContent.js.map +0 -1
- package/src/main/conversation/content/ClearedContent.ts +0 -21
- package/src/main/conversation/content/ClientActionContent.js.map +0 -1
- package/src/main/conversation/content/ClientActionContent.ts +0 -22
- package/src/main/conversation/content/ClientAddContent.js.map +0 -1
- package/src/main/conversation/content/ClientAddContent.ts +0 -24
- package/src/main/conversation/content/ClientRemoveContent.js.map +0 -1
- package/src/main/conversation/content/ClientRemoveContent.ts +0 -25
- package/src/main/conversation/content/CompositeContent.js.map +0 -1
- package/src/main/conversation/content/CompositeContent.ts +0 -21
- package/src/main/conversation/content/ConfirmationContent.js.map +0 -1
- package/src/main/conversation/content/ConfirmationContent.ts +0 -21
- package/src/main/conversation/content/ContentType.js.map +0 -1
- package/src/main/conversation/content/ContentType.ts +0 -112
- package/src/main/conversation/content/ConversationContent.js.map +0 -1
- package/src/main/conversation/content/ConversationContent.ts +0 -71
- package/src/main/conversation/content/DeletedContent.js.map +0 -1
- package/src/main/conversation/content/DeletedContent.ts +0 -21
- package/src/main/conversation/content/EditedTextContent.js.map +0 -1
- package/src/main/conversation/content/EditedTextContent.ts +0 -31
- package/src/main/conversation/content/FileContent.js.map +0 -1
- package/src/main/conversation/content/FileContent.ts +0 -32
- package/src/main/conversation/content/HiddenContent.js.map +0 -1
- package/src/main/conversation/content/HiddenContent.ts +0 -21
- package/src/main/conversation/content/ImageContent.js.map +0 -1
- package/src/main/conversation/content/ImageContent.ts +0 -25
- package/src/main/conversation/content/KnockContent.js.map +0 -1
- package/src/main/conversation/content/KnockContent.ts +0 -21
- package/src/main/conversation/content/LinkPreviewContent.js.map +0 -1
- package/src/main/conversation/content/LinkPreviewContent.ts +0 -32
- package/src/main/conversation/content/LocationContent.js.map +0 -1
- package/src/main/conversation/content/LocationContent.ts +0 -29
- package/src/main/conversation/content/MentionContent.js.map +0 -1
- package/src/main/conversation/content/MentionContent.ts +0 -21
- package/src/main/conversation/content/QuoteContent.js.map +0 -1
- package/src/main/conversation/content/QuoteContent.ts +0 -29
- package/src/main/conversation/content/ReactionContent.js.map +0 -1
- package/src/main/conversation/content/ReactionContent.ts +0 -27
- package/src/main/conversation/content/TextContent.js.map +0 -1
- package/src/main/conversation/content/TextContent.ts +0 -29
- package/src/main/conversation/content/TweetContent.js.map +0 -1
- package/src/main/conversation/content/TweetContent.ts +0 -21
- package/src/main/conversation/content/index.js.map +0 -1
- package/src/main/conversation/content/index.ts +0 -49
- package/src/main/conversation/index.js.map +0 -1
- package/src/main/conversation/index.ts +0 -28
- package/src/main/conversation/message/CompositeContentBuilder.js.map +0 -1
- package/src/main/conversation/message/CompositeContentBuilder.ts +0 -60
- package/src/main/conversation/message/Message.js.map +0 -1
- package/src/main/conversation/message/Message.ts +0 -24
- package/src/main/conversation/message/MessageBuilder.js.map +0 -1
- package/src/main/conversation/message/MessageBuilder.test.browser.js +0 -27
- package/src/main/conversation/message/MessageBuilder.ts +0 -488
- package/src/main/conversation/message/MessageService.js.map +0 -1
- package/src/main/conversation/message/MessageService.test.node.d.ts +0 -1
- package/src/main/conversation/message/MessageService.test.node.js +0 -308
- package/src/main/conversation/message/MessageService.test.node.js.map +0 -1
- package/src/main/conversation/message/MessageService.test.node.ts +0 -398
- package/src/main/conversation/message/MessageService.ts +0 -383
- package/src/main/conversation/message/MessageToProtoMapper.js.map +0 -1
- package/src/main/conversation/message/MessageToProtoMapper.ts +0 -114
- package/src/main/conversation/message/OtrMessage.js.map +0 -1
- package/src/main/conversation/message/OtrMessage.ts +0 -160
- package/src/main/conversation/message/PayloadBundle.js.map +0 -1
- package/src/main/conversation/message/PayloadBundle.ts +0 -101
- package/src/main/conversation/message/TeamMessage.js.map +0 -1
- package/src/main/conversation/message/TeamMessage.ts +0 -72
- package/src/main/conversation/message/TextContentBuilder.js.map +0 -1
- package/src/main/conversation/message/TextContentBuilder.ts +0 -88
- package/src/main/conversation/message/UserClientsUtil.js.map +0 -1
- package/src/main/conversation/message/UserClientsUtil.ts +0 -44
- package/src/main/conversation/message/UserClientsUtils.test.node.d.ts +0 -1
- package/src/main/conversation/message/UserClientsUtils.test.node.js +0 -42
- package/src/main/conversation/message/UserClientsUtils.test.node.js.map +0 -1
- package/src/main/conversation/message/UserClientsUtils.test.node.ts +0 -44
- package/src/main/conversation/message/UserMessage.js.map +0 -1
- package/src/main/conversation/message/UserMessage.ts +0 -95
- package/src/main/cryptography/AssetCryptography.browser.js.map +0 -1
- package/src/main/cryptography/AssetCryptography.browser.ts +0 -76
- package/src/main/cryptography/AssetCryptography.node.js.map +0 -1
- package/src/main/cryptography/AssetCryptography.node.ts +0 -85
- package/src/main/cryptography/CryptographyDatabaseRepository.js.map +0 -1
- package/src/main/cryptography/CryptographyDatabaseRepository.ts +0 -44
- package/src/main/cryptography/CryptographyService.js.map +0 -1
- package/src/main/cryptography/CryptographyService.test.browser.js +0 -195
- package/src/main/cryptography/CryptographyService.test.node.d.ts +0 -1
- package/src/main/cryptography/CryptographyService.test.node.js +0 -228
- package/src/main/cryptography/CryptographyService.test.node.js.map +0 -1
- package/src/main/cryptography/CryptographyService.test.node.ts +0 -246
- package/src/main/cryptography/CryptographyService.ts +0 -246
- package/src/main/cryptography/EncryptedAsset.js.map +0 -1
- package/src/main/cryptography/EncryptedAsset.ts +0 -30
- package/src/main/cryptography/GenericMessageMapper.js.map +0 -1
- package/src/main/cryptography/GenericMessageMapper.ts +0 -274
- package/src/main/cryptography/MessageHashService.js.map +0 -1
- package/src/main/cryptography/MessageHashService.test.browser.js +0 -176
- package/src/main/cryptography/MessageHashService.test.node.d.ts +0 -1
- package/src/main/cryptography/MessageHashService.test.node.js +0 -138
- package/src/main/cryptography/MessageHashService.test.node.js.map +0 -1
- package/src/main/cryptography/MessageHashService.test.node.ts +0 -176
- package/src/main/cryptography/MessageHashService.ts +0 -109
- package/src/main/cryptography/SessionPayloadBundle.js.map +0 -1
- package/src/main/cryptography/SessionPayloadBundle.ts +0 -23
- package/src/main/cryptography/index.js.map +0 -1
- package/src/main/cryptography/index.ts +0 -23
- package/src/main/giphy/GiphyService.js.map +0 -1
- package/src/main/giphy/GiphyService.ts +0 -37
- package/src/main/giphy/index.js.map +0 -1
- package/src/main/giphy/index.ts +0 -20
- package/src/main/index.js.map +0 -1
- package/src/main/index.test.browser.js +0 -22
- package/src/main/index.ts +0 -34
- package/src/main/notification/NotificationBackendRepository.js.map +0 -1
- package/src/main/notification/NotificationBackendRepository.ts +0 -33
- package/src/main/notification/NotificationDatabaseRepository.js.map +0 -1
- package/src/main/notification/NotificationDatabaseRepository.ts +0 -74
- package/src/main/notification/NotificationService.js.map +0 -1
- package/src/main/notification/NotificationService.test.browser.js +0 -179
- package/src/main/notification/NotificationService.test.node.d.ts +0 -1
- package/src/main/notification/NotificationService.test.node.js +0 -99
- package/src/main/notification/NotificationService.test.node.js.map +0 -1
- package/src/main/notification/NotificationService.test.node.ts +0 -124
- package/src/main/notification/NotificationService.ts +0 -260
- package/src/main/notification/index.js.map +0 -1
- package/src/main/notification/index.ts +0 -20
- package/src/main/self/SelfService.js.map +0 -1
- package/src/main/self/SelfService.ts +0 -59
- package/src/main/self/index.js.map +0 -1
- package/src/main/self/index.ts +0 -20
- package/src/main/team/TeamService.js.map +0 -1
- package/src/main/team/TeamService.ts +0 -68
- package/src/main/team/index.js.map +0 -1
- package/src/main/team/index.ts +0 -20
- package/src/main/test/CryptographyHelper.js.map +0 -1
- package/src/main/test/CryptographyHelper.ts +0 -57
- package/src/main/test/PayloadHelper.js.map +0 -1
- package/src/main/test/PayloadHelper.ts +0 -60
- package/src/main/user/UserMapper.js.map +0 -1
- package/src/main/user/UserMapper.test.node.d.ts +0 -1
- package/src/main/user/UserMapper.test.node.js +0 -55
- package/src/main/user/UserMapper.test.node.js.map +0 -1
- package/src/main/user/UserMapper.test.node.ts +0 -63
- package/src/main/user/UserMapper.ts +0 -92
- package/src/main/user/UserService.js.map +0 -1
- package/src/main/user/UserService.test.node.js +0 -141
- package/src/main/user/UserService.ts +0 -98
- package/src/main/user/index.js.map +0 -1
- package/src/main/user/index.ts +0 -20
- package/src/main/util/TypePredicateUtil.js.map +0 -1
- package/src/main/util/TypePredicateUtil.test.node.d.ts +0 -1
- package/src/main/util/TypePredicateUtil.test.node.js +0 -42
- package/src/main/util/TypePredicateUtil.test.node.js.map +0 -1
- package/src/main/util/TypePredicateUtil.test.node.ts +0 -44
- package/src/main/util/TypePredicateUtil.ts +0 -52
- package/src/main/util/index.js.map +0 -1
- package/src/main/util/index.ts +0 -20
|
@@ -1,398 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Wire
|
|
3
|
-
* Copyright (C) 2021 Wire Swiss GmbH
|
|
4
|
-
*
|
|
5
|
-
* This program is free software: you can redistribute it and/or modify
|
|
6
|
-
* it under the terms of the GNU General Public License as published by
|
|
7
|
-
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
* (at your option) any later version.
|
|
9
|
-
*
|
|
10
|
-
* This program is distributed in the hope that it will be useful,
|
|
11
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
* GNU General Public License for more details.
|
|
14
|
-
*
|
|
15
|
-
* You should have received a copy of the GNU General Public License
|
|
16
|
-
* along with this program. If not, see http://www.gnu.org/licenses/.
|
|
17
|
-
*
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
import UUID from 'uuidjs';
|
|
21
|
-
import {StatusCodes} from 'http-status-codes';
|
|
22
|
-
import {APIClient} from '@wireapp/api-client';
|
|
23
|
-
import {
|
|
24
|
-
ClientMismatch,
|
|
25
|
-
MessageSendingStatus,
|
|
26
|
-
OTRRecipients,
|
|
27
|
-
QualifiedOTRRecipients,
|
|
28
|
-
QualifiedUserClients,
|
|
29
|
-
UserClients,
|
|
30
|
-
} from '@wireapp/api-client/src/conversation';
|
|
31
|
-
import {GenericMessage, Text} from '@wireapp/protocol-messaging';
|
|
32
|
-
import {CryptographyService} from '../../cryptography';
|
|
33
|
-
import {MessageService} from './MessageService';
|
|
34
|
-
import {getUUID} from '../../test/PayloadHelper';
|
|
35
|
-
|
|
36
|
-
const baseMessageSendingStatus: MessageSendingStatus = {
|
|
37
|
-
deleted: {},
|
|
38
|
-
missing: {},
|
|
39
|
-
failed_to_send: {},
|
|
40
|
-
redundant: {},
|
|
41
|
-
time: new Date().toISOString(),
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
type TestUser = {id: string; domain: string; clients: string[]};
|
|
45
|
-
const user1: TestUser = {
|
|
46
|
-
id: UUID.genV4().toString(),
|
|
47
|
-
domain: '1.wire.test',
|
|
48
|
-
clients: ['client1.1', 'client1.2', 'client1.3', 'client1.4'],
|
|
49
|
-
};
|
|
50
|
-
const user2: TestUser = {
|
|
51
|
-
id: UUID.genV4().toString(),
|
|
52
|
-
domain: '2.wire.test',
|
|
53
|
-
clients: ['client2.1', 'client2.2', 'client2.3', 'client2.4'],
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
function generateQualifiedRecipients(users: TestUser[]): QualifiedUserClients {
|
|
57
|
-
const payload: QualifiedUserClients = {};
|
|
58
|
-
users.forEach(({id, domain, clients}) => {
|
|
59
|
-
payload[domain] ||= {};
|
|
60
|
-
payload[domain][id] = clients;
|
|
61
|
-
});
|
|
62
|
-
return payload;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function generateRecipients(users: TestUser[]): UserClients {
|
|
66
|
-
return users.reduce((acc, {id, clients}) => {
|
|
67
|
-
acc[id] = clients;
|
|
68
|
-
return acc;
|
|
69
|
-
}, {} as UserClients);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function fakeEncrypt(_: unknown, recipients: QualifiedUserClients): Promise<QualifiedOTRRecipients> {
|
|
73
|
-
const encryptedPayload = Object.entries(recipients).reduce((acc, [domain, users]) => {
|
|
74
|
-
acc[domain] = Object.entries(users).reduce((userClients, [userId, clients]) => {
|
|
75
|
-
userClients[userId] = clients.reduce((payloads, client) => {
|
|
76
|
-
payloads[client] = new Uint8Array();
|
|
77
|
-
return payloads;
|
|
78
|
-
}, {} as any);
|
|
79
|
-
return userClients;
|
|
80
|
-
}, {} as OTRRecipients<Uint8Array>);
|
|
81
|
-
return acc;
|
|
82
|
-
}, {} as QualifiedOTRRecipients);
|
|
83
|
-
return Promise.resolve(encryptedPayload);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
describe('MessageService', () => {
|
|
87
|
-
const apiClient = new APIClient();
|
|
88
|
-
const cryptographyService = new CryptographyService(apiClient, {} as any);
|
|
89
|
-
const messageService = new MessageService(apiClient, cryptographyService);
|
|
90
|
-
|
|
91
|
-
beforeEach(() => {
|
|
92
|
-
spyOn(cryptographyService, 'encryptQualified').and.callFake(fakeEncrypt);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
describe('sendFederatedMessage', () => {
|
|
96
|
-
it('sends a message', async () => {
|
|
97
|
-
spyOn(apiClient.conversation.api, 'postOTRMessageV2').and.returnValue(Promise.resolve(baseMessageSendingStatus));
|
|
98
|
-
const recipients = generateQualifiedRecipients([user1, user2]);
|
|
99
|
-
|
|
100
|
-
await messageService.sendFederatedMessage('senderclientid', recipients, new Uint8Array(), {
|
|
101
|
-
conversationId: {id: 'convid', domain: ''},
|
|
102
|
-
});
|
|
103
|
-
expect(apiClient.conversation.api.postOTRMessageV2).toHaveBeenCalled();
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
describe('client mismatch', () => {
|
|
107
|
-
it('handles client mismatch internally if no onClientMismatch is given', async () => {
|
|
108
|
-
let spyCounter = 0;
|
|
109
|
-
const clientMismatch = {
|
|
110
|
-
...baseMessageSendingStatus,
|
|
111
|
-
deleted: {[user1.domain]: {[user1.id]: [user1.clients[0]]}},
|
|
112
|
-
missing: {'2.wire.test': {[user2.id]: ['client22']}},
|
|
113
|
-
};
|
|
114
|
-
spyOn(apiClient.conversation.api, 'postOTRMessageV2').and.callFake(() => {
|
|
115
|
-
spyCounter++;
|
|
116
|
-
if (spyCounter === 1) {
|
|
117
|
-
const error = new Error();
|
|
118
|
-
(error as any).response = {
|
|
119
|
-
status: StatusCodes.PRECONDITION_FAILED,
|
|
120
|
-
data: clientMismatch,
|
|
121
|
-
};
|
|
122
|
-
return Promise.reject(error);
|
|
123
|
-
}
|
|
124
|
-
return Promise.resolve(baseMessageSendingStatus);
|
|
125
|
-
});
|
|
126
|
-
spyOn(apiClient.user.api, 'postQualifiedMultiPreKeyBundles').and.returnValue(Promise.resolve({}));
|
|
127
|
-
|
|
128
|
-
const recipients = generateQualifiedRecipients([user1, user2]);
|
|
129
|
-
|
|
130
|
-
await messageService.sendFederatedMessage('senderclientid', recipients, new Uint8Array(), {
|
|
131
|
-
reportMissing: true,
|
|
132
|
-
conversationId: {id: 'convid', domain: ''},
|
|
133
|
-
});
|
|
134
|
-
expect(apiClient.conversation.api.postOTRMessageV2).toHaveBeenCalledTimes(2);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it('continues message sending if onClientMismatch returns true', async () => {
|
|
138
|
-
const onClientMismatch = jasmine.createSpy('onClientMismatch').and.returnValue(true);
|
|
139
|
-
const clientMismatch = {...baseMessageSendingStatus, missing: {'2.wire.test': {[user2.id]: ['client22']}}};
|
|
140
|
-
let spyCounter = 0;
|
|
141
|
-
spyOn(apiClient.conversation.api, 'postOTRMessageV2').and.callFake(() => {
|
|
142
|
-
spyCounter++;
|
|
143
|
-
if (spyCounter === 1) {
|
|
144
|
-
const error = new Error();
|
|
145
|
-
(error as any).response = {
|
|
146
|
-
status: StatusCodes.PRECONDITION_FAILED,
|
|
147
|
-
data: clientMismatch,
|
|
148
|
-
};
|
|
149
|
-
return Promise.reject(error);
|
|
150
|
-
}
|
|
151
|
-
return Promise.resolve(baseMessageSendingStatus);
|
|
152
|
-
});
|
|
153
|
-
spyOn(apiClient.user.api, 'postQualifiedMultiPreKeyBundles').and.returnValue(Promise.resolve({}));
|
|
154
|
-
|
|
155
|
-
const recipients = generateQualifiedRecipients([user1, user2]);
|
|
156
|
-
|
|
157
|
-
await messageService.sendFederatedMessage('senderclientid', recipients, new Uint8Array(), {
|
|
158
|
-
reportMissing: true,
|
|
159
|
-
onClientMismatch,
|
|
160
|
-
conversationId: {id: 'convid', domain: ''},
|
|
161
|
-
});
|
|
162
|
-
expect(apiClient.conversation.api.postOTRMessageV2).toHaveBeenCalledTimes(2);
|
|
163
|
-
expect(onClientMismatch).toHaveBeenCalledWith(clientMismatch);
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it('stops message sending if onClientMismatch returns false', async () => {
|
|
167
|
-
const onClientMismatch = jasmine.createSpy('onClientMismatch').and.returnValue(false);
|
|
168
|
-
const clientMismatch = {...baseMessageSendingStatus, missing: {'2.wire.test': {[user2.id]: ['client22']}}};
|
|
169
|
-
spyOn(apiClient.conversation.api, 'postOTRMessageV2').and.callFake(() => {
|
|
170
|
-
const error = new Error();
|
|
171
|
-
(error as any).response = {
|
|
172
|
-
status: StatusCodes.PRECONDITION_FAILED,
|
|
173
|
-
data: clientMismatch,
|
|
174
|
-
};
|
|
175
|
-
return Promise.reject(error);
|
|
176
|
-
});
|
|
177
|
-
spyOn(apiClient.user.api, 'postQualifiedMultiPreKeyBundles').and.returnValue(Promise.resolve({}));
|
|
178
|
-
|
|
179
|
-
const recipients = generateQualifiedRecipients([user1, user2]);
|
|
180
|
-
|
|
181
|
-
await messageService.sendFederatedMessage('senderclientid', recipients, new Uint8Array(), {
|
|
182
|
-
reportMissing: true,
|
|
183
|
-
onClientMismatch,
|
|
184
|
-
conversationId: {id: 'convid', domain: ''},
|
|
185
|
-
});
|
|
186
|
-
expect(apiClient.conversation.api.postOTRMessageV2).toHaveBeenCalledTimes(1);
|
|
187
|
-
expect(onClientMismatch).toHaveBeenCalledWith(clientMismatch);
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
describe('sendMessage', () => {
|
|
193
|
-
const generateUsers = (userCount: number, clientsPerUser: number): TestUser[] => {
|
|
194
|
-
return Array.from(Array(userCount)).map<TestUser>((_, i) => ({
|
|
195
|
-
id: `user${i}`,
|
|
196
|
-
domain: `${i}.domain`,
|
|
197
|
-
clients: Array.from(Array(clientsPerUser)).map((_, j) => `client${i}${j}`),
|
|
198
|
-
}));
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
const clientId = 'sendingClient';
|
|
202
|
-
const conversationId = 'conv1';
|
|
203
|
-
const createMessage = (content: string) => {
|
|
204
|
-
const customTextMessage = GenericMessage.create({
|
|
205
|
-
messageId: getUUID(),
|
|
206
|
-
text: Text.create({content}),
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
return GenericMessage.encode(customTextMessage).finish();
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
it('should send regular to conversation', async () => {
|
|
213
|
-
const message = 'Lorem ipsum dolor sit amet';
|
|
214
|
-
spyOn(apiClient.conversation.api, 'postOTRMessage').and.returnValue(Promise.resolve({} as ClientMismatch));
|
|
215
|
-
|
|
216
|
-
await messageService.sendMessage(clientId, generateRecipients(generateUsers(3, 3)), createMessage(message), {
|
|
217
|
-
conversationId,
|
|
218
|
-
});
|
|
219
|
-
expect(apiClient.conversation.api.postOTRMessage).toHaveBeenCalledWith(
|
|
220
|
-
clientId,
|
|
221
|
-
conversationId,
|
|
222
|
-
jasmine.any(Object),
|
|
223
|
-
false,
|
|
224
|
-
);
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
it('should send protobuf message to conversation', async () => {
|
|
228
|
-
const message = 'Lorem ipsum dolor sit amet';
|
|
229
|
-
spyOn(apiClient.conversation.api, 'postOTRProtobufMessage').and.returnValue(
|
|
230
|
-
Promise.resolve({} as ClientMismatch),
|
|
231
|
-
);
|
|
232
|
-
|
|
233
|
-
await messageService.sendMessage(clientId, generateRecipients(generateUsers(3, 3)), createMessage(message), {
|
|
234
|
-
conversationId,
|
|
235
|
-
sendAsProtobuf: true,
|
|
236
|
-
});
|
|
237
|
-
expect(apiClient.conversation.api.postOTRProtobufMessage).toHaveBeenCalledWith(
|
|
238
|
-
clientId,
|
|
239
|
-
conversationId,
|
|
240
|
-
jasmine.any(Object),
|
|
241
|
-
false,
|
|
242
|
-
);
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
it('should broadcast regular message if no conversationId is given', async () => {
|
|
246
|
-
const message = 'Lorem ipsum dolor sit amet';
|
|
247
|
-
spyOn(apiClient.broadcast.api, 'postBroadcastMessage').and.returnValue(Promise.resolve({} as ClientMismatch));
|
|
248
|
-
|
|
249
|
-
await messageService.sendMessage(clientId, generateRecipients(generateUsers(3, 3)), createMessage(message));
|
|
250
|
-
expect(apiClient.broadcast.api.postBroadcastMessage).toHaveBeenCalledWith(clientId, jasmine.any(Object), false);
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
it('should broadcast protobuf message if no conversationId is given', async () => {
|
|
254
|
-
const message = 'Lorem ipsum dolor sit amet';
|
|
255
|
-
spyOn(apiClient.broadcast.api, 'postBroadcastProtobufMessage').and.returnValue(
|
|
256
|
-
Promise.resolve({} as ClientMismatch),
|
|
257
|
-
);
|
|
258
|
-
|
|
259
|
-
await messageService.sendMessage(clientId, generateRecipients(generateUsers(3, 3)), createMessage(message), {
|
|
260
|
-
sendAsProtobuf: true,
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
expect(apiClient.broadcast.api.postBroadcastProtobufMessage).toHaveBeenCalledWith(
|
|
264
|
-
clientId,
|
|
265
|
-
jasmine.any(Object),
|
|
266
|
-
false,
|
|
267
|
-
);
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
it('should not send as external if payload small', async () => {
|
|
271
|
-
const message = 'Lorem ipsum dolor sit amet';
|
|
272
|
-
spyOn(apiClient.conversation.api, 'postOTRMessage').and.returnValue(Promise.resolve({} as ClientMismatch));
|
|
273
|
-
|
|
274
|
-
await messageService.sendMessage(clientId, generateRecipients(generateUsers(3, 3)), createMessage(message), {
|
|
275
|
-
conversationId,
|
|
276
|
-
});
|
|
277
|
-
expect(apiClient.conversation.api.postOTRMessage).toHaveBeenCalledWith(
|
|
278
|
-
clientId,
|
|
279
|
-
conversationId,
|
|
280
|
-
jasmine.objectContaining({data: undefined}),
|
|
281
|
-
false,
|
|
282
|
-
);
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
it('should send as external if payload is big', async () => {
|
|
286
|
-
const longMessage =
|
|
287
|
-
'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Duis autem Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Duis autem';
|
|
288
|
-
spyOn(apiClient.conversation.api, 'postOTRMessage').and.returnValue(Promise.resolve({} as ClientMismatch));
|
|
289
|
-
|
|
290
|
-
await messageService.sendMessage(
|
|
291
|
-
clientId,
|
|
292
|
-
generateRecipients(generateUsers(30, 10)),
|
|
293
|
-
createMessage(longMessage),
|
|
294
|
-
{
|
|
295
|
-
conversationId,
|
|
296
|
-
},
|
|
297
|
-
);
|
|
298
|
-
expect(apiClient.conversation.api.postOTRMessage).toHaveBeenCalledWith(
|
|
299
|
-
clientId,
|
|
300
|
-
conversationId,
|
|
301
|
-
jasmine.objectContaining({data: jasmine.any(String)}),
|
|
302
|
-
false,
|
|
303
|
-
);
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
describe('client mismatch', () => {
|
|
307
|
-
const baseClientMismatch: ClientMismatch = {
|
|
308
|
-
deleted: {},
|
|
309
|
-
missing: {},
|
|
310
|
-
redundant: {},
|
|
311
|
-
time: new Date().toISOString(),
|
|
312
|
-
};
|
|
313
|
-
|
|
314
|
-
it('handles client mismatch internally if no onClientMismatch is given', async () => {
|
|
315
|
-
let spyCounter = 0;
|
|
316
|
-
const clientMismatch = {
|
|
317
|
-
...baseClientMismatch,
|
|
318
|
-
deleted: {[user1.id]: [user1.clients[0]]},
|
|
319
|
-
missing: {[user2.id]: ['client22']},
|
|
320
|
-
};
|
|
321
|
-
spyOn(apiClient.conversation.api, 'postOTRMessage').and.callFake(() => {
|
|
322
|
-
spyCounter++;
|
|
323
|
-
if (spyCounter === 1) {
|
|
324
|
-
const error = new Error();
|
|
325
|
-
(error as any).response = {
|
|
326
|
-
status: StatusCodes.PRECONDITION_FAILED,
|
|
327
|
-
data: clientMismatch,
|
|
328
|
-
};
|
|
329
|
-
return Promise.reject(error);
|
|
330
|
-
}
|
|
331
|
-
return Promise.resolve(baseClientMismatch);
|
|
332
|
-
});
|
|
333
|
-
spyOn(apiClient.user.api, 'postMultiPreKeyBundles').and.returnValue(Promise.resolve({}));
|
|
334
|
-
|
|
335
|
-
const recipients = generateRecipients([user1, user2]);
|
|
336
|
-
|
|
337
|
-
await messageService.sendMessage('senderclientid', recipients, new Uint8Array(), {
|
|
338
|
-
reportMissing: true,
|
|
339
|
-
conversationId: 'convid',
|
|
340
|
-
});
|
|
341
|
-
expect(apiClient.conversation.api.postOTRMessage).toHaveBeenCalledTimes(2);
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
it('continues message sending if onClientMismatch returns true', async () => {
|
|
345
|
-
const onClientMismatch = jasmine.createSpy().and.returnValue(Promise.resolve(true));
|
|
346
|
-
const clientMismatch = {...baseClientMismatch, missing: {[user2.id]: ['client22']}};
|
|
347
|
-
let spyCounter = 0;
|
|
348
|
-
spyOn(apiClient.conversation.api, 'postOTRMessage').and.callFake(() => {
|
|
349
|
-
spyCounter++;
|
|
350
|
-
if (spyCounter === 1) {
|
|
351
|
-
const error = new Error();
|
|
352
|
-
(error as any).response = {
|
|
353
|
-
status: StatusCodes.PRECONDITION_FAILED,
|
|
354
|
-
data: clientMismatch,
|
|
355
|
-
};
|
|
356
|
-
return Promise.reject(error);
|
|
357
|
-
}
|
|
358
|
-
return Promise.resolve(baseClientMismatch);
|
|
359
|
-
});
|
|
360
|
-
spyOn(apiClient.user.api, 'postMultiPreKeyBundles').and.returnValue(Promise.resolve({}));
|
|
361
|
-
|
|
362
|
-
const recipients = generateRecipients([user1, user2]);
|
|
363
|
-
|
|
364
|
-
await messageService.sendMessage('senderclientid', recipients, new Uint8Array(), {
|
|
365
|
-
reportMissing: true,
|
|
366
|
-
onClientMismatch,
|
|
367
|
-
conversationId: 'convid',
|
|
368
|
-
});
|
|
369
|
-
expect(apiClient.conversation.api.postOTRMessage).toHaveBeenCalledTimes(2);
|
|
370
|
-
expect(onClientMismatch).toHaveBeenCalledWith(clientMismatch);
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
it('stops message sending if onClientMismatch returns false', async () => {
|
|
374
|
-
const onClientMismatch = jasmine.createSpy().and.returnValue(Promise.resolve(false));
|
|
375
|
-
const clientMismatch = {...baseMessageSendingStatus, missing: {[user2.id]: ['client22']}};
|
|
376
|
-
spyOn(apiClient.conversation.api, 'postOTRMessage').and.callFake(() => {
|
|
377
|
-
const error = new Error();
|
|
378
|
-
(error as any).response = {
|
|
379
|
-
status: StatusCodes.PRECONDITION_FAILED,
|
|
380
|
-
data: clientMismatch,
|
|
381
|
-
};
|
|
382
|
-
return Promise.reject(error);
|
|
383
|
-
});
|
|
384
|
-
spyOn(apiClient.user.api, 'postMultiPreKeyBundles').and.returnValue(Promise.resolve({}));
|
|
385
|
-
|
|
386
|
-
const recipients = generateRecipients([user1, user2]);
|
|
387
|
-
|
|
388
|
-
await messageService.sendMessage('senderclientid', recipients, new Uint8Array(), {
|
|
389
|
-
reportMissing: true,
|
|
390
|
-
onClientMismatch,
|
|
391
|
-
conversationId: 'convid',
|
|
392
|
-
});
|
|
393
|
-
expect(apiClient.conversation.api.postOTRMessage).toHaveBeenCalledTimes(1);
|
|
394
|
-
expect(onClientMismatch).toHaveBeenCalledWith(clientMismatch);
|
|
395
|
-
});
|
|
396
|
-
});
|
|
397
|
-
});
|
|
398
|
-
});
|