@@ -15,6 +15,7 @@ import io.ktor.client.call.*
1515import io.ktor.client.plugins.contentnegotiation.*
1616import io.ktor.client.request.*
1717import io.ktor.client.statement.*
18+ import io.ktor.client.utils.EmptyContent.contentType
1819import io.ktor.http.*
1920import io.ktor.serialization.jackson.*
2021import io.ktor.server.testing.*
@@ -30,8 +31,10 @@ import org.junit.jupiter.api.BeforeAll
3031import org.junit.jupiter.api.Test
3132import java.time.LocalDate
3233import java.util.*
34+ import org.junit.jupiter.params.ParameterizedTest
35+ import org.junit.jupiter.params.provider.CsvSource
3336
34- class AfpOffentligServerTest {
37+ internal class AfpOffentligServerTest {
3538 companion object {
3639 private val server = MockOAuth2Server ()
3740
@@ -62,7 +65,6 @@ class AfpOffentligServerTest {
6265 val wellnowurl = server.wellKnownUrl(" default" ).toString()
6366 val jwksuri = server.jwksUrl(" default" ).toString()
6467
65-
6668 System .setProperty(" MASKINPORTEN_JWKS_URI" , jwksuri)
6769 System .setProperty(" MASKINPORTEN_ISSUER" , server.issuerUrl(" default" ).toString())
6870 System .setProperty(" MASKINPORTEN_WELL_KNOWN_URL" , wellnowurl)
@@ -165,6 +167,79 @@ class AfpOffentligServerTest {
165167 )
166168 }
167169
170+ @Test
171+ fun `AFP felles - Ugyldig request gir 400 Bad request` () = testApplication {
172+ application {
173+ api(
174+ Config (),
175+ MockProducer (),
176+ ApiInternKlient (),
177+ tpRegisterKlient(),
178+ )
179+ }
180+
181+ val jwt = issueToken(" nav:aap:afpprivat.read" )
182+
183+ val response = client.post(" /afp/fellesordningen" ) {
184+ header(" Authorization" , " Bearer ${jwt.serialize()} " )
185+ header(" X-callid" , UUID .randomUUID().toString())
186+ contentType(ContentType .Application .Json )
187+ setBody(""" {"personidentifikator":"1234","fraOgMedDato":"2025-01-01","tilOgMedDato":"2024-01-01","saksId":"123"}""" )
188+ }
189+
190+ assertEquals(HttpStatusCode .BadRequest , response.status)
191+ }
192+
193+ @Test
194+ fun `AFP offentlig - Ugyldig request gir 400 Bad request` () = testApplication {
195+ application {
196+ api(
197+ Config (),
198+ MockProducer (),
199+ ApiInternKlient (),
200+ tpRegisterKlient(),
201+ )
202+ }
203+
204+ val jwt = issueToken(" nav:aap:afpoffentlig.read" )
205+
206+ val response = client.post(" /afp/offentlig" ) {
207+ header(" Authorization" , " Bearer ${jwt.serialize()} " )
208+ header(" X-callid" , UUID .randomUUID().toString())
209+ contentType(ContentType .Application .Json )
210+ setBody(""" {"personidentifikator":"1234","fraOgMedDato":"2025-01-01","tilOgMedDato":"2024-01-01","saksId":"123"}""" )
211+ }
212+
213+ assertEquals(HttpStatusCode .BadRequest , response.status)
214+ }
215+
216+ @ParameterizedTest
217+ @CsvSource(
218+ " /tp-samhandling" ,
219+ " /tp-samhandling-med-utbetalinger" ,
220+ )
221+ fun `TP Samhandling - Ugyldig request gir 400 Bad request` (endepunkt : String ) = testApplication {
222+ application {
223+ api(
224+ Config (),
225+ MockProducer (),
226+ ApiInternKlient (),
227+ tpRegisterKlient(),
228+ )
229+ }
230+
231+ val jwt = issueToken(" nav:aap:tpordningen.read" )
232+
233+ val response = client.post(endepunkt) {
234+ header(" Authorization" , " Bearer ${jwt.serialize()} " )
235+ header(" X-callid" , UUID .randomUUID().toString())
236+ contentType(ContentType .Application .Json )
237+ setBody(""" {"personidentifikator":"1234","fraOgMedDato":"2025-01-01","tilOgMedDato":"2024-01-01"}""" )
238+ }
239+
240+ assertEquals(HttpStatusCode .BadRequest , response.status)
241+ }
242+
168243 private fun tpRegisterKlient (ønsketSvar : Boolean? = true) = object : ITpRegisterClient {
169244 override fun brukerHarTpForholdOgYtelse (
170245 fnr : String ,
0 commit comments