Skip to content

Commit

Permalink
Merge pull request #555 from jorgeblacio/release_0_21_17
Browse files Browse the repository at this point in the history
Various bug fixes for new release.
  • Loading branch information
danieltigse authored Oct 17, 2019
2 parents 2d0147e + 5663605 commit 6813197
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 13 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ android {
defaultConfig {
minSdkVersion 21
targetSdkVersion 28
versionCode 93
versionName "0.21.16"
versionCode 94
versionName "0.21.17"
applicationId "com.criptext.mail"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -893,16 +893,18 @@ class EmailDetailSceneController(private val storage: KeyValueStorage,
}

override fun onPause(){
cleanup()
cleanup(false)
}

override fun onStop() {
cleanup()
cleanup(true)
}

private fun cleanup(){
dataSource.listener = null
generalDataSource.listener = null
private fun cleanup(cleanDataSources: Boolean){
if(cleanDataSources) {
dataSource.listener = null
generalDataSource.listener = null
}
websocketEvents.clearListener(webSocketEventListener)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.criptext.mail.db.models.ActiveAccount
import com.criptext.mail.db.models.Contact
import com.criptext.mail.scenes.ActivityMessage
import com.criptext.mail.scenes.SceneController
import com.criptext.mail.scenes.composer.data.ContactDomainCheckData
import com.criptext.mail.scenes.params.MailboxParams
import com.criptext.mail.scenes.params.SignUpParams
import com.criptext.mail.scenes.settings.DevicesListItemListener
Expand Down Expand Up @@ -456,9 +457,13 @@ class SignInSceneController(
} else {
Pair(userInput.value, Contact.mainDomain)
}
val newRequest = SignInRequest.CheckUserAvailability(recipientId, domain)
dataSource.submitRequest(newRequest)
scene.setSubmitButtonState(ProgressButtonState.waiting)
if(model.checkedDomains.map { it.name }.contains(domain))
scene.drawInputError(UIMessage(R.string.username_is_not_criptext))
else {
val newRequest = SignInRequest.CheckUserAvailability(recipientId, domain)
dataSource.submitRequest(newRequest)
scene.setSubmitButtonState(ProgressButtonState.waiting)
}
}
is FormData.Error ->
scene.drawInputError(userInput.message)
Expand Down Expand Up @@ -813,6 +818,9 @@ class SignInSceneController(
}

override fun onStart(activityMessage: ActivityMessage?): Boolean {
model.checkedDomains.addAll(
ContactDomainCheckData.KNOWN_EXTERNAL_DOMAINS.filter { !it.isCriptextDomain }
)
dataSource.listener = dataSourceListener
generalDataSource.listener = generalDataSourceListener
scene.initLayout(model = model, signInUIObserver = uiObserver)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.criptext.mail.scenes.signin

import com.criptext.mail.db.models.ActiveAccount
import com.criptext.mail.scenes.SceneModel
import com.criptext.mail.scenes.composer.data.ContactDomainCheckData
import com.criptext.mail.scenes.settings.devices.data.DeviceItem
import com.criptext.mail.scenes.signin.data.LinkDeviceState
import com.criptext.mail.scenes.signin.holders.SignInLayoutState
Expand Down Expand Up @@ -33,4 +34,5 @@ class SignInSceneModel(val isMultiple: Boolean = false) : SceneModel {
var needToRemoveDevices = false
var temporalJWT = ""
var devices: ArrayList<DeviceItem> = ArrayList()
var checkedDomains = mutableListOf<ContactDomainCheckData>()
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class SignUpSceneController(
val newUsername = if (text.isEmpty()) {
model.username.copy(state = FormInputState.Unknown())
} else {
val userInput = AccountDataValidator.validateUsername(text)
val userInput = AccountDataValidator.validateUsernameOnly(text)
when (userInput) {
is FormData.Valid -> {
runnableThrottler.push(Runnable {
Expand Down
3 changes: 1 addition & 2 deletions src/main/kotlin/com/criptext/mail/utils/HTMLUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ class HTMLUtils {
}

fun addCriptextFooter(body: String): String{
val watermarkString = "<div></div><br><br>Sent with <a href=\"https://goo.gl/qW4Aks\" " +
"style=\"color: rgb(0,145,255)\">Criptext</a> secure email"
val watermarkString = "<div></div><br><br><i>Sent with Criptext secure email</i>"
if(body.contains(watermarkString)) return body
return body.plus(watermarkString)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ object AccountDataValidator {
FormData.Valid(sanitizedValue)
}

fun validateUsernameOnly(username: String): FormData<String> {
val sanitizedValue = username.trim().toLowerCase()

return when {
sanitizedValue.length < 3 -> FormData.Error(UIMessage(R.string.username_length_error))
!validCriptextUserPattern.matcher(sanitizedValue).matches() -> FormData.Error(UIMessage(R.string.username_invalid_error))
else -> FormData.Valid(sanitizedValue)
}
}

fun validateFullName(fullName: String): FormData<String> {
val sanitizedValue = fullName.trim()

Expand Down
1 change: 1 addition & 0 deletions src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -585,4 +585,5 @@
<string name="rate_us_message">Si es así, ayúdanos con una calificación. ¡Gracias por tu apoyo!</string>
<string name="rate_us">Calificar</string>
<string name="rate_remind_later">Recordar Luego</string>
<string name="username_is_not_criptext">El usuario o dirección de correo no pertenece a Criptext.</string>
</resources>
1 change: 1 addition & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -585,4 +585,5 @@
<string name="rate_us_message">If you do, please take a moment to rate it. Thanks for your support!</string>
<string name="rate_us">Rate Us</string>
<string name="rate_remind_later">Remind Later</string>
<string name="username_is_not_criptext">Not a valid Criptext address or username.</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,61 @@ class AccountDataValidatorTest {
fun `validateUsername should return valid if receives a valid username`() {
val myUsername = "tester"
AccountDataValidator.validateUsername(myUsername) `should equal` FormData.Valid("tester")
AccountDataValidator.validateUsernameOnly(myUsername) `should equal` FormData.Valid("tester")
}

@Test
fun `validateUsername should return valid if receives less than 3 characters`() {
val myUsername = "t"
AccountDataValidator.validateUsername(myUsername) `should be instance of` FormData.Error::class.java
AccountDataValidator.validateUsernameOnly(myUsername) `should be instance of` FormData.Error::class.java
}

@Test
fun `validateUsername should return error if receives spaces in the middle of the username`() {
val myUsername = "anew tester"
AccountDataValidator.validateUsername(myUsername) `should be instance of` FormData.Error::class.java
AccountDataValidator.validateUsernameOnly(myUsername) `should be instance of` FormData.Error::class.java
}

@Test
fun `validateUsername should return error if receives invalid characters in username`() {
val myUsername = "test#"
AccountDataValidator.validateUsername(myUsername) `should be instance of` FormData.Error::class.java
AccountDataValidator.validateUsernameOnly(myUsername) `should be instance of` FormData.Error::class.java
}

@Test
fun `validateUsername should return error if username starts with dot`() {
val myUsername = ".tester"
AccountDataValidator.validateUsername(myUsername) `should be instance of` FormData.Error::class.java
AccountDataValidator.validateUsernameOnly(myUsername) `should be instance of` FormData.Error::class.java
}

@Test
fun `validateUsername should return valid if receives dots, dashes or lowdashes in username`() {
val myUsername = "test.t_est-er05"
AccountDataValidator.validateUsername(myUsername) `should be instance of` FormData.Valid::class.java
AccountDataValidator.validateUsernameOnly(myUsername) `should be instance of` FormData.Valid::class.java
}

@Test
fun `validateEmailAddress should return valid if receives a valid address`() {
val address = "[email protected]"
AccountDataValidator.validateEmailAddress(address) `should equal` FormData.Valid(address)
AccountDataValidator.validateUsername(address) `should equal` FormData.Valid(address)
}

@Test
fun `validateUsernameOnly should return error if receives an email address`() {
val address = "[email protected]"
AccountDataValidator.validateUsernameOnly(address) `should be instance of` FormData.Error::class.java
}

@Test
fun `validateEmailAddress should return error if receives angular brackets and spaces`() {
val address = "Some User <[email protected]>"
AccountDataValidator.validateEmailAddress(address) `should be instance of` FormData.Error::class.java
AccountDataValidator.validateUsername(address) `should be instance of` FormData.Error::class.java
}
}

0 comments on commit 6813197

Please sign in to comment.