Skip to content

Commit 785a0f4

Browse files
author
kele-leanes
committed
add senderHmacGenerated to tamperedMessage in ConversationTest
1 parent ff7b70b commit 785a0f4

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

library/src/androidTest/java/org/xmtp/android/library/ConversationTest.kt

+12-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.xmtp.android.library
33
import androidx.test.ext.junit.runners.AndroidJUnit4
44
import app.cash.turbine.test
55
import com.google.protobuf.kotlin.toByteString
6+
import com.google.protobuf.kotlin.toByteStringUtf8
67
import kotlinx.coroutines.ExperimentalCoroutinesApi
78
import org.junit.Assert
89
import org.junit.Assert.assertEquals
@@ -228,12 +229,21 @@ class ConversationTest {
228229
signedBytes,
229230
additionalData = headerBytes,
230231
)
232+
val thirtyDayPeriodsSinceEpoch =
233+
(Date().time / 1000 / 60 / 60 / 24 / 30).toInt()
234+
val info = "$thirtyDayPeriodsSinceEpoch-${aliceClient.address}"
235+
val infoEncoded = info.toByteStringUtf8().toByteArray()
236+
val senderHmacGenerated =
237+
Crypto.calculateMac(
238+
Crypto.deriveKey(aliceConversation.keyMaterial!!, ByteArray(0), infoEncoded),
239+
headerBytes
240+
)
231241
val tamperedMessage =
232242
MessageV2Builder.buildFromCipherText(
233243
headerBytes = headerBytes,
234244
ciphertext = ciphertext,
235-
senderHmac = null,
236-
shouldPush = true,
245+
senderHmac = senderHmacGenerated,
246+
shouldPush = codec.shouldPush("this is a fake"),
237247
)
238248
val tamperedEnvelope = EnvelopeBuilder.buildFromString(
239249
topic = aliceConversation.topic,

0 commit comments

Comments
 (0)