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

Add tracelocation byterepresentation to TraceLocation database table (DEV) #2647

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "3130771db80d789cd0ef50b8d24e0354",
"identityHash": "58db835392620886de3bb25c22d5190a",
"entities": [
{
"tableName": "checkin",
Expand Down Expand Up @@ -116,7 +116,7 @@
},
{
"tableName": "traceLocations",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`guid` TEXT NOT NULL, `version` INTEGER NOT NULL, `type` INTEGER NOT NULL, `description` TEXT NOT NULL, `address` TEXT NOT NULL, `startDate` TEXT, `endDate` TEXT, `defaultCheckInLengthInMinutes` INTEGER, `signature` TEXT NOT NULL, PRIMARY KEY(`guid`))",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`guid` TEXT NOT NULL, `version` INTEGER NOT NULL, `type` INTEGER NOT NULL, `description` TEXT NOT NULL, `address` TEXT NOT NULL, `startDate` TEXT, `endDate` TEXT, `defaultCheckInLengthInMinutes` INTEGER, `byteRepresentation` TEXT NOT NULL, `signature` TEXT NOT NULL, PRIMARY KEY(`guid`))",
"fields": [
{
"fieldPath": "guid",
Expand Down Expand Up @@ -165,6 +165,11 @@
"columnName": "defaultCheckInLengthInMinutes",
"affinity": "INTEGER",
"notNull": false
},{
"fieldPath": "byteRepresentationBase64",
"columnName": "byteRepresentation",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "signatureBase64",
Expand All @@ -186,7 +191,7 @@
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '3130771db80d789cd0ef50b8d24e0354')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '58db835392620886de3bb25c22d5190a')"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class TraceLocationVerifierTest : BaseTestInstrumentation() {
startDate = Instant.ofEpochSecond(2687955),
endDate = Instant.ofEpochSecond(2687991),
defaultCheckInLengthInMinutes = 0,
byteRepresentation = verifyResult.signedTraceLocation.location.toByteArray().toByteString(),
signature = verifyResult.signedTraceLocation.signature.toByteArray().toByteString()
)

