Skip to content

Commit

Permalink
MOSIP-36410
Browse files Browse the repository at this point in the history
Signed-off-by: Jayesh Kharode <[email protected]>
  • Loading branch information
Jayesh Kharode committed Oct 10, 2024
1 parent b090929 commit 9ecb147
Showing 1 changed file with 69 additions and 93 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
package io.mosip.testrig.dslrig.ivv.e2e.methods;

import java.security.NoSuchAlgorithmException;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.json.JSONObject;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import io.mosip.testrig.apirig.dto.TestCaseDTO;
import io.mosip.testrig.apirig.testrunner.JsonPrecondtion;
import io.mosip.testrig.apirig.utils.AdminTestException;
import io.mosip.testrig.apirig.utils.AdminTestUtil;
import io.mosip.testrig.apirig.utils.AuthenticationTestException;
import io.mosip.testrig.apirig.testrunner.MosipTestRunner;
import io.mosip.testrig.apirig.testscripts.PostWithOnlyPathParam;
import io.mosip.testrig.apirig.testscripts.SimplePost;
import io.mosip.testrig.apirig.testscripts.SimplePostForAutoGenId;
Expand All @@ -26,8 +22,6 @@
import io.mosip.testrig.dslrig.ivv.orchestrator.dslConfigManager;
import io.restassured.response.Response;

