@wireapp/core 40.9.2 → 40.9.3
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/lib/messagingProtocols/proteus/ProteusService/ProteusService.d.ts +1 -1
- package/lib/messagingProtocols/proteus/ProteusService/ProteusService.d.ts.map +1 -1
- package/lib/messagingProtocols/proteus/ProteusService/ProteusService.js +28 -4
- package/lib/messagingProtocols/proteus/ProteusService/ProteusService.test.js +77 -0
- package/package.json +3 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { APIClient } from '@wireapp/api-client/lib/APIClient';
|
|
2
2
|
import type { PreKey, Context } from '@wireapp/api-client/lib/auth';
|
|
3
|
-
import
|
|
3
|
+
import { Conversation, QualifiedOTRRecipients, QualifiedUserClients } from '@wireapp/api-client/lib/conversation';
|
|
4
4
|
import type { QualifiedId, QualifiedUserPreKeyBundleMap } from '@wireapp/api-client/lib/user';
|
|
5
5
|
import { CRUDEngine } from '@wireapp/store-engine';
|
|
6
6
|
import { CryptoClient } from './CryptoClient';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProteusService.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/proteus/ProteusService/ProteusService.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,mCAAmC,CAAC;AACjE,OAAO,KAAK,EAAC,MAAM,EAAE,OAAO,EAAC,MAAM,8BAA8B,CAAC;AAClE,OAAO,
|
|
1
|
+
{"version":3,"file":"ProteusService.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/proteus/ProteusService/ProteusService.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,mCAAmC,CAAC;AACjE,OAAO,KAAK,EAAC,MAAM,EAAE,OAAO,EAAC,MAAM,8BAA8B,CAAC;AAClE,OAAO,EACL,YAAY,EAIZ,sBAAsB,EACtB,oBAAoB,EACrB,MAAM,sC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,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM;IAIxE;;;;;;OAMG;IACU,oBAAoB,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;IAQ3E,kBAAkB,CAAC,EAC9B,gBAAgB,EAChB,YAAY,GACb,EAAE,+BAA+B,GAAG,OAAO,CAAC,YAAY,CAAC;IA2C7C,sBAAsB,CAAC,EAAC,cAAc,EAAE,cAAc,EAAC,EAAE,mCAAmC;IAI5F,WAAW,CAAC,EACvB,OAAO,EACP,cAAc,EACd,UAAU,EACV,UAAU,EACV,OAAO,EACP,gBAAgB,GACjB,EAAE,wBAAwB,GAAG,OAAO,CAAC,UAAU,CAAC;YA6CnC,OAAO;IAuBd,aAAa,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM;IAQ7C,OAAO,CAClB,SAAS,EAAE,UAAU,EACrB,UAAU,EAAE,4BAA4B,GAAG,oBAAoB,GAC9D,OAAO,CAAC,gBAAgB,CAAC;IAiBtB,IAAI,CAAC,WAAW,CAAC,EAAE,UAAU;CAMpC"}
|
|
@@ -22,13 +22,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
};
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports.ProteusService = void 0;
|
|
25
|
+
const conversation_1 = require("@wireapp/api-client/lib/conversation");
|
|
25
26
|
const logdown_1 = __importDefault(require("logdown"));
|
|
26
27
|
const protocol_messaging_1 = require("@wireapp/protocol-messaging");
|
|
27
28
|
const cryptoMigrationStateStore_1 = require("./cryptoMigrationStateStore");
|
|
28
29
|
const DecryptionErrorGenerator_1 = require("./DecryptionErrorGenerator");
|
|
29
30
|
const identityClearer_1 = require("./identityClearer");
|
|
30
31
|
const sessionIdMigrator_1 = require("./sessionIdMigrator");
|
|
31
|
-
const
|
|
32
|
+
const conversation_2 = require("../../../conversation");
|
|
32
33
|
const MessageService_1 = require("../../../conversation/message/MessageService");
|
|
33
34
|
const EventHandler_1 = require("../EventHandler");
|
|
34
35
|
const getGenericMessageParams_1 = require("../Utility/getGenericMessageParams");
|
|
@@ -45,7 +46,7 @@ class ProteusService {
|
|
|
45
46
|
async handleEvent(params) {
|
|
46
47
|
const handledEvent = await (0, EventHandler_1.handleBackendEvent)(Object.assign(Object.assign({}, params), { decryptMessage: (payload, userId, clientId) => this.decrypt(payload, userId, clientId) }));
|
|
47
48
|
if (handledEvent === null || handledEvent === void 0 ? void 0 : handledEvent.decryptedData) {
|
|
48
|
-
const isSessionReset = handledEvent.decryptedData[
|
|
49
|
+
const isSessionReset = handledEvent.decryptedData[conversation_2.GenericMessageType.CLIENT_ACTION] === protocol_messaging_1.ClientAction.RESET_SESSION;
|
|
49
50
|
if (isSessionReset) {
|
|
50
51
|
this.logger.debug('A session was reset from a remote device');
|
|
51
52
|
// If a session reset message was received, we need to count a consumed prekey (because the sender has created a new session from a new prekey)
|
|
@@ -117,7 +118,30 @@ class ProteusService {
|
|
|
117
118
|
else {
|
|
118
119
|
payload = conversationData;
|
|
119
120
|
}
|
|
120
|
-
return this.apiClient.api.conversation.postConversation(payload)
|
|
121
|
+
return this.apiClient.api.conversation.postConversation(payload).catch(async (error) => {
|
|
122
|
+
var _a;
|
|
123
|
+
const backendError = error;
|
|
124
|
+
switch (backendError.label) {
|
|
125
|
+
case conversation_1.FederatedBackendsErrorLabel.UNREACHABLE_BACKENDS: {
|
|
126
|
+
const { backends } = backendError;
|
|
127
|
+
const users = (_a = payload.qualified_users) !== null && _a !== void 0 ? _a : [];
|
|
128
|
+
const availableUsers = [];
|
|
129
|
+
const unreachableUsers = [];
|
|
130
|
+
users.forEach(user => backends.includes(user.domain) ? unreachableUsers.push(user) : availableUsers.push(user));
|
|
131
|
+
payload = Object.assign(Object.assign({}, payload), { qualified_users: availableUsers });
|
|
132
|
+
// If conversation creation returns an error because a backend is offline,
|
|
133
|
+
// we try creating the conversation again with users from available backends
|
|
134
|
+
const response = await this.apiClient.api.conversation.postConversation(payload).catch((error) => {
|
|
135
|
+
throw error;
|
|
136
|
+
});
|
|
137
|
+
// on a succesfull conversation creation with the available users,
|
|
138
|
+
// we append the users from an unreachable backend to the response
|
|
139
|
+
response.failed_to_add = unreachableUsers;
|
|
140
|
+
return response;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
throw error;
|
|
144
|
+
});
|
|
121
145
|
}
|
|
122
146
|
async addUsersToConversation({ conversationId, qualifiedUsers }) {
|
|
123
147
|
return this.apiClient.api.conversation.postMembers(conversationId, qualifiedUsers);
|
|
@@ -144,7 +168,7 @@ class ProteusService {
|
|
|
144
168
|
}
|
|
145
169
|
this.logger.log(`Successfully sent Proteus message to conversation '${conversationId.id}'`);
|
|
146
170
|
}
|
|
147
|
-
const sendingState = response.canceled ?
|
|
171
|
+
const sendingState = response.canceled ? conversation_2.MessageSendingState.CANCELED : conversation_2.MessageSendingState.OUTGOING_SENT;
|
|
148
172
|
const failedToSend = response.failed || Object.keys((_a = response.failed_to_confirm_clients) !== null && _a !== void 0 ? _a : {}).length > 0
|
|
149
173
|
? {
|
|
150
174
|
queued: response.failed_to_confirm_clients,
|
|
@@ -474,4 +474,81 @@ describe('ProteusService', () => {
|
|
|
474
474
|
});
|
|
475
475
|
});
|
|
476
476
|
});
|
|
477
|
+
describe('createConversation', () => {
|
|
478
|
+
const newConversation = {
|
|
479
|
+
qualified_id: { id: '', domain: '' },
|
|
480
|
+
id: '',
|
|
481
|
+
type: conversation_1.CONVERSATION_TYPE.REGULAR,
|
|
482
|
+
creator: '',
|
|
483
|
+
access: [],
|
|
484
|
+
access_role: [conversation_1.CONVERSATION_ACCESS_ROLE.GUEST],
|
|
485
|
+
members: {
|
|
486
|
+
others: [],
|
|
487
|
+
self: {
|
|
488
|
+
qualified_id: { id: '', domain: '' },
|
|
489
|
+
hidden_ref: null,
|
|
490
|
+
id: '',
|
|
491
|
+
otr_archived_ref: null,
|
|
492
|
+
otr_muted_ref: null,
|
|
493
|
+
otr_muted_status: null,
|
|
494
|
+
service: null,
|
|
495
|
+
status_ref: '',
|
|
496
|
+
status_time: '',
|
|
497
|
+
},
|
|
498
|
+
},
|
|
499
|
+
failed_to_add: [],
|
|
500
|
+
protocol: conversation_1.ConversationProtocol.PROTEUS,
|
|
501
|
+
};
|
|
502
|
+
const userDomain1 = { id: 'user-1-1', domain: 'domain1' };
|
|
503
|
+
const user2Domain1 = { id: 'user-2-1', domain: 'domain1' };
|
|
504
|
+
const userDomain2 = { id: 'user-2-2', domain: 'domain2' };
|
|
505
|
+
it('adds all requested users to a new conversation', async () => {
|
|
506
|
+
const [proteusService, { apiClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
|
|
507
|
+
jest.spyOn(apiClient.api.conversation, 'postConversation').mockResolvedValueOnce(Object.assign({}, newConversation));
|
|
508
|
+
const result = await proteusService.createConversation({
|
|
509
|
+
conversationData: {
|
|
510
|
+
receipt_mode: null,
|
|
511
|
+
qualified_users: [userDomain1, user2Domain1, userDomain2],
|
|
512
|
+
},
|
|
513
|
+
});
|
|
514
|
+
expect(result).toEqual(newConversation);
|
|
515
|
+
});
|
|
516
|
+
it('partially add users if some backends are unreachable', async () => {
|
|
517
|
+
const [proteusService, { apiClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
|
|
518
|
+
const postConversationSpy = jest
|
|
519
|
+
.spyOn(apiClient.api.conversation, 'postConversation')
|
|
520
|
+
.mockRejectedValueOnce(new conversation_1.FederatedBackendsError(conversation_1.FederatedBackendsErrorLabel.UNREACHABLE_BACKENDS, [userDomain1.domain]))
|
|
521
|
+
.mockResolvedValueOnce(newConversation);
|
|
522
|
+
const result = await proteusService.createConversation({
|
|
523
|
+
conversationData: {
|
|
524
|
+
receipt_mode: null,
|
|
525
|
+
qualified_users: [userDomain1, user2Domain1, userDomain2],
|
|
526
|
+
},
|
|
527
|
+
});
|
|
528
|
+
expect(postConversationSpy).toHaveBeenCalledTimes(2);
|
|
529
|
+
expect(postConversationSpy).toHaveBeenCalledWith(expect.objectContaining({ qualified_users: [userDomain1, user2Domain1, userDomain2] }));
|
|
530
|
+
expect(postConversationSpy).toHaveBeenCalledWith(expect.objectContaining({ qualified_users: [userDomain2] }));
|
|
531
|
+
expect(result.failed_to_add).toEqual([userDomain1, user2Domain1]);
|
|
532
|
+
});
|
|
533
|
+
it('creates an empty conversation if no backend is reachable', async () => {
|
|
534
|
+
const [proteusService, { apiClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
|
|
535
|
+
const postConversationSpy = jest
|
|
536
|
+
.spyOn(apiClient.api.conversation, 'postConversation')
|
|
537
|
+
.mockRejectedValueOnce(new conversation_1.FederatedBackendsError(conversation_1.FederatedBackendsErrorLabel.UNREACHABLE_BACKENDS, [
|
|
538
|
+
userDomain1.domain,
|
|
539
|
+
userDomain2.domain,
|
|
540
|
+
]))
|
|
541
|
+
.mockResolvedValueOnce({});
|
|
542
|
+
const result = await proteusService.createConversation({
|
|
543
|
+
conversationData: {
|
|
544
|
+
receipt_mode: null,
|
|
545
|
+
qualified_users: [userDomain1, user2Domain1, userDomain2],
|
|
546
|
+
},
|
|
547
|
+
});
|
|
548
|
+
expect(postConversationSpy).toHaveBeenCalledTimes(2);
|
|
549
|
+
expect(postConversationSpy).toHaveBeenCalledWith(expect.objectContaining({ qualified_users: [userDomain1, user2Domain1, userDomain2] }));
|
|
550
|
+
expect(postConversationSpy).toHaveBeenCalledWith(expect.objectContaining({ qualified_users: [] }));
|
|
551
|
+
expect(result.failed_to_add).toEqual([userDomain1, user2Domain1, userDomain2]);
|
|
552
|
+
});
|
|
553
|
+
});
|
|
477
554
|
});
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"./lib/cryptography/AssetCryptography/crypto.node": "./lib/cryptography/AssetCryptography/crypto.browser.js"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@wireapp/api-client": "^24.21.
|
|
14
|
+
"@wireapp/api-client": "^24.21.2",
|
|
15
15
|
"@wireapp/commons": "^5.1.0",
|
|
16
16
|
"@wireapp/core-crypto": "1.0.0-rc.6",
|
|
17
17
|
"@wireapp/cryptobox": "12.8.0",
|
|
@@ -60,6 +60,6 @@
|
|
|
60
60
|
"test:coverage": "jest --coverage",
|
|
61
61
|
"watch": "tsc --watch"
|
|
62
62
|
},
|
|
63
|
-
"version": "40.9.
|
|
64
|
-
"gitHead": "
|
|
63
|
+
"version": "40.9.3",
|
|
64
|
+
"gitHead": "737803befa8e5090a776c8ceaff97d031c9f98da"
|
|
65
65
|
}
|