Skip to content
Snippets Groups Projects
Commit e45efa0e authored by Derek Hudson's avatar Derek Hudson Committed by Yunhua Koglin
Browse files

Added in a URL encoding for the Base64 output of the HMAC authentication URL

parent 4d77e39e
No related branches found
No related tags found
1 merge request!452Added in a URL encoding for the Base64 output of the HMAC authentication URL
...@@ -608,7 +608,6 @@ The following software have components provided under the terms of this license: ...@@ -608,7 +608,6 @@ The following software have components provided under the terms of this license:
- Animal Sniffer Annotations (from https://repo1.maven.org/maven2/org/codehaus/mojo/animal-sniffer-annotations) - Animal Sniffer Annotations (from https://repo1.maven.org/maven2/org/codehaus/mojo/animal-sniffer-annotations)
- Apache HttpClient Cache (from http://hc.apache.org/httpcomponents-client, http://hc.apache.org/httpcomponents-client-ga) - Apache HttpClient Cache (from http://hc.apache.org/httpcomponents-client, http://hc.apache.org/httpcomponents-client-ga)
- Apache Log4j API (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-api) - Apache Log4j API (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-api)
- Apache Log4j Core (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-core)
- Apache Log4j SLF4J Binding (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-slf4j-impl) - Apache Log4j SLF4J Binding (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-slf4j-impl)
- Apache Log4j to SLF4J Adapter (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-to-slf4j) - Apache Log4j to SLF4J Adapter (from https://repo1.maven.org/maven2/org/apache/logging/log4j/log4j-to-slf4j)
- Azure Java Client Authentication Library for AutoRest (from https://github.com/Azure/autorest-clientruntime-for-java) - Azure Java Client Authentication Library for AutoRest (from https://github.com/Azure/autorest-clientruntime-for-java)
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
...@@ -23,6 +23,8 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -23,6 +23,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.context.annotation.RequestScope; import org.springframework.web.context.annotation.RequestScope;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -42,10 +44,8 @@ public class HmacAuth implements SecretAuth { ...@@ -42,10 +44,8 @@ public class HmacAuth implements SecretAuth {
} }
public String getPushUrl(String endpoint) throws Exception { public String getPushUrl(String endpoint) throws Exception {
String pushUrl = endpoint;
String signedjwt = this.signatureService.getSignedSignature(endpoint, hmacSecret.getValue()); String signedjwt = this.signatureService.getSignedSignature(endpoint, hmacSecret.getValue());
pushUrl += "?hmac=" + signedjwt; return String.format("%s?hmac=%s", endpoint, URLEncoder.encode(signedjwt, StandardCharsets.UTF_8));
return pushUrl;
} }
public Map<String, String> getRequestHeaders() { public Map<String, String> getRequestHeaders() {
......
...@@ -27,6 +27,8 @@ import org.opengroup.osdu.core.common.model.notification.HmacSecret; ...@@ -27,6 +27,8 @@ import org.opengroup.osdu.core.common.model.notification.HmacSecret;
import org.opengroup.osdu.core.common.model.notification.Subscription; import org.opengroup.osdu.core.common.model.notification.Subscription;
import org.powermock.modules.junit4.PowerMockRunner; import org.powermock.modules.junit4.PowerMockRunner;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Map; import java.util.Map;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
...@@ -63,6 +65,17 @@ public class HmacAuthTest { ...@@ -63,6 +65,17 @@ public class HmacAuthTest {
hmac_subscription.setSecret(secret); hmac_subscription.setSecret(secret);
} }
@Test
public void should_return_valid_URLEncodeQueryString() throws Exception {
String signedSignatureWithEquals = "someValidBase64=";
HmacSecret secret = (HmacSecret) hmac_subscription.getSecret();
when(this.signatureService.getSignedSignature(hmac_subscription.getPushEndpoint(), secret.getValue())).thenReturn(signedSignatureWithEquals);
sut.setSecret(hmac_subscription.getSecret());
String pushUrl = sut.getPushUrl(hmac_subscription.getPushEndpoint());
String expected = hmac_subscription.getPushEndpoint() + "?hmac=" + URLEncoder.encode(signedSignatureWithEquals, StandardCharsets.UTF_8);
Assert.assertTrue(expected.equalsIgnoreCase(pushUrl));
}
@Test @Test
public void should_return_valid_EndpointAndHeaders() throws Exception { public void should_return_valid_EndpointAndHeaders() throws Exception {
HmacSecret secret = (HmacSecret) hmac_subscription.getSecret(); HmacSecret secret = (HmacSecret) hmac_subscription.getSecret();
......
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