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: Validate other members UserName and DisplayName in E2EI [WPB-10402] #2932

Conversation

borichellow
Copy link
Contributor

What's new in this PR?

Issues

The checking "if user has valid E2EI" was not full in Participants list and UserProfile.
We should also check if users displayName and handle are the same as in E2EI certificate.

Causes (Optional)

Was not implemented.

Solutions

Implement it and add/update tests for new scenarios.

@@ -114,13 +114,13 @@ internal class FetchMLSVerificationStatusUseCaseImpl(
// check that all identities are valid and name and handle are matching
for ((userId, wireIdentity) in ccIdentity) {
val persistedMemberInfo = dbData.members[userId]
val isUserVerified = wireIdentity.firstOrNull {
val isUserVerified = wireIdentity.none {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

Copy link
Contributor

github-actions bot commented Aug 5, 2024

Test Results

2 912 tests   2 894 ✔️  9m 0s ⏱️
       7 suites       18 💤
       7 files           0

Results for commit cfe4f33.

♻️ This comment has been updated with latest results.

Comment on lines 39 to 45
override suspend operator fun invoke(userId: UserId): Boolean =
if (isE2EIEnabledUseCase()) {
mlsConversationRepository.getUserIdentity(userId).fold({ false }, { it.isUserMLSVerified() }
)
val nameHandle = userRepository.getNameAndHandler(userId).getOrNull()
mlsConversationRepository.getUserIdentity(userId).fold({ false }, { it.isUserMLSVerified(nameHandle) })
} else {
false
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion:
override suspend operator fun invoke(userId: UserId): Boolean = isE2EIEnabledUseCase() && userRepository.getNameAndHandler(userId).getOrNull()?.let { nameHandle -> mlsConversationRepository.getUserIdentity(userId).fold( onSuccess = { it.isUserMLSVerified(nameHandle) }, onFailure = { false } ) } ?: false

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried even shorter:

override suspend operator fun invoke(userId: UserId): Boolean =
    isE2EIEnabledUseCase() && userRepository.getNameAndHandler(userId).flatMap { nameHandle ->
        mlsConversationRepository.getUserIdentity(userId).map { it.isUserMLSVerified(nameHandle) }
    }.getOrElse(false)

but i don't like it. Yes it's 3 lines instead of 6, but IMO if else is more readable and easier to understand in that case :)

Copy link
Contributor

@mchenani mchenani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, and one suggestion 🙌

@datadog-wireapp
Copy link

datadog-wireapp bot commented Aug 5, 2024

Datadog Report

All test runs abeee6b 🔗

2 Total Test Services: 0 Failed, 2 Passed

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Test Service View
kalium-ios 0 0 0 2799 123 1.37s Link
kalium-jvm 0 0 0 2947 107 5.27s Link

Copy link
Contributor

@alexandreferris alexandreferris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! I just have a tiny suggestion on naming in UserDAO

@borichellow borichellow enabled auto-merge (squash) August 8, 2024 13:54
Copy link

sonarqubecloud bot commented Aug 8, 2024

@borichellow borichellow merged commit ddddd54 into release/android-cycle-4.6 Aug 8, 2024
19 checks passed
@borichellow borichellow deleted the fix/validate_other_members_username_and_displayname_in_e2ei branch August 8, 2024 14:37
@echoes-hq echoes-hq bot added the echoes: unplanned Any work item that isn’t part of the product or technical roadmap. label Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
echoes: unplanned Any work item that isn’t part of the product or technical roadmap. 🚨 Potential breaking changes 👕 size: M type: bug / fix 🐞
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants