Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
3d31e3d
Renamed ChangePassPhraseActivity to ChangePassphraseOfImportedKeysFra…
DenBond7 Jun 28, 2021
fe3907e
wip| #1303
DenBond7 Jun 28, 2021
a4fd6dd
Renamed ChangePassphraseOfImportedKeysFragment to ApplyNewPassphraseF…
DenBond7 Jun 28, 2021
8fe06ad
ApplyNewPassphraseFirstStepFragment. Added some logic. Modified InfoD…
DenBond7 Jun 28, 2021
14f887d
ApplyNewPassphraseFirstStepFragment. Added more logic.| #1303
DenBond7 Jun 28, 2021
ee17d9b
Renamed ApplyNewPassphraseFirstStepFragment to CheckPassphraseStrengt…
DenBond7 Jun 28, 2021
6480d69
Renamed some resources.| #1303
DenBond7 Jun 28, 2021
099d088
Moved CheckPassphraseStrengthFragment to ui/activity/fragment.| #1303
DenBond7 Jun 28, 2021
8acc2d4
Added RecheckProvidedPassphraseFragment.| #1303
DenBond7 Jun 28, 2021
0f68b3b
Added ChangePassphraseOfImportedKeysFragment.| #1303
DenBond7 Jun 29, 2021
6643c1b
Modified navigation between fragments.| #1303
DenBond7 Jun 29, 2021
e6a0c10
Fixed navigation in BackupKeysFragment.| #1303
DenBond7 Jun 29, 2021
f45d1d8
Improved navigation between fragments.| #1303
DenBond7 Jun 29, 2021
fbb96c6
Fixed a bug in ChangePassphraseOfImportedKeysFragment.| #1303
DenBond7 Jun 29, 2021
807c9ae
Refactored code.| #1303
DenBond7 Jun 29, 2021
0d0018d
Restored fragment_info_in_webview.xml.| #1303
DenBond7 Jun 29, 2021
adaa361
Fixed intent in SystemNotificationManager.| #1303
DenBond7 Jun 29, 2021
b035083
Modified tests. Refactored code.| #1303
DenBond7 Jun 29, 2021
3ef59a5
Fixed lint warnings.| #1303
DenBond7 Jun 30, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@

package com.flowcrypt.email.ui.activity

import android.app.Activity
import android.app.Instrumentation
import android.content.ComponentName
import androidx.lifecycle.Lifecycle
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.intent.Intents.intending
import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
Expand All @@ -29,7 +23,6 @@ import com.flowcrypt.email.rules.ClearAppSettingsRule
import com.flowcrypt.email.rules.RetryRule
import com.flowcrypt.email.rules.ScreenshotTestRule
import com.flowcrypt.email.ui.activity.base.BaseBackupKeysFragmentTest
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
Expand Down Expand Up @@ -76,34 +69,6 @@ class BackupKeysFragmentSingleKeyWeakPassphraseTest : BaseBackupKeysFragmentTest
.check(matches(isDisplayed()))
}

@Test
@DependsOnMailServer
@NotReadyForCI
fun testFixWeakPasswordForEmailOption() {
onView(withId(R.id.btBackup))
.check(matches(isDisplayed()))
.perform(click())
intending(hasComponent(ComponentName(getTargetContext(), ChangePassPhraseActivity::class.java)))
.respondWith(Instrumentation.ActivityResult(Activity.RESULT_OK, null))
checkIsSnackbarDisplayedAndClick(getResString(R.string.pass_phrase_is_too_weak))
assertTrue(activityScenarioRule.scenario.state == Lifecycle.State.RESUMED)
}

@Test
fun testFixWeakPasswordForDownloadOption() {
onView(withId(R.id.rBDownloadOption))
.check(matches(isDisplayed()))
.perform(click())
intendingFileChoose(File(""))
onView(withId(R.id.btBackup))
.check(matches(isDisplayed()))
.perform(click())
intending(hasComponent(ComponentName(getTargetContext(), ChangePassPhraseActivity::class.java)))
.respondWith(Instrumentation.ActivityResult(Activity.RESULT_OK, null))
checkIsSnackbarDisplayedAndClick(getResString(R.string.pass_phrase_is_too_weak))
assertTrue(activityScenarioRule.scenario.state == Lifecycle.State.RESUMED)
}

@Test
@DependsOnMailServer
@NotReadyForCI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@

package com.flowcrypt.email.ui.activity

