Skip to content

Commit

Permalink
Add Alias for Rule Delete Endpoint (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
f11h authored Jul 7, 2021
1 parent a03db74 commit f3091b3
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,4 +325,50 @@ public ResponseEntity<Void> deleteValidationRules(

return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}

/**
* Alias endpoint to delete a Validation Rule.
*/
@CertificateAuthenticationRequired
@PostMapping(path = "/delete", consumes = CmsStringMessageConverter.CONTENT_TYPE_CMS_TEXT_VALUE)
@Operation(
security = {
@SecurityRequirement(name = OpenApiConfig.SECURITY_SCHEMA_HASH),
@SecurityRequirement(name = OpenApiConfig.SECURITY_SCHEMA_DISTINGUISH_NAME)
},
summary = "Delete all versions of a rule with id (Alias Endpoint for DELETE)",
tags = {"Validation Rules"},
requestBody = @RequestBody(
required = true,
description = "CMS Signed String representing the Rule ID. Needs to be signed with valid Upload Certificate"
),
responses = {
@ApiResponse(
responseCode = "204",
description = "Delete successful."
),
@ApiResponse(
responseCode = "400",
description = "Bad data submitted. See ProblemReport for more details.",
content = @Content(schema = @Schema(implementation = ProblemReportDto.class))
),
@ApiResponse(
responseCode = "403",
description = "You are not allowed to delete these validation rules.",
content = @Content(schema = @Schema(implementation = ProblemReportDto.class))
),
@ApiResponse(
responseCode = "404",
description = "Validation rule not found.",
content = @Content(schema = @Schema(implementation = ProblemReportDto.class))
)
}
)
public ResponseEntity<Void> deleteValidationRulesAliasEndpoint(
@org.springframework.web.bind.annotation.RequestBody SignedStringDto signedString,
@RequestAttribute(CertificateAuthenticationFilter.REQUEST_PROP_COUNTRY) String authenticatedCountryCode,
@RequestAttribute(CertificateAuthenticationFilter.REQUEST_PROP_THUMBPRINT) String thumbprint
) {
return deleteValidationRules(signedString, authenticatedCountryCode, thumbprint);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1025,4 +1025,61 @@ void testDownloadDbContainsOnlyRulesValidInFutureShouldReturnAll() throws Except

}

@Test
void testDeleteAliasEndpoint() throws Exception {
long validationRulesInDb = validationRuleRepository.count();

X509Certificate signerCertificate = trustedPartyTestHelper.getCert(TrustedPartyEntity.CertificateType.UPLOAD, countryCode);
PrivateKey signerPrivateKey = trustedPartyTestHelper.getPrivateKey(TrustedPartyEntity.CertificateType.UPLOAD, countryCode);

ValidationRule validationRule = getDummyValidationRule();

String payload = new SignedStringMessageBuilder()
.withSigningCertificate(certificateUtils.convertCertificate(signerCertificate), signerPrivateKey)
.withPayload(objectMapper.writeValueAsString(validationRule))
.buildAsString();

String authCertHash = trustedPartyTestHelper.getHash(TrustedPartyEntity.CertificateType.AUTHENTICATION, countryCode);

mockMvc.perform(post("/rules")
.content(payload)
.contentType("application/cms-text")
.header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash)
.header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject)
)
.andExpect(status().isCreated());

validationRule.setVersion("1.0.1");

payload = new SignedStringMessageBuilder()
.withSigningCertificate(certificateUtils.convertCertificate(signerCertificate), signerPrivateKey)
.withPayload(objectMapper.writeValueAsString(validationRule))
.buildAsString();

mockMvc.perform(post("/rules")
.content(payload)
.contentType("application/cms-text")
.header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash)
.header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject)
)
.andExpect(status().isCreated());

Assertions.assertEquals(validationRulesInDb + 2, validationRuleRepository.count());

String deletePayload = new SignedStringMessageBuilder()
.withSigningCertificate(certificateUtils.convertCertificate(signerCertificate), signerPrivateKey)
.withPayload(validationRule.getIdentifier())
.buildAsString();

mockMvc.perform(post("/rules/delete")
.content(deletePayload)
.contentType("application/cms-text")
.header(dgcConfigProperties.getCertAuth().getHeaderFields().getThumbprint(), authCertHash)
.header(dgcConfigProperties.getCertAuth().getHeaderFields().getDistinguishedName(), authCertSubject)
)
.andExpect(status().isNoContent());

Assertions.assertEquals(validationRulesInDb, validationRuleRepository.count());
}

}

0 comments on commit f3091b3

Please sign in to comment.