Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
Error report censoring (EXPOSUREAPP-14698) (#5833)
Browse files Browse the repository at this point in the history
* update RapidQrCodeCensor

* update RapidQrCodeCensor

---------

Co-authored-by: Mohamed <[email protected]>
  • Loading branch information
schauersbergern and mtwalli authored Feb 8, 2023
1 parent f7fe0bc commit 5cbec7f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,30 @@ class RapidQrCodeCensor @Inject constructor() : BugCensor {

override suspend fun checkLog(message: String): CensorContainer? {

val dataToCensor = dataToCensor ?: return null
if (dataToCensor.isEmpty()) return null

var newMessage = CensorContainer(message)

with(dataToCensor) {
newMessage = newMessage.censor(rawString, createReplacement(input = "ScannedRawString"))
dataToCensor.forEach { data ->
with(data) {
newMessage = newMessage.censor(rawString, createReplacement(input = "ScannedRawString"))

newMessage = newMessage.censor(hash, PLACEHOLDER + hash.takeLast(4))
newMessage = newMessage.censor(hash, PLACEHOLDER + hash.takeLast(4))

withValidName(firstName) { firstName ->
newMessage = newMessage.censor(firstName, createReplacement(input = "FirstName"))
}
withValidName(firstName) { firstName ->
newMessage = newMessage.censor(firstName, createReplacement(input = "FirstName"))
newMessage = newMessage.censor(firstName.uppercase(), createReplacement(input = "FirstName"))
}

withValidName(lastName) { lastName ->
newMessage = newMessage.censor(lastName, createReplacement(input = "LastName"))
}
withValidName(lastName) { lastName ->
newMessage = newMessage.censor(lastName, createReplacement(input = "LastName"))
newMessage = newMessage.censor(lastName.uppercase(), createReplacement(input = "FirstName"))
}

val dateOfBirthString = dateOfBirth?.format(dayOfBirthFormatter) ?: return@with
val dateOfBirthString = dateOfBirth?.format(dayOfBirthFormatter) ?: return@with

newMessage = newMessage.censor(dateOfBirthString, createReplacement(input = "DateOfBirth"))
newMessage = newMessage.censor(dateOfBirthString, createReplacement(input = "DateOfBirth"))
}
}

return newMessage.nullIfEmpty()
Expand All @@ -44,7 +48,7 @@ class RapidQrCodeCensor @Inject constructor() : BugCensor {
private fun createReplacement(input: String): String = "$PLACEHOLDER_TYPE/$input"

companion object {
var dataToCensor: CensorData? = null
val dataToCensor = mutableSetOf<CensorData>()

private const val PLACEHOLDER = "SHA256HASH-ENDING-WITH-"
private const val PLACEHOLDER_TYPE = "RapidTest"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ abstract class RapidQrCodeExtractor : QrCodeExtractor<CoronaTestQRCode> {
Timber.tag(loggingTag).v("extract(rawString=%s)", rawString)
val payload = CleanPayload(extractData(rawString))

RapidQrCodeCensor.dataToCensor = RapidQrCodeCensor.CensorData(
rawString = rawString,
hash = payload.hash,
firstName = payload.firstName,
lastName = payload.lastName,
dateOfBirth = payload.dateOfBirth
RapidQrCodeCensor.dataToCensor.add(
RapidQrCodeCensor.CensorData(
rawString = rawString,
hash = payload.hash,
firstName = payload.firstName,
lastName = payload.lastName,
dateOfBirth = payload.dateOfBirth
)
)

payload.requireValidData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,21 @@ internal class RapidQrCodeCensorTest {

@AfterEach
fun teardown() {
RapidQrCodeCensor.dataToCensor = null
RapidQrCodeCensor.dataToCensor.clear()
}

private fun createInstance() = RapidQrCodeCensor()

@Test
fun `checkLog() should return censored LogLine`() = runTest {
RapidQrCodeCensor.dataToCensor = RapidQrCodeCensor.CensorData(
rawString = testRawString,
hash = testHash,
firstName = "Milhouse",
lastName = "Van Houten",
dateOfBirth = LocalDate.parse("1980-07-01")
RapidQrCodeCensor.dataToCensor.add(
RapidQrCodeCensor.CensorData(
rawString = testRawString,
hash = testHash,
firstName = "Milhouse",
lastName = "Van Houten",
dateOfBirth = LocalDate.parse("1980-07-01")
)
)

val censor = createInstance()
Expand All @@ -57,12 +59,14 @@ internal class RapidQrCodeCensorTest {

@Test
fun `checkLog() should return null if nothing should be censored`() = runTest {
RapidQrCodeCensor.dataToCensor = RapidQrCodeCensor.CensorData(
rawString = testRawString,
hash = testHash.replace("8", "9"),
firstName = null,
lastName = null,
dateOfBirth = null
RapidQrCodeCensor.dataToCensor.add(
RapidQrCodeCensor.CensorData(
rawString = testRawString,
hash = testHash.replace("8", "9"),
firstName = null,
lastName = null,
dateOfBirth = null
)
)

val censor = createInstance()
Expand Down

0 comments on commit 5cbec7f

Please sign in to comment.