From 49124cf263e82f612f7f8f25135c3bdfca987aee Mon Sep 17 00:00:00 2001
From: Kolya Opahle <k.opahle@sap.com>
Date: Mon, 10 May 2021 10:38:35 +0200
Subject: [PATCH] Adapt censoring (EXPOSUREAPP-7080) (#3087)

* Removed debug check in censors that acted differently in debug vs prod mode (prod mode is new default)

* Changed tests to not check if debug logging is different

* Also removed build checking from RatQrCodeCensor

* Removed more obsolete mocking of isDeviceForTestersBuild from CoronaTestCensorTest and RatQrCodeCensorTest

Co-authored-by: Lukas Lechner <lukas.lechner@sap.com>
Co-authored-by: harambasicluka <64483219+harambasicluka@users.noreply.github.com>
---
 .../censors/submission/CoronaTestCensor.kt            |  8 +-------
 .../censors/submission/PcrQrCodeCensor.kt             |  8 +-------
 .../censors/submission/RatQrCodeCensor.kt             |  7 +------
 .../bugreporting/censors/CoronaTestCensorTest.kt      | 10 ----------
 .../bugreporting/censors/PcrQrCodeCensorTest.kt       | 11 -----------
 .../bugreporting/censors/RatQrCodeCensorTest.kt       | 11 -----------
 6 files changed, 3 insertions(+), 52 deletions(-)

diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/bugreporting/censors/submission/CoronaTestCensor.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/bugreporting/censors/submission/CoronaTestCensor.kt
index df934b7e6..8958fe290 100644
--- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/bugreporting/censors/submission/CoronaTestCensor.kt
+++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/bugreporting/censors/submission/CoronaTestCensor.kt
@@ -5,7 +5,6 @@ import de.rki.coronawarnapp.bugreporting.censors.BugCensor
 import de.rki.coronawarnapp.bugreporting.censors.BugCensor.Companion.toNewLogLineIfDifferent
 import de.rki.coronawarnapp.bugreporting.debuglog.LogLine
 import de.rki.coronawarnapp.coronatest.CoronaTestRepository
-import de.rki.coronawarnapp.util.CWADebug
 import kotlinx.coroutines.flow.first
 import javax.inject.Inject
 
@@ -31,11 +30,7 @@ class CoronaTestCensor @Inject constructor(
         for (token in tokenHistory) {
             if (!entry.message.contains(token)) continue
 
-            newMessage = if (CWADebug.isDeviceForTestersBuild) {
-                newMessage.replace(token, PLACEHOLDER_TESTER + token.takeLast(27))
-            } else {
-                newMessage.replace(token, PLACEHOLDER + token.takeLast(4))
-            }
+            newMessage = newMessage.replace(token, PLACEHOLDER + token.takeLast(4))
         }
 
         identifierHistory
@@ -48,7 +43,6 @@ class CoronaTestCensor @Inject constructor(
     }
 
     companion object {
-        private const val PLACEHOLDER_TESTER = "########-"
         private const val PLACEHOLDER = "########-####-####-####-########"
     }
 }
diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/bugreporting/censors/submission/PcrQrCodeCensor.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/bugreporting/censors/submission/PcrQrCodeCensor.kt
index 3880817e6..881a5396f 100644
--- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/bugreporting/censors/submission/PcrQrCodeCensor.kt
+++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/bugreporting/censors/submission/PcrQrCodeCensor.kt
@@ -4,7 +4,6 @@ import dagger.Reusable
 import de.rki.coronawarnapp.bugreporting.censors.BugCensor
 import de.rki.coronawarnapp.bugreporting.censors.BugCensor.Companion.toNewLogLineIfDifferent
 import de.rki.coronawarnapp.bugreporting.debuglog.LogLine
-import de.rki.coronawarnapp.util.CWADebug
 import javax.inject.Inject
 
 @Reusable
@@ -15,18 +14,13 @@ class PcrQrCodeCensor @Inject constructor() : BugCensor {
         val guid = lastGUID ?: return null
         if (!entry.message.contains(guid)) return null
 
-        val newMessage = if (CWADebug.isDeviceForTestersBuild) {
-            entry.message.replace(guid, PLACEHOLDER_TESTER + guid.takeLast(27))
-        } else {
-            entry.message.replace(guid, PLACEHOLDER + guid.takeLast(4))
-        }
+        val newMessage = entry.message.replace(guid, PLACEHOLDER + guid.takeLast(4))
 
         return entry.toNewLogLineIfDifferent(newMessage)
     }
 
     companion object {
         var lastGUID: String? = null
-        private const val PLACEHOLDER_TESTER = "########-"
         private const val PLACEHOLDER = "########-####-####-####-########"
     }
 }
diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/bugreporting/censors/submission/RatQrCodeCensor.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/bugreporting/censors/submission/RatQrCodeCensor.kt
index 8fe3c62f3..29a9c1fa5 100644
--- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/bugreporting/censors/submission/RatQrCodeCensor.kt
+++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/bugreporting/censors/submission/RatQrCodeCensor.kt
@@ -6,7 +6,6 @@ import de.rki.coronawarnapp.bugreporting.censors.BugCensor.Companion.toNewLogLin
 import de.rki.coronawarnapp.bugreporting.censors.BugCensor.Companion.withValidName
 import de.rki.coronawarnapp.bugreporting.debuglog.LogLine
 import de.rki.coronawarnapp.coronatest.qrcode.RapidAntigenHash
-import de.rki.coronawarnapp.util.CWADebug
 import org.joda.time.LocalDate
 import org.joda.time.format.DateTimeFormat
 import javax.inject.Inject
@@ -25,11 +24,7 @@ class RatQrCodeCensor @Inject constructor() : BugCensor {
         with(dataToCensor) {
             newMessage = newMessage.replace(rawString, "RatQrCode/ScannedRawString")
 
-            newMessage = if (CWADebug.isDeviceForTestersBuild) {
-                newMessage.replace(hash, PLACEHOLDER + hash.takeLast(28))
-            } else {
-                newMessage.replace(hash, PLACEHOLDER + hash.takeLast(4))
-            }
+            newMessage = newMessage.replace(hash, PLACEHOLDER + hash.takeLast(4))
 
             withValidName(firstName) { firstName ->
                 newMessage = newMessage.replace(firstName, "RATest/FirstName")
diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/bugreporting/censors/CoronaTestCensorTest.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/bugreporting/censors/CoronaTestCensorTest.kt
index 0b88f1988..f80997a6a 100644
--- a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/bugreporting/censors/CoronaTestCensorTest.kt
+++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/bugreporting/censors/CoronaTestCensorTest.kt
@@ -6,13 +6,11 @@ import de.rki.coronawarnapp.coronatest.CoronaTestRepository
 import de.rki.coronawarnapp.coronatest.type.CoronaTest
 import de.rki.coronawarnapp.coronatest.type.pcr.PCRCoronaTest
 import de.rki.coronawarnapp.coronatest.type.rapidantigen.RACoronaTest
-import de.rki.coronawarnapp.util.CWADebug
 import io.kotest.matchers.shouldBe
 import io.mockk.MockKAnnotations
 import io.mockk.every
 import io.mockk.impl.annotations.MockK
 import io.mockk.mockk
-import io.mockk.mockkObject
 import io.mockk.verify
 import kotlinx.coroutines.flow.MutableStateFlow
 import kotlinx.coroutines.test.runBlockingTest
@@ -44,9 +42,6 @@ class CoronaTestCensorTest : BaseTest() {
     fun setup() {
         MockKAnnotations.init(this)
 
-        mockkObject(CWADebug)
-        every { CWADebug.isDeviceForTestersBuild } returns false
-
         every { coronaTestRepository.coronaTests } returns coronaTests
     }
 
@@ -68,11 +63,6 @@ class CoronaTestCensorTest : BaseTest() {
             message = "I'm a shy registration token: ########-####-####-####-########3a2f and we are extrovert qrcode-pcr-CoronaTest/Identifier and qrcode-rat-CoronaTest/Identifier"
         )
 
-        every { CWADebug.isDeviceForTestersBuild } returns true
-        instance.checkLog(filterMe) shouldBe filterMe.copy(
-            message = "I'm a shy registration token: ########-e0de-4bd4-90c1-17c2bb683a2f and we are extrovert qrcode-pcr-CoronaTest/Identifier and qrcode-rat-CoronaTest/Identifier"
-        )
-
         verify { coronaTestRepository.coronaTests }
     }
 
diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/bugreporting/censors/PcrQrCodeCensorTest.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/bugreporting/censors/PcrQrCodeCensorTest.kt
index d89f76791..58826f8ff 100644
--- a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/bugreporting/censors/PcrQrCodeCensorTest.kt
+++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/bugreporting/censors/PcrQrCodeCensorTest.kt
@@ -2,11 +2,8 @@ package de.rki.coronawarnapp.bugreporting.censors
 
 import de.rki.coronawarnapp.bugreporting.censors.submission.PcrQrCodeCensor
 import de.rki.coronawarnapp.bugreporting.debuglog.LogLine
-import de.rki.coronawarnapp.util.CWADebug
 import io.kotest.matchers.shouldBe
 import io.mockk.MockKAnnotations
-import io.mockk.every
-import io.mockk.mockkObject
 import kotlinx.coroutines.test.runBlockingTest
 import org.junit.jupiter.api.AfterEach
 import org.junit.jupiter.api.BeforeEach
@@ -20,9 +17,6 @@ class PcrQrCodeCensorTest : BaseTest() {
     @BeforeEach
     fun setup() {
         MockKAnnotations.init(this)
-
-        mockkObject(CWADebug)
-        every { CWADebug.isDeviceForTestersBuild } returns false
     }
 
     @AfterEach
@@ -46,11 +40,6 @@ class PcrQrCodeCensorTest : BaseTest() {
         instance.checkLog(censored) shouldBe censored.copy(
             message = "I'm a shy qrcode: ########-####-####-####-########3a2f"
         )
-
-        every { CWADebug.isDeviceForTestersBuild } returns true
-        instance.checkLog(censored) shouldBe censored.copy(
-            message = "I'm a shy qrcode: ########-e0de-4bd4-90c1-17c2bb683a2f"
-        )
     }
 
     @Test
diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/bugreporting/censors/RatQrCodeCensorTest.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/bugreporting/censors/RatQrCodeCensorTest.kt
index 83b890cd1..6689f4e48 100644
--- a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/bugreporting/censors/RatQrCodeCensorTest.kt
+++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/bugreporting/censors/RatQrCodeCensorTest.kt
@@ -2,11 +2,8 @@ package de.rki.coronawarnapp.bugreporting.censors
 
 import de.rki.coronawarnapp.bugreporting.censors.submission.RatQrCodeCensor
 import de.rki.coronawarnapp.bugreporting.debuglog.LogLine
-import de.rki.coronawarnapp.util.CWADebug
 import io.kotest.matchers.shouldBe
 import io.mockk.MockKAnnotations
-import io.mockk.every
-import io.mockk.mockkObject
 import kotlinx.coroutines.test.runBlockingTest
 import org.joda.time.LocalDate
 import org.junit.jupiter.api.AfterEach
@@ -21,9 +18,6 @@ internal class RatQrCodeCensorTest {
     @BeforeEach
     fun setUp() {
         MockKAnnotations.init(this)
-
-        mockkObject(CWADebug)
-        every { CWADebug.isDeviceForTestersBuild } returns false
     }
 
     @AfterEach
@@ -56,11 +50,6 @@ internal class RatQrCodeCensorTest {
         censor.checkLog(logLineToCensor) shouldBe logLineToCensor.copy(
             message = "Here comes the hash: SHA256HASH-ENDING-WITH-15ad of the rat test of RATest/FirstName RATest/LastName. He was born on RATest/DateOfBirth"
         )
-
-        every { CWADebug.isDeviceForTestersBuild } returns true
-        censor.checkLog(logLineToCensor) shouldBe logLineToCensor.copy(
-            message = "Here comes the hash: SHA256HASH-ENDING-WITH-61a396177a9cb410ff61f20015ad of the rat test of RATest/FirstName RATest/LastName. He was born on RATest/DateOfBirth"
-        )
     }
 
     @Test
-- 
GitLab