Skip to content

Commit

Permalink
Merge pull request #108 from neeharikatech/develop
Browse files Browse the repository at this point in the history
Develop - user creation and issues fixed
  • Loading branch information
neeharikatech authored Aug 1, 2022
2 parents 170a11b + 8735c6f commit dce80ef
Show file tree
Hide file tree
Showing 14 changed files with 343 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package io.mosip.ivv.e2e.methods;

import static io.restassured.RestAssured.given;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;

import javax.ws.rs.core.MediaType;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONObject;
import org.testng.Reporter;

import io.mosip.admin.fw.util.AdminTestException;
import io.mosip.admin.fw.util.AdminTestUtil;
import io.mosip.admin.fw.util.TestCaseDTO;
import io.mosip.authentication.fw.precon.JsonPrecondtion;
import io.mosip.authentication.fw.util.AuthPartnerProcessor;
import io.mosip.authentication.fw.util.AuthenticationTestException;
import io.mosip.ivv.core.base.StepInterface;
import io.mosip.ivv.core.exceptions.RigInternalError;
import io.mosip.ivv.e2e.constant.E2EConstants;
import io.mosip.ivv.orchestrator.BaseTestCaseUtil;
import io.mosip.ivv.orchestrator.TestRunner;
import io.mosip.testscripts.BioAuth;
import io.restassured.response.Response;

