Skip to content

Commit 13690b1

Browse files
committed
Remove WithMockOauth2User annotation and related classes
- Deleted `WithMockOauth2User` annotation and `WithMockOauth2UserSecurityContextFactory` class as they are no longer used. - Replaced `@WithMockOauth2User` annotation with `withPlatformAdminHeader` and `withOrganizationUserHeader` in integration tests for consistent mock user authentication. - Updated `application-test.yml` with test API key configurations.
1 parent 1839f21 commit 13690b1

File tree

13 files changed

+280
-261
lines changed

13 files changed

+280
-261
lines changed

api/src/integrationTest/kotlin/com/cosmotech/api/home/Constants.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ object Constants {
66

77
const val PLATFORM_ADMIN_EMAIL = "user.admin@test.com"
88
const val ORGANIZATION_USER_EMAIL = "user.org@test.com"
9-
const val DEFAULT_ISSUER = "test-issuer"
10-
const val DEFAULT_SUBJECT = "test-subject"
9+
const val PLATFORM_ADMIN_API_KEY_VALUE = "PlatformAdminApiTestKeyValue"
10+
const val ORGANIZATION_USER_API_KEY_VALUE = "OrganizationUserApiTestKeyValue"
1111
}

api/src/integrationTest/kotlin/com/cosmotech/api/home/ControllerTestBase.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Licensed under the MIT license.
33
package com.cosmotech.api.home
44

5+
import com.cosmotech.api.home.Constants.ORGANIZATION_USER_EMAIL
6+
import com.cosmotech.api.home.Constants.PLATFORM_ADMIN_EMAIL
57
import com.cosmotech.dataset.domain.Dataset
68
import com.cosmotech.dataset.domain.DatasetPart
79
import com.cosmotech.organization.domain.Organization
@@ -86,7 +88,10 @@ abstract class ControllerTestBase : AbstractTestcontainersRedisTestBase() {
8688
documentationConfiguration(restDocumentationContextProvider)
8789
.operationPreprocessors()
8890
.withRequestDefaults(
89-
modifyHeaders().remove(HttpHeaders.CONTENT_LENGTH), prettyPrint())
91+
modifyHeaders().remove(HttpHeaders.CONTENT_LENGTH),
92+
modifyHeaders().remove(PLATFORM_ADMIN_EMAIL),
93+
modifyHeaders().remove(ORGANIZATION_USER_EMAIL),
94+
prettyPrint())
9095
.withResponseDefaults(
9196
modifyHeaders()
9297
.remove("X-Content-Type-Options")

api/src/integrationTest/kotlin/com/cosmotech/api/home/ControllerTestUtils.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// Licensed under the MIT license.
33
package com.cosmotech.api.home
44

5+
import com.cosmotech.api.home.Constants.ORGANIZATION_USER_API_KEY_VALUE
6+
import com.cosmotech.api.home.Constants.ORGANIZATION_USER_EMAIL
7+
import com.cosmotech.api.home.Constants.PLATFORM_ADMIN_API_KEY_VALUE
8+
import com.cosmotech.api.home.Constants.PLATFORM_ADMIN_EMAIL
59
import com.cosmotech.api.home.dataset.DatasetConstants.DATASET_DESCRIPTION
610
import com.cosmotech.api.home.dataset.DatasetConstants.DATASET_NAME
711
import com.cosmotech.api.home.dataset.DatasetConstants.DATASET_PART_DESCRIPTION
@@ -31,6 +35,7 @@ import org.springframework.http.MediaType
3135
import org.springframework.mock.web.MockMultipartFile
3236
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf
3337
import org.springframework.test.web.servlet.MockMvc
38+
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder
3439
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
3540
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart
3641
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
@@ -46,6 +51,7 @@ class ControllerTestUtils {
4651
JSONObject(
4752
mvc.perform(
4853
post("/organizations")
54+
.withPlatformAdminHeader()
4955
.contentType(MediaType.APPLICATION_JSON)
5056
.content(JSONObject(organizationCreateRequest).toString())
5157
.accept(MediaType.APPLICATION_JSON)
@@ -75,6 +81,7 @@ class ControllerTestUtils {
7581
JSONObject(
7682
mvc.perform(
7783
post("/organizations/$organizationId/solutions")
84+
.withPlatformAdminHeader()
7885
.contentType(MediaType.APPLICATION_JSON)
7986
.content(JSONObject(solutionCreateRequest).toString())
8087
.accept(MediaType.APPLICATION_JSON)
@@ -150,6 +157,7 @@ class ControllerTestUtils {
150157
JSONObject(
151158
mvc.perform(
152159
post("/organizations/$organizationId/workspaces/$workspaceId/runners")
160+
.withPlatformAdminHeader()
153161
.contentType(MediaType.APPLICATION_JSON)
154162
.content(JSONObject(runnerCreateRequest).toString())
155163
.accept(MediaType.APPLICATION_JSON)
@@ -233,6 +241,7 @@ class ControllerTestUtils {
233241
JSONObject(
234242
mvc.perform(
235243
post("/organizations/$organizationId/workspaces")
244+
.withPlatformAdminHeader()
236245
.contentType(MediaType.APPLICATION_JSON)
237246
.content(
238247
JSONObject(
@@ -257,6 +266,7 @@ class ControllerTestUtils {
257266
JSONObject(
258267
mvc.perform(
259268
post("/organizations/$organizationId/workspaces")
269+
.withPlatformAdminHeader()
260270
.contentType(MediaType.APPLICATION_JSON)
261271
.content(JSONObject(workspaceCreateRequest).toString())
262272
.accept(MediaType.APPLICATION_JSON)
@@ -356,6 +366,7 @@ class ControllerTestUtils {
356366
multipart("/organizations/$organizationId/workspaces/$workspaceId/datasets")
357367
.file(datasetCreateRequestFile)
358368
.file(files)
369+
.withPlatformAdminHeader()
359370
.accept(MediaType.APPLICATION_JSON)
360371
.with(csrf()))
361372
.andReturn()
@@ -376,6 +387,7 @@ class ControllerTestUtils {
376387
mvc.perform(
377388
get(
378389
"/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId")
390+
.withPlatformAdminHeader()
379391
.accept(MediaType.APPLICATION_JSON)
380392
.with(csrf()))
381393
.andReturn()
@@ -418,6 +430,7 @@ class ControllerTestUtils {
418430
"/organizations/$organizationId/workspaces/$workspaceId/datasets/$datasetId/parts")
419431
.file(datasetPartCreateRequestFile)
420432
.file(file)
433+
.withPlatformAdminHeader()
421434
.accept(MediaType.APPLICATION_JSON)
422435
.with(csrf()))
423436
.andReturn()
@@ -464,3 +477,9 @@ class ControllerTestUtils {
464477
}
465478
}
466479
}
480+
481+
fun MockHttpServletRequestBuilder.withPlatformAdminHeader(): MockHttpServletRequestBuilder =
482+
this.header(PLATFORM_ADMIN_EMAIL, PLATFORM_ADMIN_API_KEY_VALUE)
483+
484+
fun MockHttpServletRequestBuilder.withOrganizationUserHeader(): MockHttpServletRequestBuilder =
485+
this.header(ORGANIZATION_USER_EMAIL, ORGANIZATION_USER_API_KEY_VALUE)

api/src/integrationTest/kotlin/com/cosmotech/api/home/annotations/WithMockOauth2User.kt

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)