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

Added handling disallow_attester_search_for_domains OrgRule #1387

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
@@ -0,0 +1,93 @@
/*
* © 2016-present FlowCrypt a.s. Limitations apply. Contact [email protected]
* Contributors: DenBond7
*/

package com.flowcrypt.email.ui.activity

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.scrollTo
import androidx.test.espresso.action.ViewActions.typeText
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
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.api.retrofit.response.model.OrgRules
import com.flowcrypt.email.base.BaseTest
import com.flowcrypt.email.rules.AddAccountToDatabaseRule
import com.flowcrypt.email.rules.ClearAppSettingsRule
import com.flowcrypt.email.rules.RetryRule
import com.flowcrypt.email.rules.ScreenshotTestRule
import com.flowcrypt.email.util.AccountDaoManager
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.rules.TestRule
import org.junit.runner.RunWith

/**
* @author Denis Bondarenko
* Date: 8/6/21
* Time: 2:05 PM
* E-mail: [email protected]
*/
@MediumTest
@RunWith(AndroidJUnit4::class)
class ImportPgpContactActivityDisallowAttesterSearchForDomainTest : BaseTest() {
private val userWithOrgRules = AccountDaoManager.getUserWithOrgRules(
OrgRules(
flags = listOf(
OrgRules.DomainRule.NO_PRV_CREATE,
OrgRules.DomainRule.NO_PRV_BACKUP
),
customKeyserverUrl = null,
keyManagerUrl = "https://keymanagerurl.test",
disallowAttesterSearchForDomains = listOf(DISALLOWED_DOMAIN),
enforceKeygenAlgo = null,
enforceKeygenExpireMonths = null
)
)

private val addAccountToDatabaseRule = AddAccountToDatabaseRule(userWithOrgRules)

override val useIntents: Boolean = true
override val activityScenarioRule = activityScenarioRule<ImportPgpContactActivity>(
intent = ImportPgpContactActivity.newIntent(
context = getTargetContext(),
accountEntity = addAccountToDatabaseRule.account
)
)

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

@Test
fun testCanLookupThisRecipientOnAttester() {
onView(withId(R.id.editTextKeyIdOrEmail))
.perform(
scrollTo(),
clearText(),
typeText("user@$DISALLOWED_DOMAIN"),
closeSoftKeyboard()
)
onView(withId(R.id.iBSearchKey))
.check(matches(isDisplayed()))
.perform(click())
isToastDisplayed(getResString(R.string.supported_public_key_not_found))
}

companion object {
private const val DISALLOWED_DOMAIN = "disallowed.test"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* © 2016-present FlowCrypt a.s. Limitations apply. Contact [email protected]
* Contributors: DenBond7
*/

package com.flowcrypt.email.ui.activity

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.scrollTo
import androidx.test.espresso.action.ViewActions.typeText
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withId
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.api.retrofit.response.model.OrgRules
import com.flowcrypt.email.base.BaseTest
import com.flowcrypt.email.rules.AddAccountToDatabaseRule
import com.flowcrypt.email.rules.ClearAppSettingsRule
import com.flowcrypt.email.rules.RetryRule
import com.flowcrypt.email.rules.ScreenshotTestRule
import com.flowcrypt.email.util.AccountDaoManager
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.rules.TestRule
import org.junit.runner.RunWith

/**
* @author Denis Bondarenko
* Date: 8/6/21
* Time: 2:14 PM
* E-mail: [email protected]
*/
@MediumTest
@RunWith(AndroidJUnit4::class)
class ImportPgpContactActivityDisallowAttesterSearchTest : BaseTest() {
private val userWithOrgRules = AccountDaoManager.getUserWithOrgRules(
OrgRules(
flags = listOf(
OrgRules.DomainRule.NO_PRV_CREATE,
OrgRules.DomainRule.NO_PRV_BACKUP
),
customKeyserverUrl = null,
keyManagerUrl = "https://keymanagerurl.test",
disallowAttesterSearchForDomains = listOf("*"),
enforceKeygenAlgo = null,
enforceKeygenExpireMonths = null
)
)

private val addAccountToDatabaseRule = AddAccountToDatabaseRule(userWithOrgRules)

override val useIntents: Boolean = true
override val activityScenarioRule = activityScenarioRule<ImportPgpContactActivity>(
intent = ImportPgpContactActivity.newIntent(
context = getTargetContext(),
accountEntity = addAccountToDatabaseRule.account
)
)

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

@Test
fun testDisallowLookupOnAttester() {
onView(withId(R.id.editTextKeyIdOrEmail))
.perform(
scrollTo(),
clearText(),
typeText("user@$DISALLOWED_DOMAIN"),
closeSoftKeyboard()
)
onView(withId(R.id.iBSearchKey))
.check(matches(isDisplayed()))
.perform(click())
isToastDisplayed(getResString(R.string.supported_public_key_not_found))
}

companion object {
private const val DISALLOWED_DOMAIN = "disallowed.test"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ abstract class BaseCreateMessageActivityTest : BaseTest() {
override val activityScenario: ActivityScenario<*>?
get() = activeActivityRule.scenario

protected val addAccountToDatabaseRule = AddAccountToDatabaseRule()
protected open val addAccountToDatabaseRule = AddAccountToDatabaseRule()

protected val intent: Intent = CreateMessageActivity.generateIntent(
getTargetContext(), null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* © 2016-present FlowCrypt a.s. Limitations apply. Contact [email protected]
* Contributors: DenBond7
*/

package com.flowcrypt.email.ui.activity.fragment

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
import com.flowcrypt.email.R
import com.flowcrypt.email.TestConstants
import com.flowcrypt.email.api.retrofit.response.model.OrgRules
import com.flowcrypt.email.database.entity.KeyEntity
import com.flowcrypt.email.matchers.CustomMatchers.Companion.withChipsBackgroundColor
import com.flowcrypt.email.model.KeyImportDetails
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.BaseCreateMessageActivityTest
import com.flowcrypt.email.ui.widget.CustomChipSpanChipCreator
import com.flowcrypt.email.util.AccountDaoManager
import com.flowcrypt.email.util.UIUtil
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.rules.TestRule
import org.junit.runner.RunWith

/**
* @author Denis Bondarenko
* Date: 8/6/21
* Time: 1:24 PM
* E-mail: [email protected]
*/
@MediumTest
@RunWith(AndroidJUnit4::class)
class CreateMessageFragmentDisallowAttesterSearchForDomainTest : BaseCreateMessageActivityTest() {

private val userWithOrgRules = AccountDaoManager.getUserWithOrgRules(
OrgRules(
flags = listOf(
OrgRules.DomainRule.NO_PRV_CREATE,
OrgRules.DomainRule.NO_PRV_BACKUP
),
customKeyserverUrl = null,
keyManagerUrl = "https://keymanagerurl.test",
disallowAttesterSearchForDomains = listOf(DISALLOWED_DOMAIN),
enforceKeygenAlgo = null,
enforceKeygenExpireMonths = null
)
)

override val addAccountToDatabaseRule = AddAccountToDatabaseRule(userWithOrgRules)
private val addPrivateKeyToDatabaseRule = AddPrivateKeyToDatabaseRule(
accountEntity = addAccountToDatabaseRule.account,
keyPath = "pgp/[email protected]_fisrtKey_prv_strong.asc",
passphrase = TestConstants.DEFAULT_SECOND_STRONG_PASSWORD,
sourceType = KeyImportDetails.SourceType.EMAIL,
passphraseType = KeyEntity.PassphraseType.RAM
)

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

@Test
fun testCanLookupThisRecipientOnAttester() {
activeActivityRule.launch(intent)
registerAllIdlingResources()

val recipient = "user@$DISALLOWED_DOMAIN"

fillInAllFields(recipient)

onView(withId(R.id.editTextRecipientTo))
.check(
matches(
withChipsBackgroundColor(
recipient,
UIUtil.getColor(
getTargetContext(),
CustomChipSpanChipCreator.CHIP_COLOR_RES_ID_PGP_NOT_EXISTS
)
)
)
)
}

companion object {
private const val DISALLOWED_DOMAIN = "disallowed.test"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* © 2016-present FlowCrypt a.s. Limitations apply. Contact [email protected]
* Contributors: DenBond7
*/

package com.flowcrypt.email.ui.activity.fragment

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
import com.flowcrypt.email.R
import com.flowcrypt.email.TestConstants
import com.flowcrypt.email.api.retrofit.response.model.OrgRules
import com.flowcrypt.email.database.entity.KeyEntity
import com.flowcrypt.email.matchers.CustomMatchers.Companion.withChipsBackgroundColor
import com.flowcrypt.email.model.KeyImportDetails
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.BaseCreateMessageActivityTest
import com.flowcrypt.email.ui.widget.CustomChipSpanChipCreator
import com.flowcrypt.email.util.AccountDaoManager
import com.flowcrypt.email.util.UIUtil
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.rules.TestRule
import org.junit.runner.RunWith

/**
* @author Denis Bondarenko
* Date: 8/6/21
* Time: 1:52 PM
* E-mail: [email protected]
*/
@MediumTest
@RunWith(AndroidJUnit4::class)
class CreateMessageFragmentDisallowAttesterSearchTest : BaseCreateMessageActivityTest() {

private val userWithOrgRules = AccountDaoManager.getUserWithOrgRules(
OrgRules(
flags = listOf(
OrgRules.DomainRule.NO_PRV_CREATE,
OrgRules.DomainRule.NO_PRV_BACKUP
),
customKeyserverUrl = null,
keyManagerUrl = "https://keymanagerurl.test",
disallowAttesterSearchForDomains = listOf("*"),
enforceKeygenAlgo = null,
enforceKeygenExpireMonths = null
)
)

override val addAccountToDatabaseRule = AddAccountToDatabaseRule(userWithOrgRules)
private val addPrivateKeyToDatabaseRule = AddPrivateKeyToDatabaseRule(
accountEntity = addAccountToDatabaseRule.account,
keyPath = "pgp/[email protected]_fisrtKey_prv_strong.asc",
passphrase = TestConstants.DEFAULT_SECOND_STRONG_PASSWORD,
sourceType = KeyImportDetails.SourceType.EMAIL,
passphraseType = KeyEntity.PassphraseType.RAM
)

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

@Test
fun testDisallowLookupOnAttester() {
activeActivityRule.launch(intent)
registerAllIdlingResources()

val recipient = getResString(R.string.support_email)

fillInAllFields(recipient)

onView(withId(R.id.editTextRecipientTo))
.check(
matches(
withChipsBackgroundColor(
recipient,
UIUtil.getColor(
getTargetContext(),
CustomChipSpanChipCreator.CHIP_COLOR_RES_ID_PGP_NOT_EXISTS
)
)
)
)
}
}
Loading