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

Personal Certificate data in error Report available (EXPOSUREAPP-9923) #4195

Merged
merged 8 commits into from
Oct 12, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import de.rki.coronawarnapp.bugreporting.censors.contactdiary.DiaryLocationCenso
import de.rki.coronawarnapp.bugreporting.censors.contactdiary.DiaryPersonCensor
import de.rki.coronawarnapp.bugreporting.censors.contactdiary.DiaryVisitCensor
import de.rki.coronawarnapp.bugreporting.censors.contactdiary.OrganizerRegistrationTokenCensor
import de.rki.coronawarnapp.bugreporting.censors.dcc.CwaUserCensor
import de.rki.coronawarnapp.bugreporting.censors.dcc.DccQrCodeCensor
import de.rki.coronawarnapp.bugreporting.censors.presencetracing.CheckInsCensor
import de.rki.coronawarnapp.bugreporting.censors.presencetracing.TraceLocationCensor
Expand All @@ -36,6 +37,7 @@ import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.converter.protobuf.ProtoConverterFactory
import javax.inject.Singleton

@Suppress("TooManyFunctions")
@Module
class BugReportingSharedModule {

Expand Down Expand Up @@ -137,4 +139,8 @@ class BugReportingSharedModule {
@Provides
@IntoSet
fun organizerRegistrationTokenCensor(censor: OrganizerRegistrationTokenCensor): BugCensor = censor

@Provides
@IntoSet
fun cwaUserCensor(censor: CwaUserCensor): BugCensor = censor
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package de.rki.coronawarnapp.bugreporting.censors.dcc

import dagger.Reusable
import de.rki.coronawarnapp.bugreporting.censors.BugCensor
import de.rki.coronawarnapp.bugreporting.censors.BugCensor.CensorContainer
import de.rki.coronawarnapp.covidcertificate.common.certificate.CertificatePersonIdentifier
import de.rki.coronawarnapp.covidcertificate.person.core.PersonCertificatesSettings
import javax.inject.Inject

@Reusable
class CwaUserCensor @Inject constructor(
private val personCertificatesSettings: PersonCertificatesSettings
) : BugCensor {

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

personCertificatesSettings.currentCwaUser.value?.let { cwaUser ->
newMessage = censorCwaUserData(cwaUser, newMessage)
}

return newMessage.nullIfEmpty()
}

private fun censorCwaUserData(
cwaUser: CertificatePersonIdentifier,
message: CensorContainer
): CensorContainer {
var newMessage = message

newMessage = newMessage.censor(
cwaUser.dateOfBirthFormatted,
"cwaUser/dateOfBirth"
)

newMessage = newMessage.censor(
cwaUser.lastNameStandardized,
"cwaUser/lastNameStandardized"
)

cwaUser.firstNameStandardized?.let { firstNameStandardized ->
newMessage = newMessage.censor(
firstNameStandardized,
"cwaUser/firstNameStandardized"
)
}

return newMessage
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import de.rki.coronawarnapp.bugreporting.BugReportingSharedModule
import de.rki.coronawarnapp.contactdiary.storage.repo.ContactDiaryRepository
import de.rki.coronawarnapp.coronatest.CoronaTestRepository
import de.rki.coronawarnapp.coronatest.antigen.profile.RATProfileSettings
import de.rki.coronawarnapp.covidcertificate.person.core.PersonCertificatesSettings
import de.rki.coronawarnapp.covidcertificate.test.core.TestCertificateRepository
import de.rki.coronawarnapp.presencetracing.checkins.CheckInRepository
import de.rki.coronawarnapp.presencetracing.storage.repo.TraceLocationRepository
Expand All @@ -19,6 +20,7 @@ import io.mockk.mockk
import kotlinx.coroutines.flow.flowOf
import org.junit.jupiter.api.Test
import testhelpers.BaseTest
import testhelpers.preferences.mockFlowPreference
import timber.log.Timber
import javax.inject.Singleton

Expand Down Expand Up @@ -108,4 +110,10 @@ class MockProvider {
@Singleton
@Provides
fun ratProfileSettings(): RATProfileSettings = mockk()

@Singleton
@Provides
fun personCertificatesSettings(): PersonCertificatesSettings = mockk {
every { currentCwaUser } returns mockFlowPreference(null)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package de.rki.coronawarnapp.bugreporting.censors.dcc

import de.rki.coronawarnapp.covidcertificate.common.certificate.CertificatePersonIdentifier
import de.rki.coronawarnapp.covidcertificate.person.core.PersonCertificatesSettings
import io.kotest.matchers.shouldBe
import io.mockk.MockKAnnotations
import io.mockk.every
import io.mockk.impl.annotations.MockK
import kotlinx.coroutines.test.runBlockingTest
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import testhelpers.BaseTest
import testhelpers.preferences.mockFlowPreference

@Suppress("MaxLineLength")
class CwaUserCensorTest : BaseTest() {

@MockK lateinit var personCertificatesSettings: PersonCertificatesSettings

@BeforeEach
fun setup() {
MockKAnnotations.init(this)
}

private fun createInstance() = CwaUserCensor(personCertificatesSettings)

@Test
fun `censoring of certificate person identifier works`() = runBlockingTest {

every { personCertificatesSettings.currentCwaUser } returns mockFlowPreference(
CertificatePersonIdentifier(
"1982-02-11",
"LIME",
"MOTHER<MANDY"
)
)

val censor = createInstance()
val certDataToCensor = "PersonCertificatesProvider: vaccPersons=[], tests=[], recos=[], cwaUser=CertificatePersonIdentifier(dateOfBirthFormatted=1982-02-11, lastNameStandardized=LIME, firstNameStandardized=MOTHER<MANDY)"
censor.checkLog(certDataToCensor)!!
.compile()!!.censored shouldBe "PersonCertificatesProvider: vaccPersons=[], tests=[], recos=[], cwaUser=CertificatePersonIdentifier(dateOfBirthFormatted=cwaUser/dateOfBirth, lastNameStandardized=cwaUser/lastNameStandardized, firstNameStandardized=cwaUser/firstNameStandardized)"
}

@Test
fun `checkLog() should return null if nothing should be censored`() = runBlockingTest {
every { personCertificatesSettings.currentCwaUser } returns mockFlowPreference(null)

val censor = createInstance()
val certDataToCensor = "Nothing interesting here"
censor.checkLog(certDataToCensor) shouldBe null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import dagger.Provides
import de.rki.coronawarnapp.appconfig.AppConfigProvider
import de.rki.coronawarnapp.appconfig.ConfigData
import de.rki.coronawarnapp.appconfig.PresenceTracingConfigContainer
import de.rki.coronawarnapp.bugreporting.censors.dcc.CwaUserCensorTest
import de.rki.coronawarnapp.bugreporting.censors.dcc.DccQrCodeCensorTest
import de.rki.coronawarnapp.covidcertificate.booster.DccBoosterRulesValidatorTest
import de.rki.coronawarnapp.covidcertificate.common.certificate.DccQrCodeExtractorTest
Expand Down Expand Up @@ -67,6 +68,7 @@ interface CovidCertificateTestComponent {
fun inject(testClass: DccBoosterRulesValidatorTest)
fun inject(testClass: QrCodeValidatorTest)
fun inject(testClass: QrCodeScannerViewModelTest)
fun inject(testClass: CwaUserCensorTest)

@Component.Factory
interface Factory {
Expand Down