Skip to content

Commit

Permalink
Bruk type wrappers fra utils-pakken (#491)
Browse files Browse the repository at this point in the history
* Bruk type wrappers fra utils-pakken

* Fiks integrasjonstest

* Fiks nok en integrasjonstest
  • Loading branch information
bjerga authored Apr 26, 2024
1 parent 7b9798c commit 6d1fd42
Show file tree
Hide file tree
Showing 19 changed files with 68 additions and 418 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package no.nav.helsearbeidsgiver.inntektsmelding.api.auth

import io.ktor.server.request.ApplicationRequest
import io.ktor.server.request.authorization
import no.nav.helsearbeidsgiver.utils.wrapper.Fnr
import no.nav.security.token.support.core.jwt.JwtToken

fun ApplicationRequest.lesFnrFraAuthToken(): String {
Expand All @@ -10,7 +11,13 @@ fun ApplicationRequest.lesFnrFraAuthToken(): String {

val pid = JwtToken(authToken).jwtTokenClaims.get("pid")?.toString()

return pid ?: JwtToken(authToken).subject
val fnr = pid ?: JwtToken(authToken).subject

if (!Fnr.erGyldig(fnr)) {
throw IllegalAccessException("Fnr i autorisasjonsheader er ugyldig.")
}

return fnr
}

class ManglerAltinnRettigheterException : Exception()
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import no.nav.helsearbeidsgiver.domene.inntektsmelding.v1.Periode
import no.nav.helsearbeidsgiver.inntektsmelding.api.validation.isIdentitetsnummer
import no.nav.helsearbeidsgiver.inntektsmelding.api.validation.isOrganisasjonsnummer
import no.nav.helsearbeidsgiver.inntektsmelding.api.validation.isTelefonnummer
import no.nav.helsearbeidsgiver.inntektsmelding.api.validation.isValidBehandlingsdager
import org.valiktor.functions.isGreaterThan
import org.valiktor.functions.isGreaterThanOrEqualTo
import org.valiktor.functions.isLessThan
Expand Down Expand Up @@ -56,8 +55,6 @@ fun Innsending.validate() {
if (innsendt.fullLønnIArbeidsgiverPerioden?.utbetalerFullLønn == true) {
validate(Innsending::arbeidsgiverperioder).isNotEmpty()
}
// Fraværsperiode
validate(Innsending::behandlingsdager).isValidBehandlingsdager() // Velg behandlingsdager
// Egenmelding
validate(Innsending::egenmeldingsperioder).validateForEach {
validate(Periode::fom).isNotNull()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package no.nav.helsearbeidsgiver.inntektsmelding.api.validation

import no.nav.helsearbeidsgiver.utils.wrapper.Fnr
import org.valiktor.Validator

object IdentitetsnummerConstraint : CustomConstraint
fun <E> Validator<E>.Property<String?>.isIdentitetsnummer() =
this.validate(IdentitetsnummerConstraint) { FoedselsNrValidator.isValid(it) }
this.validate(IdentitetsnummerConstraint) {
require(it != null)
Fnr.erGyldig(it)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package no.nav.helsearbeidsgiver.inntektsmelding.api.validation

import no.nav.helsearbeidsgiver.utils.wrapper.Orgnr
import org.valiktor.Validator

object OrganisasjonsnummerConstraint : CustomConstraint
fun <E> Validator<E>.Property<String?>.isOrganisasjonsnummer() =
this.validate(OrganisasjonsnummerConstraint) { OrganisasjonsnummerValidator.isValid(it) }
this.validate(OrganisasjonsnummerConstraint) {
require(it != null)
Orgnr.erGyldig(it)
}

This file was deleted.

1 change: 0 additions & 1 deletion api/src/main/resources/messages_no.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# suppress inspection "UnusedProperty" for whole file
no.nav.helsearbeidsgiver.inntektsmelding.api.validation.IdentitetsnummerConstraint.message=Ugyldig fødsels- eller D-nummer
no.nav.helsearbeidsgiver.inntektsmelding.api.validation.OrganisasjonsnummerConstraint.message=Ugyldig virksomhetsnummer
no.nav.helsearbeidsgiver.inntektsmelding.api.validation.BehandlingsdagerConstraint.message=Tom kan ikke være før fom
org.valiktor.constraints.NotEmpty.message=Må fylles ut
org.valiktor.constraints.Less.message=Må være mindre enn {value}
org.valiktor.constraints.Greater.message=Må være større enn {value}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package no.nav.helsearbeidsgiver.inntektsmelding.api.utils

import no.nav.helsearbeidsgiver.inntektsmelding.api.Auth
import no.nav.helsearbeidsgiver.utils.test.wrapper.genererGyldig
import no.nav.helsearbeidsgiver.utils.wrapper.Fnr
import no.nav.security.mock.oauth2.MockOAuth2Server
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
Expand All @@ -9,7 +11,7 @@ abstract class MockAuthToken {
private val mockOAuth2Server = MockOAuth2Server()
private val port = 6666

val mockPid = "12345678901"
val mockPid = Fnr.genererGyldig().verdi

fun mockAuthToken(): String =
mockOAuth2Server.issueToken(
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 6d1fd42

Please sign in to comment.