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

fix: dont run the MLSStateHandler without MLS enabled #15994

Merged
merged 4 commits into from
Oct 12, 2023
Merged
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
16 changes: 10 additions & 6 deletions src/script/conversation/ConversationRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import {
} from 'Util/StringUtil';
import {TIME_IN_MILLIS} from 'Util/TimeUtil';
import {isBackendError} from 'Util/TypePredicateUtil';
import {supportsMLS} from 'Util/util';
import {createUuid} from 'Util/uuid';

import {ACCESS_STATE} from './AccessState';
Expand Down Expand Up @@ -272,12 +273,15 @@ export class ConversationRepository {
this.userState,
this.conversationState,
);
// we register a handler that will handle MLS conversations on its own
registerMLSConversationVerificationStateHandler(
this.onConversationVerificationStateChange,
this.conversationState,
this.core,
);

if (supportsMLS()) {
// we register a handler that will handle MLS conversations on its own
registerMLSConversationVerificationStateHandler(
this.onConversationVerificationStateChange,
this.conversationState,
this.core,
);
}

this.isBlockingNotificationHandling = true;
this.conversationsWithNewEvents = new Map();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,25 @@ import {ConversationProtocol} from '@wireapp/api-client/lib/conversation/NewConv

import {Conversation} from 'src/script/entity/Conversation';
import {Core} from 'src/script/service/CoreSingleton';
import {getLogger, Logger} from 'Util/Logger';
import {createUuid} from 'Util/uuid';

import {MLSConversationVerificationStateHandler} from './MLSStateHandler';
import {
MLSConversationVerificationStateHandler,
registerMLSConversationVerificationStateHandler,
} from './MLSStateHandler';

import {ConversationState} from '../../ConversationState';

jest.mock('Util/Logger', () => ({
getLogger: jest.fn().mockReturnValue({
error: jest.fn(),
log: jest.fn(),
}),
}));

describe('MLSConversationVerificationStateHandler', () => {
const uuid = createUuid();
let handler: MLSConversationVerificationStateHandler;
let mockOnConversationVerificationStateChange: jest.Mock;
let mockConversationState: jest.Mocked<ConversationState>;
let mockCore: jest.Mocked<Core>;
let logger: jest.Mocked<Logger>;
const conversation: Conversation = new Conversation(uuid, '', ConversationProtocol.MLS);
const groupId = 'groupIdXYZ';

beforeEach(() => {
jest.clearAllMocks();
conversation.groupId = groupId;

mockOnConversationVerificationStateChange = jest.fn();
Expand All @@ -67,37 +60,38 @@ describe('MLSConversationVerificationStateHandler', () => {
mockConversationState,
mockCore,
);
logger = getLogger('MLSConversationVerificationStateHandler') as jest.Mocked<Logger>;

jest.clearAllMocks();
});

it('should log an error if MLS service is not available', () => {
it('should do nothing if MLS service is not available', () => {
mockCore.service.mls = undefined;

new MLSConversationVerificationStateHandler(
mockOnConversationVerificationStateChange,
mockConversationState,
mockCore,
);
const t = () =>
registerMLSConversationVerificationStateHandler(
mockOnConversationVerificationStateChange,
mockConversationState,
mockCore,
);

// Assert
expect(logger.error).toHaveBeenCalledWith('MLS service not available');
expect(t).not.toThrow();
});

it('should log an error if e2eIdentity service is not available', () => {
it('should do nothing if e2eIdentity service is not available', () => {
mockCore.service.e2eIdentity = undefined;

new MLSConversationVerificationStateHandler(
registerMLSConversationVerificationStateHandler(
mockOnConversationVerificationStateChange,
mockConversationState,
mockCore,
);

// Assert
expect(logger.error).toHaveBeenCalledWith('E2E identity service not available');
expect(mockCore.service?.mls?.on).not.toHaveBeenCalled();
});

it('should hook into the newEpoch event of the MLS service', () => {
new MLSConversationVerificationStateHandler(
registerMLSConversationVerificationStateHandler(
mockOnConversationVerificationStateChange,
mockConversationState,
mockCore,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,11 @@ export class MLSConversationVerificationStateHandler {
private readonly core = container.resolve(Core),
) {
this.logger = getLogger('MLSConversationVerificationStateHandler');
// We need to check if the core service is available
if (!this.core.service?.mls) {
this.logger.error('MLS service not available');
return;
}
// We need to check if the e2eIdentity service is available
if (!this.core.service?.e2eIdentity) {
this.logger.error('E2E identity service not available');
// We need to check if the core service is available and if the e2eIdentity is available
if (!this.core.service?.mls || !this.core.service?.e2eIdentity) {
return;
}

// We hook into the newEpoch event of the MLS service to check if the conversation needs to be verified or degraded
this.core.service.mls.on('newEpoch', this.checkEpoch);
}
Expand Down
Loading