22// Licensed under the MIT license.
33package 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
59import com.cosmotech.api.home.dataset.DatasetConstants.DATASET_DESCRIPTION
610import com.cosmotech.api.home.dataset.DatasetConstants.DATASET_NAME
711import com.cosmotech.api.home.dataset.DatasetConstants.DATASET_PART_DESCRIPTION
@@ -31,6 +35,7 @@ import org.springframework.http.MediaType
3135import org.springframework.mock.web.MockMultipartFile
3236import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf
3337import org.springframework.test.web.servlet.MockMvc
38+ import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder
3439import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
3540import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart
3641import 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 )
0 commit comments