Skip to content

Commit

Permalink
chore: checking for invalid oppgaveId in getOppgaveRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
jaflaten committed Dec 5, 2024
1 parent 79e8ff6 commit 0949f7f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ class NasjonalOppgaveService(
return updated
}

fun isValidOppgaveId(oppgaveId: String): Boolean {
val regex = Regex("^\\d{9}$|^[a-zA-Z0-9]{1,20}$")
return oppgaveId.matches(regex)
}

fun findByOppgaveId(oppgaveId: String): NasjonalManuellOppgaveDAO? {
if(!isValidOppgaveId(oppgaveId))
Expand Down Expand Up @@ -269,3 +265,8 @@ private fun getLoggingMeta(sykmeldingId: String, oppgave: NasjonalManuellOppgave
)
}
}

fun isValidOppgaveId(oppgaveId: String): Boolean {
val regex = Regex("^\\d{9}$|^[a-zA-Z0-9]{1,20}$")
return oppgaveId.matches(regex)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import no.nav.sykdig.digitalisering.papirsykmelding.api.model.AvvisSykmeldingReq
import no.nav.sykdig.digitalisering.papirsykmelding.api.model.PapirManuellOppgave
import no.nav.sykdig.digitalisering.papirsykmelding.api.model.SmRegistreringManuell
import no.nav.sykdig.digitalisering.papirsykmelding.api.model.Sykmelder
import no.nav.sykdig.digitalisering.papirsykmelding.isValidOppgaveId
import org.springframework.beans.factory.annotation.Value
import org.springframework.http.HttpEntity
import org.springframework.http.HttpHeaders
Expand Down Expand Up @@ -57,6 +58,8 @@ class SmregistreringClient(
authorization: String,
oppgaveId: String,
): ResponseEntity<PapirManuellOppgave> {
if(!isValidOppgaveId(oppgaveId))
throw IllegalArgumentException("Invalid oppgaveId does not contain only alphanumerical characters. oppgaveId: $oppgaveId")
val headers = HttpHeaders()
headers.contentType = MediaType.APPLICATION_JSON
headers.setBearerAuth(removeBearerPrefix(authorization))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.boot.test.mock.mockito.MockBean
import org.springframework.http.HttpMethod
import org.springframework.http.HttpStatus
import org.springframework.http.HttpStatusCode
import org.springframework.http.MediaType
import org.springframework.security.core.context.ReactiveSecurityContextHolder
import org.springframework.security.core.context.SecurityContextHolder
Expand Down Expand Up @@ -131,9 +133,7 @@ class NasjonalOppgaveServiceTest : IntegrationTest() {

assertTrue(originalOppgave.avvisningsgrunn == null)
val avvistOppgave = nasjonalOppgaveService.avvisOppgave(oppgaveId, request, "enhet")
assertEquals(testDataNasjonalManuellOppgaveDAO(null, "456", oppgaveId).oppgaveId, avvistOppgave.body?.oppgaveId ?: 123)
assertTrue(avvistOppgave.body?.avvisningsgrunn == "MANGLENDE_DIAGNOSE")
assertEquals(avvistOppgave.body?.id, originalOppgave.id)
assertEquals(avvistOppgave.statusCode, HttpStatus.NO_CONTENT)
}


Expand Down

0 comments on commit 0949f7f

Please sign in to comment.