diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/CheckInsTransformer.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/CheckInsTransformer.kt index 68c52400c7bdcd9d559b1885d5bd84b4c3fe8636..723ea4bd4761c9c5a550293d6f5bd79291590038 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/CheckInsTransformer.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/CheckInsTransformer.kt @@ -13,6 +13,7 @@ import de.rki.coronawarnapp.util.TimeAndDateExtensions.seconds import de.rki.coronawarnapp.util.TimeAndDateExtensions.secondsToInstant import de.rki.coronawarnapp.util.TimeAndDateExtensions.toLocalDateUtc import de.rki.coronawarnapp.util.TimeStamper +import de.rki.coronawarnapp.util.toProtoByteString import org.joda.time.Days import org.joda.time.Instant import timber.log.Timber @@ -87,7 +88,7 @@ class CheckInsTransformer @Inject constructor( } return CheckInOuterClass.CheckIn.newBuilder() - // .locationId = TODO: Set calculated trace location + .setLocationId(traceLocationId.toProtoByteString()) .setStartIntervalNumber(checkInStart.derive10MinutesInterval().toInt()) .setEndIntervalNumber(checkInEnd.derive10MinutesInterval().toInt()) .setTransmissionRiskLevel(transmissionRiskLevel) diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/eventregistration/checkins/CheckInsTransformerTest.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/eventregistration/checkins/CheckInsTransformerTest.kt index 53cf1f3f429aed60a7290afb0598dfb067c88342..1f188c3ec580271c013d8d0e963e9533accecc8e 100644 --- a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/eventregistration/checkins/CheckInsTransformerTest.kt +++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/eventregistration/checkins/CheckInsTransformerTest.kt @@ -1,12 +1,10 @@ package de.rki.coronawarnapp.eventregistration.checkins -import com.google.protobuf.ByteString import de.rki.coronawarnapp.appconfig.AppConfigProvider import de.rki.coronawarnapp.appconfig.ConfigData import de.rki.coronawarnapp.appconfig.PresenceTracingConfigContainer import de.rki.coronawarnapp.appconfig.PresenceTracingRiskCalculationParamContainer import de.rki.coronawarnapp.appconfig.PresenceTracingSubmissionParamContainer -import de.rki.coronawarnapp.server.protocols.internal.pt.TraceLocationOuterClass import de.rki.coronawarnapp.server.protocols.internal.v2.PresenceTracingParametersOuterClass.PresenceTracingSubmissionParameters.AerosoleDecayFunctionLinear import de.rki.coronawarnapp.server.protocols.internal.v2.PresenceTracingParametersOuterClass.PresenceTracingSubmissionParameters.DurationFilter import de.rki.coronawarnapp.server.protocols.internal.v2.RiskCalculationParametersOuterClass.Range @@ -16,6 +14,7 @@ import de.rki.coronawarnapp.submission.task.TransmissionRiskVectorDeterminator import de.rki.coronawarnapp.util.TimeAndDateExtensions.seconds import de.rki.coronawarnapp.util.TimeAndDateExtensions.toLocalDateUtc import de.rki.coronawarnapp.util.TimeStamper +import de.rki.coronawarnapp.util.toOkioByteString import io.kotest.matchers.shouldBe import io.mockk.MockKAnnotations import io.mockk.coEvery @@ -198,175 +197,63 @@ class CheckInsTransformerTest : BaseTest() { // Check In 1 is excluded from submission due to time deriving // Check In 2 mapping and transformation get(0).apply { - /* - id = 2L, // Not mapped - client specific - guid = "trace_location_2", - guidHash = EMPTY, // Not mapped - client specific - version = 1, - type = 2, - description = "restaurant_2", - address = "address_2", - traceLocationStart = null, - traceLocationEnd = null, - defaultCheckInLengthInMinutes = null, - traceLocationBytes = EMPTY, - signature = "c2lnbmF0dXJlMQ==".decodeBase64()!!, - checkInStart = Instant.parse("2021-03-04T10:20:00Z"), - checkInEnd = Instant.parse("2021-03-04T10:30:00Z"), - completed = false, // Not mapped - client specific - createJournalEntry = false // Not mapped - client specific - */ - + locationId.toOkioByteString() shouldBe checkIn2.traceLocationId // New derived start time startIntervalNumber shouldBe Instant.parse("2021-03-04T10:20:00Z").seconds / TEN_MINUTES_IN_SECONDS // New derived end time endIntervalNumber shouldBe Instant.parse("2021-03-04T10:40:00Z").seconds / TEN_MINUTES_IN_SECONDS - /*signedLocation.signature shouldBe ByteString.copyFrom("signature1".toByteArray()) - parseLocation(signedLocation.location).apply { - guid shouldBe "trace_location_2" - version shouldBe 1 - type shouldBe TraceLocationOuterClass.TraceLocationType.LOCATION_TYPE_TEMPORARY_OTHER - description shouldBe "restaurant_2" - address shouldBe "address_2" - startTimestamp shouldBe 0 - endTimestamp shouldBe 0 - defaultCheckInLengthInMinutes shouldBe 0 - transmissionRiskLevel shouldBe 1 - }*/ } // Check-In 3 mappings and transformation - /* - id = 3L, // Not mapped - client specific - guid = "trace_location_3", - guidHash = EMPTY, // Not mapped - client specific - version = 1, - type = 3, - description = "restaurant_3", - address = "address_3", - traceLocationStart = Instant.parse("2021-03-04T09:00:00Z"), - traceLocationEnd = Instant.parse("2021-03-10T11:00:00Z") - defaultCheckInLengthInMinutes = 10, - traceLocationBytes = EMPTY, - signature = "c2lnbmF0dXJlMQ==".decodeBase64()!!, - checkInStart = Instant.parse("2021-03-04T09:30:00Z"), - checkInEnd = Instant.parse("2021-03-10T09:45:00Z"), - completed = false, // Not mapped - client specific - createJournalEntry = false // Not mapped - client specific - */ - // Splitted CheckIn 1 get(1).apply { + locationId.toOkioByteString() shouldBe checkIn3.traceLocationId // Start time from original check-in startIntervalNumber shouldBe Instant.parse("2021-03-04T09:30:00Z").seconds / TEN_MINUTES_IN_SECONDS // End time for splitted check-in 1 endIntervalNumber shouldBe Instant.parse("2021-03-05T00:00:00Z").seconds / TEN_MINUTES_IN_SECONDS - /*signedLocation.signature shouldBe ByteString.copyFrom("signature1".toByteArray()) - parseLocation(signedLocation.location).apply { - guid shouldBe "trace_location_3" - version shouldBe 1 - type shouldBe TraceLocationOuterClass.TraceLocationType.LOCATION_TYPE_PERMANENT_RETAIL - description shouldBe "restaurant_3" - address shouldBe "address_3" - startTimestamp shouldBe Instant.parse("2021-03-04T09:00:00Z").seconds - endTimestamp shouldBe Instant.parse("2021-03-10T11:00:00Z").seconds - defaultCheckInLengthInMinutes shouldBe 10 - transmissionRiskLevel shouldBe 1 - }*/ } // Splitted CheckIn 2 get(2).apply { + locationId.toOkioByteString() shouldBe checkIn3.traceLocationId + // Start time for splitted check-in 2 startIntervalNumber shouldBe Instant.parse("2021-03-05T00:00:00Z").seconds / TEN_MINUTES_IN_SECONDS // End time for splitted check-in 2 endIntervalNumber shouldBe Instant.parse("2021-03-06T00:00:00Z").seconds / TEN_MINUTES_IN_SECONDS - /*signedLocation.signature shouldBe ByteString.copyFrom("signature1".toByteArray()) - parseLocation(signedLocation.location).apply { - guid shouldBe "trace_location_3" - version shouldBe 1 - type shouldBe TraceLocationOuterClass.TraceLocationType.LOCATION_TYPE_PERMANENT_RETAIL - description shouldBe "restaurant_3" - address shouldBe "address_3" - startTimestamp shouldBe Instant.parse("2021-03-04T09:00:00Z").seconds - endTimestamp shouldBe Instant.parse("2021-03-10T11:00:00Z").seconds - defaultCheckInLengthInMinutes shouldBe 10 - transmissionRiskLevel shouldBe 1 - }*/ } // Splitted CheckIn 3 get(3).apply { + locationId.toOkioByteString() shouldBe checkIn3.traceLocationId // Start time from splitted check-in 3 startIntervalNumber shouldBe Instant.parse("2021-03-06T00:00:00Z").seconds / TEN_MINUTES_IN_SECONDS // End time for splitted check-in 3 endIntervalNumber shouldBe Instant.parse("2021-03-07T00:00:00Z").seconds / TEN_MINUTES_IN_SECONDS - /*signedLocation.signature shouldBe ByteString.copyFrom("signature1".toByteArray()) - parseLocation(signedLocation.location).apply { - guid shouldBe "trace_location_3" - version shouldBe 1 - type shouldBe TraceLocationOuterClass.TraceLocationType.LOCATION_TYPE_PERMANENT_RETAIL - description shouldBe "restaurant_3" - address shouldBe "address_3" - startTimestamp shouldBe Instant.parse("2021-03-04T09:00:00Z").seconds - endTimestamp shouldBe Instant.parse("2021-03-10T11:00:00Z").seconds - defaultCheckInLengthInMinutes shouldBe 10 - transmissionRiskLevel shouldBe 2 - }*/ } // Splitted CheckIn 4 get(4).apply { + locationId.toOkioByteString() shouldBe checkIn3.traceLocationId // Start time from splitted check-in 4 startIntervalNumber shouldBe Instant.parse("2021-03-07T00:00:00Z").seconds / TEN_MINUTES_IN_SECONDS // End time for splitted check-in 4 endIntervalNumber shouldBe Instant.parse("2021-03-08T00:00:00Z").seconds / TEN_MINUTES_IN_SECONDS - /*signedLocation.signature shouldBe ByteString.copyFrom("signature1".toByteArray()) - parseLocation(signedLocation.location).apply { - guid shouldBe "trace_location_3" - version shouldBe 1 - type shouldBe TraceLocationOuterClass.TraceLocationType.LOCATION_TYPE_PERMANENT_RETAIL - description shouldBe "restaurant_3" - address shouldBe "address_3" - startTimestamp shouldBe Instant.parse("2021-03-04T09:00:00Z").seconds - endTimestamp shouldBe Instant.parse("2021-03-10T11:00:00Z").seconds - defaultCheckInLengthInMinutes shouldBe 10 - transmissionRiskLevel shouldBe 4 - }*/ } // Splitted CheckIn 5 get(5).apply { + locationId.toOkioByteString() shouldBe checkIn3.traceLocationId // Start time from splitted check-in 5 startIntervalNumber shouldBe Instant.parse("2021-03-10T00:00:00Z").seconds / TEN_MINUTES_IN_SECONDS // End time for splitted check-in 5 endIntervalNumber shouldBe Instant.parse("2021-03-10T10:20:00Z").seconds / TEN_MINUTES_IN_SECONDS - /*signedLocation.signature shouldBe ByteString.copyFrom("signature1".toByteArray()) - parseLocation(signedLocation.location).apply { - guid shouldBe "trace_location_3" - version shouldBe 1 - type shouldBe TraceLocationOuterClass.TraceLocationType.LOCATION_TYPE_PERMANENT_RETAIL - description shouldBe "restaurant_3" - address shouldBe "address_3" - startTimestamp shouldBe Instant.parse("2021-03-04T09:00:00Z").seconds - endTimestamp shouldBe Instant.parse("2021-03-10T11:00:00Z").seconds - defaultCheckInLengthInMinutes shouldBe 10 - transmissionRiskLevel shouldBe 8 - }*/ } } } - private fun parseLocation(bytes: ByteString): TraceLocationOuterClass.TraceLocation = - TraceLocationOuterClass.TraceLocation.parseFrom(bytes) - companion object { private val TEN_MINUTES_IN_SECONDS = TimeUnit.MINUTES.toSeconds(10) - - // Base64 Strings of trace locations - private const val TRACE_LOCATION_2 = - "ChB0cmFjZV9sb2NhdGlvbl8yEAEYAiIMcmVzdGF1cmFudF8yKglhZGRyZXNzXzI=" - private const val TRACE_LOCATION_3 = - "ChB0cmFjZV9sb2NhdGlvbl8zEAEYAyIMcmVzdGF1cmFudF8zKglhZGRyZXNzXzMwkMOCggY4sM2iggZACg==" } }