@wireapp/core 17.30.0 → 17.31.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/CHANGELOG.md +38 -0
- package/package.json +8 -8
- package/src/main/cryptography/GenericMessageMapper.d.ts +0 -1
- package/src/main/cryptography/GenericMessageMapper.js +23 -158
- 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 -364
- 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,214 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Wire
|
|
4
|
-
* Copyright (C) 2018 Wire Swiss GmbH
|
|
5
|
-
*
|
|
6
|
-
* This program is free software: you can redistribute it and/or modify
|
|
7
|
-
* it under the terms of the GNU General Public License as published by
|
|
8
|
-
* the Free Software Foundation, either version 3 of the License, or
|
|
9
|
-
* (at your option) any later version.
|
|
10
|
-
*
|
|
11
|
-
* This program is distributed in the hope that it will be useful,
|
|
12
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
-
* GNU General Public License for more details.
|
|
15
|
-
*
|
|
16
|
-
* You should have received a copy of the GNU General Public License
|
|
17
|
-
* along with this program. If not, see http://www.gnu.org/licenses/.
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
21
|
-
if (k2 === undefined) k2 = k;
|
|
22
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
23
|
-
}) : (function(o, m, k, k2) {
|
|
24
|
-
if (k2 === undefined) k2 = k;
|
|
25
|
-
o[k2] = m[k];
|
|
26
|
-
}));
|
|
27
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
28
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
29
|
-
}) : function(o, v) {
|
|
30
|
-
o["default"] = v;
|
|
31
|
-
});
|
|
32
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
33
|
-
if (mod && mod.__esModule) return mod;
|
|
34
|
-
var result = {};
|
|
35
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
36
|
-
__setModuleDefault(result, mod);
|
|
37
|
-
return result;
|
|
38
|
-
};
|
|
39
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
-
const http_status_codes_1 = require("http-status-codes");
|
|
41
|
-
const api_client_1 = require("@wireapp/api-client");
|
|
42
|
-
const auth_1 = require("@wireapp/api-client/src/auth");
|
|
43
|
-
const client_1 = require("@wireapp/api-client/src/client");
|
|
44
|
-
const self_1 = require("@wireapp/api-client/src/self");
|
|
45
|
-
const conversation_1 = require("@wireapp/api-client/src/conversation");
|
|
46
|
-
const http_1 = require("@wireapp/api-client/src/http");
|
|
47
|
-
const notification_1 = require("@wireapp/api-client/src/notification");
|
|
48
|
-
const commons_1 = require("@wireapp/commons");
|
|
49
|
-
const protocol_messaging_1 = require("@wireapp/protocol-messaging");
|
|
50
|
-
const Proteus = __importStar(require("@wireapp/proteus"));
|
|
51
|
-
const store_engine_1 = require("@wireapp/store-engine");
|
|
52
|
-
const nock = require("nock");
|
|
53
|
-
const Account_1 = require("./Account");
|
|
54
|
-
const conversation_2 = require("./conversation");
|
|
55
|
-
const BASE_URL = 'mock-backend.wire.com';
|
|
56
|
-
const MOCK_BACKEND = {
|
|
57
|
-
name: 'mock',
|
|
58
|
-
rest: `https://${BASE_URL}`,
|
|
59
|
-
ws: `wss://${BASE_URL}`,
|
|
60
|
-
};
|
|
61
|
-
async function createAccount(storageName = `test-${Date.now()}`) {
|
|
62
|
-
const apiClient = new api_client_1.APIClient({ urls: MOCK_BACKEND });
|
|
63
|
-
const account = new Account_1.Account(apiClient);
|
|
64
|
-
await account.initServices(new store_engine_1.MemoryEngine());
|
|
65
|
-
return account;
|
|
66
|
-
}
|
|
67
|
-
describe('Account', () => {
|
|
68
|
-
const CLIENT_ID = '4e37b32f57f6da55';
|
|
69
|
-
const accessTokenData = {
|
|
70
|
-
access_token: 'iJCRCjc8oROO-dkrkqCXOade997oa8Jhbz6awMUQPBQo80VenWqp_oNvfY6AnU5BxEsdDPOBfBP-uz_b0gAKBQ==.v=1.k=1.d=1498600993.t=a.l=.u=aaf9a833-ef30-4c22-86a0-9adc8a15b3b4.c=15037015562284012115',
|
|
71
|
-
expires_in: 900,
|
|
72
|
-
token_type: 'Bearer',
|
|
73
|
-
user: 'aaf9a833-ef30-4c22-86a0-9adc8a15b3b4',
|
|
74
|
-
};
|
|
75
|
-
beforeAll(async () => {
|
|
76
|
-
await Proteus.init();
|
|
77
|
-
});
|
|
78
|
-
beforeEach(() => {
|
|
79
|
-
nock(MOCK_BACKEND.rest)
|
|
80
|
-
.post(auth_1.AuthAPI.URL.LOGIN, body => body.email && body.password)
|
|
81
|
-
.query(() => true)
|
|
82
|
-
.reply((uri, body) => {
|
|
83
|
-
if (body.password === 'wrong') {
|
|
84
|
-
return [
|
|
85
|
-
http_status_codes_1.StatusCodes.FORBIDDEN,
|
|
86
|
-
JSON.stringify({
|
|
87
|
-
code: http_status_codes_1.StatusCodes.FORBIDDEN,
|
|
88
|
-
label: 'invalid-credentials',
|
|
89
|
-
message: 'Authentication failed.',
|
|
90
|
-
}),
|
|
91
|
-
];
|
|
92
|
-
}
|
|
93
|
-
return [http_status_codes_1.StatusCodes.OK, JSON.stringify(accessTokenData)];
|
|
94
|
-
});
|
|
95
|
-
nock(MOCK_BACKEND.rest).post(`${auth_1.AuthAPI.URL.ACCESS}/${auth_1.AuthAPI.URL.LOGOUT}`).reply(http_status_codes_1.StatusCodes.OK, undefined);
|
|
96
|
-
nock(MOCK_BACKEND.rest).post(auth_1.AuthAPI.URL.ACCESS).reply(http_status_codes_1.StatusCodes.OK, accessTokenData);
|
|
97
|
-
nock(MOCK_BACKEND.rest).post(client_1.ClientAPI.URL.CLIENTS).reply(http_status_codes_1.StatusCodes.OK, { id: CLIENT_ID });
|
|
98
|
-
nock(MOCK_BACKEND.rest)
|
|
99
|
-
.post(new RegExp(`${conversation_1.ConversationAPI.URL.CONVERSATIONS}/.*/${conversation_1.ConversationAPI.URL.OTR}/${conversation_1.ConversationAPI.URL.MESSAGES}`))
|
|
100
|
-
.query({ ignore_missing: false })
|
|
101
|
-
.reply(http_status_codes_1.StatusCodes.OK)
|
|
102
|
-
.persist();
|
|
103
|
-
nock(MOCK_BACKEND.rest)
|
|
104
|
-
.get(`${notification_1.NotificationAPI.URL.NOTIFICATION}/${notification_1.NotificationAPI.URL.LAST}`)
|
|
105
|
-
.query({ client: CLIENT_ID })
|
|
106
|
-
.reply(http_status_codes_1.StatusCodes.OK, {});
|
|
107
|
-
nock(MOCK_BACKEND.rest)
|
|
108
|
-
.get(notification_1.NotificationAPI.URL.NOTIFICATION)
|
|
109
|
-
.query({ client: CLIENT_ID, size: 10000 })
|
|
110
|
-
.reply(http_status_codes_1.StatusCodes.OK, { has_more: false, notifications: [] })
|
|
111
|
-
.persist();
|
|
112
|
-
nock(MOCK_BACKEND.rest)
|
|
113
|
-
.get(client_1.ClientAPI.URL.CLIENTS)
|
|
114
|
-
.reply(http_status_codes_1.StatusCodes.OK, [{ id: CLIENT_ID }]);
|
|
115
|
-
nock(MOCK_BACKEND.rest)
|
|
116
|
-
.get(self_1.SelfAPI.URL.SELF)
|
|
117
|
-
.reply(http_status_codes_1.StatusCodes.OK, {
|
|
118
|
-
email: 'email@example.com',
|
|
119
|
-
handle: 'exampleuser',
|
|
120
|
-
locale: 'en',
|
|
121
|
-
qualified_id: {
|
|
122
|
-
domain: 'example.com',
|
|
123
|
-
id: '024174ec-c098-4104-9424-3849804acb78',
|
|
124
|
-
},
|
|
125
|
-
accent_id: commons_1.AccentColor.AccentColorID.BRIGHT_ORANGE,
|
|
126
|
-
picture: [],
|
|
127
|
-
name: 'Example User',
|
|
128
|
-
id: '024174ec-c098-4104-9424-3849804acb78',
|
|
129
|
-
assets: [],
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
describe('"createText"', () => {
|
|
133
|
-
it('creates a text payload', async () => {
|
|
134
|
-
const account = await createAccount();
|
|
135
|
-
await account.login({
|
|
136
|
-
clientType: client_1.ClientType.TEMPORARY,
|
|
137
|
-
email: 'hello@example.com',
|
|
138
|
-
password: 'my-secret',
|
|
139
|
-
});
|
|
140
|
-
expect(account['apiClient'].context.userId).toBeDefined();
|
|
141
|
-
const text = 'FIFA World Cup';
|
|
142
|
-
const payload = account.service.conversation.messageBuilder.createText({ conversationId: '', text }).build();
|
|
143
|
-
expect(payload.timestamp).toBeGreaterThan(0);
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
describe('"init"', () => {
|
|
147
|
-
it('initializes the Protocol buffers', async () => {
|
|
148
|
-
const account = new Account_1.Account();
|
|
149
|
-
await account.initServices(new store_engine_1.MemoryEngine());
|
|
150
|
-
expect(account.service.conversation).toBeDefined();
|
|
151
|
-
expect(account.service.cryptography).toBeDefined();
|
|
152
|
-
const message = protocol_messaging_1.GenericMessage.create({
|
|
153
|
-
messageId: '2d7cb6d8-118f-11e8-b642-0ed5f89f718b',
|
|
154
|
-
text: protocol_messaging_1.Text.create({ content: 'Hello, World!' }),
|
|
155
|
-
});
|
|
156
|
-
expect(message.content).toBe('text');
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
describe('"login"', () => {
|
|
160
|
-
it('logs in with correct credentials', async () => {
|
|
161
|
-
const apiClient = new api_client_1.APIClient({ urls: MOCK_BACKEND });
|
|
162
|
-
const account = new Account_1.Account(apiClient);
|
|
163
|
-
await account.initServices(new store_engine_1.MemoryEngine());
|
|
164
|
-
const { clientId, clientType, userId } = await account.login({
|
|
165
|
-
clientType: client_1.ClientType.TEMPORARY,
|
|
166
|
-
email: 'hello@example.com',
|
|
167
|
-
password: 'my-secret',
|
|
168
|
-
});
|
|
169
|
-
expect(clientId).toBe(CLIENT_ID);
|
|
170
|
-
expect(commons_1.ValidationUtil.isUUIDv4(userId)).toBe(true);
|
|
171
|
-
expect(clientType).toBe(client_1.ClientType.TEMPORARY);
|
|
172
|
-
});
|
|
173
|
-
it('does not log in with incorrect credentials', async () => {
|
|
174
|
-
const apiClient = new api_client_1.APIClient({ urls: MOCK_BACKEND });
|
|
175
|
-
const account = new Account_1.Account(apiClient);
|
|
176
|
-
await account.initServices(new store_engine_1.MemoryEngine());
|
|
177
|
-
try {
|
|
178
|
-
await account.login({
|
|
179
|
-
clientType: client_1.ClientType.TEMPORARY,
|
|
180
|
-
email: 'hello@example.com',
|
|
181
|
-
password: 'wrong',
|
|
182
|
-
});
|
|
183
|
-
fail('Should not be logged in');
|
|
184
|
-
}
|
|
185
|
-
catch (error) {
|
|
186
|
-
const backendError = error;
|
|
187
|
-
expect(backendError.code).toBe(http_status_codes_1.StatusCodes.FORBIDDEN);
|
|
188
|
-
expect(backendError.label).toBe(http_1.BackendErrorLabel.INVALID_CREDENTIALS);
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
it('emits text messages', async (done) => {
|
|
193
|
-
const account = await createAccount();
|
|
194
|
-
await account.login({
|
|
195
|
-
clientType: client_1.ClientType.TEMPORARY,
|
|
196
|
-
email: 'hello@example.com',
|
|
197
|
-
password: 'my-secret',
|
|
198
|
-
});
|
|
199
|
-
await account.listen();
|
|
200
|
-
spyOn(account.service.notification, 'handleEvent').and.returnValue({ type: conversation_2.PayloadBundleType.TEXT });
|
|
201
|
-
account.service.notification.on(conversation_2.PayloadBundleType.TEXT, message => {
|
|
202
|
-
expect(message.type).toBe(conversation_2.PayloadBundleType.TEXT);
|
|
203
|
-
});
|
|
204
|
-
account.on(conversation_2.PayloadBundleType.TEXT, message => {
|
|
205
|
-
expect(message.type).toBe(conversation_2.PayloadBundleType.TEXT);
|
|
206
|
-
done();
|
|
207
|
-
});
|
|
208
|
-
await account.service.notification.handleNotification({
|
|
209
|
-
payload: [{}],
|
|
210
|
-
transient: true,
|
|
211
|
-
}, conversation_2.PayloadBundleSource.WEBSOCKET);
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
//# sourceMappingURL=Account.test.node.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Account.test.node.js","sourceRoot":"","sources":["Account.test.node.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;;;;;;;;;;;;;;;;;;;AAEH,yDAA6D;AAC7D,oDAA8C;AAC9C,uDAAqD;AACrD,2DAAuF;AACvF,uDAA2D;AAC3D,uEAAqE;AACrE,uDAA6E;AAC7E,uEAAmF;AACnF,8CAA6D;AAC7D,oEAAiE;AACjE,0DAA4C;AAC5C,wDAAmD;AACnD,6BAA8B;AAC9B,uCAAkC;AAClC,iDAAsE;AAEtE,MAAM,QAAQ,GAAG,uBAAuB,CAAC;AACzC,MAAM,YAAY,GAAG;IACnB,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,WAAW,QAAQ,EAAE;IAC3B,EAAE,EAAE,SAAS,QAAQ,EAAE;CACxB,CAAC;AAEF,KAAK,UAAU,aAAa,CAAC,WAAW,GAAG,QAAQ,IAAI,CAAC,GAAG,EAAE,EAAE;IAC7D,MAAM,SAAS,GAAG,IAAI,sBAAS,CAAC,EAAC,IAAI,EAAE,YAAY,EAAC,CAAC,CAAC;IACtD,MAAM,OAAO,GAAG,IAAI,iBAAO,CAAC,SAAS,CAAC,CAAC;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
* 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 {StatusCodes as HTTP_STATUS} from 'http-status-codes';
|
|
21
|
-
import {APIClient} from '@wireapp/api-client';
|
|
22
|
-
import {AuthAPI} from '@wireapp/api-client/src/auth';
|
|
23
|
-
import {ClientAPI, ClientType, RegisteredClient} from '@wireapp/api-client/src/client';
|
|
24
|
-
import {Self, SelfAPI} from '@wireapp/api-client/src/self';
|
|
25
|
-
import {ConversationAPI} from '@wireapp/api-client/src/conversation';
|
|
26
|
-
import {BackendError, BackendErrorLabel} from '@wireapp/api-client/src/http';
|
|
27
|
-
import {Notification, NotificationAPI} from '@wireapp/api-client/src/notification';
|
|
28
|
-
import {AccentColor, ValidationUtil} from '@wireapp/commons';
|
|
29
|
-
import {GenericMessage, Text} from '@wireapp/protocol-messaging';
|
|
30
|
-
import * as Proteus from '@wireapp/proteus';
|
|
31
|
-
import {MemoryEngine} from '@wireapp/store-engine';
|
|
32
|
-
import nock = require('nock');
|
|
33
|
-
import {Account} from './Account';
|
|
34
|
-
import {PayloadBundleSource, PayloadBundleType} from './conversation';
|
|
35
|
-
|
|
36
|
-
const BASE_URL = 'mock-backend.wire.com';
|
|
37
|
-
const MOCK_BACKEND = {
|
|
38
|
-
name: 'mock',
|
|
39
|
-
rest: `https://${BASE_URL}`,
|
|
40
|
-
ws: `wss://${BASE_URL}`,
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
async function createAccount(storageName = `test-${Date.now()}`): Promise<Account> {
|
|
44
|
-
const apiClient = new APIClient({urls: MOCK_BACKEND});
|
|
45
|
-
const account = new Account(apiClient);
|
|
46
|
-
await account.initServices(new MemoryEngine());
|
|
47
|
-
return account;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
describe('Account', () => {
|
|
51
|
-
const CLIENT_ID = '4e37b32f57f6da55';
|
|
52
|
-
|
|
53
|
-
const accessTokenData = {
|
|
54
|
-
access_token:
|
|
55
|
-
'iJCRCjc8oROO-dkrkqCXOade997oa8Jhbz6awMUQPBQo80VenWqp_oNvfY6AnU5BxEsdDPOBfBP-uz_b0gAKBQ==.v=1.k=1.d=1498600993.t=a.l=.u=aaf9a833-ef30-4c22-86a0-9adc8a15b3b4.c=15037015562284012115',
|
|
56
|
-
expires_in: 900,
|
|
57
|
-
token_type: 'Bearer',
|
|
58
|
-
user: 'aaf9a833-ef30-4c22-86a0-9adc8a15b3b4',
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
beforeAll(async () => {
|
|
62
|
-
await Proteus.init();
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
beforeEach(() => {
|
|
66
|
-
nock(MOCK_BACKEND.rest)
|
|
67
|
-
.post(AuthAPI.URL.LOGIN, body => body.email && body.password)
|
|
68
|
-
.query(() => true)
|
|
69
|
-
.reply((uri, body: any) => {
|
|
70
|
-
if (body.password === 'wrong') {
|
|
71
|
-
return [
|
|
72
|
-
HTTP_STATUS.FORBIDDEN,
|
|
73
|
-
JSON.stringify({
|
|
74
|
-
code: HTTP_STATUS.FORBIDDEN,
|
|
75
|
-
label: 'invalid-credentials',
|
|
76
|
-
message: 'Authentication failed.',
|
|
77
|
-
}),
|
|
78
|
-
];
|
|
79
|
-
}
|
|
80
|
-
return [HTTP_STATUS.OK, JSON.stringify(accessTokenData)];
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
nock(MOCK_BACKEND.rest).post(`${AuthAPI.URL.ACCESS}/${AuthAPI.URL.LOGOUT}`).reply(HTTP_STATUS.OK, undefined);
|
|
84
|
-
|
|
85
|
-
nock(MOCK_BACKEND.rest).post(AuthAPI.URL.ACCESS).reply(HTTP_STATUS.OK, accessTokenData);
|
|
86
|
-
|
|
87
|
-
nock(MOCK_BACKEND.rest).post(ClientAPI.URL.CLIENTS).reply(HTTP_STATUS.OK, {id: CLIENT_ID});
|
|
88
|
-
|
|
89
|
-
nock(MOCK_BACKEND.rest)
|
|
90
|
-
.post(
|
|
91
|
-
new RegExp(
|
|
92
|
-
`${ConversationAPI.URL.CONVERSATIONS}/.*/${ConversationAPI.URL.OTR}/${ConversationAPI.URL.MESSAGES}`,
|
|
93
|
-
),
|
|
94
|
-
)
|
|
95
|
-
.query({ignore_missing: false})
|
|
96
|
-
.reply(HTTP_STATUS.OK)
|
|
97
|
-
.persist();
|
|
98
|
-
|
|
99
|
-
nock(MOCK_BACKEND.rest)
|
|
100
|
-
.get(`${NotificationAPI.URL.NOTIFICATION}/${NotificationAPI.URL.LAST}`)
|
|
101
|
-
.query({client: CLIENT_ID})
|
|
102
|
-
.reply(HTTP_STATUS.OK, {});
|
|
103
|
-
|
|
104
|
-
nock(MOCK_BACKEND.rest)
|
|
105
|
-
.get(NotificationAPI.URL.NOTIFICATION)
|
|
106
|
-
.query({client: CLIENT_ID, size: 10000})
|
|
107
|
-
.reply(HTTP_STATUS.OK, {has_more: false, notifications: []})
|
|
108
|
-
.persist();
|
|
109
|
-
|
|
110
|
-
nock(MOCK_BACKEND.rest)
|
|
111
|
-
.get(ClientAPI.URL.CLIENTS)
|
|
112
|
-
.reply(HTTP_STATUS.OK, [{id: CLIENT_ID}] as RegisteredClient[]);
|
|
113
|
-
|
|
114
|
-
nock(MOCK_BACKEND.rest)
|
|
115
|
-
.get(SelfAPI.URL.SELF)
|
|
116
|
-
.reply(HTTP_STATUS.OK, {
|
|
117
|
-
email: 'email@example.com',
|
|
118
|
-
handle: 'exampleuser',
|
|
119
|
-
locale: 'en',
|
|
120
|
-
qualified_id: {
|
|
121
|
-
domain: 'example.com',
|
|
122
|
-
id: '024174ec-c098-4104-9424-3849804acb78',
|
|
123
|
-
},
|
|
124
|
-
accent_id: AccentColor.AccentColorID.BRIGHT_ORANGE,
|
|
125
|
-
picture: [],
|
|
126
|
-
name: 'Example User',
|
|
127
|
-
id: '024174ec-c098-4104-9424-3849804acb78',
|
|
128
|
-
assets: [],
|
|
129
|
-
} as Self);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
describe('"createText"', () => {
|
|
133
|
-
it('creates a text payload', async () => {
|
|
134
|
-
const account = await createAccount();
|
|
135
|
-
|
|
136
|
-
await account.login({
|
|
137
|
-
clientType: ClientType.TEMPORARY,
|
|
138
|
-
email: 'hello@example.com',
|
|
139
|
-
password: 'my-secret',
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
expect(account['apiClient'].context!.userId).toBeDefined();
|
|
143
|
-
|
|
144
|
-
const text = 'FIFA World Cup';
|
|
145
|
-
const payload = account.service!.conversation.messageBuilder.createText({conversationId: '', text}).build();
|
|
146
|
-
|
|
147
|
-
expect(payload.timestamp).toBeGreaterThan(0);
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
describe('"init"', () => {
|
|
152
|
-
it('initializes the Protocol buffers', async () => {
|
|
153
|
-
const account = new Account();
|
|
154
|
-
|
|
155
|
-
await account.initServices(new MemoryEngine());
|
|
156
|
-
|
|
157
|
-
expect(account.service!.conversation).toBeDefined();
|
|
158
|
-
expect(account.service!.cryptography).toBeDefined();
|
|
159
|
-
|
|
160
|
-
const message = GenericMessage.create({
|
|
161
|
-
messageId: '2d7cb6d8-118f-11e8-b642-0ed5f89f718b',
|
|
162
|
-
text: Text.create({content: 'Hello, World!'}),
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
expect(message.content).toBe('text');
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
describe('"login"', () => {
|
|
170
|
-
it('logs in with correct credentials', async () => {
|
|
171
|
-
const apiClient = new APIClient({urls: MOCK_BACKEND});
|
|
172
|
-
const account = new Account(apiClient);
|
|
173
|
-
|
|
174
|
-
await account.initServices(new MemoryEngine());
|
|
175
|
-
const {clientId, clientType, userId} = await account.login({
|
|
176
|
-
clientType: ClientType.TEMPORARY,
|
|
177
|
-
email: 'hello@example.com',
|
|
178
|
-
password: 'my-secret',
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
expect(clientId).toBe(CLIENT_ID);
|
|
182
|
-
expect(ValidationUtil.isUUIDv4(userId)).toBe(true);
|
|
183
|
-
expect(clientType).toBe(ClientType.TEMPORARY);
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it('does not log in with incorrect credentials', async () => {
|
|
187
|
-
const apiClient = new APIClient({urls: MOCK_BACKEND});
|
|
188
|
-
const account = new Account(apiClient);
|
|
189
|
-
|
|
190
|
-
await account.initServices(new MemoryEngine());
|
|
191
|
-
|
|
192
|
-
try {
|
|
193
|
-
await account.login({
|
|
194
|
-
clientType: ClientType.TEMPORARY,
|
|
195
|
-
email: 'hello@example.com',
|
|
196
|
-
password: 'wrong',
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
fail('Should not be logged in');
|
|
200
|
-
} catch (error) {
|
|
201
|
-
const backendError = error as BackendError;
|
|
202
|
-
expect(backendError.code).toBe(HTTP_STATUS.FORBIDDEN);
|
|
203
|
-
expect(backendError.label).toBe(BackendErrorLabel.INVALID_CREDENTIALS);
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it('emits text messages', async done => {
|
|
209
|
-
const account = await createAccount();
|
|
210
|
-
|
|
211
|
-
await account.login({
|
|
212
|
-
clientType: ClientType.TEMPORARY,
|
|
213
|
-
email: 'hello@example.com',
|
|
214
|
-
password: 'my-secret',
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
await account.listen();
|
|
218
|
-
|
|
219
|
-
spyOn<any>(account.service!.notification, 'handleEvent').and.returnValue({type: PayloadBundleType.TEXT});
|
|
220
|
-
account.service!.notification.on(PayloadBundleType.TEXT, message => {
|
|
221
|
-
expect(message.type).toBe(PayloadBundleType.TEXT);
|
|
222
|
-
});
|
|
223
|
-
account.on(PayloadBundleType.TEXT, message => {
|
|
224
|
-
expect(message.type).toBe(PayloadBundleType.TEXT);
|
|
225
|
-
done();
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
await account.service!.notification.handleNotification(
|
|
229
|
-
{
|
|
230
|
-
payload: [{}],
|
|
231
|
-
transient: true,
|
|
232
|
-
} as unknown as Notification,
|
|
233
|
-
PayloadBundleSource.WEBSOCKET,
|
|
234
|
-
);
|
|
235
|
-
});
|
|
236
|
-
});
|