[IGS] Ask for consent only 5 times
^KTI-1443 In Progress
This commit is contained in:
committed by
Space Team
parent
b0254add6d
commit
ab5699f106
+5
-1
@@ -32,6 +32,8 @@ internal val USER_CONSENT_DETAILS_LINK_TEMPLATE = "You can read more details her
|
|||||||
|
|
||||||
internal const val PROMPT_REQUEST = "Do you agree with this? Please answer with 'yes' or 'no': "
|
internal const val PROMPT_REQUEST = "Do you agree with this? Please answer with 'yes' or 'no': "
|
||||||
|
|
||||||
|
private const val MAX_REQUEST_ATTEMPTS = 5
|
||||||
|
|
||||||
internal fun String.formatWithLink(link: String) = replace(linkPlaceholder, link)
|
internal fun String.formatWithLink(link: String) = replace(linkPlaceholder, link)
|
||||||
|
|
||||||
internal class ConsentManager(
|
internal class ConsentManager(
|
||||||
@@ -56,7 +58,7 @@ internal class ConsentManager(
|
|||||||
if (consentDetailsLink != null) {
|
if (consentDetailsLink != null) {
|
||||||
output.println(USER_CONSENT_DETAILS_LINK_TEMPLATE.formatWithLink(consentDetailsLink))
|
output.println(USER_CONSENT_DETAILS_LINK_TEMPLATE.formatWithLink(consentDetailsLink))
|
||||||
}
|
}
|
||||||
while (true) {
|
repeat(MAX_REQUEST_ATTEMPTS) {
|
||||||
output.println(PROMPT_REQUEST)
|
output.println(PROMPT_REQUEST)
|
||||||
when (input.readLine()) {
|
when (input.readLine()) {
|
||||||
"yes" -> {
|
"yes" -> {
|
||||||
@@ -77,5 +79,7 @@ internal class ConsentManager(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// we didn't receive an answer, let's ask next time
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+8
-3
@@ -67,10 +67,13 @@ class ConsentManagerTest {
|
|||||||
@Test
|
@Test
|
||||||
fun testConsentRequestAnswerAfterBadInput() = testUserDecision("\nasdasd\nno", false, USER_REFUSAL_MARKER, 3)
|
fun testConsentRequestAnswerAfterBadInput() = testUserDecision("\nasdasd\nno", false, USER_REFUSAL_MARKER, 3)
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testConsentRequestAnswerAfterTooManyBadInput() = testUserDecision("\n\n\n\n\n\n\n\nasdasd\nyes", false, null, 5)
|
||||||
|
|
||||||
private fun testUserDecision(
|
private fun testUserDecision(
|
||||||
prompt: String,
|
prompt: String,
|
||||||
expectedDecision: Boolean,
|
expectedDecision: Boolean,
|
||||||
expectedLine: String,
|
expectedLine: String?,
|
||||||
promptCount: Int = 1,
|
promptCount: Int = 1,
|
||||||
consentDetailsLink: String? = null,
|
consentDetailsLink: String? = null,
|
||||||
) {
|
) {
|
||||||
@@ -80,8 +83,10 @@ class ConsentManagerTest {
|
|||||||
val consentManager = ConsentManager(modifier, null, input, printStream)
|
val consentManager = ConsentManager(modifier, null, input, printStream)
|
||||||
val userDecision = consentManager.askForConsent(consentDetailsLink)
|
val userDecision = consentManager.askForConsent(consentDetailsLink)
|
||||||
assertEquals(expectedDecision, userDecision)
|
assertEquals(expectedDecision, userDecision)
|
||||||
val content = Files.readAllLines(localPropertiesFile)
|
if (expectedLine != null) {
|
||||||
assertTrue(content.contains(expectedLine))
|
val content = Files.readAllLines(localPropertiesFile)
|
||||||
|
assertTrue(content.contains(expectedLine))
|
||||||
|
}
|
||||||
val output = String(outputStream.toByteArray())
|
val output = String(outputStream.toByteArray())
|
||||||
assertContainsExactTimes(output, USER_CONSENT_REQUEST, 1)
|
assertContainsExactTimes(output, USER_CONSENT_REQUEST, 1)
|
||||||
assertContainsExactTimes(output, PROMPT_REQUEST, promptCount)
|
assertContainsExactTimes(output, PROMPT_REQUEST, promptCount)
|
||||||
|
|||||||
Reference in New Issue
Block a user