Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Sohandey committed Sep 25, 2023
2 parents 69359ba + 70d0d98 commit e5c461f
Show file tree
Hide file tree
Showing 12 changed files with 728 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3233,7 +3233,7 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) {
accessToken = request.getString("idpAccessToken");
}
jsonString = request.toString();
jsonString = replaceKeywordWithValue(jsonString, "$PROOFJWT$", signJWK(clientId, accessToken, oidcJWKKey1));
jsonString = replaceKeywordWithValue(jsonString, "$PROOFJWT$", signJWK(clientId, accessToken, oidcJWKKey1, testCaseName));
}

if (jsonString.contains(GlobalConstants.REMOVE))
Expand All @@ -3242,12 +3242,15 @@ public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) {
return jsonString;
}

public static String signJWK(String clientId, String accessToken, RSAKey jwkKey) {
public static String signJWK(String clientId, String accessToken, RSAKey jwkKey, String testCaseName) {
String tempUrl = getValueFromActuator(GlobalConstants.RESIDENT_DEFAULT_PROPERTIES, "mosip.iam.base.url");
int idTokenExpirySecs = Integer.parseInt(getValueFromEsignetActuator(GlobalConstants.ESIGNET_DEFAULT_PROPERTIES,
GlobalConstants.MOSIP_ESIGNET_ID_TOKEN_EXPIRE_SECONDS));
JWSSigner signer;
String proofJWT = "";
String nonce = "jwt_payload.c_nonce123";
String typ = "openid4vci-proof+jwt";
JWK jwkHeader = jwkKey.toPublicJWK();

try {
signer = new RSASSASigner(jwkKey);
Expand All @@ -3256,13 +3259,23 @@ public static String signJWK(String clientId, String accessToken, RSAKey jwkKey)
String jwtPayloadBase64 = jwtParts[1];
byte[] jwtPayloadBytes = Base64.getDecoder().decode(jwtPayloadBase64);
String jwtPayload = new String(jwtPayloadBytes, StandardCharsets.UTF_8);
JWTClaimsSet claimsSet = null;

if (testCaseName.contains("_Invalid_C_nonce_")) {
claimsSet = new JWTClaimsSet.Builder().audience(tempUrl)
.claim("nonce", nonce)
.issuer(clientId).issueTime(new Date())
.expirationTime(new Date(new Date().getTime() + idTokenExpirySecs)).build();
} else {

JWTClaimsSet claimsSet = new JWTClaimsSet.Builder().audience(tempUrl)
.claim("nonce", new ObjectMapper().readTree(jwtPayload).get("c_nonce").asText()).issuer(clientId)
.issueTime(new Date()).expirationTime(new Date(new Date().getTime() + idTokenExpirySecs)).build();
claimsSet = new JWTClaimsSet.Builder().audience(tempUrl)
.claim("nonce", new ObjectMapper().readTree(jwtPayload).get("c_nonce").asText())
.issuer(clientId).issueTime(new Date())
.expirationTime(new Date(new Date().getTime() + idTokenExpirySecs)).build();
}

SignedJWT signedJWT = new SignedJWT(new JWSHeader.Builder(JWSAlgorithm.RS256)
.type(new JOSEObjectType("openid4vci-proof+jwt")).jwk(jwkKey.toPublicJWK()).build(), claimsSet);
.type(new JOSEObjectType(typ)).jwk(jwkHeader).build(), claimsSet);

signedJWT.sign(signer);
proofJWT = signedJWT.serialize();
Expand Down Expand Up @@ -4811,7 +4824,6 @@ public static int getOtpExpTimeFromActuator() {
String url = ApplnURI + propsKernel.getProperty("actuatorIDAEndpoint");
try {
response = RestClient.getRequest(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);

responseJson = new org.json.JSONObject(response.getBody().asString());
responseArray = responseJson.getJSONArray("propertySources");
Expand All @@ -4824,6 +4836,8 @@ public static int getOtpExpTimeFromActuator() {
org.json.JSONObject otpExpiryTime = (org.json.JSONObject) eachJson
.getJSONObject(GlobalConstants.PROPERTIES).get("mosip.kernel.otp.expiry-time");
otpExpTime = otpExpiryTime.getString(GlobalConstants.VALUE);
if (ConfigManager.IsDebugEnabled())
logger.info("Actuator: " +url +" otpExpTime: "+otpExpTime);
break;
}
}
Expand All @@ -4833,26 +4847,28 @@ public static int getOtpExpTimeFromActuator() {
}
return Integer.parseInt(otpExpTime);
}

public static JSONArray residentActuatorResponseArray = null;

public static String getValueFromActuator(String section, String key) {

Response response = null;
JSONObject responseJson = null;
JSONArray responseArray = null;
String url = ApplnURI + propsKernel.getProperty("actuatorEndpoint");
String value = null;
try {
response = RestClient.getRequest(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);

responseJson = new JSONObject(response.getBody().asString());
responseArray = responseJson.getJSONArray("propertySources");
if (residentActuatorResponseArray == null) {
Response response = null;
JSONObject responseJson = null;
response = RestClient.getRequest(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON);

for (int i = 0, size = responseArray.length(); i < size; i++) {
JSONObject eachJson = responseArray.getJSONObject(i);
responseJson = new JSONObject(response.getBody().asString());
residentActuatorResponseArray = responseJson.getJSONArray("propertySources");
}
for (int i = 0, size = residentActuatorResponseArray.length(); i < size; i++) {
JSONObject eachJson = residentActuatorResponseArray.getJSONObject(i);
if (eachJson.get("name").toString().contains(section)) {
value = eachJson.getJSONObject(GlobalConstants.PROPERTIES).getJSONObject(key)
.get(GlobalConstants.VALUE).toString();
if (ConfigManager.IsDebugEnabled())
logger.info("Actuator: " +url + " key: "+key+" value: "+value);
break;
}
}
Expand All @@ -4864,26 +4880,28 @@ public static String getValueFromActuator(String section, String key) {
}

}

public static JSONArray esignetActuatorResponseArray = null;

public static String getValueFromEsignetActuator(String section, String key) {

Response response = null;
JSONObject responseJson = null;
JSONArray responseArray = null;
String url = ConfigManager.getEsignetBaseUrl() + propsKernel.getProperty("actuatorEsignetEndpoint");
String value = null;
String url = ConfigManager.getEsignetBaseUrl() + propsKernel.getProperty("actuatorEsignetEndpoint");
try {
response = RestClient.getRequest(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);

responseJson = new JSONObject(response.getBody().asString());
responseArray = responseJson.getJSONArray("propertySources");
if (esignetActuatorResponseArray == null) {
Response response = null;
JSONObject responseJson = null;
response = RestClient.getRequest(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON);
responseJson = new JSONObject(response.getBody().asString());
esignetActuatorResponseArray = responseJson.getJSONArray("propertySources");
}

for (int i = 0, size = responseArray.length(); i < size; i++) {
JSONObject eachJson = responseArray.getJSONObject(i);
for (int i = 0, size = esignetActuatorResponseArray.length(); i < size; i++) {
JSONObject eachJson = esignetActuatorResponseArray.getJSONObject(i);
if (eachJson.get("name").toString().contains(section)) {
value = eachJson.getJSONObject(GlobalConstants.PROPERTIES).getJSONObject(key)
.get(GlobalConstants.VALUE).toString();
if (ConfigManager.IsDebugEnabled())
logger.info("Actuator: " +url + " key: "+key+" value: "+value);
break;
}
}
Expand All @@ -4895,26 +4913,29 @@ public static String getValueFromEsignetActuator(String section, String key) {
}

}

public static JSONArray authActuatorResponseArray = null;

public static String getValueFromAuthActuator(String section, String key) {

Response response = null;
JSONObject responseJson = null;
JSONArray responseArray = null;
String url = ConfigManager.getEsignetBaseUrl() + propsKernel.getProperty("actuatorIDAEndpoint");
String url = ApplnURI + propsKernel.getProperty("actuatorIDAEndpoint");
String value = null;
try {
response = RestClient.getRequest(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
if (authActuatorResponseArray == null) {
Response response = null;
JSONObject responseJson = null;
response = RestClient.getRequest(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON);

responseJson = new JSONObject(response.getBody().asString());
responseArray = responseJson.getJSONArray("propertySources");
responseJson = new JSONObject(response.getBody().asString());
authActuatorResponseArray = responseJson.getJSONArray("propertySources");
}

for (int i = 0, size = responseArray.length(); i < size; i++) {
JSONObject eachJson = responseArray.getJSONObject(i);
for (int i = 0, size = authActuatorResponseArray.length(); i < size; i++) {
JSONObject eachJson = authActuatorResponseArray.getJSONObject(i);
if (eachJson.get("name").toString().contains(section)) {
value = eachJson.getJSONObject(GlobalConstants.PROPERTIES).getJSONObject(key)
.get(GlobalConstants.VALUE).toString();
if (ConfigManager.IsDebugEnabled())
logger.info("Actuator: " +url + " key: "+key+" value: "+value);
break;
}
}
Expand All @@ -4926,23 +4947,26 @@ public static String getValueFromAuthActuator(String section, String key) {
}

}

public static JSONArray configActuatorResponseArray = null;

public static String getValueFromConfigActuator() {

Response response = null;
JSONObject responseJson = null;
JSONArray responseArray = null;
String url = ApplnURI + propsKernel.getProperty("actuatorEndpoint");
String claims = null;
try {
response = RestClient.getRequest(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
if (configActuatorResponseArray == null) {
Response response = null;
JSONObject responseJson = null;
response = RestClient.getRequest(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);

responseJson = new JSONObject(response.getBody().asString());
responseArray = responseJson.getJSONArray("propertySources");
responseJson = new JSONObject(response.getBody().asString());
configActuatorResponseArray = responseJson.getJSONArray("propertySources");
}

for (int i = 0, size = responseArray.length(); i < size; i++) {
JSONObject eachJson = responseArray.getJSONObject(i);
for (int i = 0, size = configActuatorResponseArray.length(); i < size; i++) {
JSONObject eachJson = configActuatorResponseArray.getJSONObject(i);
if (eachJson.get("name").toString().contains(GlobalConstants.RESIDENT_DEFAULT_PROPERTIES)) {
String claimVal = eachJson.getJSONObject(GlobalConstants.PROPERTIES)
.getJSONObject("mosip.iam.module.login_flow.claims").getString(GlobalConstants.VALUE);
Expand All @@ -4959,23 +4983,25 @@ public static String getValueFromConfigActuator() {
}

}

public static JSONArray regProcActuatorResponseArray = null;

public static String getRegprocWaitFromActuator() {

Response response = null;
JSONObject responseJson = null;
JSONArray responseArray = null;
String url = ApplnURI + propsKernel.getProperty("actuatorRegprocEndpoint");
String waitInterval = null;
try {
response = RestClient.getRequest(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
if (regProcActuatorResponseArray == null) {
Response response = null;
JSONObject responseJson = null;
response = RestClient.getRequest(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);

responseJson = new JSONObject(response.getBody().asString());
responseArray = responseJson.getJSONArray("propertySources");
responseJson = new JSONObject(response.getBody().asString());
regProcActuatorResponseArray = responseJson.getJSONArray("propertySources");
}

for (int i = 0, size = responseArray.length(); i < size; i++) {
JSONObject eachJson = responseArray.getJSONObject(i);
for (int i = 0, size = regProcActuatorResponseArray.length(); i < size; i++) {
JSONObject eachJson = regProcActuatorResponseArray.getJSONObject(i);
if (eachJson.get("name").toString().contains("registration-processor-default.properties")) {
waitInterval = eachJson.getJSONObject(GlobalConstants.PROPERTIES)
.getJSONObject("registration.processor.reprocess.minutes").get(GlobalConstants.VALUE)
Expand All @@ -4989,7 +5015,6 @@ public static String getRegprocWaitFromActuator() {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
return waitInterval;
}

}

public static String isTestCaseValidForExecution(TestCaseDTO testCaseDTO) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,22 +511,26 @@ public static void userCenterMappingStatus() {
logger.info(response);
}

public static JSONArray idaActuatorResponseArray = null;

public static String getValueFromActuators(String endPoint, String section, String key) {

Response response = null;
org.json.JSONObject responseJson = null;
JSONArray responseArray = null;
String url = ApplnURI + endPoint;
String value = null;
try {
response = RestClient.getRequest(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
if (idaActuatorResponseArray == null) {
Response response = null;
org.json.JSONObject responseJson = null;
response = RestClient.getRequest(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);

responseJson = new org.json.JSONObject(response.getBody().asString());
responseArray = responseJson.getJSONArray("propertySources");
responseJson = new org.json.JSONObject(response.getBody().asString());
idaActuatorResponseArray = responseJson.getJSONArray("propertySources");
}

for (int i = 0, size = responseArray.length(); i < size; i++) {
org.json.JSONObject eachJson = responseArray.getJSONObject(i);

for (int i = 0, size = idaActuatorResponseArray.length(); i < size; i++) {
org.json.JSONObject eachJson = idaActuatorResponseArray.getJSONObject(i);
if (eachJson.get("name").toString().contains(section)) {
value = eachJson.getJSONObject(GlobalConstants.PROPERTIES).getJSONObject(key)
.get(GlobalConstants.VALUE).toString();
Expand Down
12 changes: 6 additions & 6 deletions automationtests/src/main/resources/config/Kernel.properties
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ s3-account=automation
s3-region=null
reportExpirationInDays=3
# supported values yes or no
push-reports-to-s3=no
push-reports-to-s3=yes
enableDebug=yes
# supported values are 1 to 8
threadCount=1
Expand All @@ -227,12 +227,12 @@ ida_db_schema=ida

#----------------------------------AuthDemoService Host properties----------------------------------------------------------#
#To run locally
authDemoServiceBaseURL=http://localhost
authDemoServicePort=8082
#authDemoServiceBaseURL=http://localhost
#authDemoServicePort=8082

#To run in Docker
#authDemoServiceBaseURL=http://authdemo.apitestrig
#authDemoServicePort=80
authDemoServiceBaseURL=http://authdemo.apitestrig
authDemoServicePort=80


#----------------------------------e-Signet properties----------------------------------------------------------#
Expand Down Expand Up @@ -265,4 +265,4 @@ eSignetDeployed=yes
scenariosToSkip=


partnerUrlSuffix=oYf63Lax0DY2QkYMRHnrmDqhmO3RMWQagwm0ftgLlkuin1KOND/666/576732
partnerUrlSuffix=oYf63Lax0DY2QkYMRHnrmDqhmO3RMWQagwm0ftgLlkuin1KOND/666/576732
Loading

0 comments on commit e5c461f

Please sign in to comment.