|
1 | 1 | /** |
2 | | - * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | + * Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"). |
5 | 5 | * You may not use this file except in compliance with the License. |
|
16 | 16 |
|
17 | 17 | import com.amazon.pay.request.RequestHelper; |
18 | 18 | import com.amazon.pay.TestConstants; |
| 19 | +import com.amazon.pay.request.ConfirmOrderReferenceRequest; |
19 | 20 | import com.amazon.pay.request.GetOrderReferenceDetailsRequest; |
20 | 21 | import com.amazon.pay.request.SetOrderReferenceDetailsRequest; |
21 | 22 | import com.amazon.pay.response.model.Environment; |
@@ -117,4 +118,76 @@ public void testRequestParameterConstructorSignature_2() throws Exception { |
117 | 118 | Assert.assertEquals(expectedURL, this.helper.getPostURL(request)); |
118 | 119 | } |
119 | 120 |
|
| 121 | + @Test |
| 122 | + public void testRequestUrlAndSignatureForConfirmOrderReference() throws Exception { |
| 123 | + // Non-MFA Confirm request |
| 124 | + this.helper = new RequestHelper(config); |
| 125 | + PowerMockito.stub(PowerMockito.method(Util.class, "getTimestamp")).toReturn(TestConstants.timeStamp); |
| 126 | + final ConfirmOrderReferenceRequest request = |
| 127 | + new ConfirmOrderReferenceRequest(TestConstants.amazonOrderReferenceId) |
| 128 | + .setSellerId(TestConstants.overrideSellerId) |
| 129 | + .setMWSAuthToken(TestConstants.mwsAuthToken); |
| 130 | + final String action = "ConfirmOrderReference"; |
| 131 | + final String signature = "mbJBrZKC4Jz8J%2BrhRqyfYsY6TkSapWOvCTlC%2BUDUTok%3D"; |
| 132 | + final String expectedURL = |
| 133 | + "AWSAccessKeyId=" + TestConstants.accessKey |
| 134 | + + "&Action=" + action |
| 135 | + + "&AmazonOrderReferenceId=" + TestConstants.amazonOrderReferenceId |
| 136 | + + "&MWSAuthToken=" + TestConstants.mwsAuthToken |
| 137 | + + "&SellerId=" + TestConstants.overrideSellerId |
| 138 | + + "&Signature=" + signature |
| 139 | + + "&SignatureMethod=HmacSHA256" |
| 140 | + + "&SignatureVersion=2" |
| 141 | + + "&Timestamp=" + TestConstants.urlEncoded_TimeStamp |
| 142 | + + "&Version=2013-01-01"; |
| 143 | + Assert.assertEquals(expectedURL, this.helper.getPostURL(request)); |
| 144 | + |
| 145 | + // Adding a curency code without an amount should result in same request |
| 146 | + request.setAuthorizationCurrencyCode(CurrencyCode.EUR); |
| 147 | + Assert.assertEquals(expectedURL, this.helper.getPostURL(request)); |
| 148 | + |
| 149 | + // Full MFA parameter set |
| 150 | + final String mfaSignature = "KeZbecFqPMxhR4g35iFWsdLmq1rAgwdn4B2WTIFMTHg%3D"; |
| 151 | + request.setSuccessUrl(TestConstants.SUCCESS_URL); |
| 152 | + request.setFailureUrl(TestConstants.FAILURE_URL); |
| 153 | + request.setAuthorizationAmount(TestConstants.AUTHORIZE_AMOUNT); |
| 154 | + final String expectedURLforMFA = |
| 155 | + "AWSAccessKeyId=" + TestConstants.accessKey |
| 156 | + + "&Action=" + action |
| 157 | + + "&AmazonOrderReferenceId=" + TestConstants.amazonOrderReferenceId |
| 158 | + + "&AuthorizationAmount.Amount=" + TestConstants.AUTHORIZE_AMOUNT |
| 159 | + + "&AuthorizationAmount.CurrencyCode=" + CurrencyCode.EUR |
| 160 | + + "&FailureUrl=" + Util.urlEncode(TestConstants.FAILURE_URL) |
| 161 | + + "&MWSAuthToken=" + TestConstants.mwsAuthToken |
| 162 | + + "&SellerId=" + TestConstants.overrideSellerId |
| 163 | + + "&Signature=" + mfaSignature |
| 164 | + + "&SignatureMethod=HmacSHA256" |
| 165 | + + "&SignatureVersion=2" |
| 166 | + + "&SuccessUrl=" + Util.urlEncode(TestConstants.SUCCESS_URL) |
| 167 | + + "&Timestamp=" + TestConstants.urlEncoded_TimeStamp |
| 168 | + + "&Version=2013-01-01"; |
| 169 | + Assert.assertEquals(expectedURLforMFA, this.helper.getPostURL(request)); |
| 170 | + |
| 171 | + // Partial MFA parameter set - not including FailureURL or CurrencyCode |
| 172 | + // Should default to the Config object currency code in this scenario (USD instead of EUR) |
| 173 | + final String partialMfaSignature = "vGiWtNsdtNKx3QGB%2BcNNq8tLisqwOeg2a5aIy3p6exw%3D"; |
| 174 | + request.setAuthorizationCurrencyCode(null); |
| 175 | + request.setFailureUrl(null); |
| 176 | + final String expectedURLforPartialMFA = |
| 177 | + "AWSAccessKeyId=" + TestConstants.accessKey |
| 178 | + + "&Action=" + action |
| 179 | + + "&AmazonOrderReferenceId=" + TestConstants.amazonOrderReferenceId |
| 180 | + + "&AuthorizationAmount.Amount=" + TestConstants.AUTHORIZE_AMOUNT |
| 181 | + + "&AuthorizationAmount.CurrencyCode=" + CurrencyCode.USD |
| 182 | + + "&MWSAuthToken=" + TestConstants.mwsAuthToken |
| 183 | + + "&SellerId=" + TestConstants.overrideSellerId |
| 184 | + + "&Signature=" + partialMfaSignature |
| 185 | + + "&SignatureMethod=HmacSHA256" |
| 186 | + + "&SignatureVersion=2" |
| 187 | + + "&SuccessUrl=" + Util.urlEncode(TestConstants.SUCCESS_URL) |
| 188 | + + "&Timestamp=" + TestConstants.urlEncoded_TimeStamp |
| 189 | + + "&Version=2013-01-01"; |
| 190 | + Assert.assertEquals(expectedURLforPartialMFA, this.helper.getPostURL(request)); |
| 191 | + } |
| 192 | + |
120 | 193 | } |
0 commit comments