-
Notifications
You must be signed in to change notification settings - Fork 859
Skipping passphrase screen when no passphrase is available #4115
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
edce14f
when the keyinfo doesn't contain a passphrase we shouldn't view the p…
ouchadam daa3125
adding test cases around the SharedSecureStorageViewModel initial sta…
ouchadam b55e94b
extracting the rx instant setup to a reuseable test rule
ouchadam 984ab08
adding changelog entry
ouchadam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,2 @@ | ||
| Fixes the passphrase screen being incorrectly shown when pressing back on the key verification screen. | ||
| When the user doesn't have a passphrase set we don't show the passphrase screen. |
This file contains hidden or 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
44 changes: 44 additions & 0 deletions
44
vector/src/test/java/androidx/lifecycle/LifecycleRegistry.kt
This file contains hidden or 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,44 @@ | ||
| /* | ||
| * Copyright (c) 2021 New Vector Ltd | ||
| * | ||
| * 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 androidx.lifecycle | ||
|
|
||
| /** | ||
| * Manual test override to stop BaseMvRxViewModel from interacting with the android looper/main thread | ||
| * Tests will run on their original test worker threads | ||
| * | ||
| * This has been fixed is newer versions of Mavericks via LifecycleRegistry.createUnsafe | ||
| * https://github.com/airbnb/mavericks/blob/master/mvrx-rxjava2/src/main/kotlin/com/airbnb/mvrx/BaseMvRxViewModel.kt#L61 | ||
| */ | ||
| @Suppress("UNUSED") | ||
| class LifecycleRegistry(@Suppress("UNUSED_PARAMETER") lifecycleOwner: LifecycleOwner) : Lifecycle() { | ||
|
|
||
| private var state = State.INITIALIZED | ||
|
|
||
| fun setCurrentState(state: State) { | ||
| this.state = state | ||
| } | ||
|
|
||
| override fun addObserver(observer: LifecycleObserver) { | ||
| TODO("Not yet implemented") | ||
| } | ||
|
|
||
| override fun removeObserver(observer: LifecycleObserver) { | ||
| TODO("Not yet implemented") | ||
| } | ||
|
|
||
| override fun getCurrentState() = state | ||
| } |
This file contains hidden or 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
148 changes: 148 additions & 0 deletions
148
vector/src/test/java/im/vector/app/features/crypto/quads/SharedSecureStorageViewModelTest.kt
This file contains hidden or 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,148 @@ | ||
| /* | ||
| * Copyright (c) 2021 New Vector Ltd | ||
| * | ||
| * 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 im.vector.app.features.crypto.quads | ||
|
|
||
| import com.airbnb.mvrx.Uninitialized | ||
| import im.vector.app.test.InstantRxRule | ||
| import im.vector.app.test.fakes.FakeSession | ||
| import im.vector.app.test.fakes.FakeStringProvider | ||
| import im.vector.app.test.test | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import org.matrix.android.sdk.api.session.securestorage.IntegrityResult | ||
| import org.matrix.android.sdk.api.session.securestorage.KeyInfo | ||
| import org.matrix.android.sdk.api.session.securestorage.KeyInfoResult | ||
| import org.matrix.android.sdk.api.session.securestorage.SecretStorageKeyContent | ||
| import org.matrix.android.sdk.api.session.securestorage.SsssPassphrase | ||
|
|
||
| private const val IGNORED_PASSPHRASE_INTEGRITY = false | ||
| private val KEY_INFO_WITH_PASSPHRASE = KeyInfo( | ||
| id = "id", | ||
| content = SecretStorageKeyContent(passphrase = SsssPassphrase(null, 0, null)) | ||
| ) | ||
| private val KEY_INFO_WITHOUT_PASSPHRASE = KeyInfo(id = "id", content = SecretStorageKeyContent(passphrase = null)) | ||
|
|
||
| class SharedSecureStorageViewModelTest { | ||
|
|
||
| @get:Rule | ||
| val instantRx = InstantRxRule() | ||
|
|
||
| private val stringProvider = FakeStringProvider() | ||
| private val session = FakeSession() | ||
|
|
||
| @Test | ||
| fun `given a key info with passphrase when initialising then step is EnterPassphrase`() { | ||
| givenKey(KEY_INFO_WITH_PASSPHRASE) | ||
|
|
||
| val viewModel = createViewModel() | ||
|
|
||
| viewModel.test().assertState(aViewState( | ||
| hasPassphrase = true, | ||
| step = SharedSecureStorageViewState.Step.EnterPassphrase | ||
| )) | ||
| } | ||
|
|
||
| @Test | ||
| fun `given a key info without passphrase when initialising then step is EnterKey`() { | ||
| givenKey(KEY_INFO_WITHOUT_PASSPHRASE) | ||
|
|
||
| val viewModel = createViewModel() | ||
|
|
||
| viewModel.test().assertState(aViewState( | ||
| hasPassphrase = false, | ||
| step = SharedSecureStorageViewState.Step.EnterKey | ||
| )) | ||
| } | ||
|
|
||
| @Test | ||
| fun `given on EnterKey step when going back then dismisses`() { | ||
| givenKey(KEY_INFO_WITHOUT_PASSPHRASE) | ||
|
|
||
| val viewModel = createViewModel() | ||
| val test = viewModel.test() | ||
|
|
||
| viewModel.handle(SharedSecureStorageAction.Back) | ||
|
|
||
| test.assertEvents(SharedSecureStorageViewEvent.Dismiss) | ||
| } | ||
|
|
||
| @Test | ||
| fun `given on passphrase step when using key then step is EnterKey`() { | ||
| givenKey(KEY_INFO_WITH_PASSPHRASE) | ||
| val viewModel = createViewModel() | ||
| val test = viewModel.test() | ||
|
|
||
| viewModel.handle(SharedSecureStorageAction.UseKey) | ||
|
|
||
| test.assertState(aViewState( | ||
| hasPassphrase = true, | ||
| step = SharedSecureStorageViewState.Step.EnterKey | ||
| )) | ||
| } | ||
|
|
||
| @Test | ||
| fun `given a key info with passphrase and on EnterKey step when going back then step is EnterPassphrase`() { | ||
| givenKey(KEY_INFO_WITH_PASSPHRASE) | ||
| val viewModel = createViewModel() | ||
| val test = viewModel.test() | ||
|
|
||
| viewModel.handle(SharedSecureStorageAction.UseKey) | ||
| viewModel.handle(SharedSecureStorageAction.Back) | ||
|
|
||
| test.assertState(aViewState( | ||
| hasPassphrase = true, | ||
| step = SharedSecureStorageViewState.Step.EnterPassphrase | ||
| )) | ||
| } | ||
|
|
||
| @Test | ||
| fun `given on passphrase step when going back then dismisses`() { | ||
| givenKey(KEY_INFO_WITH_PASSPHRASE) | ||
| val viewModel = createViewModel() | ||
| val test = viewModel.test() | ||
|
|
||
| viewModel.handle(SharedSecureStorageAction.Back) | ||
|
|
||
| test.assertEvents(SharedSecureStorageViewEvent.Dismiss) | ||
| } | ||
|
|
||
| private fun createViewModel() = SharedSecureStorageViewModel( | ||
| SharedSecureStorageViewState(), | ||
| SharedSecureStorageActivity.Args(keyId = null, emptyList(), "alias"), | ||
| stringProvider.instance, | ||
| session | ||
| ) | ||
|
|
||
| private fun aViewState(hasPassphrase: Boolean, step: SharedSecureStorageViewState.Step) = SharedSecureStorageViewState( | ||
| ready = true, | ||
| hasPassphrase = hasPassphrase, | ||
| checkingSSSSAction = Uninitialized, | ||
| step = step, | ||
| activeDeviceCount = 0, | ||
| showResetAllAction = false, | ||
| userId = "" | ||
| ) | ||
|
|
||
| private fun givenKey(keyInfo: KeyInfo) { | ||
| givenHasAccessToSecrets() | ||
| session.fakeSharedSecretStorageService._defaultKey = KeyInfoResult.Success(keyInfo) | ||
| } | ||
|
|
||
| private fun givenHasAccessToSecrets() { | ||
| session.fakeSharedSecretStorageService.integrityResult = IntegrityResult.Success(passphraseBased = IGNORED_PASSPHRASE_INTEGRITY) | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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,32 @@ | ||
| /* | ||
| * Copyright (c) 2021 New Vector Ltd | ||
| * | ||
| * 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 im.vector.app.test | ||
|
|
||
| import io.reactivex.android.plugins.RxAndroidPlugins | ||
| import io.reactivex.plugins.RxJavaPlugins | ||
| import io.reactivex.schedulers.Schedulers | ||
| import org.junit.rules.TestRule | ||
| import org.junit.runner.Description | ||
| import org.junit.runners.model.Statement | ||
|
|
||
| class InstantRxRule : TestRule { | ||
| override fun apply(base: Statement, description: Description?): Statement { | ||
| RxJavaPlugins.setInitNewThreadSchedulerHandler { Schedulers.trampoline() } | ||
| RxAndroidPlugins.setInitMainThreadSchedulerHandler { Schedulers.trampoline() } | ||
| return base | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this block is the fix, everything else in this PR is for the unit tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perfect, thanks!