Skip to content

Commit

Permalink
Enkel ktor integrasjonstest av signeringssertifikatendepunkt i cparepo
Browse files Browse the repository at this point in the history
  • Loading branch information
thburnett committed Oct 24, 2023
1 parent 6c03d45 commit 2aee46c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 25 deletions.
12 changes: 9 additions & 3 deletions cpa-repo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ plugins {

tasks {

shadowJar {
archiveFileName.set("app.jar")
}
shadowJar {
archiveFileName.set("app.jar")
}
test {
useJUnitPlatform()
}

}

Expand All @@ -34,6 +37,9 @@ dependencies {
implementation(libs.ktor.serialization.kotlinx.json)
implementation(testLibs.postgresql)
testRuntimeOnly(testLibs.junit.jupiter.engine)
testImplementation(testLibs.junit.jupiter.api)
testImplementation(libs.ktor.client.content.negotiation)
testImplementation("io.ktor:ktor-server-test-host")
testImplementation(kotlin("test"))

runtimeOnly("org.postgresql:postgresql:42.6.0")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package no.nav.emottak.cpa

import io.ktor.client.call.body
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.client.request.post
import io.ktor.client.request.setBody
import io.ktor.http.ContentType
import io.ktor.http.HttpStatusCode
import io.ktor.http.contentType
import io.ktor.serialization.kotlinx.json.json
import io.ktor.server.testing.testApplication
import no.nav.emottak.melding.model.SignatureDetails
import no.nav.emottak.melding.model.SignatureDetailsRequest
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class CPARepoIntegrationTest {

@Test
fun `Hent sertifikat for signatursjekk`() = testApplication {
application { myApplicationModule() }
val request = SignatureDetailsRequest(
cpaId = "cpaId", //TODO endres hvis/når respons fra getCpa ikke lenger er hardkodet
partyType = "HER",
partyId = "8141253",
role = "Behandler",
service = "BehandlerKrav",
action = "OppgjorsMelding"
)
val httpClient = createClient {
install(ContentNegotiation) {
json()
}
}
val response = httpClient.post("/signing/certificate") {
setBody(request)
contentType(ContentType.Application.Json)
}
val body = response.body<SignatureDetails>()
assertEquals(HttpStatusCode.OK, response.status)
assertEquals("http://www.w3.org/2001/04/xmldsig-more#rsa-sha256", body.signatureAlgorithm)
assertEquals("http://www.w3.org/2001/04/xmlenc#sha256", body.hashFunction)
}

}

0 comments on commit 2aee46c

Please sign in to comment.