Skip to content

Commit 51af09e

Browse files
authored
ES-2179 - Fixed esignet bugs (#1160)
* MOSIP-36485 Signed-off-by: Nandhukumar <nandhukumare@gmail.com> * MOSIP-36485 Signed-off-by: Nandhukumar <nandhukumare@gmail.com> * MOSIP-36485 Signed-off-by: Nandhukumar <nandhukumare@gmail.com> * ES-1997 Signed-off-by: Nandhukumar <nandhukumare@gmail.com> * ES-1997 Signed-off-by: Nandhukumar <nandhukumare@gmail.com> * ES-2179 Signed-off-by: Nandhukumar <nandhukumare@gmail.com> * ES-2179 Signed-off-by: Nandhukumar <nandhukumare@gmail.com> * ES-2179 Signed-off-by: Nandhukumar <nandhukumare@gmail.com> * ES-2179 Signed-off-by: Nandhukumar <nandhukumare@gmail.com> --------- Signed-off-by: Nandhukumar <nandhukumare@gmail.com>
1 parent ba709c1 commit 51af09e

File tree

6 files changed

+197
-9
lines changed

6 files changed

+197
-9
lines changed

api-test/src/main/java/io/mosip/testrig/apirig/esignet/testscripts/PutWithPathParamsAndBody.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,15 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad
122122

123123
if (testCaseName.contains("ESignet_")) {
124124
String tempUrl = EsignetConfigManager.getEsignetBaseUrl();
125-
response = putWithPathParamsBodyAndBearerToken(tempUrl + testCaseDTO.getEndPoint(), inputJson,
126-
COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName(), pathParams);
125+
if (EsignetUtil.getIdentityPluginNameFromEsignetActuator().toLowerCase().contains("mockauthenticationservice") == true){
126+
inputJson = inputJsonKeyWordHandeler(inputJson, testCaseName);
127+
response = EsignetUtil.putWithPathParamsAndBodyAndBearerToken(tempUrl + testCaseDTO.getEndPoint(), inputJson,
128+
COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName(), pathParams);
129+
}else {
130+
response = putWithPathParamsBodyAndBearerToken(tempUrl + testCaseDTO.getEndPoint(), inputJson,
131+
COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName(), pathParams);
132+
}
133+
127134
} else {
128135
response = putWithPathParamsBodyAndCookie(ApplnURI + testCaseDTO.getEndPoint(), inputJson, COOKIENAME,
129136
testCaseDTO.getRole(), testCaseDTO.getTestCaseName(), pathParams);

api-test/src/main/java/io/mosip/testrig/apirig/esignet/testscripts/SimplePost.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,16 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad
163163
COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName(), sendEsignetToken);
164164

165165
} else if (testCaseName.contains("ESignet_SendBindingOtp")) {
166-
response = postRequestWithCookieAuthHeader(tempUrl + testCaseDTO.getEndPoint(), inputJson,
167-
COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName());
166+
167+
if (EsignetUtil.getIdentityPluginNameFromEsignetActuator().toLowerCase().contains("mockauthenticationservice") == true){
168+
inputJson = inputJsonKeyWordHandeler(inputJson, testCaseName);
169+
response = EsignetUtil.postRequestWithCookieAndAuthHeader(tempUrl + testCaseDTO.getEndPoint(), inputJson,
170+
COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName());
171+
}else {
172+
response = postRequestWithCookieAuthHeader(tempUrl + testCaseDTO.getEndPoint(), inputJson,
173+
COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName());
174+
}
175+
168176
} else {
169177
response = postRequestWithCookieAuthHeaderAndXsrfToken(tempUrl + testCaseDTO.getEndPoint(),
170178
inputJson, COOKIENAME, testCaseDTO.getTestCaseName());

api-test/src/main/java/io/mosip/testrig/apirig/esignet/testscripts/SimplePostForAutoGenId.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,28 @@ public void test(TestCaseDTO testCaseDTO)
166166
testCaseDTO.setEndPoint(testCaseDTO.getEndPoint().replace("$SUNBIRDBASEURL$", ""));
167167
}
168168
inputJson = EsignetUtil.inputstringKeyWordHandeler(inputJson, testCaseName);
169-
if ((testCaseName.contains("_AuthorizationCode_")) || (testCaseName.contains("_AuthToken_Xsrf_"))) {
169+
if ((testCaseName.contains("_AuthorizationCode_")) || (testCaseName.contains("_AuthToken_Xsrf_"))
170+
|| (testCaseName.contains("_OAuthDetailsRequest_"))
171+
|| (testCaseName.contains("_GenerateLinkCode_")) || (testCaseName.contains("_LinkTransaction_"))
172+
|| (testCaseName.contains("_LinkAuthorizationCode_"))) {
170173
response = postRequestWithCookieAuthHeaderAndXsrfTokenForAutoGenId(
171174
tempUrl + testCaseDTO.getEndPoint(), inputJson, COOKIENAME, testCaseDTO.getTestCaseName(),
172175
idKeyName);
173176
} else {
174-
response = postWithBodyAndBearerTokenForAutoGeneratedId(tempUrl + testCaseDTO.getEndPoint(),
175-
inputJson, COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName(), idKeyName);
177+
if (EsignetUtil.getIdentityPluginNameFromEsignetActuator().toLowerCase()
178+
.contains("mockauthenticationservice") == true) {
179+
inputJson = inputJsonKeyWordHandeler(inputJson, testCaseName);
180+
response = EsignetUtil.postWithBodyAndBearerToken(tempUrl + testCaseDTO.getEndPoint(),
181+
inputJson, COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName(), idKeyName);
182+
if (testCaseName.toLowerCase().contains("_sid")) {
183+
writeAutoGeneratedId(testCaseName, idKeyName, new JSONObject(response.getBody().asString())
184+
.getJSONObject(GlobalConstants.RESPONSE).getString(idKeyName).toString());
185+
}
186+
} else {
187+
response = postWithBodyAndBearerTokenForAutoGeneratedId(tempUrl + testCaseDTO.getEndPoint(),
188+
inputJson, COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName(), idKeyName);
189+
}
190+
176191
}
177192
} else {
178193
inputJson = EsignetUtil.inputstringKeyWordHandeler(inputJson, testCaseName);

api-test/src/main/java/io/mosip/testrig/apirig/esignet/utils/EsignetUtil.java

Lines changed: 158 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.Calendar;
99
import java.util.Date;
1010
import java.util.HashMap;
11+
import java.util.Map;
1112
import java.util.Set;
1213
import java.util.TreeSet;
1314

@@ -40,10 +41,12 @@
4041
import io.mosip.testrig.apirig.utils.CertsUtil;
4142
import io.mosip.testrig.apirig.utils.EncryptionDecrptionUtil;
4243
import io.mosip.testrig.apirig.utils.GlobalConstants;
44+
import io.mosip.testrig.apirig.utils.GlobalMethods;
4345
import io.mosip.testrig.apirig.utils.JWKKeyUtil;
4446
import io.mosip.testrig.apirig.utils.KeycloakUserManager;
4547
import io.mosip.testrig.apirig.utils.RestClient;
4648
import io.mosip.testrig.apirig.utils.SkipTestCaseHandler;
49+
import io.restassured.RestAssured;
4750
import io.restassured.response.Response;
4851

4952
public class EsignetUtil extends AdminTestUtil {
@@ -201,7 +204,9 @@ public static String isTestCaseValidForExecution(TestCaseDTO testCaseDTO) {
201204
}
202205
if ((testCaseName.contains("_KycBioAuth_") || testCaseName.contains("_BioAuth_")
203206
|| testCaseName.contains("_SendBindingOtp_uin_Email_Valid_Smoke")
204-
|| testCaseName.contains("ESignet_AuthenticateUserIDP_NonAuth_uin_Otp_Valid_Smoke"))) {
207+
|| testCaseName.contains("ESignet_AuthenticateUserIDP_NonAuth_uin_Otp_Valid_Smoke")
208+
|| testCaseName.contains("ESignet_UpdateOIDCClient_StatusCode_Diff_Token_Neg")
209+
|| testCaseName.contains("ESignet_CreateOIDCClient_StatusCode_Diff_Token_Neg"))) {
205210
throw new SkipException(GlobalConstants.FEATURE_NOT_SUPPORTED_MESSAGE);
206211
}
207212

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

687692
}
688693
}
694+
689695
public static String getAuthTransactionId(String oidcTransactionId) {
690696
final String transactionId = oidcTransactionId.replaceAll("_|-", "");
691697
String lengthOfTransactionId = getValueFromEsignetActuator(
@@ -1185,4 +1191,155 @@ private static void settriggerESignetKeyGen13(boolean value) {
11851191
private static boolean gettriggerESignetKeyGen13() {
11861192
return triggerESignetKeyGen13;
11871193
}
1194+
1195+
private static final String TOKEN_URL = EsignetConfigManager.getproperty("keycloak-external-url")
1196+
+ EsignetConfigManager.getproperty("keycloakAuthTokenEndPoint");
1197+
private static final String GRANT_TYPE = "client_credentials";
1198+
private static final String CLIENT_ID = "client_id";
1199+
private static final String CLIENT_SECRET = "client_secret";
1200+
private static final String GRANT_TYPE_KEY = "grant_type";
1201+
private static final String ACCESS_TOKEN = "access_token";
1202+
1203+
private static String partnerCookie = null;
1204+
private static String mobileAuthCookie = null;
1205+
1206+
private static Response sendPostRequest(String url, Map<String, String> params) {
1207+
try {
1208+
return RestAssured.given().contentType("application/x-www-form-urlencoded; charset=utf-8")
1209+
.formParams(params).log().all().when().log().all().post(url);
1210+
} catch (Exception e) {
1211+
logger.error("Error sending POST request to URL: " + url, e);
1212+
return null;
1213+
}
1214+
}
1215+
1216+
public static String getAuthTokenFromKeyCloak(String clientId, String clientSecret) {
1217+
Map<String, String> params = new HashMap<>();
1218+
params.put(CLIENT_ID, clientId);
1219+
params.put(CLIENT_SECRET, clientSecret);
1220+
params.put(GRANT_TYPE_KEY, GRANT_TYPE);
1221+
1222+
Response response = sendPostRequest(TOKEN_URL, params);
1223+
1224+
if (response == null) {
1225+
return "";
1226+
}
1227+
logger.info(response.getBody().asString());
1228+
1229+
JSONObject responseJson = new JSONObject(response.getBody().asString());
1230+
return responseJson.optString(ACCESS_TOKEN, "");
1231+
}
1232+
1233+
public static String getAuthTokenByRole(String role) {
1234+
if (role == null) return "";
1235+
1236+
String roleLowerCase = role.toLowerCase();
1237+
switch (roleLowerCase) {
1238+
case "partner":
1239+
if (!AdminTestUtil.isValidToken(partnerCookie)) {
1240+
partnerCookie = getAuthTokenFromKeyCloak(EsignetConfigManager.getPmsClientId(), EsignetConfigManager.getPmsClientSecret());
1241+
}
1242+
return partnerCookie;
1243+
case "mobileauth":
1244+
if (!AdminTestUtil.isValidToken(mobileAuthCookie)) {
1245+
mobileAuthCookie = getAuthTokenFromKeyCloak(EsignetConfigManager.getMPartnerMobileClientId(), EsignetConfigManager.getMPartnerMobileClientSecret());
1246+
}
1247+
return mobileAuthCookie;
1248+
default:
1249+
return "";
1250+
}
1251+
}
1252+
1253+
public static Response postRequestWithCookieAndAuthHeader(String url, String jsonInput, String cookieName, String role,
1254+
String testCaseName) {
1255+
Response response = null;
1256+
token = getAuthTokenByRole(role);
1257+
String apiKey = null;
1258+
String partnerId = null;
1259+
JSONObject req = new JSONObject(jsonInput);
1260+
apiKey = req.getString(GlobalConstants.APIKEY);
1261+
req.remove(GlobalConstants.APIKEY);
1262+
partnerId = req.getString(GlobalConstants.PARTNERID);
1263+
req.remove(GlobalConstants.PARTNERID);
1264+
1265+
HashMap<String, String> headers = new HashMap<>();
1266+
headers.put("PARTNER-API-KEY", apiKey);
1267+
headers.put("PARTNER-ID", partnerId);
1268+
headers.put(cookieName, "Bearer " + token);
1269+
jsonInput = req.toString();
1270+
if (BaseTestCase.currentModule.equals(GlobalConstants.ESIGNET)) {
1271+
jsonInput = smtpOtpHandler(jsonInput, testCaseName);
1272+
}
1273+
1274+
logger.info(GlobalConstants.POST_REQ_URL + url);
1275+
GlobalMethods.reportRequest(headers.toString(), jsonInput, url);
1276+
try {
1277+
response = RestClient.postRequestWithMultipleHeadersWithoutCookie(url, jsonInput,
1278+
MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, headers);
1279+
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
1280+
return response;
1281+
} catch (Exception e) {
1282+
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
1283+
return response;
1284+
}
1285+
}
1286+
1287+
public static Response postWithBodyAndBearerToken(String url, String jsonInput, String cookieName,
1288+
String role, String testCaseName, String idKeyName) {
1289+
Response response = null;
1290+
if (testCaseName.contains("Invalid_Token")) {
1291+
token = "xyz";
1292+
} else if (testCaseName.contains("NOAUTH")) {
1293+
token = "";
1294+
} else {
1295+
token = getAuthTokenByRole(role);
1296+
}
1297+
logger.info(GlobalConstants.POST_REQ_URL + url);
1298+
GlobalMethods.reportRequest(null, jsonInput, url);
1299+
try {
1300+
response = RestClient.postRequestWithBearerToken(url, jsonInput, MediaType.APPLICATION_JSON,
1301+
MediaType.APPLICATION_JSON, cookieName, token);
1302+
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
1303+
1304+
return response;
1305+
} catch (Exception e) {
1306+
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
1307+
return response;
1308+
}
1309+
}
1310+
1311+
public static Response putWithPathParamsAndBodyAndBearerToken(String url, String jsonInput, String cookieName, String role,
1312+
String testCaseName, String pathParams) {
1313+
Response response = null;
1314+
logger.info("inputJson is::" + jsonInput);
1315+
JSONObject req = new JSONObject(jsonInput);
1316+
logger.info(GlobalConstants.REQ_STR + req);
1317+
HashMap<String, String> pathParamsMap = new HashMap<>();
1318+
String[] params = pathParams.split(",");
1319+
for (String param : params) {
1320+
logger.info("param is::" + param);
1321+
if (req.has(param)) {
1322+
logger.info(GlobalConstants.REQ_STR + req);
1323+
pathParamsMap.put(param, req.get(param).toString());
1324+
req.remove(param);
1325+
} else
1326+
logger.error(GlobalConstants.ERROR_STRING_2 + param + GlobalConstants.IN_STRING + jsonInput);
1327+
}
1328+
if (testCaseName.contains("Invalid_Token")) {
1329+
token = "xyz";
1330+
} else {
1331+
token = getAuthTokenByRole(role);
1332+
}
1333+
logger.info(GlobalConstants.PUT_REQ_STRING + url);
1334+
GlobalMethods.reportRequest(null, req.toString(), url);
1335+
try {
1336+
response = RestClient.putWithPathParamsBodyAndBearerToken(url, pathParamsMap, req.toString(),
1337+
MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, cookieName, token);
1338+
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
1339+
return response;
1340+
} catch (Exception e) {
1341+
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
1342+
return response;
1343+
}
1344+
}
11881345
}

api-test/src/main/resources/config/esignet.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ actuatorSignupEndpoint=/v1/signup/actuator/env
44
tokenEndpoint=/v1/esignet/oauth/token
55
validateBindingEndpoint=ida-binding
66
esignetWellKnownEndPoint=/v1/esignet/oidc/.well-known/openid-configuration
7+
keycloakAuthTokenEndPoint=/auth/realms/mosip/protocol/openid-connect/token
78
signupSettingsEndPoint=/v1/signup/settings
89
esignetActuatorPropertySection=classpath:/application-default.properties
910
# uncomment below property while executing on camdgc env locally

api-test/src/main/resources/esignet/LinkTransaction/LinkTransaction.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ LinkTransaction:
165165
166166
}'
167167

168-
ESignet_Link_Transaction_Absent_RequestTime_Neg:
168+
ESignet_LinkTransaction_Absent_RequestTime_Neg:
169169
endPoint: /v1/esignet/linked-authorization/link-transaction
170170
description: link transaction without requestTime
171171
role: resident

0 commit comments

Comments
 (0)