diff --git a/build.gradle b/build.gradle index 9a3102c..fe955fd 100644 --- a/build.gradle +++ b/build.gradle @@ -1,9 +1,9 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile buildscript { - ext.kotlinVersion = '1.5.0' - ext.kotlinCoroutinesVersion = '1.4.3-native-mt' - ext.ktorVersion = '1.5.0' + ext.kotlinVersion = '1.5.20' + ext.kotlinCoroutinesVersion = '1.5.0' + ext.ktorVersion = '1.6.1' ext.okhttpVersion = '4.9.1' } diff --git a/src/test/kotlin/tech/relaycorp/poweb/ParcelDeliveryTest.kt b/src/test/kotlin/tech/relaycorp/poweb/ParcelDeliveryTest.kt index 68c837f..90fd7e8 100644 --- a/src/test/kotlin/tech/relaycorp/poweb/ParcelDeliveryTest.kt +++ b/src/test/kotlin/tech/relaycorp/poweb/ParcelDeliveryTest.kt @@ -7,8 +7,7 @@ import io.ktor.client.request.HttpRequestData import io.ktor.http.HttpMethod import io.ktor.http.HttpStatusCode import io.ktor.http.content.OutgoingContent -import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.test.runBlockingTest +import kotlinx.coroutines.runBlocking import org.bouncycastle.util.encoders.Base64 import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows @@ -23,14 +22,13 @@ import kotlin.test.assertEquals import kotlin.test.assertNotNull import kotlin.test.assertTrue -@ExperimentalCoroutinesApi class ParcelDeliveryTest { private val parcelSerialized = "Let's say I'm the serialization of a parcel".toByteArray() private val signer = Signer(PDACertPath.PRIVATE_ENDPOINT, KeyPairSet.PRIVATE_ENDPOINT.private) @Test - fun `Request should be made with HTTP POST`() = runBlockingTest { + fun `Request should be made with HTTP POST`() = runBlocking { var method: HttpMethod? = null val client = makeTestClient { request: HttpRequestData -> method = request.method @@ -43,7 +41,7 @@ class ParcelDeliveryTest { } @Test - fun `Endpoint should be the one for parcels`() = runBlockingTest { + fun `Endpoint should be the one for parcels`() = runBlocking { var endpointURL: String? = null val client = makeTestClient { request: HttpRequestData -> endpointURL = request.url.toString() @@ -56,7 +54,7 @@ class ParcelDeliveryTest { } @Test - fun `Request content type should be the appropriate value`() = runBlockingTest { + fun `Request content type should be the appropriate value`() = runBlocking { var contentType: String? = null val client = makeTestClient { request: HttpRequestData -> contentType = request.body.contentType.toString() @@ -69,7 +67,7 @@ class ParcelDeliveryTest { } @Test - fun `Request body should be the parcel serialized`() = runBlockingTest { + fun `Request body should be the parcel serialized`() = runBlocking { var requestBody: ByteArray? = null val client = makeTestClient { request: HttpRequestData -> assertTrue(request.body is OutgoingContent.ByteArrayContent) @@ -83,7 +81,7 @@ class ParcelDeliveryTest { } @Test - fun `Delivery signature should be in the request headers`() = runBlockingTest { + fun `Delivery signature should be in the request headers`(): Unit = runBlocking { var authorizationHeader: String? = null val client = makeTestClient { request: HttpRequestData -> authorizationHeader = request.headers["Authorization"] @@ -104,7 +102,7 @@ class ParcelDeliveryTest { } @Test - fun `HTTP 20X should be regarded a successful delivery`() = runBlockingTest { + fun `HTTP 20X should be regarded a successful delivery`() = runBlocking { val client = makeTestClient { respond("", HttpStatusCode.Accepted) } client.use { client.deliverParcel(parcelSerialized, signer) } @@ -116,7 +114,7 @@ class ParcelDeliveryTest { client.use { val exception = assertThrows { - runBlockingTest { client.deliverParcel(parcelSerialized, signer) } + runBlocking { client.deliverParcel(parcelSerialized, signer) } } assertEquals("The server rejected the parcel", exception.message) @@ -130,7 +128,7 @@ class ParcelDeliveryTest { client.use { val exception = assertThrows { - runBlockingTest { client.deliverParcel(parcelSerialized, signer) } + runBlocking { client.deliverParcel(parcelSerialized, signer) } } assertEquals("The server returned a $status response", exception.message) diff --git a/src/test/kotlin/tech/relaycorp/poweb/PoWebClientTest.kt b/src/test/kotlin/tech/relaycorp/poweb/PoWebClientTest.kt index 8c7990f..b90c7b7 100644 --- a/src/test/kotlin/tech/relaycorp/poweb/PoWebClientTest.kt +++ b/src/test/kotlin/tech/relaycorp/poweb/PoWebClientTest.kt @@ -14,9 +14,7 @@ import io.ktor.http.HttpStatusCode import io.ktor.http.content.ByteArrayContent import io.ktor.http.content.OutgoingContent import io.ktor.util.InternalAPI -import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.runBlocking -import kotlinx.coroutines.test.runBlockingTest import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows @@ -35,7 +33,6 @@ import kotlin.test.assertFalse import kotlin.test.assertNull import kotlin.test.assertTrue -@ExperimentalCoroutinesApi @Suppress("RedundantInnerClassModifier") class PoWebClientTest { @Nested @@ -163,7 +160,7 @@ class PoWebClientTest { @Nested inner class Request { @Test - fun `Request should be made with HTTP POST`() = runBlockingTest { + fun `Request should be made with HTTP POST`() = runBlocking { var method: HttpMethod? = null val client = makeTestClient { request: HttpRequestData -> method = request.method @@ -176,7 +173,7 @@ class PoWebClientTest { } @Test - fun `Specified path should be honored`() = runBlockingTest { + fun `Specified path should be honored`() = runBlocking { var endpointURL: String? = null val client = makeTestClient { request: HttpRequestData -> endpointURL = request.url.toString() @@ -189,7 +186,7 @@ class PoWebClientTest { } @Test - fun `Specified Content-Type should be honored`() = runBlockingTest { + fun `Specified Content-Type should be honored`() = runBlocking { var contentType: String? = null val client = makeTestClient { request: HttpRequestData -> contentType = request.body.contentType.toString() @@ -202,7 +199,7 @@ class PoWebClientTest { } @Test - fun `Request body should be the parcel serialized`() = runBlockingTest { + fun `Request body should be the parcel serialized`() = runBlocking { var requestBody: ByteArray? = null val client = makeTestClient { request: HttpRequestData -> assertTrue(request.body is OutgoingContent.ByteArrayContent) @@ -216,7 +213,7 @@ class PoWebClientTest { } @Test - fun `No Authorization header should be set by default`() = runBlockingTest { + fun `No Authorization header should be set by default`() = runBlocking { var authorizationHeader: String? = null val client = makeTestClient { request: HttpRequestData -> authorizationHeader = request.headers["Authorization"] @@ -229,7 +226,7 @@ class PoWebClientTest { } @Test - fun `Authorization should be set if requested`() = runBlockingTest { + fun `Authorization should be set if requested`() = runBlocking { val expectedAuthorizationHeader = "Foo bar" var actualAuthorizationHeader: String? = null val client = makeTestClient { request: HttpRequestData -> @@ -246,7 +243,7 @@ class PoWebClientTest { @Nested inner class Response { @Test - fun `HTTP 20X should be regarded a successful delivery`() = runBlockingTest { + fun `HTTP 20X should be regarded a successful delivery`(): Unit = runBlocking { val client = makeTestClient { respond("", HttpStatusCode.Accepted) } client.use { client.post(path, body) } @@ -258,7 +255,7 @@ class PoWebClientTest { client.use { val exception = assertThrows { - runBlockingTest { client.post(path, body) } + runBlocking { client.post(path, body) } } assertEquals( @@ -275,7 +272,7 @@ class PoWebClientTest { client.use { val exception = assertThrows { - runBlockingTest { client.post(path, body) } + runBlocking { client.post(path, body) } } assertEquals(status, exception.responseStatus) @@ -288,7 +285,7 @@ class PoWebClientTest { client.use { val exception = assertThrows { - runBlockingTest { client.post(path, body) } + runBlocking { client.post(path, body) } } assertEquals( @@ -378,14 +375,14 @@ class PoWebClientTest { } @Test - fun `Client should use WS if TLS is not required`() = runBlockingTest { + fun `Client should use WS if TLS is not required`() = runBlocking { val client = PoWebClient(hostName, mockWebServer.port, false) assertTrue(client.baseWsUrl.startsWith("ws:"), "Actual URL: ${client.baseWsUrl}") } @Test - fun `Client should use WSS if TLS is required`() = runBlockingTest { + fun `Client should use WSS if TLS is required`() = runBlocking { val client = PoWebClient(hostName, mockWebServer.port, true) assertTrue(client.baseWsUrl.startsWith("wss:")) diff --git a/src/test/kotlin/tech/relaycorp/poweb/RegistrationTest.kt b/src/test/kotlin/tech/relaycorp/poweb/RegistrationTest.kt index 9af2d28..8d5f63b 100644 --- a/src/test/kotlin/tech/relaycorp/poweb/RegistrationTest.kt +++ b/src/test/kotlin/tech/relaycorp/poweb/RegistrationTest.kt @@ -7,9 +7,7 @@ import io.ktor.http.HttpMethod import io.ktor.http.HttpStatusCode import io.ktor.http.content.OutgoingContent import io.ktor.http.headersOf -import io.ktor.util.KtorExperimentalAPI -import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.test.runBlockingTest +import kotlinx.coroutines.runBlocking import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows @@ -25,8 +23,6 @@ import kotlin.test.assertEquals import kotlin.test.assertTrue @Suppress("RedundantInnerClassModifier") -@ExperimentalCoroutinesApi -@KtorExperimentalAPI class RegistrationTest { @Nested inner class PreRegistration { @@ -35,7 +31,7 @@ class RegistrationTest { headersOf("Content-Type", ContentTypes.NODE_REGISTRATION_AUTHORIZATION.value) @Test - fun `Request method should be POST`() = runBlockingTest { + fun `Request method should be POST`() = runBlocking { var method: HttpMethod? = null val client = makeTestClient { request: HttpRequestData -> method = request.method @@ -48,7 +44,7 @@ class RegistrationTest { } @Test - fun `Request should be made to the appropriate endpoint`() = runBlockingTest { + fun `Request should be made to the appropriate endpoint`() = runBlocking { var endpointURL: String? = null val client = makeTestClient { request: HttpRequestData -> endpointURL = request.url.toString() @@ -61,7 +57,7 @@ class RegistrationTest { } @Test - fun `Request Content-Type should be plain text`() = runBlockingTest { + fun `Request Content-Type should be plain text`() = runBlocking { var contentType: ContentType? = null val client = makeTestClient { request: HttpRequestData -> contentType = request.body.contentType @@ -74,7 +70,7 @@ class RegistrationTest { } @Test - fun `Request body should be SHA-256 digest of the node public key`() = runBlockingTest { + fun `Request body should be SHA-256 digest of the node public key`() = runBlocking { var requestBody: ByteArray? = null val client = makeTestClient { request: HttpRequestData -> assertTrue(request.body is OutgoingContent.ByteArrayContent) @@ -101,7 +97,7 @@ class RegistrationTest { } val exception = assertThrows { - runBlockingTest { + runBlocking { client.use { client.preRegisterNode(publicKey) } } } @@ -120,7 +116,7 @@ class RegistrationTest { } val exception = assertThrows { - runBlockingTest { + runBlocking { client.use { client.preRegisterNode(publicKey) } } } @@ -133,7 +129,7 @@ class RegistrationTest { @Test fun `Registration request should be output if pre-registration succeeds`() = - runBlockingTest { + runBlocking { val authorizationSerialized = "This is the PNRA".toByteArray() val client = makeTestClient { respond(authorizationSerialized, headers = responseHeaders) @@ -161,7 +157,7 @@ class RegistrationTest { private val registrationSerialized = registration.serialize() @Test - fun `Request method should be POST`() = runBlockingTest { + fun `Request method should be POST`() = runBlocking { var method: HttpMethod? = null val client = makeTestClient { request: HttpRequestData -> method = request.method @@ -174,7 +170,7 @@ class RegistrationTest { } @Test - fun `Request should be made to the appropriate endpoint`() = runBlockingTest { + fun `Request should be made to the appropriate endpoint`() = runBlocking { var endpointURL: String? = null val client = makeTestClient { request: HttpRequestData -> endpointURL = request.url.toString() @@ -187,7 +183,7 @@ class RegistrationTest { } @Test - fun `Request Content-Type should be a PNRR`() = runBlockingTest { + fun `Request Content-Type should be a PNRR`() = runBlocking { var contentType: ContentType? = null val client = makeTestClient { request: HttpRequestData -> contentType = request.body.contentType @@ -200,7 +196,7 @@ class RegistrationTest { } @Test - fun `Request body should be the PNRR serialized`() = runBlockingTest { + fun `Request body should be the PNRR serialized`() = runBlocking { var requestBody: ByteArray? = null val client = makeTestClient { request: HttpRequestData -> assertTrue(request.body is OutgoingContent.ByteArrayContent) @@ -224,7 +220,7 @@ class RegistrationTest { } val exception = assertThrows { - runBlockingTest { + runBlocking { client.use { client.registerNode(pnrrSerialized) } } } @@ -242,7 +238,7 @@ class RegistrationTest { } val exception = assertThrows { - runBlockingTest { + runBlocking { client.use { client.registerNode(pnrrSerialized) } } } @@ -252,13 +248,13 @@ class RegistrationTest { } @Test - fun `Exception should be thrown if server reports we violated binding`() = runBlockingTest { + fun `Exception should be thrown if server reports we violated binding`() = runBlocking { val client = makeTestClient { respond("{}", status = HttpStatusCode.Forbidden) } val exception = assertThrows { - runBlockingTest { + runBlocking { client.use { client.registerNode(pnrrSerialized) } } } @@ -270,7 +266,7 @@ class RegistrationTest { } @Test - fun `Registration should be output if request succeeds`() = runBlockingTest { + fun `Registration should be output if request succeeds`() = runBlocking { val client = makeTestClient { respond(registrationSerialized, headers = responseHeaders) }