Skip to content

Commit

Permalink
You can now configure if unsecured certificates are accepted at robot…
Browse files Browse the repository at this point in the history
… level.

Country attribute 2 is now map to browser lang. You can also force extra parameters at robot level. fix #2368
  • Loading branch information
vertigo17 committed Apr 2, 2022
1 parent b6fdf25 commit 6b0a058
Show file tree
Hide file tree
Showing 16 changed files with 168 additions and 30 deletions.
16 changes: 11 additions & 5 deletions source/src/main/java/org/cerberus/crud/dao/impl/RobotDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public Robot readByKey(String robot) throws CerberusException {
ps -> ps.setString(1, robot),
rs -> loadFromResultSet(rs)
);

//sets the message
return result;
}
Expand Down Expand Up @@ -381,9 +381,9 @@ public AnswerList<Robot> readByCriteria(int start, int amount, String column, St
public Answer create(Robot robot) {
MessageEvent msg = null;
StringBuilder query = new StringBuilder();
query.append("INSERT INTO robot (`robot`, `platform`,`browser`, `version`,`active` , `description`, `useragent`, `screensize`, `ProfileFolder`, `robotdecli`, `lbexemethod`, `type`) ");
query.append("INSERT INTO robot (`robot`, `platform`,`browser`, `version`,`active` , `description`, `useragent`, `screensize`, `ProfileFolder`, `ExtraParam`, `IsAcceptInsecureCerts`, `robotdecli`, `lbexemethod`, `type`) ");

query.append("VALUES (?,?,?,?,?,?,?,?,?,?,?,?)");
query.append("VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");

// Debug message on SQL.
if (LOG.isDebugEnabled()) {
Expand All @@ -403,6 +403,8 @@ public Answer create(Robot robot) {
preStat.setString(i++, robot.getUserAgent());
preStat.setString(i++, robot.getScreenSize());
preStat.setString(i++, robot.getProfileFolder());
preStat.setString(i++, robot.getExtraParam());
preStat.setBoolean(i++, robot.isAcceptInsecureCerts());
preStat.setString(i++, robot.getRobotDecli());
preStat.setString(i++, robot.getLbexemethod());
preStat.setString(i++, robot.getType());
Expand Down Expand Up @@ -486,7 +488,7 @@ public Answer update(Robot robot) {
MessageEvent msg = null;
StringBuilder query = new StringBuilder();
query.append("UPDATE robot SET robot= ? ,");
query.append("platform = ?, browser = ? , version = ?, active=?, description = ?, useragent = ?, screensize = ?, ProfileFolder = ?, robotdecli = ?, lbexemethod = ?, type = ?, dateModif = NOW() ");
query.append("platform = ?, browser = ? , version = ?, active=?, description = ?, useragent = ?, screensize = ?, ProfileFolder = ?, ExtraParam = ?, IsAcceptInsecureCerts = ?, robotdecli = ?, lbexemethod = ?, type = ?, dateModif = NOW() ");
query.append("WHERE robotID = ?");

// Debug message on SQL.
Expand All @@ -507,6 +509,8 @@ public Answer update(Robot robot) {
preStat.setString(cpt++, robot.getUserAgent());
preStat.setString(cpt++, robot.getScreenSize());
preStat.setString(cpt++, robot.getProfileFolder());
preStat.setString(cpt++, robot.getExtraParam());
preStat.setBoolean(cpt++, robot.isAcceptInsecureCerts());
preStat.setString(cpt++, robot.getRobotDecli());
preStat.setString(cpt++, robot.getLbexemethod());
preStat.setString(cpt++, robot.getType());
Expand Down Expand Up @@ -553,10 +557,12 @@ public Robot loadFromResultSet(ResultSet rs) throws SQLException {
String profileFolder = ParameterParserUtil.parseStringParam(rs.getString("ProfileFolder"), "");
String robotDecli = ParameterParserUtil.parseStringParam(rs.getString("robotdecli"), "");
String type = ParameterParserUtil.parseStringParam(rs.getString("type"), "");
String extraParam = ParameterParserUtil.parseStringParam(rs.getString("ExtraParam"), "");
boolean isAcceptInsecureCerts = rs.getBoolean("isAcceptInsecureCerts");

//TODO remove when working in test with mockito and autowired
factoryRobot = new FactoryRobot();
return factoryRobot.create(robotID, robot, platform, browser, version, active, lbexemethod, description, userAgent, screenSize, profileFolder, robotDecli, type);
return factoryRobot.create(robotID, robot, platform, browser, version, active, lbexemethod, description, userAgent, screenSize, profileFolder, extraParam, isAcceptInsecureCerts, robotDecli, type);
}

@Override
Expand Down
20 changes: 20 additions & 0 deletions source/src/main/java/org/cerberus/crud/entity/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class Robot {
private String userAgent;
private String screenSize;
private String profileFolder;
private String extraParam;
private boolean isAcceptInsecureCerts;
private String robotDecli;
private String lbexemethod; // Contain the method used in order to spread the load against all executors of the robot.
private String description;
Expand All @@ -64,6 +66,22 @@ public class Robot {
private List<RobotCapability> capabilitiesDecoded;
private List<RobotExecutor> executors;

public String getExtraParam() {
return extraParam;
}

public void setExtraParam(String extraParam) {
this.extraParam = extraParam;
}

public boolean isAcceptInsecureCerts() {
return isAcceptInsecureCerts;
}

public void setIsAcceptInsecureCerts(boolean isAcceptInsecureCerts) {
this.isAcceptInsecureCerts = isAcceptInsecureCerts;
}

public String getProfileFolder() {
return profileFolder;
}
Expand Down Expand Up @@ -246,6 +264,8 @@ public JSONObject toJson(boolean withChilds, boolean secured) {
result.put("browser", this.getBrowser());
result.put("lbexemethod", this.getLbexemethod());
result.put("type", this.getType());
result.put("isAcceptInsecureCerts", this.isAcceptInsecureCerts());
result.put("extraParam", this.getExtraParam());

if (withChilds) {
// Looping on ** Capabilities **
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,9 @@ public void setSecrets(HashMap<String, String> secrets) {
}

public void appendSecret(String secret) {
this.secrets.put(secret, "");
if (secret != null) {
this.secrets.put(secret, "");
}
}

public void appendSecrets(List<String> secrets) {
Expand Down Expand Up @@ -1185,7 +1187,7 @@ public JSONObject toJson(boolean withChilds) {
result.put("robotExecutor", this.getRobotExecutor());
result.put("robotHost", StringUtil.secureFromSecrets(this.getRobotHost(), this.getSecrets()));
result.put("robotPort", this.getRobotPort());
result.put("url", this.getUrl());
result.put("url", StringUtil.secureFromSecrets(this.getUrl(), this.getSecrets()));
result.put("tag", this.getTag());
result.put("verbose", this.getVerbose());
result.put("status", this.getStatus());
Expand Down Expand Up @@ -1380,7 +1382,7 @@ public JSONObject toJsonV001(String cerberusURL, List<Invariant> prioritiesList,
robotLocal.put("userAgent", this.getUserAgent());
result.put("robot", robotLocal);

result.put("url", this.getUrl());
result.put("url", StringUtil.secureFromSecrets(this.getUrl(), this.getSecrets()));
result.put("tag", this.getTag());
result.put("status", this.getStatus());
result.put("executor", this.getExecutor());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ public interface IFactoryRobot {
* @param description
* @param userAgent
* @param type
* @param profileFolder
* @param extraParam
* @param screenSize
* @param isAcceptInsecureCerts
* @param robotDecli
* @return
*/
Robot create(Integer robotID, String robot, String platform,
String browser, String version, String active, String lbexemethod, String description, String userAgent, String screenSize, String profileFolder, String robotDecli, String type);
String browser, String version, String active, String lbexemethod, String description, String userAgent, String screenSize, String profileFolder, String extraParam, boolean isAcceptInsecureCerts, String robotDecli, String type);

/**
*
Expand All @@ -61,14 +64,16 @@ Robot create(Integer robotID, String robot, String platform,
* @param userAgent userAgent to Use
* @param screenSize
* @param profileFolder
* @param extraParam
* @param isAcceptInsecureCerts
* @param capabilities
* @param executors
* @param robotDecli
* @param type
* @return
*/
Robot create(Integer robotID, String robot, String platform,
String browser, String version, String active, String lbexemethod, String description, String userAgent, String screenSize, String profileFolder,
String browser, String version, String active, String lbexemethod, String description, String userAgent, String screenSize, String profileFolder, String extraParam, boolean isAcceptInsecureCerts,
List<RobotCapability> capabilities, List<RobotExecutor> executors, String robotDecli, String type);

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ public class FactoryRobot implements IFactoryRobot {

@Override
public Robot create(Integer robotID, String robot, String platform,
String browser, String version, String active, String lbexemethod, String description, String userAgent, String screenSize, String profileFolder, String robotDecli, String type) {
Robot r = create(robotID, robot, platform, browser, version, active, lbexemethod, description, userAgent, screenSize, profileFolder, new ArrayList<>(), new ArrayList<>(), robotDecli, type);
String browser, String version, String active, String lbexemethod, String description, String userAgent, String screenSize, String profileFolder, String extraParam, boolean isAcceptInsecureCerts, String robotDecli, String type) {
Robot r = create(robotID, robot, platform, browser, version, active, lbexemethod, description, userAgent, screenSize, profileFolder, extraParam, isAcceptInsecureCerts, new ArrayList<>(), new ArrayList<>(), robotDecli, type);
return r;
}

@Override
public Robot create(Integer robotID, String robot, String platform, String browser, String version, String active, String lbexemethod, String description, String userAgent,
String screenSize, String profileFolder, List<RobotCapability> capabilities, List<RobotExecutor> executors, String robotDecli, String type) {
String screenSize, String profileFolder, String extraParam, boolean isAcceptInsecureCerts, List<RobotCapability> capabilities, List<RobotExecutor> executors, String robotDecli, String type) {
Robot newRobot = new Robot();
newRobot.setRobotID(robotID);
newRobot.setRobot(robot);
Expand All @@ -59,6 +59,8 @@ public Robot create(Integer robotID, String robot, String platform, String brows
newRobot.setProfileFolder(profileFolder);
newRobot.setRobotDecli(robotDecli);
newRobot.setType(type);
newRobot.setIsAcceptInsecureCerts(isAcceptInsecureCerts);
newRobot.setExtraParam(extraParam);
return newRobot;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,10 @@ public ArrayList<String> getSqlDocumentation() {
b.append(",('robot','screensize','','fr','Taille d\\'écran','Cette valeur correspond à la taille d\\'écran qui sera utilisé lors de l\\'execution.<br><br>Les valeurs sont définies dans la table d\\'invariant et peuvent être complétées si besoin via la page d\\'invariant.<br>Les valeur doivent être deux entiers séparé par une <b>*</b>.<br><i>Par Example : 1024*768</i><br><br>Pour ajouter de nouvelles valeurs, contactez votre administrateur Cerberus.',NULL)");
b.append(",('robot','useragent','','en','User Agent','User Agent of the robot.',NULL)");
b.append(",('robot','useragent','','fr','User Agent','User Agent du Robot.',NULL)");
b.append(",('robot','IsAcceptInsecureCerts','','en','Accept Insecure Certs','Accept any insecured certificate.',NULL)");
b.append(",('robot','IsAcceptInsecureCerts','','fr','Accepter Certificats','Accepte les certificats invalides.',NULL)");
b.append(",('robot','ExtraParam','','en','Extra Parameters','Extra parameters sent to the robot.',NULL)");
b.append(",('robot','ExtraParam','','fr','Parametres additionnels','Parametres additionnel envoyé au robot.',NULL)");
b.append(",('robot','ProfileFolder','','en','Profile Folder','Profile Folder of the robot (user data or profile). That allow to avoid starting all testcases from an empty user session.',NULL)");
b.append(",('robot','ProfileFolder','','fr','Dossier du Profil Utilisateur','Repertoire contenant le profile de l\\'utilisateur. Definir ce parametre permet de lancer des tests avec un profil utilisateur specific (sans repartir d\\'une session vide à chaque execution)',NULL)");
b.append(",('robot','version','','en','Version','Brower Version of the robot.',NULL)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ public TestCaseExecution startExecution(TestCaseExecution tCExecution) throws Ce
*
*/
LOG.debug("Checking if connectivity parameters are manual or automatic from the database. '" + tCExecution.getManualURL() + "'");
String appURL = "";
if (tCExecution.getManualURL() == 1) {
LOG.debug("Execution will be done with manual application connectivity setting.");
if (StringUtil.isNullOrEmpty(tCExecution.getMyHost())) {
Expand All @@ -271,7 +272,8 @@ public TestCaseExecution startExecution(TestCaseExecution tCExecution) throws Ce
cea = this.factorycountryEnvironmentParameters.create(tCExecution.getApplicationObj().getSystem(), tCExecution.getCountry(), tCExecution.getEnvironment(), tCExecution.getApplicationObj().getApplication(), tCExecution.getMyHost(), "", tCExecution.getMyContextRoot(), tCExecution.getMyLoginRelativeURL(), "", "", "", "", CountryEnvironmentParameters.DEFAULT_POOLSIZE, "", "");
cea.setIp(tCExecution.getMyHost());
cea.setUrl(tCExecution.getMyContextRoot());
String appURL = StringUtil.getURLFromString(cea.getIp(), cea.getUrl(), "", "");
appURL = StringUtil.getURLFromString(cea.getIp(), cea.getUrl(), "", "");
tCExecution.appendSecret(StringUtil.getPasswordFromUrl(appURL));
tCExecution.setUrl(appURL);
// If domain is empty we guess it from URL.
if (StringUtil.isNullOrEmpty(cea.getDomain())) {
Expand Down Expand Up @@ -316,8 +318,9 @@ public TestCaseExecution startExecution(TestCaseExecution tCExecution) throws Ce
cea.setUrlLogin(tCExecution.getMyLoginRelativeURL());
}
}

tCExecution.setUrl(StringUtil.getURLFromString(cea.getIp(), cea.getUrl(), "", ""));
appURL = StringUtil.getURLFromString(cea.getIp(), cea.getUrl(), "", "");
tCExecution.appendSecret(StringUtil.getPasswordFromUrl(appURL));
tCExecution.setUrl(appURL);
if ("GUI".equals(tCExecution.getApplicationObj().getType())) {
// Domain calculation only make sense for Web applications.
// If domain is empty we guess it from URL.
Expand Down
Loading

0 comments on commit 6b0a058

Please sign in to comment.