Skip to content
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
1,026 changes: 1,026 additions & 0 deletions FlowCrypt/schemas/com.flowcrypt.email.database.FlowCryptRoomDatabase/30.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class MigrationTest {
FlowCryptRoomDatabase.MIGRATION_25_26,
FlowCryptRoomDatabase.MIGRATION_26_27,
FlowCryptRoomDatabase.MIGRATION_27_28,
FlowCryptRoomDatabase.MIGRATION_28_29
FlowCryptRoomDatabase.MIGRATION_28_29,
FlowCryptRoomDatabase.MIGRATION_29_30
)

@get:Rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,26 @@ class CreateMessageActivityTest : BaseCreateMessageActivityTest() {
)
}

@Test
fun testWebPortalPasswordButtonIsHidden() {
activeActivityRule?.launch(intent)
registerAllIdlingResources()

onView(withId(R.id.editTextRecipientTo))
.perform(
typeText(TestConstants.RECIPIENT_WITHOUT_PUBLIC_KEY_ON_ATTESTER),
closeSoftKeyboard()
)

//need to leave focus from 'To' field. move the focus to the next view
onView(withId(R.id.editTextEmailSubject))
.perform(scrollTo(), click())

//because account.useFES == false btnSetWebPortalPassword should not be visible
onView(withId(R.id.btnSetWebPortalPassword))
.check(matches(not(isDisplayed())))
}

