From ca29375f3520720010714f8c67c2f7c588489d40 Mon Sep 17 00:00:00 2001 From: Gus Narea Date: Thu, 25 Jul 2024 15:34:05 +0100 Subject: [PATCH] fix(deps): Upgrade Awala lib to v1.69.0 (#736) * fix(deps): Upgrade Awala lib to v1.69.0 * upgrade poweb * fix tests * improve tests --- app/build.gradle | 8 +-- .../domain/publicsync/RegisterGateway.kt | 1 + .../CollectParcelsFromGatewayTest.kt | 62 ++++++++++++++++++- .../domain/publicsync/RegisterGatewayTest.kt | 5 +- .../gateway/test/BaseDataTestCase.kt | 1 + .../relaycorp/gateway/test/TestLogHandler.kt | 23 +++++++ 6 files changed, 92 insertions(+), 8 deletions(-) create mode 100644 app/src/test/java/tech/relaycorp/gateway/test/TestLogHandler.kt diff --git a/app/build.gradle b/app/build.gradle index 1e000369..dbe47fdb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -12,7 +12,7 @@ buildscript { ext { ktorVersion = '2.3.7' junitVersion = '5.8.2' - awalaTestingVersion = '1.5.10' + awalaTestingVersion = '1.5.31' } } @@ -150,8 +150,8 @@ dependencies { kapt 'com.google.dagger:dagger-compiler:2.48.1' // Awala - implementation 'tech.relaycorp:awala:1.67.10' - implementation 'tech.relaycorp:awala-keystore-file:1.6.31' + implementation 'tech.relaycorp:awala:1.69.0' + implementation 'tech.relaycorp:awala-keystore-file:1.6.53' implementation 'tech.relaycorp:cogrpc:1.1.32' implementation 'tech.relaycorp:cogrpc-okhttp:1.1.28' testImplementation "tech.relaycorp:awala-testing:$awalaTestingVersion" @@ -162,7 +162,7 @@ dependencies { implementation 'org.conscrypt:conscrypt-android:2.5.2' // Local and Internet-based Parcel Delivery Connections (PDCs) - implementation 'tech.relaycorp:poweb:1.5.80' + implementation 'tech.relaycorp:poweb:1.5.87' implementation "io.ktor:ktor-server-core:$ktorVersion" implementation "io.ktor:ktor-server-netty:$ktorVersion" implementation "io.ktor:ktor-server-websockets:$ktorVersion" diff --git a/app/src/main/java/tech/relaycorp/gateway/domain/publicsync/RegisterGateway.kt b/app/src/main/java/tech/relaycorp/gateway/domain/publicsync/RegisterGateway.kt index d39c9884..dab44176 100644 --- a/app/src/main/java/tech/relaycorp/gateway/domain/publicsync/RegisterGateway.kt +++ b/app/src/main/java/tech/relaycorp/gateway/domain/publicsync/RegisterGateway.kt @@ -124,6 +124,7 @@ class RegisterGateway localConfig.setParcelDeliveryCertificate(registration.privateNodeCertificate) publicKeyStore.save( registration.gatewaySessionKey!!, + registration.privateNodeCertificate.subjectId, registration.gatewayCertificate.subjectId, ) internetGatewayPreferences.setRegistrationState(RegistrationState.Done) diff --git a/app/src/test/java/tech/relaycorp/gateway/domain/publicsync/CollectParcelsFromGatewayTest.kt b/app/src/test/java/tech/relaycorp/gateway/domain/publicsync/CollectParcelsFromGatewayTest.kt index 2702895f..f1be9a68 100644 --- a/app/src/test/java/tech/relaycorp/gateway/domain/publicsync/CollectParcelsFromGatewayTest.kt +++ b/app/src/test/java/tech/relaycorp/gateway/domain/publicsync/CollectParcelsFromGatewayTest.kt @@ -10,9 +10,11 @@ import com.nhaarman.mockitokotlin2.verify import com.nhaarman.mockitokotlin2.verifyNoMoreInteractions import com.nhaarman.mockitokotlin2.whenever import io.ktor.test.dispatcher.testSuspend +import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.test.runTest import org.junit.Assert.assertEquals +import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import tech.relaycorp.gateway.data.doh.InternetAddressResolutionException @@ -24,6 +26,7 @@ import tech.relaycorp.gateway.domain.StoreParcel import tech.relaycorp.gateway.domain.endpoint.IncomingParcelNotifier import tech.relaycorp.gateway.pdc.PoWebClientProvider import tech.relaycorp.gateway.test.BaseDataTestCase +import tech.relaycorp.gateway.test.TestLogHandler import tech.relaycorp.poweb.PoWebClient import tech.relaycorp.relaynet.bindings.pdc.ClientBindingException import tech.relaycorp.relaynet.bindings.pdc.NonceSignerException @@ -33,6 +36,8 @@ import tech.relaycorp.relaynet.bindings.pdc.StreamingMode import tech.relaycorp.relaynet.messages.Parcel import tech.relaycorp.relaynet.messages.Recipient import tech.relaycorp.relaynet.testing.pki.PDACertPath +import java.util.logging.Level +import java.util.logging.Logger class CollectParcelsFromGatewayTest : BaseDataTestCase() { @@ -54,6 +59,7 @@ class CollectParcelsFromGatewayTest : BaseDataTestCase() { notifyEndpoints, mockLocalConfig, ) + private val testLogHandler = TestLogHandler() @BeforeEach fun setUp() = testSuspend { @@ -62,6 +68,14 @@ class CollectParcelsFromGatewayTest : BaseDataTestCase() { .thenReturn(StoreParcel.Result.Success(mock())) whenever(mockInternetGatewayPreferences.getId()) .thenReturn(PDACertPath.INTERNET_GW.subjectId) + + Logger.getLogger(CollectParcelsFromGateway::class.java.name).addHandler(testLogHandler) + } + + @AfterEach + fun tearDown() { + testLogHandler.close() + Logger.getLogger(CollectParcelsFromGateway::class.java.name).removeHandler(testLogHandler) } @Test @@ -154,19 +168,61 @@ class CollectParcelsFromGatewayTest : BaseDataTestCase() { @Test fun `poWebClient client binding issues are handled`() = testSuspend { - whenever(poWebClient.collectParcels(any(), any())).thenThrow(ClientBindingException("")) + whenever(poWebClient.collectParcels(any(), any())).thenReturn( + flow { + throw ClientBindingException("Message") + }, + ) + subject.collect(false) + + val logRecord = testLogHandler.filterLogs( + Level.SEVERE, + "Could not collect parcels due to client error", + ) + .singleOrNull() + assert(logRecord != null) + assert(logRecord?.thrown is ClientBindingException) + verifyNoMoreInteractions(storeParcel, notifyEndpoints) } @Test fun `poWebClient signer issues are handled`() = testSuspend { - whenever(poWebClient.collectParcels(any(), any())).thenThrow(NonceSignerException("")) + whenever(poWebClient.collectParcels(any(), any())).thenReturn( + flow { + throw NonceSignerException("Message") + }, + ) + subject.collect(false) + + val logRecord = testLogHandler.filterLogs( + Level.SEVERE, + "Could not collect parcels due to signing error", + ) + .singleOrNull() + assert(logRecord != null) + assert(logRecord?.thrown is NonceSignerException) + verifyNoMoreInteractions(storeParcel, notifyEndpoints) } @Test fun `poWebClient with keepAlive false, server issues are handled`() = testSuspend { - whenever(poWebClient.collectParcels(any(), any())).thenThrow(ServerConnectionException("")) + whenever(poWebClient.collectParcels(any(), any())).thenReturn( + flow { + throw ServerConnectionException("Message") + }, + ) + subject.collect(false) + + val logRecord = testLogHandler.filterLogs( + Level.WARNING, + "Could not collect parcels due to server error", + ) + .singleOrNull() + assert(logRecord != null) + assert(logRecord?.thrown is ServerConnectionException) + verifyNoMoreInteractions(storeParcel, notifyEndpoints) } } diff --git a/app/src/test/java/tech/relaycorp/gateway/domain/publicsync/RegisterGatewayTest.kt b/app/src/test/java/tech/relaycorp/gateway/domain/publicsync/RegisterGatewayTest.kt index 131d967e..45e6fa2d 100644 --- a/app/src/test/java/tech/relaycorp/gateway/domain/publicsync/RegisterGatewayTest.kt +++ b/app/src/test/java/tech/relaycorp/gateway/domain/publicsync/RegisterGatewayTest.kt @@ -137,7 +137,10 @@ class RegisterGatewayTest : BaseDataTestCase() { verify(pgwPreferences).setPublicKey(eq(pnr.gatewayCertificate.subjectPublicKey)) verify(pgwPreferences).setRegistrationState(eq(RegistrationState.Done)) - publicKeyStore.retrieve(pnr.gatewayCertificate.subjectId) + publicKeyStore.retrieve( + pnr.privateNodeCertificate.subjectId, + pnr.gatewayCertificate.subjectId, + ) assertEquals(pnr.privateNodeCertificate, localConfig.getParcelDeliveryCertificate()) } diff --git a/app/src/test/java/tech/relaycorp/gateway/test/BaseDataTestCase.kt b/app/src/test/java/tech/relaycorp/gateway/test/BaseDataTestCase.kt index 0d7afe01..f9743fcd 100644 --- a/app/src/test/java/tech/relaycorp/gateway/test/BaseDataTestCase.kt +++ b/app/src/test/java/tech/relaycorp/gateway/test/BaseDataTestCase.kt @@ -59,6 +59,7 @@ abstract class BaseDataTestCase { protected suspend fun registerInternetGatewaySessionKey() { publicKeyStore.save( internetGatewaySessionKeyPair.sessionKey, + KeyPairSet.PRIVATE_GW.public.nodeId, KeyPairSet.INTERNET_GW.public.nodeId, ) } diff --git a/app/src/test/java/tech/relaycorp/gateway/test/TestLogHandler.kt b/app/src/test/java/tech/relaycorp/gateway/test/TestLogHandler.kt new file mode 100644 index 00000000..77a69841 --- /dev/null +++ b/app/src/test/java/tech/relaycorp/gateway/test/TestLogHandler.kt @@ -0,0 +1,23 @@ +package tech.relaycorp.gateway.test + +import java.util.logging.Handler +import java.util.logging.Level +import java.util.logging.LogRecord + +class TestLogHandler : Handler() { + private val logs = mutableListOf() + + override fun publish(record: LogRecord) { + logs.add(record) + } + + override fun flush() {} + + override fun close() { + logs.clear() + } + + fun filterLogs(level: Level, message: String): List { + return logs.filter { it.level == level && it.message == message } + } +}