Skip to content

Commit

Permalink
Merge pull request #1588 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 authored Sep 2, 2024
2 parents 1d92a0f + 940ed50 commit 343f775
Show file tree
Hide file tree
Showing 29 changed files with 518 additions and 6 deletions.
5 changes: 5 additions & 0 deletions automationtests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,11 @@
<artifactId>itextpdf</artifactId>
<version>5.5.13</version>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>4.4.0</version>
</dependency>

<dependency>
<groupId>de.mkammerer</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
import org.testng.SkipException;
import org.yaml.snakeyaml.Yaml;

import com.auth0.jwt.JWT;
import com.auth0.jwt.interfaces.DecodedJWT;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -103,6 +105,7 @@
import com.opencsv.CSVReader;
import com.opencsv.CSVWriter;

import io.jsonwebtoken.JwtException;
import io.mosip.kernel.core.util.HMACUtils2;
import io.mosip.testrig.apirig.authentication.fw.dto.OutputValidationDto;
import io.mosip.testrig.apirig.authentication.fw.precon.JsonPrecondtion;
Expand Down Expand Up @@ -620,6 +623,7 @@ 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");

Expand All @@ -640,6 +644,13 @@ public void getvalueFromResponseHeader(Response response, String testCaseName) {
break;
}
}
if (eachSetCookieValue.trim().endsWith("~path-fragment")) {
if (!eachSetCookieValue.split("=")[1].isBlank()) {
headerPathFragment = eachSetCookieValue.split("=")[1];
writeAutoGeneratedId(testCaseName, "pathFragmentCookie", headerPathFragment);
break;
}
}
}
}
}
Expand Down Expand Up @@ -688,6 +699,8 @@ protected Response postRequestWithCookieAuthHeaderAndXsrfTokenForAutoGenId(Strin
JSONObject request = new JSONObject(inputJson);
String encodedResp = null;
String transactionId = null;
String pathFragmentCookie = null;
String pathFragmentCookieTransactionId = null;
if (request.has(GlobalConstants.ENCODEDHASH)) {
encodedResp = request.get(GlobalConstants.ENCODEDHASH).toString();
request.remove(GlobalConstants.ENCODEDHASH);
Expand All @@ -701,6 +714,13 @@ protected Response postRequestWithCookieAuthHeaderAndXsrfTokenForAutoGenId(Strin
headers.put(XSRF_HEADERNAME, properties.getProperty(GlobalConstants.XSRFTOKEN));
headers.put(OAUTH_HASH_HEADERNAME, encodedResp);
headers.put(OAUTH_TRANSID_HEADERNAME, transactionId);

if (request.has(GlobalConstants.PATH_FRAGMENT_COOKIE_TRANSACTIONID) && request.has(GlobalConstants.PATH_FRAGMENT_COOKIE)) {
pathFragmentCookieTransactionId = request.get(GlobalConstants.PATH_FRAGMENT_COOKIE_TRANSACTIONID).toString();
pathFragmentCookie = request.get(GlobalConstants.PATH_FRAGMENT_COOKIE).toString();
request.remove(GlobalConstants.PATH_FRAGMENT_COOKIE_TRANSACTIONID);
request.remove(GlobalConstants.PATH_FRAGMENT_COOKIE);
}

inputJson = request.toString();
if (BaseTestCase.currentModule.equals(GlobalConstants.MIMOTO) || BaseTestCase.currentModule.equals("auth")
Expand All @@ -713,12 +733,20 @@ protected Response postRequestWithCookieAuthHeaderAndXsrfTokenForAutoGenId(Strin
logger.info(GlobalConstants.POST_REQ_URL + url);
GlobalMethods.reportRequest(headers.toString(), inputJson, url);
try {
response = RestClient.postRequestWithMultipleHeadersAndCookies(url, inputJson, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, cookieName, token, headers);
if (pathFragmentCookie!=null) {
response = RestClient.postRequestWithMultipleHeadersAndMultipleCookies(url, inputJson, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, pathFragmentCookieTransactionId, pathFragmentCookie, headers);
} else {
response = RestClient.postRequestWithMultipleHeadersAndCookies(url, inputJson, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, cookieName, token, headers);
}
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
if (testCaseName.toLowerCase().contains("_sid")) {
writeAutoGeneratedId(response, idKeyName, testCaseName);
}
if (testCaseName.contains("_STransId")) {
getvalueFromResponseHeader(response, testCaseName);
}
return response;
} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
Expand Down Expand Up @@ -2352,6 +2380,40 @@ protected Response getWithQueryParamAndCookie(String url, String jsonInput, Stri
return response;
}
}

protected Response getRequestWithCookieAuthHeaderAndXsrfToken(String url, String jsonInput, String cookieName,
String role, String testCaseName) {
Response response = null;
HashMap<String, String> headers = new HashMap<>();
String inputJson = inputJsonKeyWordHandeler(jsonInput, testCaseName);
JSONObject request = new JSONObject(inputJson);
String encodedResp = null;
String transactionId = null;
if (request.has(GlobalConstants.ENCODEDHASH)) {
encodedResp = request.get(GlobalConstants.ENCODEDHASH).toString();
request.remove(GlobalConstants.ENCODEDHASH);
}
if (request.has(GlobalConstants.TRANSACTIONID)) {
transactionId = request.get(GlobalConstants.TRANSACTIONID).toString();
request.remove(GlobalConstants.ENCODEDHASH);
}
headers.put(XSRF_HEADERNAME, properties.getProperty(GlobalConstants.XSRFTOKEN));
headers.put(OAUTH_HASH_HEADERNAME, encodedResp);
headers.put(OAUTH_TRANSID_HEADERNAME, transactionId);

token = null;
logger.info(GlobalConstants.GET_REQ_STRING + url);
GlobalMethods.reportRequest(headers.toString(), null, url);
try {
response = RestClient.getRequestWithMultipleHeadersAndCookies(url, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, cookieName, token, headers);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
return response;
} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
return response;
}
}

protected Response patchWithQueryParamAndCookie(String url, String jsonInput, String cookieName, String role,
String testCaseName) {
Expand Down Expand Up @@ -3313,6 +3375,10 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) {
jsonString = replaceKeywordWithValue(jsonString, "$IDPREDIRECTURI$",
ApplnURI.replace(GlobalConstants.API_INTERNAL, "healthservices") + "/userprofile");
}
if (jsonString.contains("$SIGNUPREDIRECTURI$")) {
jsonString = replaceKeywordWithValue(jsonString, "$SIGNUPREDIRECTURI$",
ApplnURI.replace(GlobalConstants.API_INTERNAL, "signup") + "/identity-verification");
}
if (jsonString.contains("$BASE64URI$")) {
String redirectUri = ApplnURI.replace(GlobalConstants.API_INTERNAL, GlobalConstants.RESIDENT)
+ propsKernel.getProperty("currentUserURI");
Expand Down Expand Up @@ -3714,6 +3780,24 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) {
jsonString = replaceKeywordWithValue(jsonString, "$PROOF_JWT_2$",
signJWKForMock(clientId, accessToken, oidcJWKKey4, testCaseName));
}

if (jsonString.contains(GlobalConstants.IDT_TOKEN) && jsonString.contains("$IDTINDIVIUALID$") && jsonString.contains("$IDTCHALLENGE$")) {
JSONObject request = new JSONObject(jsonString);
String idtToken = request.get(GlobalConstants.IDT_TOKEN).toString();
request.remove(GlobalConstants.IDT_TOKEN);
jsonString = request.toString();

Map<String, String> map = new HashMap<>();
map.put(GlobalConstants.TOKEN, idtToken);
JSONObject encodingToken = new JSONObject(map);

String challenge = encodeBase64(encodingToken.toString());
String individualId = getSubjectFromJwt(idtToken);

jsonString = replaceKeywordWithValue(jsonString, "$IDTINDIVIUALID$", individualId);
jsonString = replaceKeywordWithValue(jsonString, "$IDTCHALLENGE$", challenge);

}

if (jsonString.contains(GlobalConstants.REMOVE))
jsonString = removeObject(new JSONObject(jsonString));
Expand Down Expand Up @@ -6974,5 +7058,17 @@ public String getPasswordPattern() {
}
return password;
}

public String getSubjectFromJwt(String JwtEncodedString) {
String subject = "";
try {
DecodedJWT decodedJWT = JWT.decode(JwtEncodedString);
subject = decodedJWT.getSubject();
logger.info("The subject of the Jwt Encoded String is " + subject);
} catch (JwtException e) {
logger.info("Invalid JWT token.");
}
return subject;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,29 @@ public static Response getRequestWithQueryParm(String url, Map<String, String> b

return getResponse;
}

public static Response postRequestWithMultipleHeadersAndMultipleCookies(String url, Object body,
String contentHeader, String acceptHeader, String cookieName, String cookieValue, Map<String, String> headers) {
Response postResponse;
if (ConfigManager.IsDebugEnabled()) {
RESTCLIENT_LOGGER.info(GlobalConstants.REST_ASSURED_STRING_1 + url);

postResponse = given().config(config).relaxedHTTPSValidation().headers(headers).body(body)
.contentType(contentHeader).cookie("XSRF-TOKEN", properties.getProperty(GlobalConstants.XSRFTOKEN))
.cookie(cookieName, cookieValue).accept(acceptHeader).log().all().when().post(url)
.then().log().all().extract().response();

RESTCLIENT_LOGGER.info(GlobalConstants.REST_ASSURED_STRING_2 + postResponse.asString());
RESTCLIENT_LOGGER.info(GlobalConstants.REST_ASSURED_STRING_3 + postResponse.time());
} else {
postResponse = given().config(config).relaxedHTTPSValidation().headers(headers).body(body)
.contentType(contentHeader).cookie("XSRF-TOKEN", properties.getProperty(GlobalConstants.XSRFTOKEN))
.cookie(cookieName, cookieValue).accept(acceptHeader).when().post(url).then().extract()
.response();
}

return postResponse;
}

public static Response patchRequestWithCookieAndQueryParm(String url, Map<String, String> body,
String contentHeader, String acceptHeader, String cookieName, String cookieValue) {
Expand Down Expand Up @@ -1691,4 +1714,24 @@ public static Response postRequestWithQueryParamBodyAndCookie(String url, Object

return postResponse;
}

public static Response getRequestWithMultipleHeadersAndCookies(String url, String contentHeader,
String acceptHeader, String cookieName, String cookieValue, Map<String, String> headers) {
Response postResponse;
if (ConfigManager.IsDebugEnabled()) {
RESTCLIENT_LOGGER.info(GlobalConstants.REST_ASSURED_STRING_1 + url);

postResponse = given().config(config).relaxedHTTPSValidation().headers(headers).contentType(contentHeader)
.cookie(cookieName, cookieValue).accept(acceptHeader).log().all().when().get(url).then().log().all()
.extract().response();

RESTCLIENT_LOGGER.info(GlobalConstants.REST_ASSURED_STRING_2 + postResponse.asString());
RESTCLIENT_LOGGER.info(GlobalConstants.REST_ASSURED_STRING_3 + postResponse.time());
} else {
postResponse = given().config(config).relaxedHTTPSValidation().headers(headers).contentType(contentHeader)
.cookie(cookieName, cookieValue).accept(acceptHeader).when().get(url).then().extract().response();
}

return postResponse;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,7 @@ public class GlobalConstants {
public static final String TARGET_ENV_HEALTH_CHECK_FAILED = "Target env health check failed ";
public static final String HOTLIST = "hotlist";
public static final String XSRF_TOKEN = "XSRF-TOKEN";
public static final String PATH_FRAGMENT_COOKIE = "pathFragmentCookie";
public static final String IDT_TOKEN = "idtToken";
public static final String PATH_FRAGMENT_COOKIE_TRANSACTIONID = "pathFragmentCookieTransactionId";
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,15 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad
if (testCaseDTO.getEndPoint().contains("/signup/"))
tempUrl = ConfigManager.getSignupBaseUrl();

response = getWithPathParamAndCookie(tempUrl + testCaseDTO.getEndPoint(),
getJsonFromTemplate(testCaseDTO.getInput(), testCaseDTO.getInputTemplate()), COOKIENAME,
testCaseDTO.getRole(), testCaseDTO.getTestCaseName());
if (testCaseName.contains("_AuthToken_Xsrf_")) {
response = getRequestWithCookieAuthHeaderAndXsrfToken(tempUrl + testCaseDTO.getEndPoint(),
getJsonFromTemplate(testCaseDTO.getInput(), testCaseDTO.getInputTemplate()), COOKIENAME,
testCaseDTO.getRole(), testCaseDTO.getTestCaseName());
} else {
response = getWithPathParamAndCookie(tempUrl + testCaseDTO.getEndPoint(),
getJsonFromTemplate(testCaseDTO.getInput(), testCaseDTO.getInputTemplate()), COOKIENAME,
testCaseDTO.getRole(), testCaseDTO.getTestCaseName());
}
} else {
response = getWithPathParamAndCookie(ApplnURI + testCaseDTO.getEndPoint(),
getJsonFromTemplate(testCaseDTO.getInput(), testCaseDTO.getInputTemplate()), auditLogCheck,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void test(TestCaseDTO testCaseDTO)
tempUrl = ApplnURI.replace("api-internal.", ConfigManager.getEsignetMockBaseURL());
testCaseDTO.setEndPoint(testCaseDTO.getEndPoint().replace("$ESIGNETMOCKBASEURL$", ""));
}
if (testCaseName.contains("_AuthorizationCode_")) {
if ((testCaseName.contains("_AuthorizationCode_")) || (testCaseName.contains("_AuthToken_Xsrf_"))) {
response = postRequestWithCookieAuthHeaderAndXsrfTokenForAutoGenId(
tempUrl + testCaseDTO.getEndPoint(), inputJson, COOKIENAME, testCaseDTO.getTestCaseName(),
idKeyName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,4 +591,31 @@ AddIdentity:
}'
output: '{
"status":"ACTIVATED"
}'

ESignet_AddIdentity_L2_Valid_Parameters_smoke_Pos:
endPoint: /idrepository/v1/identity/
role: idrepo
restMethod: post
inputTemplate: esignet/AddIdentity/addIdentity_$LANGNUMBER$
outputTemplate: esignet/AddIdentity/addIdentityResult
input: '{
"value": "$BIOVALUE$",
"id": "mosip.id.create",
"registrationId": "$RID$",
"biometricReferenceId": "23452353",
"UIN": "$UIN$",
"dateOfBirth": "1992/04/15",
"postalCode": "14022",
"email": "[email protected]",
"phone": "9876543210",
"referenceIdentityNumber": "6789545678878",
"version": "v1",
"introducerRID": "212124324784879",
"introducerUIN": "212124324784879",
"category": "individualBiometrics",
"requesttime": "$TIMESTAMP$"
}'
output: '{
"status":"ACTIVATED"
}'
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"encodedHash": "{{encodedHash}}",
"requestTime": "{{requestTime}}",
"request": {
"transactionId": "{{transactionId}}",
"individualId": "{{individualId}}",
"challengeList" : [
{
"authFactorType" : "{{authFactorType}}",
"challenge" : "{{challenge}}",
"format": "alpha-numeric"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
AuthenticateUserV3:
ESignet_AuthenticateUser_V3_AuthToken_Xsrf__uin_Otp_Valid_Smoke:
endPoint: /v1/esignet/authorization/v3/authenticate
role: resident
restMethod: post
checkErrorsOnlyInResponse: true
validityCheckRequired: true
inputTemplate: esignet/AuthenticateUserV3/AuthenticateUser
outputTemplate: esignet/AuthenticateUserV3/AuthenticateUserResult
input: '{
"encodedHash": "$ID:OAuthDetailsRequest_V3_AuthToken_Xsrf_uin_all_Valid_Smoke_sid_encodedResp$",
"requestTime": "$TIMESTAMP$",
"transactionId": "$ID:OAuthDetailsRequest_V3_AuthToken_Xsrf_uin_all_Valid_Smoke_sid_transactionId$",
"individualId": "$ID:AddIdentity_L2_Valid_Parameters_smoke_Pos_UIN$",
"authFactorType" : "OTP",
"challenge" : "$ID:AddIdentity_L2_Valid_Parameters_smoke_Pos_EMAIL$",
"sendOtp":{
"encodedHash": "$ID:OAuthDetailsRequest_V3_AuthToken_Xsrf_uin_all_Valid_Smoke_sid_encodedResp$",
"requestTime": "$TIMESTAMP$",
"transactionId": "$ID:OAuthDetailsRequest_V3_AuthToken_Xsrf_uin_all_Valid_Smoke_sid_transactionId$",
"individualId": "$ID:AddIdentity_L2_Valid_Parameters_smoke_Pos_UIN$",
"otpChannels": [{channel: "email"},{channel: "phone"}],
"sendOtpReqTemplate": "esignet/SendOtp/SendOtp",
"sendOtpEndPoint": "/v1/esignet/authorization/send-otp"
}
}'
output: '{
"sendOtpResp":{
"maskedMobile": "$IGNORE$",
"sendOtpResTemplate":"esignet/SendOtp/SendOtpResult",
"maskedEmail": "$IGNORE$"
}
}'
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,4 @@
{
"encodedHash": "{{encodedHash}}",
"transactionId": "{{transactionId}}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ClaimDetails:
ESignet_ClaimDetails_AuthToken_Xsrf_uin_Valid_Smoke:
endPoint: /v1/esignet/authorization/claim-details
role: resident
restMethod: get
checkErrorsOnlyInResponse: true
validityCheckRequired: true
inputTemplate: esignet/ClaimDetails/ClaimDetails
outputTemplate: esignet/ClaimDetails/ClaimDetailsResult
input: '{
"encodedHash": "$ID:OAuthDetailsRequest_V3_AuthToken_Xsrf_uin_all_Valid_Smoke_sid_encodedResp$",
"transactionId": "$ID:OAuthDetailsRequest_V3_AuthToken_Xsrf_uin_all_Valid_Smoke_sid_transactionId$"
}'
output: '{
}'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Loading

0 comments on commit 343f775

Please sign in to comment.