diff --git a/devops/gc/deploy/templates/register-variables.yml b/devops/gc/deploy/templates/register-variables.yml index 5ff4cf9c13d9221093973ef790573c9963e4d963..cce7a7163122449d43fc368d42bf1041ed147b20 100644 --- a/devops/gc/deploy/templates/register-variables.yml +++ b/devops/gc/deploy/templates/register-variables.yml @@ -19,3 +19,6 @@ data: KEY_RING: {{ .Values.data.keyRing | quote}} KMS_KEY: {{ .Values.data.kmsKey | quote }} {{- end }} + {{- if .Values.conf.intTestEndpoint }} + TEST_ENDPOINT: "true" + {{- end }} diff --git a/devops/gc/deploy/values.yaml b/devops/gc/deploy/values.yaml index 9136489c6854f8122cb4e779484a372bcf963084..6b82a0f075594450cd1669c0bce5205d44e39abc 100644 --- a/devops/gc/deploy/values.yaml +++ b/devops/gc/deploy/values.yaml @@ -35,6 +35,7 @@ conf: registerKeycloakSecretName: "register-keycloak-secret" registerKmsSecretName: "register-kms-secret" appName: "register" + intTestEndpoint: false istio: proxyCPU: "10m" diff --git a/provider/register-gc/src/main/java/org/opengroup/osdu/register/provider/gcp/api/test/SubscriberListenerTestApi.java b/provider/register-gc/src/main/java/org/opengroup/osdu/register/provider/gcp/api/test/SubscriberListenerTestApi.java new file mode 100644 index 0000000000000000000000000000000000000000..482a163c6a361eaf70c26cd4071a9b30b0da112d --- /dev/null +++ b/provider/register-gc/src/main/java/org/opengroup/osdu/register/provider/gcp/api/test/SubscriberListenerTestApi.java @@ -0,0 +1,100 @@ +package org.opengroup.osdu.register.provider.gcp.api.test; + +import org.opengroup.osdu.core.common.cryptographic.ISignatureService; +import org.opengroup.osdu.core.common.cryptographic.SignatureServiceException; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.register.api.dto.ChallengeResponse; +import org.opengroup.osdu.register.provider.interfaces.subscriber.ITestSubscription; +import org.opengroup.osdu.register.provider.interfaces.verifier.GsaTokenVerifier; +import org.opengroup.osdu.register.utils.AppServiceConfig; +import org.opengroup.osdu.register.utils.HashingUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.inject.Inject; +import javax.inject.Provider; +import javax.validation.ValidationException; +import javax.validation.constraints.NotBlank; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.atomic.AtomicLong; + +@RestController +@RequestMapping("/test-gc") +@ConditionalOnProperty(prefix = "test", name = "endpoint", havingValue = "true") +@Validated +public class SubscriberListenerTestApi { + @Autowired + private ISignatureService signatureService; + @Autowired + private AppServiceConfig serviceConfig; + @Autowired + private JaxRsDpsLog logger; + @Autowired + private ITestSubscription testSubscription; + @Autowired + private GsaTokenVerifier gsaTokenVerifier; + @Inject + private Provider<DpsHeaders> headersProvider; + private final static Map<String, AtomicLong> notificationsState = new HashMap<>(); + + @GetMapping("challenge/{path}") + public ChallengeResponse testCrc(@PathVariable String path, @RequestParam("crc") @NotBlank String crc, + @RequestParam("hmac") @NotBlank String hmac) { + try { + signatureService.verifyHmacSignature(hmac, this.serviceConfig.getSubscriberSecret()); + logger.debug("GC tests: Signature verified and sending response"); + notificationsState.put(path, new AtomicLong()); + // Use the secret you send to the subscriber registration create request + return new ChallengeResponse(HashingUtil.hashString(crc, this.serviceConfig.getSubscriberSecret())); + } catch (SignatureServiceException e) { + throw new ValidationException("Authorization signature validation Failed"); + } + } + + @PostMapping("challenge/{path}") + public void testPushHmac(@PathVariable String path, @RequestBody Object o, @RequestParam("hmac") String hmac) { + try { + signatureService.verifyHmacSignature(hmac, this.serviceConfig.getSubscriberSecret()); + logger.debug("GC tests: Sending acknowledgement from hmac endpoint"); + // Performing End Point Notification Acknowledgement + try { + testSubscription.performTestAcknowledgement(); + notificationsState.get(path).getAndIncrement(); + } catch (Exception e) { + logger.error("An error occurred in Test Acknowledgement: " + e.toString()); + } + } catch (SignatureServiceException e) { + throw new ValidationException("Authorization signature validation Failed"); + } + } + + @GetMapping("/gsa-challenge/{path}") + public ChallengeResponse testGsa(@PathVariable String path, @RequestParam("crc") @NotBlank String crc) { + DpsHeaders headers = headersProvider.get(); + if (!gsaTokenVerifier.verify(headers.getAuthorization())) { + throw new ValidationException("GC tests: Authorization signature validation Failed"); + } + notificationsState.put(path, new AtomicLong()); + logger.debug("GC tests: Token verified and sending response"); + return new ChallengeResponse(HashingUtil.hashString(crc, this.serviceConfig.getSubscriberPrivateKeyId())); + } + + @PostMapping("/gsa-challenge/{path}") + public void testPushGsa(@PathVariable String path, @RequestBody Object o) { + DpsHeaders headers = headersProvider.get(); + if (!gsaTokenVerifier.verify(headers.getAuthorization())) { + throw new ValidationException("Authorization signature validation Failed"); + } + notificationsState.get(path).getAndIncrement(); + logger.debug("Sending acknowledgement from gsa endpoint"); + } + + @GetMapping("state") + public Map<String, AtomicLong> getTestEndpointState() { + return notificationsState; + } +}