public class OperatorOnboardAuthentication extends BaseTestCaseUtil implements StepInterface {
static Logger logger = Logger.getLogger(OperatorOnboardAuthentication.class);
private static final String BIOMETRIC_FACE = "regproc/OperatorOnboardAuth/operatorOnboardAuth.yml";
Properties deviceProp =null;
Properties uinResidentDataPathFinalProps = new Properties();
BioAuth bioAuth = new BioAuth();
String bioResponse = null;

@Override
public void run() throws RigInternalError {
AuthPartnerProcessor.startProcess();
//uinPersonaProp.put("8497438207", "C:\\Users\\NEEHAR~1.GAR\\AppData\\Local\\Temp\\residents_11835704006002908658\\5645168410.json");
List<String> modalityList = new ArrayList<>();
String personFilePathvalue = null;
String deviceInfoFilePath = null;
String uins = null;
List<String> uinList = null;
if (step.getParameters() == null || step.getParameters().isEmpty() || step.getParameters().size() < 1) {
logger.error("Parameter is missing from DSL step");
throw new RigInternalError("Modality paramter is missing in step: " + step.getName());
} else {
deviceInfoFilePath = step.getParameters().get(0);
if (!StringUtils.isBlank(deviceInfoFilePath)) {
deviceInfoFilePath = TestRunner.getExternalResourcePath()
+ props.getProperty("ivv.path.deviceinfo.folder") + deviceInfoFilePath + ".properties";
deviceProp = AdminTestUtil.getproperty(deviceInfoFilePath);
} else
throw new RigInternalError("deviceInfo file path Parameter is missing from DSL step");
}
if (step.getParameters().size() == 2) {
uins = step.getParameters().get(1);
if (!StringUtils.isBlank(uins))
uinList = new ArrayList<>(Arrays.asList(uins.split("@@")));
} else if (step.getParameters().size() == 3) { // e2e_bioAuthentication(faceDevice,$$uin,$$personaFilePath)
uins = step.getParameters().get(1);
String _personaFilePath = step.getParameters().get(2);
if (uins.startsWith("$$") && _personaFilePath.startsWith("$$")) {
uins = step.getScenario().getVariables().get(uins);
_personaFilePath = step.getScenario().getVariables().get(_personaFilePath);
uinList = new ArrayList<>();
uinList.add(uins);
uinPersonaProp.put(uins, _personaFilePath);
}
}
else
uinList = new ArrayList<>(uinPersonaProp.stringPropertyNames());

for (String uin : uinList) {



if (uinPersonaProp.containsKey(uin))
personFilePathvalue = uinPersonaProp.getProperty(uin);
else
throw new RigInternalError("Persona doesn't exist for the given UIN " + uin);

String bioType=null, bioSubType=null;

String modalityToLog = null;
String modalityKeyTogetBioValue = null;
if(deviceProp != null) {
bioType= deviceProp.getProperty("bioType");

bioSubType= deviceProp.getProperty("bioSubType");
switch(bioType) {
case E2EConstants.FACEBIOTYPE:
modalityList.add(E2EConstants.FACEFETCH);
modalityToLog = bioType;
modalityKeyTogetBioValue = E2EConstants.FACEFETCH;
break;
case E2EConstants.IRISBIOTYPE:
modalityList.add(E2EConstants.IRISFETCH);
modalityToLog = bioSubType+"_"+bioType;
modalityKeyTogetBioValue = (bioSubType.equalsIgnoreCase("left"))? E2EConstants.LEFT_EYE:E2EConstants.RIGHT_EYE;
break;
case E2EConstants.FINGERBIOTYPE:
modalityList.add(E2EConstants.FINGERFETCH);
modalityToLog = bioSubType;
modalityKeyTogetBioValue = bioSubType;
break;
default:
throw new RigInternalError("Given BIO Type in device property file is not valid");
}
}

/*
deviceInfoFilePath = TestRunner.getExternalResourcePath()
+ props.getProperty("ivv.path.deviceinfo.folder") + "faceDevice" + ".properties";
deviceProp = AdminTestUtil.getproperty(deviceInfoFilePath);
String uin="8497438207";
personFilePathvalue = uinPersonaProp.getProperty(uin);
String modalityToLog = null;
String modalityKeyTogetBioValue = null;
modalityList.add(E2EConstants.FACEFETCH);
modalityToLog = "FACE";
modalityKeyTogetBioValue = "face_encrypted";
*/
bioResponse = packetUtility.retrieveBiometric(personFilePathvalue, modalityList);

String fileName = BIOMETRIC_FACE;
bioAuth.isInternal = false;
Object[] casesList = bioAuth.getYmlTestData(fileName);

if (bioResponse != null && !bioResponse.isEmpty() && modalityKeyTogetBioValue!= null) {
String bioValue = JsonPrecondtion.getValueFromJson(bioResponse, modalityKeyTogetBioValue);
if(bioValue== null || bioValue.length()<100)
throw new RigInternalError("Not able to get the bio value for field "+modalityToLog+" from persona");
for (Object object : casesList) {
TestCaseDTO test = (TestCaseDTO) object;
packetUtility.operatorOnboardAuth(modalityToLog, bioValue, "dsl1", test, bioAuth,"USERID",deviceProp);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ public void run() throws RigInternalError {
case "ADD_User":
HashMap<String, List<String>> attrmap=new HashMap<String, List<String>>();
List<String> list=new ArrayList<String>();
list.add("11000000");
attrmap.put("individualid", list);
String val=map.get("$$uin")!=null ?map.get("$$uin") : "11000000";
list.add(val);
attrmap.put("individualid",list);
KeycloakUserManager.removeUser(user);
KeycloakUserManager.createUsers(user, pwd,"roles", attrmap);
HashMap<String, String> userdetails=new HashMap<String, String>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1245,4 +1245,49 @@ public Response putReqestWithCookiesAndNoBody(String url, String token, String o
return puttResponse;
}

public void operatorOnboardAuth(String modility, String bioValue, String user, TestCaseDTO test,
BioAuth bioAuth, String individualIdType,Properties deviceProps ) throws RigInternalError {

test.setEndPoint(test.getEndPoint().replace("$PartnerKey$", deviceProps.getProperty("partnerKey")));
String input = test.getInput();
input = JsonPrecondtion.parseAndReturnJsonContent(input, user, "individualId");
input = JsonPrecondtion.parseAndReturnJsonContent(input, deviceProps.getProperty("bioSubType"),
"identityRequest.bioSubType");
input = JsonPrecondtion.parseAndReturnJsonContent(input, deviceProps.getProperty("bioType"),
"identityRequest.bioType");
input = JsonPrecondtion.parseAndReturnJsonContent(input, deviceProps.getProperty("deviceCode"),
"identityRequest.deviceCode");
input = JsonPrecondtion.parseAndReturnJsonContent(input, deviceProps.getProperty("deviceProviderID"),
"identityRequest.deviceProviderID");
input = JsonPrecondtion.parseAndReturnJsonContent(input, deviceProps.getProperty("deviceServiceID"),
"identityRequest.deviceServiceID");
input = JsonPrecondtion.parseAndReturnJsonContent(input, deviceProps.getProperty("deviceServiceVersion"),
"identityRequest.deviceServiceVersion");
input = JsonPrecondtion.parseAndReturnJsonContent(input, deviceProps.getProperty("deviceProvider"),
"identityRequest.deviceProvider");
input = JsonPrecondtion.parseAndReturnJsonContent(input, deviceProps.getProperty("deviceSubType"),
"identityRequest.deviceSubType");
input = JsonPrecondtion.parseAndReturnJsonContent(input, deviceProps.getProperty("make"),
"identityRequest.make");
input = JsonPrecondtion.parseAndReturnJsonContent(input, deviceProps.getProperty("model"),
"identityRequest.model");
input = JsonPrecondtion.parseAndReturnJsonContent(input, deviceProps.getProperty("serialNo"),
"identityRequest.serialNo");
input = JsonPrecondtion.parseAndReturnJsonContent(input, deviceProps.getProperty("type"),
"identityRequest.type");
input = JsonPrecondtion.parseAndReturnJsonContent(input, individualIdType,
"individualIdType");
input = JsonPrecondtion.parseAndReturnJsonContent(input, bioValue, "identityRequest.bioValue");
test.setInput(input);
Reporter.log("<b><u>" + test.getTestCaseName() + "_" + modility + "</u></b>");

try {
bioAuth.test(test);
} catch (AuthenticationTestException | AdminTestException e) {
throw new RigInternalError(e.getMessage());
} finally {
AuthPartnerProcessor.authPartherProcessor.destroyForcibly();

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ public class TestResources {
public static void copyPreRegTestResource() {
try {
File source = new File(TestResources.getGlobalResourcePaths() + "/preReg");
File source2 = new File(TestResources.getGlobalResourcePaths()+"/config");
File source3 = new File(TestResources.getGlobalResourcePaths() + "/idaData");

File source4 = new File(TestResources.getGlobalResourcePaths() + "/regproc");
File source6 = new File(TestResources.getGlobalResourcePaths()+"/syncdata");
File source7 = new File(TestResources.getGlobalResourcePaths()+"/ivv_masterdata");
File destination = new File(TestResources.getGlobalResourcePaths() + "/"+TestResources.resourceFolderName);
FileUtils.copyDirectoryToDirectory(source, destination);
String path=TestResources.getGlobalResourcePaths().replace("classes", "test-classes");
File source2 = new File(TestResources.getGlobalResourcePaths()+"/config");

File destination2 = new File(path);
FileUtils.copyDirectoryToDirectory(source2, destination2);
FileUtils.copyDirectoryToDirectory(source, destination2);
Expand All @@ -29,6 +30,8 @@ public static void copyPreRegTestResource() {
FileUtils.copyDirectoryToDirectory(source6, destination);
FileUtils.copyDirectoryToDirectory(source7, destination2);
FileUtils.copyDirectoryToDirectory(source7, destination);
FileUtils.copyDirectoryToDirectory(source4, destination2);
FileUtils.copyDirectoryToDirectory(source4, destination);
logger.info("Copied the preReg test resource successfully");
} catch (Exception e) {
logger.error("Exception occured while copying the file: "+e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public static void extractResourceFromJar() {
getListOfFilesFromJarAndCopyToExternalResource("idaData/");
getListOfFilesFromJarAndCopyToExternalResource("ivv_masterdata/");
getListOfFilesFromJarAndCopyToExternalResource("syncdata/");

getListOfFilesFromJarAndCopyToExternalResource("regproc/");
}

public static void getListOfFilesFromJarAndCopyToExternalResource(String key) {
Expand Down Expand Up @@ -163,6 +165,7 @@ private static void copyTestResources() {
TestResources.copyTestResource("/idaData");
TestResources.copyTestResource("/ivv_masterdata");
TestResources.copyTestResource("/syncdata");
TestResources.copyTestResource("/regproc");
}

public static String getExternalResourcePath() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ center_id=10002
#supervisor_id=110126
#supervisor_id=mosipautouser
preconfigured_otp=111111
#partnerKey=Kc0w35WMYCTqlnaKqmnW5uu3Z3hrDS0tYHAnSw47a5H6NTs6Bm/4810/212959
#partnerKey=0IOTJiWATFqSs0vwZe6hYf79A0ZKfvlSvODuq8gwFK5iw33sVw/1634039512502/186655
# qa-triple
partnerKey=4bpu3vQiUnkhvBIxM7HhmXYPmAe6W54gXTJGKAkqITKH5oYlXJ/117/236611

# qa4
partnerKey=ZiwWYu89gkZOIatPQkPRcx5iUJX9WQNjjn3v4S0yzMXFdb7LcU/870/458517

# dev3
#partnerKey=hxzYi809LXcSbJViBBgjrvT4hI3FWmCSb3byuYWhnZdssm3PCQ/646/774354
Loading

0 comments on commit dce80ef

Please sign in to comment.