Skip to content

Commit

Permalink
feat(bpdm): added test and auth permissions to upload partner end point
Browse files Browse the repository at this point in the history
  • Loading branch information
SujitMBRDI committed Jun 17, 2024
1 parent afc50ea commit f6b62cc
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 5 deletions.
12 changes: 10 additions & 2 deletions bpdm-common-test/src/main/resources/keycloak/CX-Central.json
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,14 @@
"clientRole" : true,
"containerId" : "0562ecfa-f17b-4d32-86cc-061f7da34b6b",
"attributes" : { }
}, {
"id" : "e3ca0b50-95c7-43d5-baf6-359d87fc272a",
"name" : "upload_input_partner",
"description" : "Upload access to business partner input data",
"composite" : false,
"clientRole" : true,
"containerId" : "0562ecfa-f17b-4d32-86cc-061f7da34b6b",
"attributes" : {}
} ],
"account-console" : [ ],
"EDC-GATE-OUTPUT-CONSUMER" : [ ],
Expand Down Expand Up @@ -551,7 +559,7 @@
"attributes" : { },
"realmRoles" : [ ],
"clientRoles" : {
"BPDM-GATE" : [ "write_sharing_state", "read_output_partner", "read_input_changelog", "read_stats", "read_output_changelog", "write_input_partner", "read_sharing_state", "read_input_partner" ]
"BPDM-GATE" : [ "write_sharing_state", "read_output_partner", "read_input_changelog", "read_stats", "read_output_changelog", "write_input_partner", "read_sharing_state", "read_input_partner", "upload_input_partner" ]
},
"subGroups" : [ ]
}, {
Expand All @@ -571,7 +579,7 @@
"attributes" : { },
"realmRoles" : [ ],
"clientRoles" : {
"BPDM-GATE" : [ "write_sharing_state", "read_input_changelog", "read_stats", "write_input_partner", "read_sharing_state", "read_input_partner" ]
"BPDM-GATE" : [ "write_sharing_state", "read_input_changelog", "read_stats", "write_input_partner", "read_sharing_state", "read_input_partner", "upload_input_partner" ]
},
"subGroups" : [ ]
}, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ data class PermissionConfigProperties(
val readOutputChangelog: String = "read_output_changelog",
val readSharingState: String = "read_sharing_state",
val writeSharingState: String = "write_sharing_state",
val readStats: String = "read_stats"
val readStats: String = "read_stats",
val uploadInputPartner: String = "upload_input_partner"
) {
companion object {
const val PREFIX = "bpdm.security.permissions"
Expand All @@ -49,5 +50,6 @@ data class PermissionConfigProperties(
const val READ_SHARING_STATE = "@$BEAN_QUALIFIER.getReadSharingState()"
const val WRITE_SHARING_STATE = "@$BEAN_QUALIFIER.getWriteSharingState()"
const val READ_STATS = "@$BEAN_QUALIFIER.getReadStats()"
const val UPLOAD_INPUT_PARTNER = "@$BEAN_QUALIFIER.getUploadInputPartner()"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class PartnerUploadController(
val partnerUploadService: PartnerUploadService
) : GatePartnerUploadApi {

@PreAuthorize("hasAuthority(${PermissionConfigProperties.WRITE_INPUT_PARTNER})")
@PreAuthorize("hasAuthority(${PermissionConfigProperties.UPLOAD_INPUT_PARTNER})")
override fun uploadPartnerCsvFile(
file: MultipartFile
): ResponseEntity<Collection<BusinessPartnerInputDto>> {
Expand Down
2 changes: 2 additions & 0 deletions bpdm-gate/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ bpdm:
writeSharingState: write_sharing_state
# Name of the permission to read business partner statistics
read_stats: read_stats
# Name of the permission to upload business partner entries for business partner input data
uploadInputPartner: upload_input_partner
datasource:
# Host name of the used datasource
host: localhost
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class AuthAdminIT @Autowired constructor(
getStage = AuthExpectationType.Authorized,
getAddressType = AuthExpectationType.Authorized,
getConfidenceCriteria = AuthExpectationType.Authorized
),
uploadPartner = UploadPartnerAuthExpections(
postInput = AuthExpectationType.Authorized
)
)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class AuthInputConsumerIT @Autowired constructor(
getStage = AuthExpectationType.Authorized,
getAddressType = AuthExpectationType.Authorized,
getConfidenceCriteria = AuthExpectationType.Authorized
),
uploadPartner = UploadPartnerAuthExpections(
postInput = AuthExpectationType.Forbidden
)
)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class AuthInputManagerIT @Autowired constructor(
getStage = AuthExpectationType.Authorized,
getAddressType = AuthExpectationType.Authorized,
getConfidenceCriteria = AuthExpectationType.Authorized
),
uploadPartner = UploadPartnerAuthExpections(
postInput = AuthExpectationType.Authorized
)
)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class AuthOutputConsumerIT @Autowired constructor(
getStage = AuthExpectationType.Authorized,
getAddressType = AuthExpectationType.Authorized,
getConfidenceCriteria = AuthExpectationType.Authorized
),
uploadPartner = UploadPartnerAuthExpections(
postInput = AuthExpectationType.Forbidden
)
)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import org.eclipse.tractusx.bpdm.gate.api.model.request.PostSharingStateReadyReq
import org.eclipse.tractusx.bpdm.test.util.AuthAssertionHelper
import org.eclipse.tractusx.bpdm.test.util.AuthExpectationType
import org.junit.jupiter.api.Test
import org.springframework.mock.web.MockMultipartFile
import java.nio.file.Files
import java.nio.file.Paths

abstract class AuthTestBase(
private val gateClient: GateClient,
Expand Down Expand Up @@ -91,13 +94,21 @@ abstract class AuthTestBase(
authAssertions.assert(authExpectations.stats.getConfidenceCriteria) { gateClient.stats.getConfidenceCriteriaStats() }
}

@Test
fun `POST Partner Input`() {
val bytes = Files.readAllBytes(Paths.get("src/test/resources/testData/valid_partner_data.csv"))
val uploadedFile = MockMultipartFile("valid_partner_data.csv", "valid_partner_data.csv", "text/csv", bytes)
authAssertions.assert(authExpectations.uploadPartner.postInput) { gateClient.partnerUpload.uploadPartnerCsvFile(uploadedFile) }
}

}

data class GateAuthExpectations(
val businessPartner: BusinessPartnerAuthExpectations,
val changelog: ChangelogAuthExpectations,
val sharingState: SharingStateAuthExpectations,
val stats: StatsAuthExpectations
val stats: StatsAuthExpectations,
val uploadPartner: UploadPartnerAuthExpections
)

data class BusinessPartnerAuthExpectations(
Expand All @@ -123,3 +134,6 @@ data class StatsAuthExpectations(
val getConfidenceCriteria: AuthExpectationType
)

data class UploadPartnerAuthExpections(
val postInput: AuthExpectationType
)
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ class NoAuthIT @Autowired constructor(
getStage = AuthExpectationType.Unauthorized,
getAddressType = AuthExpectationType.Unauthorized,
getConfidenceCriteria = AuthExpectationType.Unauthorized
),
uploadPartner = UploadPartnerAuthExpections(
postInput = AuthExpectationType.Unauthorized
)
)
)
Expand Down
9 changes: 9 additions & 0 deletions charts/bpdm/templates/keycloakRealm.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,13 @@ roles:
clientRole: true
containerId: 0562ecfa-f17b-4d32-86cc-061f7da34b6b
attributes: {}
- id: e3ca0b50-95c7-43d5-baf6-359d87fc272a
name: upload_input_partner
description: Upload access to business partner input data
composite: false
clientRole: true
containerId: 0562ecfa-f17b-4d32-86cc-061f7da34b6b
attributes: {}
account-console: []
EDC-GATE-OUTPUT-CONSUMER: []
broker:
Expand Down Expand Up @@ -549,6 +556,7 @@ groups:
- write_input_partner
- read_sharing_state
- read_input_partner
- upload_input_partner
subGroups: []
- id: d0cbde40-4896-4484-bff4-8666d2ad1a14
name: Input Consumer
Expand All @@ -575,6 +583,7 @@ groups:
- write_input_partner
- read_sharing_state
- read_input_partner
- upload_input_partner
subGroups: []
- id: a66cad54-3ff3-4673-88ea-304892073e13
name: Output Consumer
Expand Down

0 comments on commit f6b62cc

Please sign in to comment.