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

fix: E2EI required: grace period in seconds (WPB-5771) #2313

Merged
merged 2 commits into from
Dec 15, 2023
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 @@ -134,7 +134,7 @@ class FeatureConfigMapperImpl : FeatureConfigMapper {
E2EIModel(
E2EIConfigModel(
data?.config?.url ?: "",
data?.config?.verificationExpirationNS ?: 0L
data?.config?.verificationExpirationSeconds ?: 0L
),
fromDTO(data?.status ?: FeatureFlagStatusDTO.DISABLED)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,5 @@ data class E2EIModel(

data class E2EIConfigModel(
val discoverUrl: String,
val verificationExpirationNS: Long
val verificationExpirationSeconds: Long
)
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ import com.wire.kalium.logic.data.featureConfig.E2EIModel
import com.wire.kalium.logic.data.featureConfig.Status
import com.wire.kalium.logic.functional.Either
import com.wire.kalium.util.DateTimeUtil
import kotlinx.datetime.Instant
import kotlin.time.DurationUnit
import kotlin.time.toDuration

class E2EIConfigHandler(
private val userConfigRepository: UserConfigRepository,
) {
fun handle(e2eiConfig: E2EIModel): Either<CoreFailure, Unit> {
val gracePeriodEndMs = e2eiConfig.config.verificationExpirationNS.toDuration(DurationUnit.NANOSECONDS).inWholeMilliseconds
val gracePeriodEnd = DateTimeUtil.currentInstant()
.plus(e2eiConfig.config.verificationExpirationSeconds.toDuration(DurationUnit.SECONDS))
userConfigRepository.setE2EISettings(
E2EISettings(
isRequired = e2eiConfig.status == Status.ENABLED,
discoverUrl = e2eiConfig.config.discoverUrl,
gracePeriodEnd = Instant.fromEpochMilliseconds(gracePeriodEndMs)
gracePeriodEnd = gracePeriodEnd
)
)
return userConfigRepository.setE2EINotificationTime(DateTimeUtil.currentInstant())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import com.wire.kalium.logic.util.shouldSucceed
import com.wire.kalium.persistence.config.inMemoryUserConfigStorage
import com.wire.kalium.persistence.dao.SupportedProtocolEntity
import com.wire.kalium.persistence.dao.unread.UserConfigDAO
import com.wire.kalium.util.DateTimeUtil
import io.mockative.Mock
import io.mockative.any
import io.mockative.classOf
Expand All @@ -63,7 +64,6 @@ import io.mockative.mock
import io.mockative.once
import io.mockative.verify
import kotlinx.coroutines.test.runTest
import kotlinx.datetime.Instant
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
Expand Down Expand Up @@ -590,7 +590,8 @@ class SyncFeatureConfigsUseCaseTest {

@Test
fun givenE2EIIsDisabled_whenSyncing_thenItShouldBeStoredAsDisabled() = runTest {
val e2EIModel = E2EIModel(E2EIConfigModel("url", 10_000_000_000L), Status.DISABLED)
val e2EIModel = E2EIModel(E2EIConfigModel("url", 10_000L), Status.DISABLED)
val expectedGracePeriodEnd = DateTimeUtil.currentInstant().plus(10_000.toDuration(DurationUnit.SECONDS))
val (arrangement, syncFeatureConfigsUseCase) = Arrangement()
.withRemoteFeatureConfigsSucceeding(
FeatureConfigTest.newModel(e2EIModel = e2EIModel)
Expand All @@ -604,7 +605,9 @@ class SyncFeatureConfigsUseCaseTest {
arrangement.userConfigRepository.getE2EISettings().shouldSucceed {
assertFalse(it.isRequired)
assertEquals("url", it.discoverUrl)
assertEquals(Instant.fromEpochMilliseconds(10_000L), it.gracePeriodEnd)

val gracePeriodsDiff = it.gracePeriodEnd?.minus(expectedGracePeriodEnd)?.inWholeMilliseconds ?: Long.MAX_VALUE
assertTrue(gracePeriodsDiff > -1000 || gracePeriodsDiff < 1000)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ data class E2EIConfigDTO(
@SerialName("acmeDiscoveryUrl")
val url: String?,
@SerialName("verificationExpiration")
val verificationExpirationNS: Long = 0L
val verificationExpirationSeconds: Long = 0L
)

@OptIn(ExperimentalSerializationApi::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ class UserConfigStorageImpl(
E2EI_NOTIFICATION_TIME,
timeStamp
).also {
e2EIFlow.tryEmit(Unit)
e2EINotificationFlow.tryEmit(Unit)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this doesn't relate to the original task, i just found some copy-past mistake (which causes unknown yet issue) and fixed it :)

}
}

Expand Down
Loading