import android.app.Activity
import android.app.Instrumentation
import android.content.ComponentName
import androidx.lifecycle.Lifecycle
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.intent.Intents.intending
import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.runners.AndroidJUnit4
Expand Down Expand Up @@ -70,8 +65,8 @@ class BackupKeysFragmentTwoKeysDiffPassphrasesTest : BaseBackupKeysFragmentTest(
onView(withId(R.id.btBackup))
.check(matches(isDisplayed()))
.perform(click())
intending(hasComponent(ComponentName(getTargetContext(), ChangePassPhraseActivity::class.java)))
.respondWith(Instrumentation.ActivityResult(Activity.RESULT_OK, null))
/*intending(hasComponent(ComponentName(getTargetContext(), ChangePassPhraseActivity::class.java)))
.respondWith(Instrumentation.ActivityResult(Activity.RESULT_OK, null))*/
checkIsSnackbarDisplayedAndClick(getResString(R.string.different_pass_phrases))
assertTrue(activityScenarioRule.scenario.state == Lifecycle.State.RESUMED)
}
Expand All @@ -85,8 +80,8 @@ class BackupKeysFragmentTwoKeysDiffPassphrasesTest : BaseBackupKeysFragmentTest(
onView(withId(R.id.btBackup))
.check(matches(isDisplayed()))
.perform(click())
intending(hasComponent(ComponentName(getTargetContext(), ChangePassPhraseActivity::class.java)))
.respondWith(Instrumentation.ActivityResult(Activity.RESULT_OK, null))
/*intending(hasComponent(ComponentName(getTargetContext(), ChangePassPhraseActivity::class.java)))
.respondWith(Instrumentation.ActivityResult(Activity.RESULT_OK, null))*/
checkIsSnackbarDisplayedAndClick(getResString(R.string.different_pass_phrases))
assertTrue(activityScenarioRule.scenario.state == Lifecycle.State.RESUMED)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,23 @@

package com.flowcrypt.email.ui.activity

import android.app.Activity
import android.os.Bundle
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.closeSoftKeyboard
import androidx.test.espresso.action.ViewActions.replaceText
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
import com.flowcrypt.email.R
import com.flowcrypt.email.base.BaseTest
import com.flowcrypt.email.junit.annotations.DependsOnMailServer
import com.flowcrypt.email.rules.AddAccountToDatabaseRule
import com.flowcrypt.email.rules.AddPrivateKeyToDatabaseRule
import com.flowcrypt.email.rules.ClearAppSettingsRule
import com.flowcrypt.email.rules.RetryRule
import com.flowcrypt.email.rules.ScreenshotTestRule
import com.flowcrypt.email.ui.activity.base.BasePassphraseActivityTest
import org.junit.Assert
import com.flowcrypt.email.ui.activity.settings.SettingsActivity
import com.flowcrypt.email.util.TestGeneralUtil
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
Expand All @@ -33,43 +30,47 @@ import org.junit.runner.RunWith

/**
* @author Denis Bondarenko
* Date: 3/13/19
* Time: 12:15 PM
* E-mail: DenBond7@gmail.com
* Date: 6/29/21
* Time: 6:09 PM
* E-mail: DenBond7@gmail.com
*/
@MediumTest
@RunWith(AndroidJUnit4::class)
class ChangePassPhraseActivityTest : BasePassphraseActivityTest() {
class ChangePassphraseOfImportedKeysFragmentTest : BaseTest() {
private val addAccountToDatabaseRule = AddAccountToDatabaseRule()

override val useIntents: Boolean = true
override val activityScenarioRule = activityScenarioRule<ChangePassPhraseActivity>()
override val activityScenarioRule = activityScenarioRule<SettingsActivity>(
TestGeneralUtil.genIntentForNavigationComponent(
uri = "flowcrypt://email.flowcrypt.com/settings/security/change_passphrase",
extras = Bundle().apply {
putInt("popBackStackIdIfSuccess", R.id.securitySettingsFragment)
putString("title", getResString(R.string.pass_phrase_changed))
putString("subTitle", getResString(R.string.passphrase_was_changed))
putString("passphrase", PERFECT_PASSWORD)
putParcelable("accountEntity", addAccountToDatabaseRule.account)
}
)
)

@get:Rule
var ruleChain: TestRule = RuleChain
.outerRule(ClearAppSettingsRule())
.around(addAccountToDatabaseRule)
.around(AddPrivateKeyToDatabaseRule())
.around(RetryRule.DEFAULT)
//.around(RetryRule.DEFAULT)
.around(activityScenarioRule)
.around(ScreenshotTestRule())

@Test
@DependsOnMailServer
fun testUseCorrectPassPhrase() {
onView(withId(R.id.editTextKeyPassword))
fun testShowSuccess() {
onView(withText(getResString(R.string.pass_phrase_changed)))
.check(matches(isDisplayed()))
.perform(replaceText(PERFECT_PASSWORD), closeSoftKeyboard())
onView(withId(R.id.buttonSetPassPhrase))
onView(withText(getResString(R.string.passphrase_was_changed)))
.check(matches(isDisplayed()))
.perform(click())
onView(withId(R.id.editTextKeyPasswordSecond))
.check(matches(isDisplayed()))
.perform(replaceText(PERFECT_PASSWORD), closeSoftKeyboard())
onView(withId(R.id.buttonConfirmPassPhrases))
.check(matches(isDisplayed()))
.perform(click())
}

Assert.assertTrue(activityScenarioRule.scenario.result.resultCode == Activity.RESULT_OK)
companion object {
internal const val PERFECT_PASSWORD = "unconventional blueberry unlike any other"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
* © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com
* Contributors: DenBond7
*/

package com.flowcrypt.email.ui.activity

import android.os.Bundle
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.clearText
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.closeSoftKeyboard
import androidx.test.espresso.action.ViewActions.replaceText
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.rules.activityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
import com.flowcrypt.email.R
import com.flowcrypt.email.base.BaseTest
import com.flowcrypt.email.rules.AddAccountToDatabaseRule
import com.flowcrypt.email.rules.AddPrivateKeyToDatabaseRule
import com.flowcrypt.email.rules.ClearAppSettingsRule
import com.flowcrypt.email.rules.RetryRule
import com.flowcrypt.email.rules.ScreenshotTestRule
import com.flowcrypt.email.ui.activity.settings.SettingsActivity
import com.flowcrypt.email.util.TestGeneralUtil
import org.hamcrest.Matchers.startsWith
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.rules.TestRule
import org.junit.runner.RunWith
import java.util.Locale

/**
* @author Denis Bondarenko
* Date: 3/13/19
* Time: 12:15 PM
* E-mail: DenBond7@gmail.com
*/
@MediumTest
@RunWith(AndroidJUnit4::class)
class CheckPassphraseStrengthFragmentTest : BaseTest() {
private val addAccountToDatabaseRule = AddAccountToDatabaseRule()

override val activityScenarioRule = activityScenarioRule<SettingsActivity>(
TestGeneralUtil.genIntentForNavigationComponent(
uri = "flowcrypt://email.flowcrypt.com/settings/security/check_passphrase",
extras = Bundle().apply {
putInt("popBackStackIdIfSuccess", R.id.securitySettingsFragment)
putString("title", getResString(R.string.change_pass_phrase))
}
)
)

@get:Rule
var ruleChain: TestRule = RuleChain
.outerRule(ClearAppSettingsRule())
.around(addAccountToDatabaseRule)
.around(AddPrivateKeyToDatabaseRule())
.around(RetryRule.DEFAULT)
.around(activityScenarioRule)
.around(ScreenshotTestRule())

@Test
fun testShowDialogWithPasswordRecommendation() {
onView(withId(R.id.iBShowPasswordHint))
.check(matches(isDisplayed()))
.perform(click())
onView(withId(R.id.webView))
.check(matches(isDisplayed()))
}

@Test
fun testEmptyPassPhrase() {
closeSoftKeyboard()
onView(withId(R.id.btSetPassphrase))
.check(matches(isDisplayed()))
.perform(click())

checkIsNonEmptyHintShown()
}

@Test
fun testChangingQualityOfPassPhrase() {
val passPhrases = arrayOf(
WEAK_PASSWORD, POOR_PASSWORD, REASONABLE_PASSWORD, GOOD_PASSWORD,
GREAT_PASSWORD, PERFECT_PASSWORD
)

val degreeOfReliabilityOfPassPhrase = arrayOf(
getResString(R.string.password_quality_weak),
getResString(R.string.password_quality_poor),
getResString(R.string.password_quality_reasonable),
getResString(R.string.password_quality_good),
getResString(R.string.password_quality_great),
getResString(R.string.password_quality_perfect)
)

for (i in passPhrases.indices) {
onView(withId(R.id.eTPassphrase))
.check(matches(isDisplayed()))
.perform(replaceText(passPhrases[i]))
onView(withId(R.id.tVPassphraseQuality))
.check(matches(withText(startsWith(degreeOfReliabilityOfPassPhrase[i].toUpperCase(Locale.getDefault())))))
onView(withId(R.id.eTPassphrase))
.check(matches(isDisplayed()))
.perform(clearText())
}
}

@Test
fun testShowDialogAboutBadPassPhrase() {
val badPassPhrases = arrayOf(WEAK_PASSWORD, POOR_PASSWORD)

for (passPhrase in badPassPhrases) {
onView(withId(R.id.eTPassphrase))
.check(matches(isDisplayed()))
.perform(replaceText(passPhrase), closeSoftKeyboard())
onView(withId(R.id.btSetPassphrase))
.check(matches(isDisplayed()))
.perform(click())
onView(withText(getResString(R.string.select_stronger_pass_phrase)))
.check(matches(isDisplayed()))
onView(withId(android.R.id.button1))
.check(matches(isDisplayed()))
.perform(click())
onView(withId(R.id.eTPassphrase))
.check(matches(isDisplayed()))
.perform(clearText())
}
}

private fun checkIsNonEmptyHintShown() {
onView(withText(getResString(R.string.passphrase_must_be_non_empty)))
.check(matches(isDisplayed()))
onView(withId(com.google.android.material.R.id.snackbar_action))
.check(matches(isDisplayed()))
.perform(click())
}

companion object {
internal const val WEAK_PASSWORD = "weak"
internal const val POOR_PASSWORD = "weak, perfect, great"
internal const val REASONABLE_PASSWORD = "weak, poor, reasonable"
internal const val GOOD_PASSWORD = "weak, poor, good,"
internal const val GREAT_PASSWORD = "weak, poor, great, good"
internal const val PERFECT_PASSWORD = "unconventional blueberry unlike any other"
}
}
Loading