-
Notifications
You must be signed in to change notification settings - Fork 750
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3739 from vector-im/feature/bca/accept_unbound_3p…
…id_invite support email invite
- Loading branch information
Showing
28 changed files
with
512 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Support accept 3pid invite when email is not bound to account |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Update Email invite to be aware of spaces |
60 changes: 60 additions & 0 deletions
60
matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/PermalinkParserTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2021 The Matrix.org Foundation C.I.C. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.matrix.android.sdk | ||
|
||
import org.junit.Assert | ||
import org.junit.FixMethodOrder | ||
import org.junit.Test | ||
import org.junit.runners.MethodSorters | ||
import org.matrix.android.sdk.api.session.permalinks.PermalinkData | ||
import org.matrix.android.sdk.api.session.permalinks.PermalinkParser | ||
|
||
@FixMethodOrder(MethodSorters.JVM) | ||
class PermalinkParserTest { | ||
|
||
@Test | ||
fun testParseEmailInvite() { | ||
val rawInvite = """ | ||
https://app.element.io/#/room/%21MRBNLPtFnMAazZVPMO%3Amatrix.org?email=bob%2Bspace%40example.com&signurl=https%3A%2F%2Fvector.im%2F_matrix%2Fidentity%2Fapi%2Fv1%2Fsign-ed25519%3Ftoken%3DXmOwRZnSFabCRhTywFbJWKXWVNPysOpXIbroMGaUymqkJSvHeVKRsjHajwjCYdBsvGSvHauxbKfJmOxtXldtyLnyBMLKpBQCMzyYggrdapbVIceWZBtmslOQrXLABRoe%26private_key%3DT2gq0c3kJB_8OroXVxl1pBnzHsN7V6Xn4bEBSeW1ep4&room_name=Team2&room_avatar_url=&inviter_name=hiphop5&guest_access_token=&guest_user_id= | ||
""".trimIndent() | ||
.replace("https://app.element.io/#/room/", "https://matrix.to/#/") | ||
|
||
val parsedLink = PermalinkParser.parse(rawInvite) | ||
Assert.assertTrue("Should be parsed as email invite but was ${parsedLink::class.java}", parsedLink is PermalinkData.RoomEmailInviteLink) | ||
parsedLink as PermalinkData.RoomEmailInviteLink | ||
Assert.assertEquals("!MRBNLPtFnMAazZVPMO:matrix.org", parsedLink.roomId) | ||
Assert.assertEquals("XmOwRZnSFabCRhTywFbJWKXWVNPysOpXIbroMGaUymqkJSvHeVKRsjHajwjCYdBsvGSvHauxbKfJmOxtXldtyLnyBMLKpBQCMzyYggrdapbVIceWZBtmslOQrXLABRoe", parsedLink.token) | ||
Assert.assertEquals("vector.im", parsedLink.identityServer) | ||
Assert.assertEquals("Team2", parsedLink.roomName) | ||
Assert.assertEquals("hiphop5", parsedLink.inviterName) | ||
} | ||
|
||
@Test | ||
fun testParseLinkWIthEvent() { | ||
val rawInvite = "https://matrix.to/#/!OGEhHVWSdvArJzumhm:matrix.org/\$xuvJUVDJnwEeVjPx029rAOZ50difpmU_5gZk_T0jGfc?via=matrix.org&via=libera.chat&via=matrix.example.io" | ||
|
||
val parsedLink = PermalinkParser.parse(rawInvite) | ||
Assert.assertTrue("Should be parsed as room link", parsedLink is PermalinkData.RoomLink) | ||
parsedLink as PermalinkData.RoomLink | ||
Assert.assertEquals("!OGEhHVWSdvArJzumhm:matrix.org", parsedLink.roomIdOrAlias) | ||
Assert.assertEquals("\$xuvJUVDJnwEeVjPx029rAOZ50difpmU_5gZk_T0jGfc", parsedLink.eventId) | ||
Assert.assertEquals(3, parsedLink.viaParameters.size) | ||
Assert.assertTrue(parsedLink.viaParameters.contains("matrix.example.io")) | ||
Assert.assertTrue(parsedLink.viaParameters.contains("matrix.org")) | ||
Assert.assertTrue(parsedLink.viaParameters.contains("matrix.example.io")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
.../src/main/java/org/matrix/android/sdk/internal/session/identity/Sign3pidInvitationTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2021 The Matrix.org Foundation C.I.C. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.matrix.android.sdk.internal.session.identity | ||
|
||
import dagger.Lazy | ||
import okhttp3.OkHttpClient | ||
import org.matrix.android.sdk.internal.di.Unauthenticated | ||
import org.matrix.android.sdk.internal.di.UserId | ||
import org.matrix.android.sdk.internal.network.RetrofitFactory | ||
import org.matrix.android.sdk.internal.session.identity.model.SignInvitationResult | ||
import org.matrix.android.sdk.internal.task.Task | ||
import javax.inject.Inject | ||
|
||
internal interface Sign3pidInvitationTask : Task<Sign3pidInvitationTask.Params, SignInvitationResult> { | ||
data class Params( | ||
val token: String, | ||
val url: String, | ||
val privateKey: String | ||
) | ||
} | ||
|
||
internal class DefaultSign3pidInvitationTask @Inject constructor( | ||
@Unauthenticated | ||
private val okHttpClient: Lazy<OkHttpClient>, | ||
private val retrofitFactory: RetrofitFactory, | ||
@UserId private val userId: String | ||
) : Sign3pidInvitationTask { | ||
|
||
override suspend fun execute(params: Sign3pidInvitationTask.Params): SignInvitationResult { | ||
val identityAPI = retrofitFactory | ||
.create(okHttpClient, "https://${params.url}") | ||
.create(IdentityAPI::class.java) | ||
return identityAPI.signInvitationDetails(params.token, params.privateKey, userId) | ||
} | ||
} |
Oops, something went wrong.