-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from ostdotcom/parameter_escape_fix
Fix for escaping spacial character from parameters and added test case for signature matching.
- Loading branch information
Showing
8 changed files
with
180 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.0.3 | ||
2.0.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
src/test/java/com/ost/kyc/services/v2/SignatureTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package com.ost.kyc.services.v2; | ||
|
||
import com.ost.kyc.lib.OSTKYCRequestClient; | ||
import com.ost.kyc.services.ServiceTestBase; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.Iterator; | ||
import java.util.Map; | ||
|
||
public class SignatureTest extends ServiceTestBase { | ||
|
||
public SignatureTest() { | ||
super(); | ||
} | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
} | ||
|
||
public HashMap<String, Object> getParams() { | ||
HashMap<String, Object> params = new HashMap<String, Object>(); | ||
HashMap<String, Object> emptyHash = new HashMap<String, Object>(); | ||
ArrayList<String> emptyArray = new ArrayList<String>(); | ||
ArrayList<String> list = new ArrayList<String>(); | ||
list.add(""); | ||
list.add(null); | ||
params.put("a", null); | ||
params.put("b", emptyArray); | ||
params.put("c", ""); | ||
params.put("d", list); | ||
params.put("e", emptyHash); | ||
ArrayList<String> array = new ArrayList<String>(); | ||
array.add("Hello"); | ||
array.add("There"); | ||
array.add("12345"); | ||
params.put("k1", 125.45); | ||
params.put("k2", "Tejas"); | ||
|
||
HashMap<String, Object> hashWithKeyValue1 = new HashMap<String, Object>(); | ||
hashWithKeyValue1.put("a", "L21A"); | ||
hashWithKeyValue1.put("b", "L21B"); | ||
HashMap<String, Object> hashWithKeyValue2 = new HashMap<String, Object>(); | ||
hashWithKeyValue2.put("a", "L22A"); | ||
hashWithKeyValue2.put("b", "L22B"); | ||
HashMap<String, Object> hashWithKeyValue3 = new HashMap<String, Object>(); | ||
hashWithKeyValue3.put("a", "L23A"); | ||
hashWithKeyValue3.put("b", "L23B"); | ||
|
||
HashMap<String, Object> nestedparams = new HashMap<String, Object>(); | ||
nestedparams.put("a" , hashWithKeyValue1); | ||
nestedparams.put("b" , hashWithKeyValue2); | ||
nestedparams.put("c" , hashWithKeyValue3); | ||
|
||
params.put("aaaaa", nestedparams); | ||
params.put("arrayValues", array); | ||
params.put("garbage_str", "~!@#$%^&*()_+-= {}[]:\";'?/<>,. this is garbage"); | ||
|
||
|
||
return params; | ||
} | ||
|
||
@Test | ||
public void testSignature() throws Exception { | ||
|
||
HashMap<String, Object> params = getParams(); | ||
String apiKey = "d437535591587e8df4dd30b771651ebb"; | ||
String apiSecret = "a0431203671f42c079b2154066fd04ba"; | ||
String apiEndpoint = "https://kyc.ost.com"; | ||
|
||
params.put("apiSecret",apiSecret); | ||
params.put("apiKey",apiKey); | ||
params.put("apiEndpoint",apiEndpoint); | ||
|
||
// Test-Case: Test Signature. | ||
String signature; | ||
OSTKYCRequestClient obj = new OSTKYCRequestClient(params); | ||
signature = getSignature("/api/v2/users", params, obj); | ||
boolean success; | ||
if (signature.equalsIgnoreCase("ca84293b5b901a8c9972b873a224ce05db28d36471bedf613ae451a5a80b8f99")) { | ||
success = true; | ||
} else { | ||
success = false; | ||
} | ||
Assert.assertEquals( success, true); | ||
} | ||
|
||
public String getSignature(String resource, Map<String, Object> paramValObj, OSTKYCRequestClient obj) { | ||
ArrayList<OSTKYCRequestClient.HttpParam> paramsArray = (ArrayList<OSTKYCRequestClient.HttpParam>) obj.getRequestParam(resource,paramValObj); | ||
String paramKey; | ||
String paramVal; | ||
Iterator it = paramsArray.iterator(); | ||
while (it.hasNext()) { | ||
OSTKYCRequestClient.HttpParam pair = (OSTKYCRequestClient.HttpParam) it.next(); | ||
|
||
paramKey = pair.getParamName(); | ||
paramVal = pair.getParamValue(); | ||
|
||
if(paramKey.equalsIgnoreCase("signature")) | ||
{ | ||
return paramVal; | ||
} | ||
} | ||
return ""; | ||
} | ||
} |
Oops, something went wrong.