Skip to content

Commit

Permalink
Merge pull request #1592 from mohanachandran-s/release-1.3.0-ES
Browse files Browse the repository at this point in the history
MOSIP-34827 - Added test cases for L2 flow api's
  • Loading branch information
lsivanand committed Sep 17, 2024
2 parents 343f775 + 88b29cf commit dbd2099
Show file tree
Hide file tree
Showing 14 changed files with 176 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,8 @@ protected Response postRequestWithCookieAuthHeaderAndXsrfToken(String url, Strin
headers.put(OAUTH_TRANSID_HEADERNAME, transactionId);
}

token = properties.getProperty(GlobalConstants.XSRFTOKEN);

if (request.has(GlobalConstants.HEADERTRANSACTIONID)) {
headerTransactionID = request.get(GlobalConstants.HEADERTRANSACTIONID).toString();
cookiesMap.put(GlobalConstants.TRANSACTION_ID_KEY, headerTransactionID);
Expand All @@ -567,13 +569,20 @@ protected Response postRequestWithCookieAuthHeaderAndXsrfToken(String url, Strin
cookiesMap.put(GlobalConstants.XSRF_TOKEN, token);
request.remove(GlobalConstants.VERIFIEDTRANSACTIONID);
}

if (request.has(GlobalConstants.ENCODEDHASH)) {
encodedResp = request.get(GlobalConstants.ENCODEDHASH).toString();
logger.info("encodedhash = " + encodedResp);
headers.put(OAUTH_HASH_HEADERNAME, encodedResp);
request.remove(GlobalConstants.ENCODEDHASH);
}
if (request.has(GlobalConstants.IDV_TRANSACTION_ID)) {
headerTransactionID = request.get(GlobalConstants.IDV_TRANSACTION_ID).toString();
headers.put(GlobalConstants.IDV_TRANSACTION_ID_KEY, headerTransactionID);
cookiesMap.put(GlobalConstants.IDV_TRANSACTION_ID_KEY, headerTransactionID);
cookiesMap.put(GlobalConstants.XSRF_TOKEN, token);
request.remove(GlobalConstants.IDV_TRANSACTION_ID);
}

inputJson = request.toString();
if (BaseTestCase.currentModule.equals(GlobalConstants.MASTERDATA)) {
inputJson = smtpOtpHandler(inputJson, testCaseName);
Expand All @@ -589,13 +598,14 @@ protected Response postRequestWithCookieAuthHeaderAndXsrfToken(String url, Strin
requestInput.remove("client_id");
inputJson = requestInput.toString();
}
token = properties.getProperty(GlobalConstants.XSRFTOKEN);


logger.info(GlobalConstants.POST_REQ_URL + url);
GlobalMethods.reportRequest(headers.toString(), inputJson, url);
try {
if (cookiesMap.containsKey(GlobalConstants.TRANSACTION_ID_KEY)
|| cookiesMap.containsKey(GlobalConstants.VERIFIED_TRANSACTION_ID_KEY)) {
|| cookiesMap.containsKey(GlobalConstants.VERIFIED_TRANSACTION_ID_KEY)
|| cookiesMap.containsKey(GlobalConstants.IDV_TRANSACTION_ID_KEY)) {
if (testCaseName.contains("_Missing_CSRF_"))
headers.remove(XSRF_HEADERNAME);
response = RestClient.postRequestWithMultipleHeadersAndCookies(url, inputJson,
Expand All @@ -621,40 +631,35 @@ protected Response postRequestWithCookieAuthHeaderAndXsrfToken(String url, Strin
public void getvalueFromResponseHeader(Response response, String testCaseName) {

if (testCaseName.contains("_STransId") && response.getHeaders().hasHeaderWithName("set-cookie")) {
String headerTransactionId = "";
String headerVerifyTransactionId = "";
String headerPathFragment = "";

List<String> ListOfSetCookieValues = response.getHeaders().getValues("set-cookie");

for (String eachSetCookieValues : ListOfSetCookieValues) {
String[] setCookieValues = eachSetCookieValues.split(";");
for (String eachSetCookieValue : setCookieValues) {
if (eachSetCookieValue.trim().startsWith("VERIFIED_TRANSACTION_ID=")) {
if (!eachSetCookieValue.split("=")[1].isBlank()) {
headerVerifyTransactionId = eachSetCookieValue.split("=")[1];
writeAutoGeneratedId(testCaseName, "VTransactionID", headerVerifyTransactionId);
break;
}
getCookieAndWriteAutoGenId(eachSetCookieValue, "VTransactionID", testCaseName);
}
if (eachSetCookieValue.trim().startsWith("TRANSACTION_ID=")) {
if (!eachSetCookieValue.split("=")[1].isBlank()) {
headerTransactionId = eachSetCookieValue.split("=")[1];
writeAutoGeneratedId(testCaseName, "TransactionID", headerTransactionId);
break;
}
getCookieAndWriteAutoGenId(eachSetCookieValue, "TransactionID", testCaseName);
}
if (eachSetCookieValue.trim().endsWith("~path-fragment")) {
if (!eachSetCookieValue.split("=")[1].isBlank()) {
headerPathFragment = eachSetCookieValue.split("=")[1];
writeAutoGeneratedId(testCaseName, "pathFragmentCookie", headerPathFragment);
break;
}
getCookieAndWriteAutoGenId(eachSetCookieValue, "pathFragmentCookie", testCaseName);
}
if (eachSetCookieValue.trim().startsWith("IDV_TRANSACTION_ID")) {
getCookieAndWriteAutoGenId(eachSetCookieValue, "idvTransactionID", testCaseName);
}
}
}
}
}

protected void getCookieAndWriteAutoGenId(String cookieValue, String key, String testCaseName) {
if (!cookieValue.split("=")[1].isBlank()) {
String value = cookieValue.split("=")[1];
writeAutoGeneratedId(testCaseName, key, value);
}
}

protected Response postWithBodyAndCookieAuthHeaderAndXsrfTokenForAutoGeneratedId(String url, String jsonInput,
String cookieName, String testCaseName, String idKeyName) {
Expand Down Expand Up @@ -2089,6 +2094,13 @@ protected Response getWithPathParamAndCookie(String url, String jsonInput, boole
cookiesMap.put(GlobalConstants.XSRF_TOKEN, token);
map.remove(GlobalConstants.VERIFIEDTRANSACTIONID);
}

if (map.containsKey(GlobalConstants.IDV_TRANSACTION_ID)) {
headerTransactionID = map.get(GlobalConstants.IDV_TRANSACTION_ID).toString();
cookiesMap.put(GlobalConstants.IDV_TRANSACTION_ID_KEY, headerTransactionID);
cookiesMap.put(GlobalConstants.XSRF_TOKEN, token);
map.remove(GlobalConstants.IDV_TRANSACTION_ID);
}

if (bothAccessAndIdToken) {
token = kernelAuthLib.getTokenByRole(role, ACCESSTOKENCOOKIENAME);
Expand All @@ -2103,6 +2115,9 @@ protected Response getWithPathParamAndCookie(String url, String jsonInput, boole
if (bothAccessAndIdToken) {
response = RestClient.getRequestWithCookieAndPathParm(url, map, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, cookieName, token, IDTOKENCOOKIENAME, idToken);
} else if (cookiesMap.containsKey(GlobalConstants.IDV_TRANSACTION_ID_KEY)) {
response = RestClient.getRequestWithMultipleCookieAndPathParam(url, map, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, cookiesMap);
} else {
response = RestClient.getRequestWithCookieAndPathParm(url, map, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, cookieName, token);
Expand Down Expand Up @@ -2611,9 +2626,23 @@ else if (responseJson.has("partners")) {
String urlEncodedResp = Base64.getUrlEncoder().withoutPadding().encodeToString(hash);
logger.info("encoded response = " + urlEncodedResp);
props.put(identifierKeyName, urlEncodedResp);
} else
} else if (responseJson.has(GlobalConstants.IDENTITY)) {
props.put(identifierKeyName,
responseJson.getJSONObject(GlobalConstants.IDENTITY).get(filedName));
} else {
for (String key : responseJson.keySet()) {
if (responseJson.get(key) instanceof JSONArray) {
JSONArray jsonArray = responseJson.getJSONArray(key);
if (jsonArray.length() > 0) {
JSONObject firstObject = jsonArray.getJSONObject(0);
if (firstObject.has(idKeyName)) {
props.put(identifierKeyName, firstObject.getString(idKeyName));
break;
}
}
}
}
}
} else if (responseBody != null) {
String identifierKeyName = getAutogenIdKeyName(testCaseName, filedName);
if (responseBody.has(filedName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,11 @@ public static Response postRequestWithMultipleHeadersAndCookies(String url, Obje
String acceptHeader, Map<String, String> cookieValue, Map<String, String> headers) {
Response postResponse;
String key = GlobalConstants.TRANSACTION_ID_KEY;
if (cookieValue.containsKey(GlobalConstants.VERIFIED_TRANSACTION_ID_KEY))
if (cookieValue.containsKey(GlobalConstants.VERIFIED_TRANSACTION_ID_KEY)) {
key = GlobalConstants.VERIFIED_TRANSACTION_ID_KEY;
} else if (cookieValue.containsKey(GlobalConstants.IDV_TRANSACTION_ID_KEY)) {
key = GlobalConstants.IDV_TRANSACTION_ID_KEY;
}

if (ConfigManager.IsDebugEnabled()) {
RESTCLIENT_LOGGER.info(GlobalConstants.REST_ASSURED_STRING_1 + url);
Expand Down Expand Up @@ -889,8 +892,9 @@ public static Response getRequestWithMultipleCookie(String url, String contentHe
Map<String, String> cookieMap) {
Response getResponse;
String key = GlobalConstants.TRANSACTION_ID_KEY;
if (cookieMap.containsKey(GlobalConstants.VERIFIED_TRANSACTION_ID_KEY))
if (cookieMap.containsKey(GlobalConstants.VERIFIED_TRANSACTION_ID_KEY))
key = GlobalConstants.VERIFIED_TRANSACTION_ID_KEY;

if (ConfigManager.IsDebugEnabled()) {
RESTCLIENT_LOGGER.info("REST-ASSURED: Sending a GET request to " + url);

Expand All @@ -909,6 +913,29 @@ public static Response getRequestWithMultipleCookie(String url, String contentHe

return getResponse;
}

public static Response getRequestWithMultipleCookieAndPathParam(String url, Map<String, String> body, String contentHeader, String acceptHeader,
Map<String, String> cookieMap) {
Response getResponse;
String key = GlobalConstants.IDV_TRANSACTION_ID_KEY;
if (ConfigManager.IsDebugEnabled()) {
RESTCLIENT_LOGGER.info("REST-ASSURED: Sending a GET request to " + url);

getResponse = given().config(config).relaxedHTTPSValidation().pathParams(body)
.cookie(GlobalConstants.XSRF_TOKEN, cookieMap.get(GlobalConstants.XSRF_TOKEN))
.cookie(key, cookieMap.get(key)).log().all().when().get(url).then().log().all().extract()
.response();

RESTCLIENT_LOGGER.info(GlobalConstants.REST_ASSURED_STRING_2 + getResponse.asString());
RESTCLIENT_LOGGER.info(GlobalConstants.REST_ASSURED_STRING_3 + getResponse.time());
} else {
getResponse = given().config(config).relaxedHTTPSValidation().pathParams(body)
.cookie(GlobalConstants.XSRF_TOKEN, cookieMap.get(GlobalConstants.XSRF_TOKEN))
.cookie(key, cookieMap.get(key)).when().get(url).then().extract().response();
}

return getResponse;
}

public static Response getRequestWithCookie(String url, String contentHeader, String acceptHeader,
String cookieName, String cookieValue, String idTokenName, String idTokenValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,6 @@ public class GlobalConstants {
public static final String PATH_FRAGMENT_COOKIE = "pathFragmentCookie";
public static final String IDT_TOKEN = "idtToken";
public static final String PATH_FRAGMENT_COOKIE_TRANSACTIONID = "pathFragmentCookieTransactionId";
public static final String IDV_TRANSACTION_ID = "idvTransactionID";
public static final String IDV_TRANSACTION_ID_KEY = "IDV_TRANSACTION_ID";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"idvTransactionID": "{{idvTransactionID}}",
"verifierId": "{{verifierId}}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
GetIdVerifier:
ESignet_GetIdVerifier_STransId_uin_all_Valid_Smoke:
endPoint: /v1/signup/identity-verification/identity-verifier/{verifierId}
role: resident
restMethod: post
checkErrorsOnlyInResponse: true
inputTemplate: esignet/GetIdVerifier/GetIdVerifier
outputTemplate: esignet/GetIdVerifier/GetIdVerifierResult
input: '{
"idvTransactionID": "$ID:InitiateIdVerification_STransId_AuthToken_Xsrf_uin_all_Valid_Smoke_Sid_idvTransactionID$",
"verifierId": "$ID:InitiateIdVerification_STransId_AuthToken_Xsrf_uin_all_Valid_Smoke_Sid_id$"
}'
output: '{
}'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"requestTime": "{{requestTime}}",
"idvTransactionID": "{{idvTransactionID}}",
"request": {
"verifierId": "{{verifierId}}",
"consent": "{{consent}}"
}
}
17 changes: 17 additions & 0 deletions automationtests/src/main/resources/esignet/GetSlot/GetSlot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
GetSlot:
ESignet_GetSlot_STransId_uin_all_Valid_Smoke:
endPoint: /v1/signup/identity-verification/slot
role: resident
restMethod: post
checkErrorsOnlyInResponse: true
inputTemplate: esignet/GetSlot/GetSlot
outputTemplate: esignet/GetSlot/GetSlotResult
input: '{
"requestTime": "$TIMESTAMP$",
"idvTransactionID": "$ID:InitiateIdVerification_STransId_AuthToken_Xsrf_uin_all_Valid_Smoke_Sid_idvTransactionID$",
"verifierId": "$ID:InitiateIdVerification_STransId_AuthToken_Xsrf_uin_all_Valid_Smoke_Sid_id$",
"consent": "AGREE"
}'
output: '{
}'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
IDTAuthentication:
ESignet_IDTAuthentication_AuthToken_Xsrf_uin_all_Valid_Smoke_sid:
ESignet_IDTAuthentication_AuthToken_Xsrf_uin_all_Valid_Smoke:
endPoint: /v1/esignet/authorization/v3/authenticate
role: resident
restMethod: post
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"requestTime": "{{requestTime}}",
"request": {
"authorizationCode": "{{authorizationCode}}",
"state": "{{state}}"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
InitiateIdVerification:
ESignet_InitiateIdVerification_STransId_AuthToken_Xsrf_uin_all_Valid_Smoke_Sid:
endPoint: /v1/signup/identity-verification/initiate
role: resident
restMethod: post
checkErrorsOnlyInResponse: true
inputTemplate: esignet/InitiateIdVerification/InitiateIdVerification
outputTemplate: esignet/InitiateIdVerification/InitiateIdVerificationResult
input: '{
"requestTime": "$TIMESTAMP$",
"authorizationCode": "$ID:SignupAuthorizeCode_AuthToken_Xsrf_uin_all_Valid_Smoke_sid_code$",
"state": "urlInfo1724138417665"
}'
output: '{
}'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
23 changes: 23 additions & 0 deletions automationtests/testNgXmlFiles/esignetSuite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -996,9 +996,32 @@
<test name="SignupAuthorizeCode">
<parameter name="ymlFile"
value="esignet/SignupAuthorizeCode/SignupAuthorizeCode.yml" />
<parameter name="idKeyName" value="code" />
<classes>
<class name="io.mosip.testrig.apirig.testscripts.SimplePostForAutoGenId" />
</classes>
</test>
<test name="InitiateIdVerification">
<parameter name="ymlFile"
value="esignet/InitiateIdVerification/InitiateIdVerification.yml" />
<parameter name="idKeyName" value="id" />
<classes>
<class name="io.mosip.testrig.apirig.testscripts.SimplePostForAutoGenId" />
</classes>
</test>
<test name="GetIdVerifier">
<parameter name="ymlFile"
value="esignet/GetIdVerifier/GetIdVerifier.yml" />
<classes>
<class name="io.mosip.testrig.apirig.testscripts.GetWithParam" />
</classes>
</test>
<test name="GetSlot">
<parameter name="ymlFile"
value="esignet/GetSlot/GetSlot.yml" />
<classes>
<class name="io.mosip.testrig.apirig.testscripts.SimplePost" />
</classes>
</test>
<!-- End of Sign up L2 phase test cases -->
</suite>

0 comments on commit dbd2099

Please sign in to comment.