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
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -94,13 +105,20 @@ 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 =
"Password-protected messages are disabled, please check $URL"

val TERMS = listOf(
"droid",
"test-feature",
"[Classification: Data Control: Internal Data Control]",
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,18 +226,18 @@ 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 = "|",
prefix = "(",
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))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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(
Expand All @@ -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))
Expand Down
Loading