File tree Expand file tree Collapse file tree 3 files changed +30
-7
lines changed
main/kotlin/no/ssb/metadata/vardef/security
test/kotlin/no/ssb/metadata/vardef
controllers/validityperiods Expand file tree Collapse file tree 3 files changed +30
-7
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,6 @@ import io.micronaut.web.router.RouteAttributes
1414import io.micronaut.web.router.RouteMatch
1515import jakarta.inject.Singleton
1616import no.ssb.metadata.vardef.constants.ACTIVE_GROUP
17- import no.ssb.metadata.vardef.constants.LABID_ACTIVE_GROUP
1817import no.ssb.metadata.vardef.constants.VARIABLE_DEFINITION_ID_PATH_VARIABLE
1918import no.ssb.metadata.vardef.models.Owner
2019import no.ssb.metadata.vardef.models.SavedVariableDefinition
@@ -118,11 +117,8 @@ class VariableOwnerSecurityRule(
118117 // The next call is blocking, so we need to run it on another thread
119118 .publishOn(Schedulers .boundedElastic())
120119 .map { definitionId ->
121- // Get active group from either query params or authentication claims
122- val activeGroup =
123- request.parameters
124- .getFirst(ACTIVE_GROUP )
125- .orElseGet { authentication.attributes[LABID_ACTIVE_GROUP ] as ? String }
120+ // Get active group from authentication attributes
121+ val activeGroup = authentication.attributes[ACTIVE_GROUP ] as String?
126122 if (activeGroup == null ) {
127123 logger.info(" No active group found in request or authentication claims. Request: $request " )
128124 return @map false
Original file line number Diff line number Diff line change @@ -422,4 +422,29 @@ class CreateTests : BaseVardefTest() {
422422 .then()
423423 .statusCode(HttpStatus .BAD_REQUEST .code)
424424 }
425+
426+ @Test
427+ fun `create new validity period with active group as paramater and labid token` (spec : RequestSpecification ) {
428+ spec
429+ .given()
430+ .contentType(ContentType .JSON )
431+ .body(allMandatoryFieldsChanged())
432+ .queryParam(ACTIVE_GROUP , " other-group-developers" )
433+ .`when `()
434+ .post(" /variable-definitions/${INCOME_TAX_VP1_P1 .definitionId} /validity-periods" )
435+ .then()
436+ .statusCode(201 )
437+ val lastPatchInSecondToLastValidityPeriod =
438+ validityPeriods
439+ .getAsMap(INCOME_TAX_VP1_P1 .definitionId)
440+ .let { it.values.elementAt(it.values.size - 2 ) }
441+ ?.last()
442+ val lastPatch = patches.latest(INCOME_TAX_VP1_P1 .definitionId)
443+ assertThat(
444+ lastPatch.validUntil,
445+ ).isNull()
446+ assertThat(
447+ lastPatchInSecondToLastValidityPeriod?.validUntil,
448+ ).isEqualTo(lastPatch.validFrom.minusDays(1 ))
449+ }
425450}
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ import org.junit.jupiter.params.provider.MethodSource
1616import java.util.stream.Stream
1717
1818@MicronautTest
19- class KeycloakTokenSupportTest {
19+ class KeycloakTokenSupportTest : BaseVardefTest () {
2020 @ParameterizedTest
2121 @MethodSource(" variableCreatorOperations" )
2222 @MethodSource(" variableOwnerOperations" )
@@ -138,6 +138,8 @@ class KeycloakTokenSupportTest {
138138 }
139139 spec
140140 .given()
141+ .auth()
142+ .oauth2(JwtTokenHelper .jwtTokenSigned().parsedString)
141143 .queryParam(ACTIVE_GROUP , " play-foeniks-a-developers" )
142144 .`when `()
143145 .request(method, path)
You can’t perform that action at this time.
0 commit comments