Skip to content

Commit

Permalink
Merge branch 'tilgangsstyring_roller' into TAG-2161-api-spec
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbb committed Oct 12, 2023
2 parents d153afe + 950db3f commit be2296c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ class AltinnRollerClient(
.build()

private val safeRoleName = Regex("^[A-ZÆØÅ]+$")
private val orgnrRegex = Regex("^[0-9]{9}$")

fun harAltinnRolle(
fnr: String,
orgnr: String,
altinnRoller: Set<String>,
externalRoller: Set<String>,
): Boolean {
require(orgnr.matches(orgnrRegex)) // user-controlled, so ensure only digits before injecting into query
require(altinnRoller.isNotEmpty() && externalRoller.isNotEmpty()) {
"skrevet under antagelse om at både altinnRoller og externalRoller er non-empty"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,87 +34,87 @@ class AltinnRollerClientTest {

@Test
fun `ingen tilgang ved ingen roller`() {
mockRoles("1234", "5678", ingenRollerResponse)
mockRoles("1234", "567812345", ingenRollerResponse)
assertFalse(altinnRollerClient.harAltinnRolle(
fnr = "1234",
orgnr = "5678",
orgnr = "567812345",
altinnRoller = setOf("SIGNE"),
externalRoller = setOf("DAGL")
))
}

@Test
fun `tilgang hvis vi sjekker DAGL(ereg) og bruker er DAGL(ereg), ATTST(altinn)`() {
mockRoles("1234", "5678", daglOgAttstRolleResponse)
mockRoles("1234", "567812345", daglOgAttstRolleResponse)
assertTrue(altinnRollerClient.harAltinnRolle(
fnr = "1234",
orgnr = "5678",
orgnr = "567812345",
altinnRoller = setOf("SIGN"),
externalRoller = setOf("DAGL"),
))
}

@Test
fun `tilgang hvis vi sjekker HADM(altinn) og bruker er DAGL(ereg), HADM(altinn)`() {
mockRoles("1234", "5678", daglOgHadmRolleResponse)
mockRoles("1234", "567812345", daglOgHadmRolleResponse)
assertTrue(altinnRollerClient.harAltinnRolle(
fnr = "1234",
orgnr = "5678",
orgnr = "567812345",
altinnRoller = setOf("HADM"),
externalRoller = setOf("ANNENROLLE"),
))
}

@Test
fun `ikke tilgang hvis altinn- og ereg-roller byttes om`() {
mockRoles("1234", "5678", daglOgHadmRolleResponse)
mockRoles("1234", "567811223", daglOgHadmRolleResponse)
assertFalse(altinnRollerClient.harAltinnRolle(
fnr = "1234",
orgnr = "5678",
orgnr = "567811223",
altinnRoller = setOf("DAGL"),
externalRoller = setOf("HADM"),
))
}

@Test
fun `har tilgang hvis man både har ereg- og altinn-rolle`() {
mockRoles("1234", "5678", daglOgAttstRolleResponse)
mockRoles("1234", "567811223", daglOgAttstRolleResponse)
assertTrue(altinnRollerClient.harAltinnRolle(
fnr = "1234",
orgnr = "5678",
orgnr = "567811223",
altinnRoller = setOf("ATTST"),
externalRoller = setOf("DAGL")
))
}

@Test
fun `bruker trenger ikke å ha alle rollene vi spør om`() {
mockRoles("1234", "5678", daglOgAttstRolleResponse)
mockRoles("1234", "567811223", daglOgAttstRolleResponse)
assertTrue(altinnRollerClient.harAltinnRolle(
fnr = "1234",
orgnr = "5678",
orgnr = "567811223",
altinnRoller = setOf("ATTST"),
externalRoller = setOf("DAGL", "ANNENROLLE"),
))
}

@Test
fun `ikke tilgang selv med flere roller og rolle-sjekker`() {
mockRoles("789", "5678", daglOgAttstRolleResponse)
mockRoles("789", "567811223", daglOgAttstRolleResponse)
assertFalse(altinnRollerClient.harAltinnRolle(
fnr = "789",
orgnr = "5678",
orgnr = "567811223",
altinnRoller = setOf("IKKEROLLE"),
externalRoller = setOf("ANNENIKKEROLLE"),
))
}

@Test
fun `tolker ikke Local-roller som ereg-roller`() {
mockRoles("1234", "567", daglMenLocalRolleResponse)
mockRoles("1234", "567811223", daglMenLocalRolleResponse)
assertFalse(altinnRollerClient.harAltinnRolle(
fnr = "1234",
orgnr = "567",
orgnr = "567811223",
altinnRoller = setOf("ANNEN"),
externalRoller = setOf("DAGL"),
))
Expand All @@ -123,11 +123,11 @@ class AltinnRollerClientTest {

@Test
fun `exception hvis ingen roller oppgis`() {
mockRoles("1234", "5678", daglOgAttstRolleResponse)
mockRoles("1234", "567811223", daglOgAttstRolleResponse)
assertThrows<IllegalArgumentException> {
altinnRollerClient.harAltinnRolle(
fnr = "1234",
orgnr = "5678",
orgnr = "567811223",
altinnRoller = setOf(),
externalRoller = setOf()
)
Expand Down

0 comments on commit be2296c

Please sign in to comment.