This repository was archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 487
Add otp censor (EXPOSUREAPP-14190) #5708
Merged
Merged
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cca8771
add otp censor
schauersbergern 2c0d0cf
remove teardown
schauersbergern 0373ed2
fix tests
schauersbergern d49f792
Merge branch 'release/3.0.x' into feature/14190_censor-otp
mtwalli acd33e2
Merge branch 'release/3.0.x' into feature/14190_censor-otp
mtwalli 17020d1
censor otp on fetch and renewal
schauersbergern 9ced721
update const
schauersbergern fb62da3
Merge branch 'release/3.0.x' into feature/14190_censor-otp
mtwalli c3333a4
remove redundant OtpCensor setting
schauersbergern File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...-Warn-App/src/main/java/de/rki/coronawarnapp/bugreporting/censors/submission/OtpCensor.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package de.rki.coronawarnapp.bugreporting.censors.submission | ||
|
||
import dagger.Reusable | ||
import de.rki.coronawarnapp.bugreporting.censors.BugCensor | ||
import de.rki.coronawarnapp.srs.core.storage.SrsSubmissionSettings | ||
import kotlinx.coroutines.flow.last | ||
import javax.inject.Inject | ||
|
||
@Reusable | ||
class OtpCensor @Inject constructor( | ||
private val srsSubmissionSettings: SrsSubmissionSettings, | ||
) : BugCensor { | ||
|
||
override suspend fun checkLog(message: String): BugCensor.CensorContainer? { | ||
var container = BugCensor.CensorContainer(message) | ||
|
||
val otp = srsSubmissionSettings.otp.last() | ||
|
||
otp?.uuid?.let { | ||
container = container.censor(it.toString(), "########-####-####-####-########") | ||
} | ||
|
||
otp?.expiresAt?.toString()?.let { | ||
container = container.censor(it, "SrsOtp/expiresAt") | ||
} | ||
|
||
return container.nullIfEmpty() | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
Corona-Warn-App/src/test/java/de/rki/coronawarnapp/bugreporting/censors/OtpCensorTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package de.rki.coronawarnapp.bugreporting.censors | ||
|
||
import de.rki.coronawarnapp.bugreporting.censors.submission.OtpCensor | ||
import de.rki.coronawarnapp.srs.core.model.SrsOtp | ||
import de.rki.coronawarnapp.srs.core.storage.SrsSubmissionSettings | ||
import io.kotest.matchers.shouldBe | ||
import io.mockk.MockKAnnotations | ||
import io.mockk.coEvery | ||
import io.mockk.every | ||
import io.mockk.impl.annotations.MockK | ||
import kotlinx.coroutines.flow.flowOf | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import testhelpers.BaseTest | ||
import java.time.Instant | ||
import java.util.UUID | ||
|
||
class OtpCensorTest : BaseTest() { | ||
|
||
@MockK lateinit var srsSubmissionSettings: SrsSubmissionSettings | ||
|
||
private val srsOtp = SrsOtp( | ||
uuid = UUID.fromString("73a373fd-3a7b-49b9-b71c-2ae7a2824760"), | ||
expiresAt = Instant.parse("2023-11-07T12:10:10Z") | ||
) | ||
|
||
@BeforeEach | ||
fun setup() { | ||
MockKAnnotations.init(this) | ||
|
||
every { srsSubmissionSettings.otp } returns flowOf(srsOtp) | ||
coEvery { srsSubmissionSettings.getOtp() } returns srsOtp | ||
} | ||
|
||
private fun createInstance() = OtpCensor( | ||
srsSubmissionSettings | ||
) | ||
|
||
@Test | ||
fun `censoring replaces the otp uuid`() = runTest { | ||
val instance = createInstance() | ||
val censored = "This is the very secret otp: ${srsOtp.uuid}" | ||
instance.checkLog(censored)!! | ||
.compile()!!.censored shouldBe "This is the very secret otp: ########-####-####-####-########" | ||
} | ||
|
||
@Test | ||
fun `censoring replaces the otp expiration date`() = runTest { | ||
val instance = createInstance() | ||
val censored = "This is the expiration date of the secret otp: ${srsOtp.expiresAt}" | ||
instance.checkLog(censored)!! | ||
.compile()!!.censored shouldBe "This is the expiration date of the secret otp: SrsOtp/expiresAt" | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.