private fun checkIsDisplayedEncryptedAttributes() {
onView(withId(R.id.underToolbarTextTextView))
.check(matches(not(isDisplayed())))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ import com.flowcrypt.email.R
import com.flowcrypt.email.TestConstants
import com.flowcrypt.email.matchers.CustomMatchers.Companion.withTextViewDrawable
import com.flowcrypt.email.matchers.TextViewDrawableMatcher
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.util.AccountDaoManager
import org.hamcrest.Matchers.not
import org.junit.Rule
import org.junit.Test
Expand All @@ -47,6 +49,9 @@ class CreateMessageFragmentPasswordProtectedTest : BaseCreateMessageActivityTest
private val addPrivateKeyToDatabaseRule = AddPrivateKeyToDatabaseRule()
private val temporaryFolderRule = TemporaryFolder()

override val addAccountToDatabaseRule: AddAccountToDatabaseRule
get() = AddAccountToDatabaseRule(AccountDaoManager.getDefaultAccountDao().copy(useFES = true))

@get:Rule
var ruleChain: TestRule = RuleChain
.outerRule(RetryRule.DEFAULT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ abstract class FlowCryptRoomDatabase : RoomDatabase() {

companion object {
const val DB_NAME = "flowcrypt.db"
const val DB_VERSION = 29
const val DB_VERSION = 30

private val MIGRATION_1_3 = object : FlowCryptMigration(1, 3) {
override fun doMigration(database: SupportSQLiteDatabase) {
Expand Down Expand Up @@ -559,6 +559,13 @@ abstract class FlowCryptRoomDatabase : RoomDatabase() {
}
}

@VisibleForTesting
val MIGRATION_29_30 = object : FlowCryptMigration(29, 30) {
override fun doMigration(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE accounts ADD COLUMN use_fes INTEGER NOT NULL DEFAULT 0;")
}
}

// Singleton prevents multiple instances of database opening at the same time.
@Volatile
private var INSTANCE: FlowCryptRoomDatabase? = null
Expand Down Expand Up @@ -601,7 +608,8 @@ abstract class FlowCryptRoomDatabase : RoomDatabase() {
MIGRATION_25_26,
MIGRATION_26_27,
MIGRATION_27_28,
MIGRATION_28_29
MIGRATION_28_29,
MIGRATION_29_30
).build()
INSTANCE = instance
return instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import com.flowcrypt.email.api.email.model.SecurityType
import com.flowcrypt.email.api.retrofit.response.model.OrgRules
import com.flowcrypt.email.util.FlavorSettings
import com.google.android.gms.auth.api.signin.GoogleSignInAccount
import java.util.Locale

/**
* @author Denis Bondarenko
Expand Down Expand Up @@ -74,57 +73,61 @@ data class AccountEntity constructor(
name = "client_configuration",
defaultValue = "NULL"
) val clientConfiguration: OrgRules? = null,
@ColumnInfo(name = "use_api", defaultValue = "0") val useAPI: Boolean = false
@ColumnInfo(name = "use_api", defaultValue = "0") val useAPI: Boolean = false,
@ColumnInfo(name = "use_fes", defaultValue = "0") val useFES: Boolean = false
) : Parcelable {

@Ignore
val account: Account = Account(
this.email, accountType
?: this.email.substring(this.email.indexOf('@') + 1).toLowerCase(Locale.US)
?: this.email.substring(this.email.indexOf('@') + 1).lowercase()
)

val useOAuth2: Boolean
get() = JavaEmailConstants.AUTH_MECHANISMS_XOAUTH2 == imapAuthMechanisms

constructor(
googleSignInAccount: GoogleSignInAccount, uuid: String? = null, orgRules: OrgRules? = null
) :
this(
email = googleSignInAccount.email!!.toLowerCase(Locale.US),
accountType = googleSignInAccount.account?.type?.toLowerCase(Locale.US),
displayName = googleSignInAccount.displayName,
givenName = googleSignInAccount.givenName,
familyName = googleSignInAccount.familyName,
photoUrl = googleSignInAccount.photoUrl?.toString(),
isEnabled = true,
isActive = false,
username = googleSignInAccount.email!!,
password = "",
imapServer = GmailConstants.GMAIL_IMAP_SERVER,
imapPort = GmailConstants.GMAIL_IMAP_PORT,
imapUseSslTls = true,
imapUseStarttls = false,
imapAuthMechanisms = JavaEmailConstants.AUTH_MECHANISMS_XOAUTH2,
smtpServer = GmailConstants.GMAIL_SMTP_SERVER,
smtpPort = GmailConstants.GMAIL_SMTP_PORT,
smtpUseSslTls = true,
smtpUseStarttls = false,
smtpAuthMechanisms = JavaEmailConstants.AUTH_MECHANISMS_XOAUTH2,
smtpUseCustomSign = false,
smtpUsername = null,
smtpPassword = null,
contactsLoaded = false,
showOnlyEncrypted = false,
uuid = uuid,
clientConfiguration = orgRules,
useAPI = FlavorSettings.isGMailAPIEnabled()
)
googleSignInAccount: GoogleSignInAccount,
uuid: String? = null,
orgRules: OrgRules? = null,
useFES: Boolean
) : this(
email = googleSignInAccount.email!!.lowercase(),
accountType = googleSignInAccount.account?.type?.lowercase(),
displayName = googleSignInAccount.displayName,
givenName = googleSignInAccount.givenName,
familyName = googleSignInAccount.familyName,
photoUrl = googleSignInAccount.photoUrl?.toString(),
isEnabled = true,
isActive = false,
username = googleSignInAccount.email!!,
password = "",
imapServer = GmailConstants.GMAIL_IMAP_SERVER,
imapPort = GmailConstants.GMAIL_IMAP_PORT,
imapUseSslTls = true,
imapUseStarttls = false,
imapAuthMechanisms = JavaEmailConstants.AUTH_MECHANISMS_XOAUTH2,
smtpServer = GmailConstants.GMAIL_SMTP_SERVER,
smtpPort = GmailConstants.GMAIL_SMTP_PORT,
smtpUseSslTls = true,
smtpUseStarttls = false,
smtpAuthMechanisms = JavaEmailConstants.AUTH_MECHANISMS_XOAUTH2,
smtpUseCustomSign = false,
smtpUsername = null,
smtpPassword = null,
contactsLoaded = false,
showOnlyEncrypted = false,
uuid = uuid,
clientConfiguration = orgRules,
useAPI = FlavorSettings.isGMailAPIEnabled(),
useFES = useFES
)

constructor(authCredentials: AuthCredentials, uuid: String? = null, orgRules: OrgRules? = null) :
this(
email = authCredentials.email.toLowerCase(Locale.US),
accountType = authCredentials.email.substring(authCredentials.email.indexOf('@') + 1)
.toLowerCase(Locale.getDefault()),
email = authCredentials.email.lowercase(),
accountType =
authCredentials.email.substring(authCredentials.email.indexOf('@') + 1).lowercase(),
displayName = authCredentials.displayName,
givenName = null,
familyName = null,
Expand All @@ -133,12 +136,12 @@ data class AccountEntity constructor(
isActive = false,
username = authCredentials.username,
password = authCredentials.password,
imapServer = authCredentials.imapServer.toLowerCase(Locale.US),
imapServer = authCredentials.imapServer.lowercase(),
imapPort = authCredentials.imapPort,
imapUseSslTls = authCredentials.imapOpt === SecurityType.Option.SSL_TLS,
imapUseStarttls = authCredentials.imapOpt === SecurityType.Option.STARTLS,
imapAuthMechanisms = if (authCredentials.useOAuth2) JavaEmailConstants.AUTH_MECHANISMS_XOAUTH2 else null,
smtpServer = authCredentials.smtpServer.toLowerCase(Locale.US),
smtpServer = authCredentials.smtpServer.lowercase(),
smtpPort = authCredentials.smtpPort,
smtpUseSslTls = authCredentials.smtpOpt === SecurityType.Option.SSL_TLS,
smtpUseStarttls = authCredentials.smtpOpt === SecurityType.Option.STARTLS,
Expand All @@ -150,7 +153,8 @@ data class AccountEntity constructor(
showOnlyEncrypted = false,
uuid = uuid,
clientConfiguration = orgRules,
useAPI = false
useAPI = false,
useFES = false
)

constructor(email: String) :
Expand Down Expand Up @@ -214,6 +218,7 @@ data class AccountEntity constructor(
source.readValue(Boolean::class.java.classLoader) as Boolean?,
source.readString(),
source.readParcelable(OrgRules::class.java.classLoader),
source.readValue(Boolean::class.java.classLoader) as Boolean,
source.readValue(Boolean::class.java.classLoader) as Boolean
)

Expand Down Expand Up @@ -281,6 +286,7 @@ data class AccountEntity constructor(
writeString(uuid)
writeParcelable(clientConfiguration, flags)
writeValue(useAPI)
writeValue(useFES)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1872,8 +1872,7 @@ class CreateMessageFragment : BaseSyncFragment(), View.OnFocusChangeListener,
}

private fun isPasswordProtectedFunctionalityEnabled(): Boolean {
val account = accountViewModel.activeAccountLiveData.value?.email ?: return false
return EmailUtil.getDomain(account) in listOf("flowcrypt.com", "flowcrypt.test")
return accountViewModel.activeAccountLiveData.value?.useFES ?: return false
}

private fun getForwardedAttachments(): List<AttachmentInfo> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,14 @@ class MainSignInFragment : BaseSingInFragment() {
}

override fun getTempAccount(): AccountEntity? {
return googleSignInAccount?.let { AccountEntity(it, uuid, orgRules) }
return googleSignInAccount?.let {
AccountEntity(
googleSignInAccount = it,
uuid = uuid,
orgRules = orgRules,
useFES = fesUrl?.isNotEmpty() == true
)
}
}

override fun returnResultOk() {
Expand Down