Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runfix: prevent user from setting invalid supported protocols list #16217

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
"@peculiar/x509": "1.9.6",
"@wireapp/avs": "9.5.2",
"@wireapp/commons": "5.2.3",
"@wireapp/core": "43.2.0",
"@wireapp/core": "42.20.0",
"@wireapp/react-ui-kit": "9.12.3",
"@wireapp/store-engine-dexie": "2.1.7",
"@wireapp/store-engine-sqleet": "1.8.9",
"@wireapp/webapp-events": "0.18.3",
"amplify": "https://github.com/wireapp/amplify#head=master",
"beautiful-react-hooks": "^5.0.1",
Expand Down
6 changes: 6 additions & 0 deletions src/__mocks__/@wireapp/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ export class Account extends EventEmitter {
client: {
deleteClient: jest.fn(),
},
self: {
putSupportedProtocols: jest.fn(),
},
user: {
getUserSupportedProtocols: jest.fn(),
},
};
}

Expand Down
25 changes: 15 additions & 10 deletions src/script/self/SelfService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,24 @@ import type {Consent, Self} from '@wireapp/api-client/lib/self/';
import type {UserUpdate} from '@wireapp/api-client/lib/user/';
import {container} from 'tsyringe';

import {getLogger} from 'Util/Logger';

import {APIClient} from '../service/APIClientSingleton';
import {Core} from '../service/CoreSingleton';

export class SelfService {
private readonly logger = getLogger('ConversationService');
constructor(
private readonly apiClient = container.resolve(APIClient),
private readonly core = container.resolve(Core),
) {}

private get coreSelfService() {
const selfService = this.core.service?.self;

constructor(private readonly apiClient = container.resolve(APIClient)) {}
if (!selfService) {
throw new Error('Self service not available');
}

return selfService;
}

deleteSelf(password?: string): Promise<void> {
return this.apiClient.api.self.deleteSelf({password});
Expand Down Expand Up @@ -74,11 +84,6 @@ export class SelfService {
}

public async putSupportedProtocols(supportedProtocols: ConversationProtocol[]): Promise<void> {
if (!this.apiClient.backendFeatures.supportsMLS) {
this.logger.warn('Self supported protocols were not updated, because MLS is not supported by the backend');
return;
}

return this.apiClient.api.self.putSupportedProtocols(supportedProtocols);
return this.coreSelfService.putSupportedProtocols(supportedProtocols);
}
}
18 changes: 13 additions & 5 deletions src/script/user/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type {User as APIClientUser, QualifiedHandle, QualifiedId} from '@wireapp
import {container} from 'tsyringe';

import {APIClient} from '../service/APIClientSingleton';
import {Core} from '../service/CoreSingleton';
import {UserRecord} from '../storage';
import {StorageSchemata} from '../storage/StorageSchemata';
import {StorageService} from '../storage/StorageService';
Expand All @@ -33,10 +34,21 @@ export class UserService {
constructor(
private readonly storageService = container.resolve(StorageService),
private readonly apiClient = container.resolve(APIClient),
private readonly core = container.resolve(Core),
) {
this.USER_STORE_NAME = StorageSchemata.OBJECT_STORE.USERS;
}

private get coreUserService() {
const userService = this.core.service?.user;

if (!userService) {
throw new Error('User service not available');
}

return userService;
}

//##############################################################################
// Database interactions
//##############################################################################
Expand Down Expand Up @@ -154,10 +166,6 @@ export class UserService {
* Get the list of user's supported protocols.
*/
public async getUserSupportedProtocols(userId: QualifiedId): Promise<ConversationProtocol[]> {
// Clients that uses version below the one supporting MLS, are not aware of MLS, we default to Proteus in this case.
if (!this.apiClient.backendFeatures.supportsMLS) {
return [ConversationProtocol.PROTEUS];
}
return this.apiClient.api.user.getUserSupportedProtocols(userId);
return this.coreUserService.getUserSupportedProtocols(userId);
}
}
Loading
Loading