@Scope("prototype")
@Component
public class OidcClient extends BaseTestCaseUtil implements StepInterface {
static Logger logger = Logger.getLogger(OidcClient.class);

Expand Down Expand Up @@ -68,6 +62,7 @@ public void run() throws RigInternalError, FeatureNotSupportedError {
String policyName = null;
String mappingkey = null;
String clientId = null;
Response response = null;

// check if esignet is installed on the target system
if (dslConfigManager.isInServiceNotDeployedList(GlobalConstants.ESIGNET)) {
Expand All @@ -81,27 +76,22 @@ public void run() throws RigInternalError, FeatureNotSupportedError {
TestCaseDTO test1 = (TestCaseDTO) testObj1[0];

try {
try {
createPolicyGroup.test(test1);
} catch (NoSuchAlgorithmException e) {
logger.error(e.getMessage());
}
Response response = createPolicyGroup.response;
if (response != null) {
JSONObject jsonResp = new JSONObject(response.getBody().asString());
name = jsonResp.getJSONObject("response").getString("name");
policygroupId = jsonResp.getJSONObject("response").getString("id");

step.getScenario().getOidcPmsProp().put("name", name);
step.getScenario().getOidcPmsProp().put("policygroupId", policygroupId);

logger.info(name);
}

} catch (AuthenticationTestException | AdminTestException e) {
createPolicyGroup.test(test1);
} catch (Exception e) {
logger.error(e.getMessage());
this.hasError = true;
throw new RigInternalError(e.getMessage());
}
response = createPolicyGroup.response;
if (response != null) {
JSONObject jsonResp = new JSONObject(response.getBody().asString());
name = jsonResp.getJSONObject("response").getString("name");
policygroupId = jsonResp.getJSONObject("response").getString("id");

step.getScenario().getOidcPmsProp().put("name", name);
step.getScenario().getOidcPmsProp().put("policygroupId", policygroupId);

logger.info(name);
}

// DefinePolicy Call
Expand All @@ -116,25 +106,20 @@ public void run() throws RigInternalError, FeatureNotSupportedError {
test2.setInput(inputForDefinePolicy);

try {
try {
definePolicy.test(test2);
} catch (NoSuchAlgorithmException e) {
logger.error(e.getMessage());
}
Response response = definePolicy.response;
if (response != null) {
JSONObject jsonResp = new JSONObject(response.getBody().asString());
policyId = jsonResp.getJSONObject("response").getString("id");
policyName = jsonResp.getJSONObject("response").getString("name");
step.getScenario().getOidcPmsProp().put("policyId", policyId); // "$$clientId=e2e_OidcClient()"

logger.info(policyId);
}

} catch (AuthenticationTestException | AdminTestException e) {
definePolicy.test(test2);
} catch (Exception e) {
logger.error(e.getMessage());
this.hasError = true;
throw new RigInternalError(e.getMessage());

}
response = definePolicy.response;
if (response != null) {
JSONObject jsonResp = new JSONObject(response.getBody().asString());
policyId = jsonResp.getJSONObject("response").getString("id");
policyName = jsonResp.getJSONObject("response").getString("name");
step.getScenario().getOidcPmsProp().put("policyId", policyId); // "$$clientId=e2e_OidcClient()"

logger.info(policyId);
}

// PublishPolicy Call
Expand All @@ -153,13 +138,14 @@ public void run() throws RigInternalError, FeatureNotSupportedError {

try {
publishPolicy.test(test3);
Response response = publishPolicy.response;
response = publishPolicy.response;
if (response != null) {
JSONObject jsonResp = new JSONObject(response.getBody().asString());

}

} catch (AuthenticationTestException | AdminTestException e) {
logger.error(e.getMessage());
this.hasError = true;
throw new RigInternalError(e.getMessage());

Expand All @@ -178,23 +164,18 @@ public void run() throws RigInternalError, FeatureNotSupportedError {
test4.setInput(inputForCreatePartner);

try {
try {
createPartner.test(test4);
} catch (NoSuchAlgorithmException e) {
logger.error(e.getMessage());
}
Response response = createPartner.response;
if (response != null) {
JSONObject jsonResp = new JSONObject(response.getBody().asString());
partnerId = jsonResp.getJSONObject("response").getString("partnerId");

step.getScenario().getOidcPmsProp().put("partnerId", partnerId);
}

} catch (AuthenticationTestException | AdminTestException e) {
createPartner.test(test4);
} catch (Exception e) {
logger.error(e.getMessage());
this.hasError = true;
throw new RigInternalError(e.getMessage());
}
response = createPartner.response;
if (response != null) {
JSONObject jsonResp = new JSONObject(response.getBody().asString());
partnerId = jsonResp.getJSONObject("response").getString("partnerId");

step.getScenario().getOidcPmsProp().put("partnerId", partnerId);
}

// Upload CA Call
Expand All @@ -212,12 +193,13 @@ public void run() throws RigInternalError, FeatureNotSupportedError {

try {
uploadCACertificate.test(test5);
Response response = uploadCACertificate.response;
response = uploadCACertificate.response;
if (response != null) {
JSONObject jsonResp = new JSONObject(response.getBody().asString());
}

} catch (AuthenticationTestException | AdminTestException e) {
logger.error(e.getMessage());
this.hasError = true;
throw new RigInternalError(e.getMessage());

Expand All @@ -233,12 +215,13 @@ public void run() throws RigInternalError, FeatureNotSupportedError {
test6.setInput(inputForUploadInterCertificate);
try {
uploadInterCertificate.test(test6);
Response response = uploadInterCertificate.response;
response = uploadInterCertificate.response;
if (response != null) {
JSONObject jsonResp = new JSONObject(response.getBody().asString());
}

} catch (AuthenticationTestException | AdminTestException e) {
logger.error(e.getMessage());
this.hasError = true;
throw new RigInternalError(e.getMessage());

Expand All @@ -259,12 +242,14 @@ public void run() throws RigInternalError, FeatureNotSupportedError {

try {
uploadPartnerCertificate.test(test7);
Response response = uploadPartnerCertificate.response;
response = uploadPartnerCertificate.response;
if (response != null) {
JSONObject jsonResp = new JSONObject(response.getBody().asString());
}

} catch (AuthenticationTestException | AdminTestException e) {
logger.error(e.getMessage());
this.hasError = true;
throw new RigInternalError(e.getMessage());

}
Expand All @@ -285,23 +270,18 @@ public void run() throws RigInternalError, FeatureNotSupportedError {
test8.setInput(inputForRequestAPIKeyForAuthPartner);

try {
try {
requestAPIKeyForAuthPartner.test(test8);
} catch (NoSuchAlgorithmException e) {
logger.error(e.getMessage());
}
Response response = requestAPIKeyForAuthPartner.response;
if (response != null) {
JSONObject jsonResp = new JSONObject(response.getBody().asString());
mappingkey = jsonResp.getJSONObject("response").getString("mappingkey");

step.getScenario().getOidcPmsProp().put("mappingkey", partnerId);
}

} catch (AuthenticationTestException | AdminTestException e) {
requestAPIKeyForAuthPartner.test(test8);
} catch (Exception e) {
logger.error(e.getMessage());
this.hasError = true;
throw new RigInternalError(e.getMessage());
}
response = requestAPIKeyForAuthPartner.response;
if (response != null) {
JSONObject jsonResp = new JSONObject(response.getBody().asString());
mappingkey = jsonResp.getJSONObject("response").getString("mappingkey");

step.getScenario().getOidcPmsProp().put("mappingkey", partnerId);
}

// Request API Key For Auth Partner Call
Expand All @@ -318,12 +298,14 @@ public void run() throws RigInternalError, FeatureNotSupportedError {

try {
approveAPIKey.test(test9);
Response response = approveAPIKey.response;
response = approveAPIKey.response;
if (response != null) {
JSONObject jsonResp = new JSONObject(response.getBody().asString());
}

} catch (AdminTestException e) {
logger.error(e.getMessage());
this.hasError = true;
throw new RigInternalError(e.getMessage());

}
Expand All @@ -335,15 +317,14 @@ public void run() throws RigInternalError, FeatureNotSupportedError {

String inputForOidcClient = PacketUtility.getJsonFromTemplate(test11.getInput(), test11.getInputTemplate());

String oidcJwkKey = MosipTestRunner.generateJWKPublicKey();
String oidcJwkKey = AdminTestUtil.generateJWKPublicKey();
// String inputForOidcClient = test11.getInput();
step.getScenario().getOidcPmsProp().put("oidcJwkKey" + step.getScenario().getId(), oidcJwkKey);

if (inputForOidcClient.contains("$OIDCJWKKEY$")) {
inputForOidcClient = inputForOidcClient.replace("$OIDCJWKKEY$", oidcJwkKey);
}

// String inputForOidcClient = test11.getInput();

if (inputForOidcClient.contains("$POLICYID$")) {
inputForOidcClient = inputForOidcClient.replace("$POLICYID$", policyId);
}
Expand All @@ -354,23 +335,18 @@ public void run() throws RigInternalError, FeatureNotSupportedError {
test11.setInput(inputForOidcClient);

try {
try {
oidcClient.test(test11);
} catch (NoSuchAlgorithmException e) {
logger.error(e.getMessage());
}
Response response = oidcClient.response;
if (response != null) {
JSONObject jsonResp = new JSONObject(response.getBody().asString());
clientId = jsonResp.getJSONObject("response").getString("clientId");
step.getScenario().getOidcPmsProp().put("clientId", clientId);
step.getScenario().getOidcClientProp().put("clientId", clientId);
}

} catch (AuthenticationTestException | AdminTestException e) {
oidcClient.test(test11);
} catch (Exception e) {
logger.error(e.getMessage());
this.hasError = true;
throw new RigInternalError(e.getMessage());

}
response = oidcClient.response;
if (response != null) {
JSONObject jsonResp = new JSONObject(response.getBody().asString());
clientId = jsonResp.getJSONObject("response").getString("clientId");
step.getScenario().getOidcPmsProp().put("clientId", clientId);
step.getScenario().getOidcClientProp().put("clientId", clientId);
}

}
Expand Down

0 comments on commit 9ecb147

Please sign in to comment.