kikocis/dataspace-portal public
Changesets · Branches · Tags · Compare
| Changeset | 582bd8848e4abd458c787e09686ceb3e7432a41fb3af75caf13dde9d4af90dfb |
|---|---|
| Author | Kamil Czaja <46053356+kamilczaja@users.noreply.github.com> · 2024-12-02 08:52 +01:00 |
| Committer | GitHub <noreply@github.com> · 2024-12-02 07:52 UTC |
| Parents | 0851d8a418d8 |
6 files changed
modified CHANGELOG.md +2 −1
| @@ -24,9 +24,10 @@ | ||
| 24 | 24 | - Fixed final step not showing when registering a central component ([#305](https://github.com/sovity/authority-portal/issues/305)) |
| 25 | 25 | - Fixed My Organization page not updated when switching between environments ([#255](https://github.com/sovity/authority-portal/issues/255)) |
| 26 | 26 | - Added live update when deactivating/reactivating users ([#287](https://github.com/sovity/authority-portal/issues/287)) |
| 27 | -- Fixed Website title not updating in some scenarios [#237](https://github.com/sovity/authority-portal/issues/237) | |
| 27 | +- Fixed Website title not updating in some scenarios ([#237](https://github.com/sovity/authority-portal/issues/237)) | |
| 28 | 28 | - Fixed security vulnerabilities |
| 29 | 29 | - Fixed the user not being redirected to the correct URL after login ([#324](https://github.com/sovity/authority-portal/issues/324)) |
| 30 | +- Fixed an issue wherein it was possible to bypass the CaaS request limit in an organization ([PR #384](https://github.com/sovity/authority-portal/pull/384)) | |
| 30 | 31 | |
| 31 | 32 | ### Known issues |
| 32 | 33 |
modified authority-portal-backend/authority-portal-quarkus/build.gradle.kts +1 −0
| @@ -61,6 +61,7 @@ | ||
| 61 | 61 | // https://github.com/quarkusio/quarkus/wiki/Migration-Guide-3.0#fixation-of-the-mockito-subclass-mockmaker |
| 62 | 62 | exclude(group = libs.mockito.subclass.get().group, module = libs.mockito.subclass.get().name) |
| 63 | 63 | } |
| 64 | + testImplementation("io.quarkus:quarkus-test-security") | |
| 64 | 65 | testImplementation(libs.bundles.assertj) |
| 65 | 66 | testImplementation(libs.awaitility) |
| 66 | 67 | testImplementation(libs.bundles.mockito) |
modified authority-portal-backend/authority-portal-quarkus/src/main/kotlin/de/sovity/authorityportal/seeds/utils/ScenarioData.kt +17 −0
| @@ -14,6 +14,7 @@ | ||
| 14 | 14 | package de.sovity.authorityportal.seeds.utils |
| 15 | 15 | |
| 16 | 16 | import com.fasterxml.jackson.databind.ObjectMapper |
| 17 | +import de.sovity.authorityportal.db.jooq.Tables | |
| 17 | 18 | import de.sovity.authorityportal.db.jooq.enums.ConnectorContractOffersExceeded |
| 18 | 19 | import de.sovity.authorityportal.db.jooq.enums.ConnectorDataOffersExceeded |
| 19 | 20 | import de.sovity.authorityportal.db.jooq.enums.ConnectorOnlineStatus |
| @@ -57,6 +58,22 @@ | ||
| 57 | 58 | private val contractOffers = mutableListOf<ContractOfferRecord>() |
| 58 | 59 | private val crawlerEventLogEntries = mutableListOf<CrawlerEventLogRecord>() |
| 59 | 60 | |
| 61 | + companion object { | |
| 62 | + fun uninstall(dsl: DSLContext) { | |
| 63 | + dsl.deleteFrom(Tables.CRAWLER_EVENT_LOG).execute() | |
| 64 | + dsl.deleteFrom(Tables.CONTRACT_OFFER).execute() | |
| 65 | + dsl.deleteFrom(Tables.DATA_OFFER_VIEW_COUNT).execute() | |
| 66 | + dsl.deleteFrom(Tables.DATA_OFFER).execute() | |
| 67 | + dsl.deleteFrom(Tables.COMPONENT).execute() | |
| 68 | + dsl.deleteFrom(Tables.CONNECTOR).execute() | |
| 69 | + dsl.update(Tables.USER) | |
| 70 | + .set(Tables.USER.ORGANIZATION_ID, null as String?) | |
| 71 | + .execute() | |
| 72 | + dsl.deleteFrom(Tables.ORGANIZATION).execute() | |
| 73 | + dsl.deleteFrom(Tables.USER).execute() | |
| 74 | + } | |
| 75 | + } | |
| 76 | + | |
| 60 | 77 | fun install(dsl: DSLContext) { |
| 61 | 78 | val userOrgMap = users.associate { it.id to it.organizationId } |
| 62 | 79 | users.forEach { |
modified authority-portal-backend/authority-portal-quarkus/src/main/kotlin/de/sovity/authorityportal/web/UiResourceImpl.kt +3 −2
| @@ -64,11 +64,12 @@ | ||
| 64 | 64 | import de.sovity.authorityportal.web.pages.usermanagement.UserRoleApiService |
| 65 | 65 | import de.sovity.authorityportal.web.pages.usermanagement.UserUpdateApiService |
| 66 | 66 | import de.sovity.authorityportal.web.pages.userregistration.UserRegistrationApiService |
| 67 | +import io.quarkus.arc.Lock | |
| 67 | 68 | import jakarta.annotation.security.PermitAll |
| 68 | 69 | import jakarta.enterprise.context.ApplicationScoped |
| 69 | 70 | import jakarta.transaction.Transactional |
| 70 | 71 | |
| 71 | -@PermitAll // auth checks will be in code in this unit | |
| 72 | +@PermitAll | |
| 72 | 73 | @ApplicationScoped |
| 73 | 74 | class UiResourceImpl( |
| 74 | 75 | val authUtils: AuthUtils, |
| @@ -412,7 +413,7 @@ | ||
| 412 | 413 | ) |
| 413 | 414 | } |
| 414 | 415 | |
| 415 | - @Transactional | |
| 416 | + @Lock | |
| 416 | 417 | override fun createCaas(environmentId: String, caasRequest: CreateCaasRequest): CreateConnectorResponse { |
| 417 | 418 | authUtils.requiresRole(Roles.UserRoles.PARTICIPANT_CURATOR) |
| 418 | 419 | authUtils.requiresMemberOfAnyOrganization() |
modified authority-portal-backend/authority-portal-quarkus/src/main/kotlin/de/sovity/authorityportal/web/pages/connectormanagement/CaasManagementApiService.kt +2 −0
| @@ -31,6 +31,7 @@ | ||
| 31 | 31 | import de.sovity.authorityportal.web.utils.idmanagement.DataspaceComponentIdUtils |
| 32 | 32 | import io.quarkus.logging.Log |
| 33 | 33 | import jakarta.enterprise.context.ApplicationScoped |
| 34 | +import jakarta.transaction.Transactional | |
| 34 | 35 | import org.eclipse.microprofile.config.inject.ConfigProperty |
| 35 | 36 | import kotlin.jvm.optionals.getOrNull |
| 36 | 37 | |
| @@ -48,6 +49,7 @@ | ||
| 48 | 49 | @ConfigProperty(name = "quarkus.oidc-client.sovity.client-enabled") val isCaasClientEnabled: Boolean |
| 49 | 50 | ) { |
| 50 | 51 | |
| 52 | + @Transactional(Transactional.TxType.REQUIRES_NEW) | |
| 51 | 53 | fun createCaas( |
| 52 | 54 | organizationId: String, |
| 53 | 55 | userId: String, |
modified authority-portal-backend/authority-portal-quarkus/src/test/kotlin/de/sovity/authorityportal/web/tests/services/connector/CaasManagementApiServiceTest.kt +65 −2
| @@ -38,9 +38,12 @@ | ||
| 38 | 38 | import io.quarkus.test.InjectMock |
| 39 | 39 | import io.quarkus.test.TestTransaction |
| 40 | 40 | import io.quarkus.test.junit.QuarkusTest |
| 41 | +import io.quarkus.test.security.TestSecurity | |
| 41 | 42 | import jakarta.inject.Inject |
| 42 | 43 | import org.assertj.core.api.Assertions.assertThat |
| 44 | +import org.flywaydb.core.Flyway | |
| 43 | 45 | import org.jooq.DSLContext |
| 46 | +import org.junit.jupiter.api.AfterEach | |
| 44 | 47 | import org.junit.jupiter.api.Test |
| 45 | 48 | import org.junit.jupiter.api.extension.ExtendWith |
| 46 | 49 | import org.mockito.junit.jupiter.MockitoExtension |
| @@ -48,6 +51,10 @@ | ||
| 48 | 51 | import org.mockito.kotlin.eq |
| 49 | 52 | import org.mockito.kotlin.whenever |
| 50 | 53 | import java.time.OffsetDateTime |
| 54 | +import java.util.concurrent.CountDownLatch | |
| 55 | +import java.util.concurrent.ExecutorService | |
| 56 | +import java.util.concurrent.TimeUnit | |
| 57 | +import java.util.concurrent.atomic.AtomicInteger | |
| 51 | 58 | |
| 52 | 59 | @QuarkusTest |
| 53 | 60 | @ExtendWith(MockitoExtension::class) |
| @@ -65,11 +72,18 @@ | ||
| 65 | 72 | @Inject |
| 66 | 73 | lateinit var clientIdUtils: ClientIdUtils |
| 67 | 74 | |
| 75 | + @Inject | |
| 76 | + lateinit var executorService: ExecutorService | |
| 77 | + | |
| 68 | 78 | @InjectMock |
| 69 | 79 | lateinit var caasClient: CaasClient |
| 70 | 80 | |
| 81 | + @AfterEach | |
| 82 | + fun cleanup() { | |
| 83 | + ScenarioData.uninstall(dsl) | |
| 84 | + } | |
| 85 | + | |
| 71 | 86 | @Test |
| 72 | - @TestTransaction | |
| 73 | 87 | fun `create caas creates connector with caas configuration`() { |
| 74 | 88 | // arrange |
| 75 | 89 | val now = OffsetDateTime.now() |
| @@ -143,7 +157,6 @@ | ||
| 143 | 157 | } |
| 144 | 158 | |
| 145 | 159 | @Test |
| 146 | - @TestTransaction | |
| 147 | 160 | fun `check free caas slots returns the correct amount`() { |
| 148 | 161 | // arrange |
| 149 | 162 | useDevUser(0, 0, setOf(Roles.UserRoles.PARTICIPANT_CURATOR)) |
| @@ -166,4 +179,54 @@ | ||
| 166 | 179 | assertThat(result.limit).isEqualTo(0) |
| 167 | 180 | assertThat(result.current).isEqualTo(0) |
| 168 | 181 | } |
| 182 | + | |
| 183 | + @Test | |
| 184 | + @TestSecurity(authorizationEnabled = false) | |
| 185 | + fun `create caas endpoint should lock correctly`() { | |
| 186 | + // arrange | |
| 187 | + val now = OffsetDateTime.now() | |
| 188 | + val i = AtomicInteger(0) | |
| 189 | + | |
| 190 | + useDevUser(0, 0, setOf(Roles.UserRoles.PARTICIPANT_CURATOR)) | |
| 191 | + useMockNow(now) | |
| 192 | + | |
| 193 | + ScenarioData().apply { | |
| 194 | + organization(0, 0) | |
| 195 | + user(0, 0) | |
| 196 | + | |
| 197 | + scenarioInstaller.install(this) | |
| 198 | + } | |
| 199 | + | |
| 200 | + whenever(caasClient.validateSubdomain(any())).thenReturn(true) | |
| 201 | + whenever(caasClient.requestCaas(any())).thenReturn( | |
| 202 | + CaasPortalResponse().apply { | |
| 203 | + value = CaasDetails(connectorId = dummyDevConnectorId(0, 0)) | |
| 204 | + } | |
| 205 | + ) | |
| 206 | + | |
| 207 | + // act | |
| 208 | + val count = 10 | |
| 209 | + val latch = CountDownLatch(count) | |
| 210 | + | |
| 211 | + repeat(count) { | |
| 212 | + executorService.execute { | |
| 213 | + uiResource.createCaas( | |
| 214 | + "test", CreateCaasRequest( | |
| 215 | + connectorSubdomain = "test-caas-${i.addAndGet(1)}", | |
| 216 | + connectorTitle = "Test CaaS-${i.addAndGet(1)}", | |
| 217 | + connectorDescription = "Connector-as-a-service for testing purposes" | |
| 218 | + ) | |
| 219 | + ) | |
| 220 | + latch.countDown() | |
| 221 | + } | |
| 222 | + } | |
| 223 | + latch.await(20, TimeUnit.SECONDS) | |
| 224 | + | |
| 225 | + // assert | |
| 226 | + val connectors = dsl.selectFrom(Tables.CONNECTOR) | |
| 227 | + .where(Tables.CONNECTOR.TYPE.eq(ConnectorType.CAAS)) | |
| 228 | + .fetch() | |
| 229 | + | |
| 230 | + assertThat(connectors).hasSize(1) | |
| 231 | + } | |
| 169 | 232 | } |