Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support new properties in posthog UTD reports #4020

Merged
merged 4 commits into from
Dec 13, 2024
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 @@ -39,6 +39,10 @@ class UtdTracker(
timeToDecryptMillis = info.timeToDecryptMs?.toInt() ?: -1,
domain = Error.Domain.E2EE,
name = name,
eventLocalAgeMillis = info.eventLocalAgeMillis.toInt(),
userTrustsOwnIdentity = info.userTrustsOwnIdentity,
isFederated = info.ownHomeserver != info.senderHomeserver,
isMatrixDotOrg = info.ownHomeserver == "matrix.org",
Copy link
Member

Choose a reason for hiding this comment

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

I did not check but are you sure that the ownHomeserver will be "matrix.org"? This looks more like a domain. Maybe a naming issue SDK side?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't quite follow. The name of the matrix.org homeserver is matrix.org.

This matches the behaviour on Element Web: https://github.com/element-hq/element-web/blob/edaf9773c02e71b20eedebbd9619ff8a2b2e4cf2/src/DecryptionFailureTracker.ts#L322.

Copy link
Member

Choose a reason for hiding this comment

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

ok, thanks!

)
analyticsService.capture(event)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class UtdTrackerTest {
eventId = AN_EVENT_ID.value,
timeToDecryptMs = null,
cause = UtdCause.UNKNOWN,
eventLocalAgeMillis = 100L,
)
)
assertThat(fakeAnalyticsService.capturedEvents).containsExactly(
Expand All @@ -34,7 +35,11 @@ class UtdTrackerTest {
cryptoSDK = Error.CryptoSDK.Rust,
timeToDecryptMillis = -1,
domain = Error.Domain.E2EE,
name = Error.Name.OlmKeysNotSentError
name = Error.Name.OlmKeysNotSentError,
isFederated = false,
isMatrixDotOrg = false,
userTrustsOwnIdentity = false,
eventLocalAgeMillis = 100,
)
)
assertThat(fakeAnalyticsService.screenEvents).isEmpty()
Expand All @@ -59,7 +64,11 @@ class UtdTrackerTest {
cryptoSDK = Error.CryptoSDK.Rust,
timeToDecryptMillis = 123,
domain = Error.Domain.E2EE,
name = Error.Name.OlmKeysNotSentError
name = Error.Name.OlmKeysNotSentError,
isFederated = false,
isMatrixDotOrg = false,
userTrustsOwnIdentity = false,
eventLocalAgeMillis = 0,
)
)
assertThat(fakeAnalyticsService.screenEvents).isEmpty()
Expand All @@ -84,7 +93,11 @@ class UtdTrackerTest {
cryptoSDK = Error.CryptoSDK.Rust,
timeToDecryptMillis = 123,
domain = Error.Domain.E2EE,
name = Error.Name.ExpectedDueToMembership
name = Error.Name.ExpectedDueToMembership,
isFederated = false,
isMatrixDotOrg = false,
userTrustsOwnIdentity = false,
eventLocalAgeMillis = 0,
)
)
assertThat(fakeAnalyticsService.screenEvents).isEmpty()
Expand All @@ -109,7 +122,11 @@ class UtdTrackerTest {
cryptoSDK = Error.CryptoSDK.Rust,
timeToDecryptMillis = 123,
domain = Error.Domain.E2EE,
name = Error.Name.ExpectedSentByInsecureDevice
name = Error.Name.ExpectedSentByInsecureDevice,
isFederated = false,
isMatrixDotOrg = false,
userTrustsOwnIdentity = false,
eventLocalAgeMillis = 0,
)
)
}
Expand All @@ -132,7 +149,90 @@ class UtdTrackerTest {
cryptoSDK = Error.CryptoSDK.Rust,
timeToDecryptMillis = 123,
domain = Error.Domain.E2EE,
name = Error.Name.ExpectedVerificationViolation
name = Error.Name.ExpectedVerificationViolation,
isFederated = false,
isMatrixDotOrg = false,
userTrustsOwnIdentity = false,
eventLocalAgeMillis = 0,
)
)
}

@Test
fun `when onUtd is called with different sender and receiver servers, the expected analytics Event is sent`() {
val fakeAnalyticsService = FakeAnalyticsService()
val sut = UtdTracker(fakeAnalyticsService)
sut.onUtd(
aRustUnableToDecryptInfo(
eventId = AN_EVENT_ID.value,
ownHomeserver = "example.com",
senderHomeserver = "matrix.org",
)
)
assertThat(fakeAnalyticsService.capturedEvents).containsExactly(
Error(
context = null,
cryptoModule = Error.CryptoModule.Rust,
cryptoSDK = Error.CryptoSDK.Rust,
timeToDecryptMillis = -1,
domain = Error.Domain.E2EE,
name = Error.Name.OlmKeysNotSentError,
isFederated = true,
isMatrixDotOrg = false,
userTrustsOwnIdentity = false,
eventLocalAgeMillis = 0,
)
)
}

@Test
fun `when onUtd is called from a matrix-org user, the expected analytics Event is sent`() {
val fakeAnalyticsService = FakeAnalyticsService()
val sut = UtdTracker(fakeAnalyticsService)
sut.onUtd(
aRustUnableToDecryptInfo(
eventId = AN_EVENT_ID.value,
ownHomeserver = "matrix.org",
)
)
assertThat(fakeAnalyticsService.capturedEvents).containsExactly(
Error(
context = null,
cryptoModule = Error.CryptoModule.Rust,
cryptoSDK = Error.CryptoSDK.Rust,
timeToDecryptMillis = -1,
domain = Error.Domain.E2EE,
name = Error.Name.OlmKeysNotSentError,
isFederated = true,
isMatrixDotOrg = true,
userTrustsOwnIdentity = false,
eventLocalAgeMillis = 0,
)
)
}

@Test
fun `when onUtd is called from a verified device, the expected analytics Event is sent`() {
val fakeAnalyticsService = FakeAnalyticsService()
val sut = UtdTracker(fakeAnalyticsService)
sut.onUtd(
aRustUnableToDecryptInfo(
eventId = AN_EVENT_ID.value,
userTrustsOwnIdentity = true,
)
)
assertThat(fakeAnalyticsService.capturedEvents).containsExactly(
Error(
context = null,
cryptoModule = Error.CryptoModule.Rust,
cryptoSDK = Error.CryptoSDK.Rust,
timeToDecryptMillis = -1,
domain = Error.Domain.E2EE,
name = Error.Name.OlmKeysNotSentError,
isFederated = false,
isMatrixDotOrg = false,
userTrustsOwnIdentity = true,
eventLocalAgeMillis = 0,
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import uniffi.matrix_sdk_crypto.UtdCause

internal fun aRustUnableToDecryptInfo(
eventId: String,
timeToDecryptMs: ULong?,
cause: UtdCause,
timeToDecryptMs: ULong? = null,
cause: UtdCause = UtdCause.UNKNOWN,
eventLocalAgeMillis: Long = 0L,
userTrustsOwnIdentity: Boolean = false,
senderHomeserver: String = "",
Expand Down
Loading