Skip to content

Commit

Permalink
feat: Expose content types (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnarea authored Sep 10, 2020
1 parent d679d1f commit f7633c7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
11 changes: 6 additions & 5 deletions src/main/kotlin/tech/relaycorp/poweb/PoWebClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.flow.flow
import tech.relaycorp.poweb.handshake.Challenge
import tech.relaycorp.poweb.handshake.InvalidChallengeException
import tech.relaycorp.poweb.handshake.PoWebContentType
import tech.relaycorp.poweb.handshake.Response
import tech.relaycorp.relaynet.bindings.pdc.NonceSigner
import tech.relaycorp.relaynet.bindings.pdc.ParcelCollection
Expand Down Expand Up @@ -264,12 +265,12 @@ public class PoWebClient internal constructor(
private const val DEFAULT_LOCAL_PORT = 276
private const val DEFAULT_REMOTE_PORT = 443

private val PARCEL_CONTENT_TYPE = ContentType("application", "vnd.relaynet.parcel")
internal val PNRA_CONTENT_TYPE =
ContentType("application", "vnd.relaynet.node-registration.authorization")
internal val PNRR_CONTENT_TYPE =
private val PARCEL_CONTENT_TYPE = ContentType.parse(PoWebContentType.PARCEL.value)
private val PNRA_CONTENT_TYPE =
ContentType.parse(PoWebContentType.REGISTRATION_AUTHORIZATION.value)
private val PNRR_CONTENT_TYPE =
ContentType("application", "vnd.relaynet.node-registration.request")
internal val PNR_CONTENT_TYPE =
private val PNR_CONTENT_TYPE =
ContentType("application", "vnd.relaynet.node-registration.registration")

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package tech.relaycorp.poweb.handshake

public enum class PoWebContentType(public val value: String) {
PARCEL("application/vnd.relaynet.parcel"),
REGISTRATION_AUTHORIZATION("application/vnd.relaynet.node-registration.authorization"),
REGISTRATION_REQUEST("application/vnd.relaynet.node-registration.request"),
REGISTRATION("application/vnd.relaynet.node-registration.registration")
}
3 changes: 2 additions & 1 deletion src/test/kotlin/tech/relaycorp/poweb/ParcelDeliveryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runBlockingTest
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import tech.relaycorp.poweb.handshake.PoWebContentType
import kotlin.test.assertEquals
import kotlin.test.assertTrue

Expand Down Expand Up @@ -56,7 +57,7 @@ class ParcelDeliveryTest {

client.use { client.deliverParcel(parcelSerialized) }

assertEquals("application/vnd.relaynet.parcel", contentType)
assertEquals(PoWebContentType.PARCEL.value, contentType)
}

@Test
Expand Down
7 changes: 4 additions & 3 deletions src/test/kotlin/tech/relaycorp/poweb/RegistrationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import kotlinx.coroutines.test.runBlockingTest
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import tech.relaycorp.poweb.handshake.PoWebContentType
import tech.relaycorp.relaynet.messages.InvalidMessageException
import tech.relaycorp.relaynet.messages.control.PrivateNodeRegistration
import tech.relaycorp.relaynet.testing.CertificationPath
Expand All @@ -28,7 +29,7 @@ class RegistrationTest {
inner class PreRegistration {
private val publicKey = KeyPairSet.PRIVATE_GW.public
private val responseHeaders =
headersOf("Content-Type", PoWebClient.PNRA_CONTENT_TYPE.toString())
headersOf("Content-Type", PoWebContentType.REGISTRATION_AUTHORIZATION.value)

@Test
fun `Request method should be POST`() = runBlockingTest {
Expand Down Expand Up @@ -128,7 +129,7 @@ class RegistrationTest {
inner class Registration {
private val pnrrSerialized = "The PNRR".toByteArray()
private val responseHeaders =
headersOf("Content-Type", PoWebClient.PNR_CONTENT_TYPE.toString())
headersOf("Content-Type", PoWebContentType.REGISTRATION.value)

private val registration =
PrivateNodeRegistration(CertificationPath.PRIVATE_GW, CertificationPath.PUBLIC_GW)
Expand Down Expand Up @@ -170,7 +171,7 @@ class RegistrationTest {

client.use { client.registerNode(pnrrSerialized) }

assertEquals(PoWebClient.PNRR_CONTENT_TYPE, contentType)
assertEquals(PoWebContentType.REGISTRATION_REQUEST.value, contentType.toString())
}

@Test
Expand Down

0 comments on commit f7633c7

Please sign in to comment.