Expand Down Expand Up @@ -193,6 +194,7 @@ class TraceLocationVerifierTest : BaseTestInstrumentation() {
startDate = Instant.ofEpochSecond(2687955),
endDate = Instant.ofEpochSecond(2687991),
defaultCheckInLengthInMinutes = 0,
byteRepresentation = signedTraceLocation.location.toByteArray().toByteString(),
signature = signedTraceLocation.signature.toByteArray().toByteString()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ object TraceLocationDatabaseData {
startDate = Instant.parse("2021-01-01T12:00:00.000Z"),
endDate = Instant.parse("2021-01-01T18:00:00.000Z"),
defaultCheckInLengthInMinutes = null,
byteRepresentationBase64 = "byteRepresentationBase64",
signatureBase64 = "signature1"
)

Expand All @@ -28,6 +29,7 @@ object TraceLocationDatabaseData {
startDate = null,
endDate = null,
defaultCheckInLengthInMinutes = 15,
byteRepresentationBase64 = "byteRepresentationBase64",
signatureBase64 = "signature2"
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class CreateEventTestViewModel @AssistedInject constructor(
startDate?.toInstant(),
endDate?.toInstant(),
defaultCheckInLengthInMinutes.toInt(),
"ByteRepresentation".toByteArray().toByteString(),
"ServerSignature".toByteArray().toByteString()
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ data class TraceLocation(
val startDate: Instant?,
val endDate: Instant?,
val defaultCheckInLengthInMinutes: Int?,
val byteRepresentation: ByteString,
val signature: ByteString,
val version: Int = TRACE_LOCATION_VERSION,
) : Parcelable
Expand All @@ -33,6 +34,7 @@ fun TraceLocationEntity.toTraceLocation() = TraceLocation(
startDate = startDate,
endDate = endDate,
defaultCheckInLengthInMinutes = defaultCheckInLengthInMinutes,
byteRepresentation = byteRepresentationBase64.decodeBase64()!!,
signature = signatureBase64.decodeBase64()!!,
version = version
)
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ data class TraceLocationVerifyResult(
startDate = traceLocation.startTimestamp.toInstant(),
endDate = traceLocation.endTimestamp.toInstant(),
defaultCheckInLengthInMinutes = traceLocation.defaultCheckInLengthInMinutes,
byteRepresentation = signedTraceLocation.location.toByteArray().toByteString(),
signature = signedTraceLocation.signature.toByteArray().toByteString()
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ data class TraceLocationEntity(
@ColumnInfo(name = "startDate") val startDate: Instant?,
@ColumnInfo(name = "endDate") val endDate: Instant?,
@ColumnInfo(name = "defaultCheckInLengthInMinutes") val defaultCheckInLengthInMinutes: Int?,
@ColumnInfo(name = "byteRepresentation") val byteRepresentationBase64: String,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the columnName then also be byteRepresentationBase64 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes makes sense. However we are also not suffixing the base64 encoded values in the CheckInEntity. I think a PR in which we refactor the 2 entities would be best. I can do this after this one is merged, if that's fine for you?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good.

@ColumnInfo(name = "signature") val signatureBase64: String

)

fun TraceLocation.toTraceLocationEntity(): TraceLocationEntity =
Expand All @@ -31,6 +31,7 @@ fun TraceLocation.toTraceLocationEntity(): TraceLocationEntity =
startDate = startDate,
endDate = endDate,
defaultCheckInLengthInMinutes = defaultCheckInLengthInMinutes,
byteRepresentationBase64 = byteRepresentation.base64(),
signatureBase64 = signature.base64(),
version = version
)
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ internal class DefaultTraceLocationKtTest : BaseTest() {
startDate = Instant.parse("2021-01-01T12:00:00.000Z"),
endDate = Instant.parse("2021-01-01T18:00:00.000Z"),
defaultCheckInLengthInMinutes = 15,
byteRepresentationBase64 = "byteRepresentation".toByteArray().toByteString().base64(),
signatureBase64 = "signature".toByteArray().toByteString().base64()
).toTraceLocation() shouldBe TraceLocation(
guid = "TestGuid",
Expand All @@ -35,6 +36,7 @@ internal class DefaultTraceLocationKtTest : BaseTest() {
startDate = Instant.parse("2021-01-01T12:00:00.000Z"),
endDate = Instant.parse("2021-01-01T18:00:00.000Z"),
defaultCheckInLengthInMinutes = 15,
byteRepresentation = "byteRepresentation".toByteArray().toByteString(),
signature = "signature".toByteArray().toByteString()
)
}
Expand All @@ -50,6 +52,7 @@ internal class DefaultTraceLocationKtTest : BaseTest() {
startDate = null,
endDate = null,
defaultCheckInLengthInMinutes = null,
byteRepresentationBase64 = "byteRepresentation".toByteArray().toByteString().base64(),
signatureBase64 = "signature".toByteArray().toByteString().base64()
).toTraceLocation() shouldBe TraceLocation(
guid = "TestGuid",
Expand All @@ -60,6 +63,7 @@ internal class DefaultTraceLocationKtTest : BaseTest() {
startDate = null,
endDate = null,
defaultCheckInLengthInMinutes = null,
byteRepresentation = "byteRepresentation".toByteArray().toByteString(),
signature = "signature".toByteArray().toByteString()
)
}
Expand All @@ -76,6 +80,7 @@ internal class DefaultTraceLocationKtTest : BaseTest() {
startDate = Instant.parse("2021-01-01T12:00:00.000Z"),
endDate = Instant.parse("2021-01-01T18:00:00.000Z"),
defaultCheckInLengthInMinutes = 15,
byteRepresentationBase64 = "byteRepresentation".toByteArray().toByteString().base64(),
signatureBase64 = "signature".toByteArray().toByteString().base64()
),
TraceLocationEntity(
Expand All @@ -87,6 +92,7 @@ internal class DefaultTraceLocationKtTest : BaseTest() {
startDate = null,
endDate = null,
defaultCheckInLengthInMinutes = null,
byteRepresentationBase64 = "byteRepresentation".toByteArray().toByteString().base64(),
signatureBase64 = "signature".toByteArray().toByteString().base64()
)
).toTraceLocations() shouldBe listOf(
Expand All @@ -99,6 +105,7 @@ internal class DefaultTraceLocationKtTest : BaseTest() {
startDate = Instant.parse("2021-01-01T12:00:00.000Z"),
endDate = Instant.parse("2021-01-01T18:00:00.000Z"),
defaultCheckInLengthInMinutes = 15,
byteRepresentation = "byteRepresentation".toByteArray().toByteString(),
signature = "signature".toByteArray().toByteString()
),
TraceLocation(
Expand All @@ -110,6 +117,7 @@ internal class DefaultTraceLocationKtTest : BaseTest() {
startDate = null,
endDate = null,
defaultCheckInLengthInMinutes = null,
byteRepresentation = "byteRepresentation".toByteArray().toByteString(),
signature = "signature".toByteArray().toByteString()
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ internal class TraceLocationEntityTest : BaseTest() {
startDate = Instant.parse("2021-01-01T12:00:00.000Z"),
endDate = Instant.parse("2021-01-01T18:00:00.000Z"),
defaultCheckInLengthInMinutes = 15,
byteRepresentation = "byteRepresentation".toByteArray().toByteString(),
signature = "signature".toByteArray().toByteString()
).toTraceLocationEntity() shouldBe TraceLocationEntity(
guid = "TestGuid",
Expand All @@ -32,6 +33,7 @@ internal class TraceLocationEntityTest : BaseTest() {
startDate = Instant.parse("2021-01-01T12:00:00.000Z"),
endDate = Instant.parse("2021-01-01T18:00:00.000Z"),
defaultCheckInLengthInMinutes = 15,
byteRepresentationBase64 = "byteRepresentation".toByteArray().toByteString().base64(),
signatureBase64 = "signature".toByteArray().toByteString().base64()
)
}
Expand All @@ -47,6 +49,7 @@ internal class TraceLocationEntityTest : BaseTest() {
startDate = null,
endDate = null,
defaultCheckInLengthInMinutes = null,
byteRepresentation = "byteRepresentation".toByteArray().toByteString(),
signature = "signature".toByteArray().toByteString()
).toTraceLocationEntity() shouldBe TraceLocationEntity(
guid = "TestGuid",
Expand All @@ -57,6 +60,7 @@ internal class TraceLocationEntityTest : BaseTest() {
startDate = null,
endDate = null,
defaultCheckInLengthInMinutes = null,
byteRepresentationBase64 = "byteRepresentation".toByteArray().toByteString().base64(),
signatureBase64 = "signature".toByteArray().toByteString().base64()
)
}
Expand Down