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(deps): update to PoWeb library to 1.5.80 #727

Merged
merged 14 commits into from
Feb 8, 2024
12 changes: 6 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {
classpath 'de.mannodermaus.gradle.plugins:android-junit5:1.8.2.1'
}
ext {
ktorVersion = '1.6.8'
ktorVersion = '2.3.7'
junitVersion = '5.8.2'
awalaTestingVersion = '1.5.10'
}
Expand Down Expand Up @@ -152,8 +152,8 @@ dependencies {
// Awala
implementation 'tech.relaycorp:awala:1.67.10'
implementation 'tech.relaycorp:awala-keystore-file:1.6.31'
implementation 'tech.relaycorp:cogrpc:1.1.31'
implementation 'tech.relaycorp:cogrpc-okhttp:1.1.22'
implementation 'tech.relaycorp:cogrpc:1.1.32'
implementation 'tech.relaycorp:cogrpc-okhttp:1.1.28'
testImplementation "tech.relaycorp:awala-testing:$awalaTestingVersion"
androidTestImplementation "tech.relaycorp:awala-testing:$awalaTestingVersion"

Expand All @@ -162,14 +162,14 @@ dependencies {
implementation 'org.conscrypt:conscrypt-android:2.5.2'

// Local and Internet-based Parcel Delivery Connections (PDCs)
implementation 'tech.relaycorp:poweb:1.5.69'
implementation 'tech.relaycorp:poweb:1.5.80'
implementation "io.ktor:ktor-server-core:$ktorVersion"
implementation "io.ktor:ktor-server-netty:$ktorVersion"
implementation "io.ktor:ktor-server-websockets:$ktorVersion"
implementation "io.ktor:ktor-utils:$ktorVersion"
implementation "io.ktor:ktor-websockets:$ktorVersion"
implementation "io.ktor:ktor-client-websockets:$ktorVersion"
implementation "io.ktor:ktor-client-cio:$ktorVersion"
implementation 'tech.relaycorp:doh:1.0.10'
implementation 'tech.relaycorp:doh:1.0.51'
testImplementation "io.ktor:ktor-server-test-host:$ktorVersion"
testImplementation "io.ktor:ktor-test-dispatcher:$ktorVersion"

Expand Down
2 changes: 2 additions & 0 deletions app/lint.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<ignore path="**/grpc-core*.jar" />
<!-- Ignore errors about jacoco importing javax.management because we don’t use those modules -->
<ignore path="**/org.jacoco/**" />
<!-- Ignore errors about ktor-utils-jvm importing java.lang.management because we don't use it -->
<ignore path="**/ktor-utils-jvm/**" />
</issue>
<issue id="TrustAllX509TrustManager">
<ignore path="org/bouncycastle/est/jcajce/*.class" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import android.os.Message
import android.os.Messenger
import androidx.test.core.app.ApplicationProvider.getApplicationContext
import androidx.test.rule.ServiceTestRule
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertTrue
Expand Down Expand Up @@ -43,18 +44,19 @@ class EndpointPreRegistrationServiceTest {
@Inject
lateinit var internetGatewayPreferences: InternetGatewayPreferences

private val coroutineContext get() = app.backgroundScope.coroutineContext
private val coroutineContext
get() = app.backgroundScope.coroutineContext + UnconfinedTestDispatcher()

@Before
fun setUp() {
AppTestProvider.component.inject(this)
runBlocking(coroutineContext) {
runTest(coroutineContext) {
internetGatewayPreferences.setRegistrationState(RegistrationState.Done)
}
}

@Test
fun requestPreRegistration() = runBlocking(coroutineContext) {
fun requestPreRegistration() = runTest(coroutineContext) {
val serviceIntent = Intent(
getApplicationContext<Context>(),
EndpointPreRegistrationService::class.java,
Expand Down Expand Up @@ -111,7 +113,7 @@ class EndpointPreRegistrationServiceTest {
}

@Test
fun errorReturnedWhenGatewayIsNotRegisteredYet() = runBlocking(coroutineContext) {
fun errorReturnedWhenGatewayIsNotRegisteredYet() = runTest(coroutineContext) {
internetGatewayPreferences.setRegistrationState(RegistrationState.ToDo)

val serviceIntent = Intent(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package tech.relaycorp.gateway.background.endpoint

import android.content.Context
import android.content.Intent
import androidx.test.core.app.ApplicationProvider.getApplicationContext
import androidx.test.rule.ServiceTestRule
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.take
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.runTest
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Before
Expand Down Expand Up @@ -43,19 +44,22 @@ class GatewaySyncServiceParcelCollectionTest {
@Inject
lateinit var storeParcel: StoreParcel

private val coroutineContext
get() = UnconfinedTestDispatcher()

@Before
fun setUp() {
AppTestProvider.component.inject(this)
serviceRule.bindService(
Intent(
getApplicationContext<Context>(),
GatewaySyncService::class.java,
),
)
serviceRule.bindService(Intent(getApplicationContext(), GatewaySyncService::class.java))
}

@After
fun tearDown() {
Thread.sleep(3000) // Wait for netty to properly stop, to avoid a RejectedExecutionException
}

@Test
fun parcelCollection_receiveParcel() = runBlocking {
fun parcelCollection_receiveParcel() = runTest(coroutineContext) {
val parcel = ParcelFactory.buildSerialized()
val storeResult = storeParcel.store(parcel, RecipientLocation.LocalEndpoint)
assertTrue(storeResult is StoreParcel.Result.Success)
Expand All @@ -79,7 +83,7 @@ class GatewaySyncServiceParcelCollectionTest {
}

@Test(expected = ServerConnectionException::class)
fun parcelCollection_invalidHandshake() = runBlocking {
fun parcelCollection_invalidHandshake() = runTest(coroutineContext) {
val parcel = ParcelFactory.buildSerialized()
val storeResult = storeParcel.store(parcel, RecipientLocation.LocalEndpoint)
assertTrue(storeResult is StoreParcel.Result.Success)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package tech.relaycorp.gateway.background.endpoint

import android.content.Context
import android.content.Intent
import androidx.test.core.app.ApplicationProvider.getApplicationContext
import androidx.test.rule.ServiceTestRule
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Rule
Expand Down Expand Up @@ -44,16 +44,16 @@ class GatewaySyncServiceParcelDeliveryTest {
@Before
fun setUp() {
AppTestProvider.component.inject(this)
serviceRule.bindService(
Intent(
getApplicationContext<Context>(),
GatewaySyncService::class.java,
),
)
serviceRule.bindService(Intent(getApplicationContext(), GatewaySyncService::class.java))
}

@After
fun tearDown() {
Thread.sleep(3000) // Wait for netty to properly stop, to avoid a RejectedExecutionException
}

@Test
fun parcelDelivery_validParcel() = runBlocking {
fun parcelDelivery_validParcel() = runTest {
setGatewayCertificate(PDACertPath.PRIVATE_GW)
val recipientId = "0deadbeef"
val recipientInternetAddress = "example.org"
Expand All @@ -76,7 +76,7 @@ class GatewaySyncServiceParcelDeliveryTest {
}

@Test(expected = RejectedParcelException::class)
fun parcelDelivery_invalidParcel() = runBlocking {
fun parcelDelivery_invalidParcel() = runTest {
val fiveMinutesAgo = ZonedDateTime.now().minusMinutes(5)
val recipientId = "0deadbeef"
val recipientInternetAddress = "example.org"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.content.Context
import androidx.room.Room
import androidx.test.core.app.ApplicationProvider.getApplicationContext
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals
import org.junit.Test
import tech.relaycorp.gateway.test.factory.LocalEndpointFactory
Expand All @@ -17,31 +17,27 @@ class LocalEndpointDaoTest {
.localEndpointDao()

@Test
internal fun countApplicationIds() {
runBlocking {
val endpoint1 = LocalEndpointFactory.build()
val endpoint2 = LocalEndpointFactory.build()
val endpoint3 =
LocalEndpointFactory.build().copy(applicationId = endpoint2.applicationId)

listOf(endpoint1, endpoint2, endpoint3).forEach { dao.insert(it) }

val result = dao.countApplicationIds().first()
assertEquals(2, result)
}
internal fun countApplicationIds() = runTest {
val endpoint1 = LocalEndpointFactory.build()
val endpoint2 = LocalEndpointFactory.build()
val endpoint3 =
LocalEndpointFactory.build().copy(applicationId = endpoint2.applicationId)

listOf(endpoint1, endpoint2, endpoint3).forEach { dao.insert(it) }

val result = dao.countApplicationIds().first()
assertEquals(2, result)
}

@Test
internal fun listAll() {
runBlocking {
val endpoint1 = LocalEndpointFactory.build()
val endpoint2 = LocalEndpointFactory.build()
val endpoint3 = LocalEndpointFactory.build()
internal fun listAll() = runTest {
val endpoint1 = LocalEndpointFactory.build()
val endpoint2 = LocalEndpointFactory.build()
val endpoint3 = LocalEndpointFactory.build()

listOf(endpoint1, endpoint2, endpoint3).forEach { dao.insert(it) }
listOf(endpoint1, endpoint2, endpoint3).forEach { dao.insert(it) }

val result = dao.list()
assertEquals(3, result.size)
}
val result = dao.list()
assertEquals(3, result.size)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package tech.relaycorp.gateway.data.database
import android.content.Context
import androidx.room.Room
import androidx.test.core.app.ApplicationProvider.getApplicationContext
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
Expand All @@ -17,17 +17,15 @@ class ParcelCollectionDaoTest {
.parcelCollectionDao()

@Test
internal fun exists() {
runBlocking {
val element = ParcelCollectionFactory.build()
assertFalse(
dao.exists(element.recipientAddress, element.senderAddress, element.messageId),
)
internal fun exists() = runTest {
val element = ParcelCollectionFactory.build()
assertFalse(
dao.exists(element.recipientAddress, element.senderAddress, element.messageId),
)

dao.insert(element)
assertTrue(
dao.exists(element.recipientAddress, element.senderAddress, element.messageId),
)
}
dao.insert(element)
assertTrue(
dao.exists(element.recipientAddress, element.senderAddress, element.messageId),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.content.Context
import androidx.room.Room
import androidx.test.core.app.ApplicationProvider.getApplicationContext
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals
import org.junit.Test
import tech.relaycorp.gateway.common.nowInUtc
Expand All @@ -19,43 +19,39 @@ class StoredParcelDaoTest {
.storedParcelDao()

@Test
internal fun countSizeForRecipientLocation() {
runBlocking {
val parcels =
(1..3).map {
StoredParcelFactory.build()
.copy(recipientLocation = RecipientLocation.ExternalGateway)
.also { dao.insert(it) }
}
val totalSize = parcels.map { it.size }.reduce { acc, size -> size + acc }

val result =
dao.countSizeForRecipientLocation(RecipientLocation.ExternalGateway).first()
assertEquals(totalSize, result)
}
internal fun countSizeForRecipientLocation() = runTest {
val parcels =
(1..3).map {
StoredParcelFactory.build()
.copy(recipientLocation = RecipientLocation.ExternalGateway)
.also { dao.insert(it) }
}
val totalSize = parcels.map { it.size }.reduce { acc, size -> size + acc }

val result =
dao.countSizeForRecipientLocation(RecipientLocation.ExternalGateway).first()
assertEquals(totalSize, result)
}

@Test
internal fun listForRecipientLocation_skipsExpired() {
runBlocking {
// expired
StoredParcelFactory.build()
.copy(
recipientLocation = RecipientLocation.ExternalGateway,
expirationTimeUtc = nowInUtc().minusMinutes(5),
)
.also { dao.insert(it) }
val parcelUnexpired = StoredParcelFactory.build()
.copy(
recipientLocation = RecipientLocation.ExternalGateway,
expirationTimeUtc = nowInUtc().plusMinutes(5),
)
.also { dao.insert(it) }

val result = dao.listForRecipientLocation(RecipientLocation.ExternalGateway)

assertEquals(1, result.size)
assertEquals(parcelUnexpired, result.first())
}
internal fun listForRecipientLocation_skipsExpired() = runTest {
// expired
StoredParcelFactory.build()
.copy(
recipientLocation = RecipientLocation.ExternalGateway,
expirationTimeUtc = nowInUtc().minusMinutes(5),
)
.also { dao.insert(it) }
val parcelUnexpired = StoredParcelFactory.build()
.copy(
recipientLocation = RecipientLocation.ExternalGateway,
expirationTimeUtc = nowInUtc().plusMinutes(5),
)
.also { dao.insert(it) }

val result = dao.listForRecipientLocation(RecipientLocation.ExternalGateway)

assertEquals(1, result.size)
assertEquals(parcelUnexpired, result.first())
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tech.relaycorp.gateway.data.disk

import androidx.test.core.app.ApplicationProvider
import kotlinx.coroutines.test.runBlockingTest
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals
import org.junit.Test
import tech.relaycorp.awala.keystores.file.FileKeystoreRoot
Expand All @@ -14,7 +14,7 @@ class AndroidPrivateKeyStoreTest {
private val privateKey = KeyPairSet.PRIVATE_GW.private

@Test
fun saveAndRetrieve() = runBlockingTest {
fun saveAndRetrieve() = runTest {
val androidContext = ApplicationProvider.getApplicationContext<App>()
val root = FileKeystoreRoot(File(androidContext.filesDir, "tmp-keystore"))
val store = AndroidPrivateKeyStore(root, androidContext)
Expand All @@ -25,7 +25,7 @@ class AndroidPrivateKeyStoreTest {
}

@Test
fun overrideKey() = runBlockingTest {
fun overrideKey() = runTest {
val androidContext = ApplicationProvider.getApplicationContext<App>()
val root = FileKeystoreRoot(File(androidContext.filesDir, "tmp-keystore"))
val store = AndroidPrivateKeyStore(root, androidContext)
Expand Down
Loading