Skip to content
Snippets Groups Projects
Commit 55682e2e authored by Derek Hudson's avatar Derek Hudson
Browse files

Fixing the AWS integration tests.

parent 39a2dd24
No related branches found
No related tags found
1 merge request!494Fixing the AWS integration tests.
Pipeline #279908 failed
......@@ -13,17 +13,12 @@
// limitations under the License.
package org.opengroup.osdu.register.provider.aws.push_api;
import com.amazonaws.services.sns.AmazonSNS;
import com.amazonaws.services.sns.model.ConfirmSubscriptionRequest;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.google.common.hash.Hashing;
import io.swagger.v3.oas.annotations.Hidden;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.checkerframework.checker.units.qual.C;
import org.opengroup.osdu.core.aws.sns.AmazonSNSConfig;
import org.opengroup.osdu.core.common.cryptographic.ISignatureService;
import org.opengroup.osdu.core.common.cryptographic.SignatureServiceException;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
......@@ -39,9 +34,8 @@ import org.springframework.web.context.annotation.RequestScope;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotBlank;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.Scanner;
......@@ -96,41 +90,32 @@ public class AwsSubscriberTestListenerApi {
try {
signatureService.verifyHmacSignature(hmac, this.serviceConfig.getSubscriberSecret());
} catch (SignatureServiceException e) {
EntityBodyWrapper wrapper = new EntityBodyWrapper(new ChallengeResponse(), AUTHORIZATION_SIGNATURE_VALIDATION_FAILED);
EntityBodyWrapper wrapper = new EntityBodyWrapper(null, AUTHORIZATION_SIGNATURE_VALIDATION_FAILED);
return new ResponseEntity<>(wrapper, HttpStatus.BAD_REQUEST);
}
logger.info("Signature verified and sending response");
// Use the secret you send to the subscriber registration create request
ResponseEntity<ChallengeResponse> cr = getResponse(crc, this.serviceConfig.getSubscriberSecret());
EntityBodyWrapper wrapper = new EntityBodyWrapper(cr.getBody(), "");
return new ResponseEntity<>(wrapper, cr.getStatusCode());
String responseHash = getResponseHash(crc, this.serviceConfig.getSubscriberSecret());
EntityBodyWrapper wrapper = new EntityBodyWrapper(responseHash, null);
return new ResponseEntity<>(wrapper, HttpStatus.OK);
}
private ResponseEntity<ChallengeResponse> getResponse(String crc, String secretString) {
private String getResponseHash(String crc, String secretString) {
String response = secretString + crc;
response = Hashing.sha256()
.hashString(response, StandardCharsets.UTF_8)
.toString();
response = Base64.getEncoder().encodeToString(response.getBytes());
ChallengeResponse cr = new ChallengeResponse();
cr.setResponseHash(response);
return new ResponseEntity<>(cr, HttpStatus.OK);
return Base64.getEncoder().encodeToString(response.getBytes());
}
@Data
@NoArgsConstructor
@AllArgsConstructor
private static class ChallengeResponse {
private String responseHash = "";
}
@Data
@NoArgsConstructor
@AllArgsConstructor
private static class EntityBodyWrapper {
private ChallengeResponse challengeResponse;
private String message;
@JsonInclude(JsonInclude.Include.NON_NULL)
private String responseHash = null;
@JsonInclude(JsonInclude.Include.NON_NULL)
private String message = null;
}
......
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