summaryrefslogtreecommitdiff
path: root/app/src/androidTest/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/androidTest/java')
-rw-r--r--app/src/androidTest/java/com/zeapo/pwdstore/MigrationsTest.kt81
-rw-r--r--app/src/androidTest/java/com/zeapo/pwdstore/git/GitServerConfigActivityTest.kt126
2 files changed, 81 insertions, 126 deletions
diff --git a/app/src/androidTest/java/com/zeapo/pwdstore/MigrationsTest.kt b/app/src/androidTest/java/com/zeapo/pwdstore/MigrationsTest.kt
new file mode 100644
index 00000000..d1b04fc3
--- /dev/null
+++ b/app/src/androidTest/java/com/zeapo/pwdstore/MigrationsTest.kt
@@ -0,0 +1,81 @@
+/*
+ * Copyright © 2014-2020 The Android Password Store Authors. All Rights Reserved.
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+@file:Suppress("DEPRECATION")
+package com.zeapo.pwdstore
+
+import android.content.Context
+import androidx.core.content.edit
+import com.zeapo.pwdstore.utils.PreferenceKeys
+import com.zeapo.pwdstore.utils.getString
+import com.zeapo.pwdstore.utils.sharedPrefs
+import org.junit.Test
+
+import org.junit.Assert.*
+
+class MigrationsTest {
+
+ private fun checkOldKeysAreRemoved(context: Context) = with(context.sharedPrefs) {
+ assertNull(getString(PreferenceKeys.GIT_REMOTE_PORT))
+ assertNull(getString(PreferenceKeys.GIT_REMOTE_USERNAME))
+ assertNull(getString(PreferenceKeys.GIT_REMOTE_SERVER))
+ assertNull(getString(PreferenceKeys.GIT_REMOTE_LOCATION))
+ }
+
+ @Test
+ fun verifySshWithCustomPortMigration() {
+ val context = Application.instance.applicationContext
+ context.sharedPrefs.edit {
+ clear()
+ putString(PreferenceKeys.GIT_REMOTE_PORT, "2200")
+ putString(PreferenceKeys.GIT_REMOTE_USERNAME, "msfjarvis")
+ putString(PreferenceKeys.GIT_REMOTE_LOCATION, "/mnt/disk3/pass-repo")
+ putString(PreferenceKeys.GIT_REMOTE_SERVER, "192.168.0.102")
+ putString(PreferenceKeys.GIT_REMOTE_PROTOCOL, "ssh://")
+ }
+ runMigrations(context)
+ checkOldKeysAreRemoved(context)
+ assertEquals(
+ context.sharedPrefs.getString(PreferenceKeys.GIT_REMOTE_URL),
+ "ssh://msfjarvis@192.168.0.102:2200/mnt/disk3/pass-repo"
+ )
+ }
+
+ @Test
+ fun verifySshWithDefaultPortMigration() {
+ val context = Application.instance.applicationContext
+ context.sharedPrefs.edit {
+ clear()
+ putString(PreferenceKeys.GIT_REMOTE_USERNAME, "msfjarvis")
+ putString(PreferenceKeys.GIT_REMOTE_LOCATION, "/mnt/disk3/pass-repo")
+ putString(PreferenceKeys.GIT_REMOTE_SERVER, "192.168.0.102")
+ putString(PreferenceKeys.GIT_REMOTE_PROTOCOL, "ssh://")
+ }
+ runMigrations(context)
+ checkOldKeysAreRemoved(context)
+ assertEquals(
+ context.sharedPrefs.getString(PreferenceKeys.GIT_REMOTE_URL),
+ "msfjarvis@192.168.0.102:/mnt/disk3/pass-repo"
+ )
+ }
+
+ @Test
+ fun verifyHttpsWithGitHubMigration() {
+ val context = Application.instance.applicationContext
+ context.sharedPrefs.edit {
+ clear()
+ putString(PreferenceKeys.GIT_REMOTE_USERNAME, "msfjarvis")
+ putString(PreferenceKeys.GIT_REMOTE_LOCATION, "Android-Password-Store/pass-test")
+ putString(PreferenceKeys.GIT_REMOTE_SERVER, "github.com")
+ putString(PreferenceKeys.GIT_REMOTE_PROTOCOL, "https://")
+ }
+ runMigrations(context)
+ checkOldKeysAreRemoved(context)
+ assertEquals(
+ context.sharedPrefs.getString(PreferenceKeys.GIT_REMOTE_URL),
+ "https://github.com/Android-Password-Store/pass-test"
+ )
+ }
+}
diff --git a/app/src/androidTest/java/com/zeapo/pwdstore/git/GitServerConfigActivityTest.kt b/app/src/androidTest/java/com/zeapo/pwdstore/git/GitServerConfigActivityTest.kt
deleted file mode 100644
index 2c2691b1..00000000
--- a/app/src/androidTest/java/com/zeapo/pwdstore/git/GitServerConfigActivityTest.kt
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright © 2014-2020 The Android Password Store Authors. All Rights Reserved.
- * SPDX-License-Identifier: GPL-3.0-only
- */
-
-package com.zeapo.pwdstore.git
-
-import android.view.View
-import androidx.test.espresso.Espresso.onView
-import androidx.test.espresso.UiController
-import androidx.test.espresso.ViewAction
-import androidx.test.espresso.action.ViewActions.replaceText
-import androidx.test.espresso.matcher.ViewMatchers.isEnabled
-import androidx.test.espresso.matcher.ViewMatchers.withId
-import androidx.test.ext.junit.runners.AndroidJUnit4
-import androidx.test.rule.ActivityTestRule
-import com.google.android.material.button.MaterialButtonToggleGroup
-import com.zeapo.pwdstore.R
-import com.zeapo.pwdstore.git.BaseGitActivity.GitUpdateUrlResult
-import kotlin.test.assertEquals
-import org.hamcrest.Matcher
-import org.junit.Rule
-import org.junit.Test
-import org.junit.runner.RunWith
-
-@RunWith(AndroidJUnit4::class)
-class GitServerConfigActivityTest {
-
- @Rule
- @JvmField
- val activityRule = ActivityTestRule(GitServerConfigActivity::class.java, true)
-
- private val activity get() = activityRule.activity
-
- @Test
- fun invalidValuesFailPredictably() {
- setDefaultSshValues()
- onView(withId(R.id.server_port)).perform(replaceText("69420"))
- assertEquals(activity.updateUrl(), GitUpdateUrlResult.CustomPortRequiresAbsoluteUrlError)
-
- setDefaultSshValues()
- onView(withId(R.id.server_url)).perform(replaceText(""))
- assertEquals(activity.updateUrl(), GitUpdateUrlResult.EmptyHostnameError)
-
- setDefaultSshValues()
- onView(withId(R.id.server_port)).perform(replaceText("xyz_is_not_a_port"))
- assertEquals(activity.updateUrl(), GitUpdateUrlResult.NonNumericPortError)
-
- setDefaultHttpsValues()
- onView(withId(R.id.server_port)).perform(replaceText("xyz_is_not_a_port"))
- assertEquals(activity.updateUrl(), GitUpdateUrlResult.NonNumericPortError)
-
- setDefaultHttpsValues()
- onView(withId(R.id.server_url)).perform(replaceText(""))
- assertEquals(activity.updateUrl(), GitUpdateUrlResult.EmptyHostnameError)
- }
-
- @Test
- fun urlIsConstructedCorrectly() {
- setDefaultSshValues()
- activity.updateUrl()
- assertEquals("john_doe@github.com:john_doe/my_secret_repository", activity.url)
-
- setDefaultSshValues()
- onView(withId(R.id.server_port)).perform(replaceText("69420"))
- onView(withId(R.id.server_url)).perform(replaceText("192.168.0.102"))
- onView(withId(R.id.server_path)).perform(replaceText("/home/john_doe/my_secret_repository"))
- activity.updateUrl()
- assertEquals("ssh://john_doe@192.168.0.102:69420/home/john_doe/my_secret_repository", activity.url)
-
- setDefaultHttpsValues()
- activity.updateUrl()
- assertEquals("https://github.com/john_doe/my_secret_repository", activity.url)
-
- setDefaultHttpsValues()
- onView(withId(R.id.server_port)).perform(replaceText("69420"))
- onView(withId(R.id.server_url)).perform(replaceText("192.168.0.102"))
- onView(withId(R.id.server_path)).perform(replaceText("/home/john_doe/my_secret_repository"))
- activity.updateUrl()
- assertEquals("https://192.168.0.102:69420/home/john_doe/my_secret_repository", activity.url)
- }
-
- private fun <T> callMethod(message: String = "", viewMethod: (view: T) -> Unit): ViewAction {
- return object : ViewAction {
- override fun getDescription(): String {
- return if (message.isBlank()) viewMethod.toString() else message
- }
-
- override fun getConstraints(): Matcher<View> {
- return isEnabled()
- }
-
- @Suppress("UNCHECKED_CAST")
- override fun perform(uiController: UiController?, view: View?) {
- viewMethod(view!! as T)
- }
-
- }
- }
-
- private fun setDefaultHttpsValues() {
- onView(withId(R.id.clone_protocol_group)).perform(callMethod<MaterialButtonToggleGroup> {
- it.check(R.id.clone_protocol_https)
- })
- onView(withId(R.id.connection_mode_group)).perform(callMethod<MaterialButtonToggleGroup> {
- it.check(R.id.connection_mode_password)
- })
- onView(withId(R.id.server_path)).perform(replaceText("john_doe/my_secret_repository"))
- onView(withId(R.id.server_port)).perform(replaceText(""))
- onView(withId(R.id.server_url)).perform(replaceText("github.com"))
- onView(withId(R.id.server_user)).perform(replaceText("john_doe"))
- }
-
- private fun setDefaultSshValues() {
- onView(withId(R.id.clone_protocol_group)).perform(callMethod<MaterialButtonToggleGroup> {
- it.check(R.id.clone_protocol_ssh)
- })
- onView(withId(R.id.connection_mode_group)).perform(callMethod<MaterialButtonToggleGroup> {
- it.check(R.id.connection_mode_ssh_key)
- })
- onView(withId(R.id.server_path)).perform(replaceText("john_doe/my_secret_repository"))
- onView(withId(R.id.server_port)).perform(replaceText(""))
- onView(withId(R.id.server_url)).perform(replaceText("github.com"))
- onView(withId(R.id.server_user)).perform(replaceText("john_doe"))
- }
-}