Skip to content
Snippets Groups Projects
Commit ed82a43f authored by Kanstantsin Dubrouski [EPAM / GCP]'s avatar Kanstantsin Dubrouski [EPAM / GCP] Committed by Riabokon Stanislav(EPAM)[GCP]
Browse files

Alternate GC int-tests endpoint

parent b9fbc8fc
No related branches found
No related tags found
1 merge request!324Alternate GC int-tests endpoint (GONRG-6803)
......@@ -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 }}
......@@ -35,6 +35,7 @@ conf:
registerKeycloakSecretName: "register-keycloak-secret"
registerKmsSecretName: "register-kms-secret"
appName: "register"
intTestEndpoint: false
istio:
proxyCPU: "10m"
......
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;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment