From 9cd5443b19da7654b83de8cdeadcb372ff7bbec2 Mon Sep 17 00:00:00 2001 From: DenBond7 Date: Wed, 18 Dec 2024 12:35:36 +0200 Subject: [PATCH 1/2] wip --- .../response/model/ClientConfiguration.kt | 6 +++--- .../response/model/ClientConfigurationTest.kt | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/FlowCrypt/src/main/java/com/flowcrypt/email/api/retrofit/response/model/ClientConfiguration.kt b/FlowCrypt/src/main/java/com/flowcrypt/email/api/retrofit/response/model/ClientConfiguration.kt index e46e688d19..ac5f41dc6e 100644 --- a/FlowCrypt/src/main/java/com/flowcrypt/email/api/retrofit/response/model/ClientConfiguration.kt +++ b/FlowCrypt/src/main/java/com/flowcrypt/email/api/retrofit/response/model/ClientConfiguration.kt @@ -226,7 +226,7 @@ data class ClientConfiguration( } fun getDisallowPasswordMessagesForTermsRegex(): Regex? { - val startAndEntWithAnyNonWordCharacterRegex = "^\\W.*\\W\$".toRegex(RegexOption.IGNORE_CASE) + val startAndEndWithAnyNonWordCharacterRegex = "^\\W.*\\W\$".toRegex(RegexOption.IGNORE_CASE) return disallowPasswordMessagesForTerms?.joinToString( separator = "|", @@ -234,10 +234,10 @@ data class ClientConfiguration( postfix = ")" ) { term -> val escapedTerm = Regex.escape(term) - if (startAndEntWithAnyNonWordCharacterRegex.matches(term)) { + if (startAndEndWithAnyNonWordCharacterRegex.matches(term)) { "($escapedTerm)" } else { - "(\\W$escapedTerm\\W)" + "(((^|\\s)+[^\\sa-zA-Z0-9_]$escapedTerm[^\\sa-zA-Z0-9_](\$|\\s)+)|((^|\\s)+$escapedTerm(\$|\\s)+))" } }?.toRegex(setOf(RegexOption.IGNORE_CASE)) } diff --git a/FlowCrypt/src/test/java/com/flowcrypt/email/api/retrofit/response/model/ClientConfigurationTest.kt b/FlowCrypt/src/test/java/com/flowcrypt/email/api/retrofit/response/model/ClientConfigurationTest.kt index 73872bedbc..6d260a9304 100644 --- a/FlowCrypt/src/test/java/com/flowcrypt/email/api/retrofit/response/model/ClientConfigurationTest.kt +++ b/FlowCrypt/src/test/java/com/flowcrypt/email/api/retrofit/response/model/ClientConfigurationTest.kt @@ -18,11 +18,13 @@ class ClientConfigurationTest { val clientConfiguration = ClientConfiguration( disallowPasswordMessagesForTerms = listOf( "droid", + "test-feature", "[Classification: Data Control: Internal Data Control]", ) ) val regex = requireNotNull(clientConfiguration.getDisallowPasswordMessagesForTermsRegex()) + println(regex) val matchingSubjects = listOf( "[Classification: Data Control: Internal Data Control] Quarter results", @@ -31,6 +33,17 @@ class ClientConfigurationTest { "aaaa[Classification: Data Control: Internal Data Control]bbb", "[droid]", "check -droid- case", + "TEST-FEATURE", + "[test-feature}", + "before {test-feature}", + "[test-feature] after", + "before [test-feature} after", + "test-feature", + "test-feature after", + "before test-feature", + "before test-feature after", + "before TEST-feature after", + "before {TEST-feature} after" ) val nonMatchingSubjects = listOf( @@ -39,6 +52,12 @@ class ClientConfigurationTest { "[1Classification: Data Control: Internal Data Control]", "aaaa[1Classification: Data Control: Internal Data Control]bbb", "Microdroid androids", + "beforetest-feature", + "test-featureafter", + "beforetest-featureafter", + "before {TEST-feature}after", + "before{TEST-feature} after", + "before{TEST-feature}after" ) matchingSubjects.forEach { subject -> assertNotNull("Exception in :$subject", regex.find(subject)) From 7ad97f1dca2452bd1a5e0b76a8f66e637a57c398 Mon Sep 17 00:00:00 2001 From: DenBond7 Date: Wed, 18 Dec 2024 13:55:56 +0200 Subject: [PATCH 2/2] Updated tests --- ...reenPasswordProtectedDisallowedTermsTest.kt | 18 ++++++++++++++++++ ...PasswordProtectedDisallowedTermsFlowTest.kt | 4 +++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/gmailapi/passwordprotected/BaseComposeScreenPasswordProtectedDisallowedTermsTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/gmailapi/passwordprotected/BaseComposeScreenPasswordProtectedDisallowedTermsTest.kt index 129f48cc93..a364e4fc09 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/gmailapi/passwordprotected/BaseComposeScreenPasswordProtectedDisallowedTermsTest.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/gmailapi/passwordprotected/BaseComposeScreenPasswordProtectedDisallowedTermsTest.kt @@ -86,6 +86,17 @@ open class BaseComposeScreenPasswordProtectedDisallowedTermsTest( "aaaa[Classification: Data Control: Internal Data Control]bbb", "[droid]", "check -droid- case", + "TEST-FEATURE", + "[test-feature}", + "before {test-feature}", + "[test-feature] after", + "before [test-feature} after", + "test-feature", + "test-feature after", + "before test-feature", + "before test-feature after", + "before TEST-feature after", + "before {TEST-feature} after" ) val NON_MATCHING_SUBJECTS = listOf( @@ -94,6 +105,12 @@ open class BaseComposeScreenPasswordProtectedDisallowedTermsTest( "[1Classification: Data Control: Internal Data Control]", "aaaa[1Classification: Data Control: Internal Data Control]bbb", "Microdroid androids", + "beforetest-feature", + "test-featureafter", + "beforetest-featureafter", + "before {TEST-feature}after", + "before{TEST-feature} after", + "before{TEST-feature}after" ) const val ERROR_TEXT = @@ -101,6 +118,7 @@ open class BaseComposeScreenPasswordProtectedDisallowedTermsTest( val TERMS = listOf( "droid", + "test-feature", "[Classification: Data Control: Internal Data Control]", ) } diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/gmailapi/passwordprotected/ComposeScreenPasswordProtectedDisallowedTermsFlowTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/gmailapi/passwordprotected/ComposeScreenPasswordProtectedDisallowedTermsFlowTest.kt index 323337c07d..e10df8a527 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/gmailapi/passwordprotected/ComposeScreenPasswordProtectedDisallowedTermsFlowTest.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/gmailapi/passwordprotected/ComposeScreenPasswordProtectedDisallowedTermsFlowTest.kt @@ -35,6 +35,7 @@ import org.junit.Test import org.junit.rules.RuleChain import org.junit.rules.TestRule import org.junit.runner.RunWith +import java.util.concurrent.TimeUnit /** * @author Denys Bondarenko @@ -76,6 +77,8 @@ class ComposeScreenPasswordProtectedDisallowedTermsFlowTest : onView(withId(R.id.editTextEmailSubject)) .perform(scrollTo(), click(), replaceText(subject)) + waitForObjectWithText(subject, TimeUnit.SECONDS.toMillis(5)) + onView(withId(R.id.menuActionSend)) .check(matches(isDisplayed())) .perform(click()) @@ -95,7 +98,6 @@ class ComposeScreenPasswordProtectedDisallowedTermsFlowTest : .perform(openLinkWithText(URL)) //asserting our expected intent was recorded Intents.intended(expectingIntent) - Thread.sleep(1000) Intents.release() onView(withId(android.R.id.button1))