Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES-2179 - Fixed esignet bugs #1160

Merged
merged 15 commits into from
Feb 6, 2025
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,15 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad

if (testCaseName.contains("ESignet_")) {
String tempUrl = EsignetConfigManager.getEsignetBaseUrl();
response = putWithPathParamsBodyAndBearerToken(tempUrl + testCaseDTO.getEndPoint(), inputJson,
COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName(), pathParams);
if (EsignetUtil.getIdentityPluginNameFromEsignetActuator().toLowerCase().contains("mockauthenticationservice") == true){
inputJson = inputJsonKeyWordHandeler(inputJson, testCaseName);
response = EsignetUtil.putWithPathParamsAndBodyAndBearerToken(tempUrl + testCaseDTO.getEndPoint(), inputJson,
COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName(), pathParams);
}else {
response = putWithPathParamsBodyAndBearerToken(tempUrl + testCaseDTO.getEndPoint(), inputJson,
COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName(), pathParams);
}

} else {
response = putWithPathParamsBodyAndCookie(ApplnURI + testCaseDTO.getEndPoint(), inputJson, COOKIENAME,
testCaseDTO.getRole(), testCaseDTO.getTestCaseName(), pathParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,16 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad
COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName(), sendEsignetToken);

} else if (testCaseName.contains("ESignet_SendBindingOtp")) {
response = postRequestWithCookieAuthHeader(tempUrl + testCaseDTO.getEndPoint(), inputJson,
COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName());

if (EsignetUtil.getIdentityPluginNameFromEsignetActuator().toLowerCase().contains("mockauthenticationservice") == true){
inputJson = inputJsonKeyWordHandeler(inputJson, testCaseName);
response = EsignetUtil.postRequestWithCookieAndAuthHeader(tempUrl + testCaseDTO.getEndPoint(), inputJson,
COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName());
}else {
response = postRequestWithCookieAuthHeader(tempUrl + testCaseDTO.getEndPoint(), inputJson,
COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName());
}

} else {
response = postRequestWithCookieAuthHeaderAndXsrfToken(tempUrl + testCaseDTO.getEndPoint(),
inputJson, COOKIENAME, testCaseDTO.getTestCaseName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,28 @@ public void test(TestCaseDTO testCaseDTO)
testCaseDTO.setEndPoint(testCaseDTO.getEndPoint().replace("$SUNBIRDBASEURL$", ""));
}
inputJson = EsignetUtil.inputstringKeyWordHandeler(inputJson, testCaseName);
if ((testCaseName.contains("_AuthorizationCode_")) || (testCaseName.contains("_AuthToken_Xsrf_"))) {
if ((testCaseName.contains("_AuthorizationCode_")) || (testCaseName.contains("_AuthToken_Xsrf_"))
|| (testCaseName.contains("_OAuthDetailsRequest_"))
|| (testCaseName.contains("_GenerateLinkCode_")) || (testCaseName.contains("_LinkTransaction_"))
|| (testCaseName.contains("_LinkAuthorizationCode_"))) {
response = postRequestWithCookieAuthHeaderAndXsrfTokenForAutoGenId(
tempUrl + testCaseDTO.getEndPoint(), inputJson, COOKIENAME, testCaseDTO.getTestCaseName(),
idKeyName);
} else {
response = postWithBodyAndBearerTokenForAutoGeneratedId(tempUrl + testCaseDTO.getEndPoint(),
inputJson, COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName(), idKeyName);
if (EsignetUtil.getIdentityPluginNameFromEsignetActuator().toLowerCase()
.contains("mockauthenticationservice") == true) {
inputJson = inputJsonKeyWordHandeler(inputJson, testCaseName);
response = EsignetUtil.postWithBodyAndBearerToken(tempUrl + testCaseDTO.getEndPoint(),
inputJson, COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName(), idKeyName);
if (testCaseName.toLowerCase().contains("_sid")) {
writeAutoGeneratedId(testCaseName, idKeyName, new JSONObject(response.getBody().asString())
.getJSONObject(GlobalConstants.RESPONSE).getString(idKeyName).toString());
}
} else {
response = postWithBodyAndBearerTokenForAutoGeneratedId(tempUrl + testCaseDTO.getEndPoint(),
inputJson, COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName(), idKeyName);
}

}
} else {
inputJson = EsignetUtil.inputstringKeyWordHandeler(inputJson, testCaseName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

Expand Down Expand Up @@ -40,10 +41,12 @@
import io.mosip.testrig.apirig.utils.CertsUtil;
import io.mosip.testrig.apirig.utils.EncryptionDecrptionUtil;
import io.mosip.testrig.apirig.utils.GlobalConstants;
import io.mosip.testrig.apirig.utils.GlobalMethods;
import io.mosip.testrig.apirig.utils.JWKKeyUtil;
import io.mosip.testrig.apirig.utils.KeycloakUserManager;
import io.mosip.testrig.apirig.utils.RestClient;
import io.mosip.testrig.apirig.utils.SkipTestCaseHandler;
import io.restassured.RestAssured;
import io.restassured.response.Response;

public class EsignetUtil extends AdminTestUtil {
Expand Down Expand Up @@ -201,7 +204,9 @@ public static String isTestCaseValidForExecution(TestCaseDTO testCaseDTO) {
}
if ((testCaseName.contains("_KycBioAuth_") || testCaseName.contains("_BioAuth_")
|| testCaseName.contains("_SendBindingOtp_uin_Email_Valid_Smoke")
|| testCaseName.contains("ESignet_AuthenticateUserIDP_NonAuth_uin_Otp_Valid_Smoke"))) {
|| testCaseName.contains("ESignet_AuthenticateUserIDP_NonAuth_uin_Otp_Valid_Smoke")
|| testCaseName.contains("ESignet_UpdateOIDCClient_StatusCode_Diff_Token_Neg")
|| testCaseName.contains("ESignet_CreateOIDCClient_StatusCode_Diff_Token_Neg"))) {
throw new SkipException(GlobalConstants.FEATURE_NOT_SUPPORTED_MESSAGE);
}

Expand Down Expand Up @@ -686,6 +691,7 @@ public static String replaceKeywordValue(String jsonString, String keyword, Stri

}
}

public static String getAuthTransactionId(String oidcTransactionId) {
final String transactionId = oidcTransactionId.replaceAll("_|-", "");
String lengthOfTransactionId = getValueFromEsignetActuator(
Expand Down Expand Up @@ -1185,4 +1191,155 @@ private static void settriggerESignetKeyGen13(boolean value) {
private static boolean gettriggerESignetKeyGen13() {
return triggerESignetKeyGen13;
}

private static final String TOKEN_URL = EsignetConfigManager.getproperty("keycloak-external-url")
+ EsignetConfigManager.getproperty("keycloakAuthTokenEndPoint");
private static final String GRANT_TYPE = "client_credentials";
private static final String CLIENT_ID = "client_id";
private static final String CLIENT_SECRET = "client_secret";
private static final String GRANT_TYPE_KEY = "grant_type";
private static final String ACCESS_TOKEN = "access_token";

private static String partnerCookie = null;
private static String mobileAuthCookie = null;

private static Response sendPostRequest(String url, Map<String, String> params) {
try {
return RestAssured.given().contentType("application/x-www-form-urlencoded; charset=utf-8")
.formParams(params).log().all().when().log().all().post(url);
} catch (Exception e) {
logger.error("Error sending POST request to URL: " + url, e);
return null;
}
}

public static String getAuthTokenFromKeyCloak(String clientId, String clientSecret) {
Map<String, String> params = new HashMap<>();
params.put(CLIENT_ID, clientId);
params.put(CLIENT_SECRET, clientSecret);
params.put(GRANT_TYPE_KEY, GRANT_TYPE);

Response response = sendPostRequest(TOKEN_URL, params);

if (response == null) {
return "";
}
logger.info(response.getBody().asString());

JSONObject responseJson = new JSONObject(response.getBody().asString());
return responseJson.optString(ACCESS_TOKEN, "");
}

public static String getAuthTokenByRole(String role) {
if (role == null) return "";

String roleLowerCase = role.toLowerCase();
switch (roleLowerCase) {
case "partner":
if (!AdminTestUtil.isValidToken(partnerCookie)) {
partnerCookie = getAuthTokenFromKeyCloak(EsignetConfigManager.getPmsClientId(), EsignetConfigManager.getPmsClientSecret());
}
return partnerCookie;
case "mobileauth":
if (!AdminTestUtil.isValidToken(mobileAuthCookie)) {
mobileAuthCookie = getAuthTokenFromKeyCloak(EsignetConfigManager.getMPartnerMobileClientId(), EsignetConfigManager.getMPartnerMobileClientSecret());
}
return mobileAuthCookie;
default:
return "";
}
}

public static Response postRequestWithCookieAndAuthHeader(String url, String jsonInput, String cookieName, String role,
String testCaseName) {
Response response = null;
token = getAuthTokenByRole(role);
String apiKey = null;
String partnerId = null;
JSONObject req = new JSONObject(jsonInput);
apiKey = req.getString(GlobalConstants.APIKEY);
req.remove(GlobalConstants.APIKEY);
partnerId = req.getString(GlobalConstants.PARTNERID);
req.remove(GlobalConstants.PARTNERID);

HashMap<String, String> headers = new HashMap<>();
headers.put("PARTNER-API-KEY", apiKey);
headers.put("PARTNER-ID", partnerId);
headers.put(cookieName, "Bearer " + token);
jsonInput = req.toString();
if (BaseTestCase.currentModule.equals(GlobalConstants.ESIGNET)) {
jsonInput = smtpOtpHandler(jsonInput, testCaseName);
}

logger.info(GlobalConstants.POST_REQ_URL + url);
GlobalMethods.reportRequest(headers.toString(), jsonInput, url);
try {
response = RestClient.postRequestWithMultipleHeadersWithoutCookie(url, jsonInput,
MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, headers);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
return response;
} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
return response;
}
}

public static Response postWithBodyAndBearerToken(String url, String jsonInput, String cookieName,
String role, String testCaseName, String idKeyName) {
Response response = null;
if (testCaseName.contains("Invalid_Token")) {
token = "xyz";
} else if (testCaseName.contains("NOAUTH")) {
token = "";
} else {
token = getAuthTokenByRole(role);
}
logger.info(GlobalConstants.POST_REQ_URL + url);
GlobalMethods.reportRequest(null, jsonInput, url);
try {
response = RestClient.postRequestWithBearerToken(url, jsonInput, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, cookieName, token);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);

return response;
} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
return response;
}
}

public static Response putWithPathParamsAndBodyAndBearerToken(String url, String jsonInput, String cookieName, String role,
String testCaseName, String pathParams) {
Response response = null;
logger.info("inputJson is::" + jsonInput);
JSONObject req = new JSONObject(jsonInput);
logger.info(GlobalConstants.REQ_STR + req);
HashMap<String, String> pathParamsMap = new HashMap<>();
String[] params = pathParams.split(",");
for (String param : params) {
logger.info("param is::" + param);
if (req.has(param)) {
logger.info(GlobalConstants.REQ_STR + req);
pathParamsMap.put(param, req.get(param).toString());
req.remove(param);
} else
logger.error(GlobalConstants.ERROR_STRING_2 + param + GlobalConstants.IN_STRING + jsonInput);
}
if (testCaseName.contains("Invalid_Token")) {
token = "xyz";
} else {
token = getAuthTokenByRole(role);
}
logger.info(GlobalConstants.PUT_REQ_STRING + url);
GlobalMethods.reportRequest(null, req.toString(), url);
try {
response = RestClient.putWithPathParamsBodyAndBearerToken(url, pathParamsMap, req.toString(),
MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, cookieName, token);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
return response;
} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
return response;
}
}
}
1 change: 1 addition & 0 deletions api-test/src/main/resources/config/esignet.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ actuatorSignupEndpoint=/v1/signup/actuator/env
tokenEndpoint=/v1/esignet/oauth/token
validateBindingEndpoint=ida-binding
esignetWellKnownEndPoint=/v1/esignet/oidc/.well-known/openid-configuration
keycloakAuthTokenEndPoint=/auth/realms/mosip/protocol/openid-connect/token
signupSettingsEndPoint=/v1/signup/settings
esignetActuatorPropertySection=classpath:/application-default.properties
# uncomment below property while executing on camdgc env locally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ LinkTransaction:

}'

ESignet_Link_Transaction_Absent_RequestTime_Neg:
ESignet_LinkTransaction_Absent_RequestTime_Neg:
endPoint: /v1/esignet/linked-authorization/link-transaction
description: link transaction without requestTime
role: resident
Expand Down
Loading