Best Cerberus-source code snippet using org.cerberus.util.ParameterParserUtil.parseStringParamAndSanitize
Source:RunTestCase.java
...119 int getSeleniumLog = 0;120 String manualExecution = "N";121 List<RobotCapability> capabilities = null;122 //Test123 String test = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("Test"), "");124 String testCase = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("TestCase"), "");125 String country = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("Country"), "");126 String environment = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("Environment"), "");127 //Test Dev Environment128 boolean manualURL = ParameterParserUtil.parseBooleanParam(request.getParameter("manualURL"), false);129 String myHost = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("myhost"), "");130 String myContextRoot = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("mycontextroot"), "");131 String myLoginRelativeURL = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("myloginrelativeurl"), "");132 //TODO find another solution133 myLoginRelativeURL = myLoginRelativeURL.replace("=", "=");134 String myEnvData = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("myenvdata"), "");135 //Execution136 String tag = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("Tag"), "");137 String outputFormat = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("outputformat"), "compact");138 int screenshot = ParameterParserUtil.parseIntegerParam(request.getParameter("screenshot"), 1);139 int verbose = ParameterParserUtil.parseIntegerParam(request.getParameter("verbose"), 0);140 timeout = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("timeout"), "");141 synchroneous = ParameterParserUtil.parseBooleanParam(request.getParameter("synchroneous"), false);142 getPageSource = ParameterParserUtil.parseIntegerParam(request.getParameter("pageSource"), 1);143 getSeleniumLog = ParameterParserUtil.parseIntegerParam(request.getParameter("seleniumLog"), 1);144 manualExecution = ParameterParserUtil.parseStringParam(request.getParameter("manualExecution"), "N");145 int numberOfRetries = ParameterParserUtil.parseIntegerParam(request.getParameter("retries"), 0);146 screenSize = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("screenSize"), "");147 robot = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("robot"), "");148 ss_ip = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("ss_ip"), "");149 ss_p = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("ss_p"), "");150 browser = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("Browser"), ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("browser"), ""));151 version = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("version"), "");152 platform = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("platform"), "");153 // hidden parameters.154 long idFromQueue = ParameterParserUtil.parseIntegerParam(request.getParameter("IdFromQueue"), 0);155 String executor = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("executor"), ParameterParserUtil.parseStringParamAndSanitize(request.getRemoteUser(), null));156 String helpMessage = "\nThis servlet is used to start the execution of a test case.\n"157 + "Parameter list :\n"158 + "- Test [mandatory] : Test to execute. [" + test + "]\n"159 + "- TestCase [mandatory] : Test Case reference to execute. [" + testCase + "]\n"160 + "- Country [mandatory] : Country where the test case will execute. [" + country + "]\n"161 + "- Environment : Environment where the test case will execute. This parameter is mandatory only if manualURL is not set to Y. [" + environment + "]\n"162 + "- robot : robot name on which the test will be executed. [" + robot + "]\n"163 + "- ss_ip : Host of the Robot where the test will be executed. (Can be overwriten if robot is defined) [" + ss_ip + "]\n"164 + "- ss_p : Port of the Robot. (Can be overwriten if robot is defined) [" + ss_p + "]\n"165 + "- browser : Browser to use for the execution. (Can be overwriten if robot is defined) [" + browser + "]\n"166 + "- version : Version to use for the execution. (Can be overwriten if robot is defined) [" + version + "]\n"167 + "- platform : Platform to use for the execution. (Can be overwriten if robot is defined) [" + platform + "]\n"168 + "- screenSize : Size of the screen to set for the execution. [" + screenSize + "]\n"169 + "- manualURL : Activate or not the Manual URL of the application to execute. If activated the 4 parameters after (myhost, mycontextroot, myloginrelativeurl, myenvdata) are necessary. [" + manualURL + "]\n"...
Source:DuplicateTestCase.java
...133 ServletUtil.servletStart(request);134 /**135 * Parsing and securing all required parameters.136 */137 String test = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("test"), "");138 String testCase = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("testCase"), "");139 String originalTest = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("originalTest"), "");140 String originalTestCase = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("originalTestCase"), null);141 /**142 * Checking all constrains before calling the services.143 */144 if (StringUtil.isNullOrEmpty(test) || StringUtil.isNullOrEmpty(testCase)145 || StringUtil.isNullOrEmpty(originalTest) || originalTestCase != null) {146 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);147 msg.setDescription(msg.getDescription().replace("%ITEM%", "Test Case")148 .replace("%OPERATION%", "Duplicate")149 .replace("%REASON%", "mandatory fields are missing."));150 ans.setResultMessage(msg);151 } else {152 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());153 ITestCaseService testCaseService = appContext.getBean(ITestCaseService.class);154 ITestCaseCountryService testCaseCountryService = appContext.getBean(ITestCaseCountryService.class);155 ITestCaseCountryPropertiesService testCaseCountryPropertiesService = appContext.getBean(ITestCaseCountryPropertiesService.class);156 ITestCaseStepService testCaseStepService = appContext.getBean(ITestCaseStepService.class);157 ITestCaseStepActionService testCaseStepActionService = appContext.getBean(ITestCaseStepActionService.class);158 ITestCaseStepActionControlService testCaseStepActionControlService = appContext.getBean(ITestCaseStepActionControlService.class);159 ITestCaseLabelService testCaseLabelService = appContext.getBean(ITestCaseLabelService.class);160 AnswerItem originalTestAI = testCaseService.readByKey(originalTest, originalTestCase);161 AnswerItem targetTestAI = testCaseService.readByKey(test, testCase);162 TestCase originalTC = (TestCase) originalTestAI.getItem();163 TestCase targetTC = (TestCase) targetTestAI.getItem();164 if (!(originalTestAI.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && originalTestAI.getItem() != null)) {165 /**166 * Object could not be found. We stop here and report the error.167 */168 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);169 msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase")170 .replace("%OPERATION%", "Duplicate")171 .replace("%REASON%", "TestCase does not exist."));172 ans.setResultMessage(msg);173 } else /**174 * The service was able to perform the query and confirm the object175 * exist, then we can update it.176 */177 if (!request.isUserInRole("Test")) { // We cannot update the testcase if the user is not at least in Test role.178 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);179 msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase")180 .replace("%OPERATION%", "Duplicate")181 .replace("%REASON%", "Not enought privilege to duplicate the testcase. You must belong to Test Privilege."));182 ans.setResultMessage(msg);183 } else if (targetTC != null) { // If target Test Case already exists.184 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);185 msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase")186 .replace("%OPERATION%", "Duplicate")187 .replace("%REASON%", "The test case you try to create already exists. Please define a test/testcase that is not already existing."));188 ans.setResultMessage(msg);189 } else {190 getInfo(request, originalTC);191 //Update object with new testcase id and insert it in db192 originalTC.setTest(test);193 originalTC.setTestCase(testCase);194 ans = testCaseService.create(originalTC);195 List<TestCaseCountry> countryList = new ArrayList();196 countryList = testCaseCountryService.findTestCaseCountryByTestTestCase(originalTest, originalTestCase);197 boolean success = true;198 if (!countryList.isEmpty()) {199 ans = testCaseCountryService.duplicateList(countryList, test, testCase);200 }201 202// List<TestCaseCountry> countryList = getCountryList(test, testCase, request);203// boolean success = false;204// if (countryList.isEmpty()) {205// success = true;206// } else {207// success = testCaseCountryService.insertListTestCaseCountry(countryList);208// }209 List<TestCaseCountryProperties> tccpList = new ArrayList();210 if (!countryList.isEmpty() && ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && success) {211 tccpList = testCaseCountryPropertiesService.findListOfPropertyPerTestTestCase(originalTest, originalTestCase);212 if (!tccpList.isEmpty()) {213 ans = testCaseCountryPropertiesService.duplicateList(tccpList, test, testCase);214 }215 }216 List<TestCaseStep> tcsList = new ArrayList();217 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && success) {218 tcsList = testCaseStepService.getListOfSteps(originalTest, originalTestCase);219 if (!tcsList.isEmpty()) {220 ans = testCaseStepService.duplicateList(tcsList, test, testCase);221 }222 }223 List<TestCaseStepAction> tcsaList = new ArrayList();224 if (!tcsList.isEmpty() && ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && success) {225 tcsaList = testCaseStepActionService.findTestCaseStepActionbyTestTestCase(originalTest, originalTestCase);226 if (!tcsaList.isEmpty()) {227 ans = testCaseStepActionService.duplicateList(tcsaList, test, testCase);228 }229 }230 if (!tcsList.isEmpty() && !tcsaList.isEmpty() && ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && success) {231 List<TestCaseStepActionControl> tcsacList = testCaseStepActionControlService.findControlByTestTestCase(originalTest, originalTestCase);232 if (!tcsacList.isEmpty()) {233 ans = testCaseStepActionControlService.duplicateList(tcsacList, test, testCase);234 }235 }236 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && success) {237 List<TestCaseLabel> tclList = testCaseLabelService.readByTestTestCase(originalTest, originalTestCase).getDataList();238 if (!tclList.isEmpty()) {239 ans = testCaseLabelService.duplicateList(tclList, test, testCase);240 }241 }242 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())243 && success) {244 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);245 msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase")246 .replace("%OPERATION%", "Duplicate"));247 ans.setResultMessage(msg);248 /**249 * Update was successful. Adding Log entry.250 */251 ILogEventService logEventService = appContext.getBean(LogEventService.class);252 logEventService.createForPrivateCalls("/DuplicateTestCase", "CREATE", "Create testcase : ['" + test + "'|'" + testCase + "']", request);253 }254 }255 }256 /**257 * Formating and returning the json result.258 */259 jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());260 jsonResponse.put("message", ans.getResultMessage().getDescription());261 response.getWriter().print(jsonResponse);262 response.getWriter().flush();263 }264 private TestCase getInfo(HttpServletRequest request, TestCase tc) throws CerberusException, JSONException, UnsupportedEncodingException {265 String charset = request.getCharacterEncoding();266 // Parameter that are already controled by GUI (no need to decode) --> We SECURE them267 tc.setImplementer(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("imlementer"), tc.getImplementer()));268 tc.setUsrCreated(request.getUserPrincipal().getName());269 tc.setUsrModif(request.getUserPrincipal().getName());270 if (!Strings.isNullOrEmpty(request.getParameter("project"))) {271 tc.setProject(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("project"), tc.getProject()));272 } else if (request.getParameter("project") != null && request.getParameter("project").isEmpty()) {273 tc.setProject(null);274 } else {275 tc.setProject(tc.getProject());276 }277 tc.setTest(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("test"), tc.getTest()));278 tc.setApplication(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("application"), tc.getApplication()));279 tc.setActiveQA(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("activeQA"), tc.getActiveQA()));280 tc.setActiveUAT(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("activeUAT"), tc.getActiveUAT()));281 tc.setActivePROD(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("activeProd"), tc.getActivePROD()));282 tc.setTcActive(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("active"), tc.getTcActive()));283 tc.setFromBuild(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("fromSprint"), tc.getFromBuild()));284 tc.setFromRev(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("fromRev"), tc.getFromRev()));285 tc.setToBuild(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("toSprint"), tc.getToBuild()));286 tc.setToRev(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("toRev"), tc.getToRev()));287 tc.setTargetBuild(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("targetSprint"), tc.getTargetBuild()));288 tc.setTargetRev(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("targetRev"), tc.getTargetRev()));289 tc.setPriority(ParameterParserUtil.parseIntegerParam(request.getParameter("priority"), tc.getPriority()));290 // Parameter that needs to be secured --> We SECURE+DECODE them291 tc.setTestCase(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("testCase"), tc.getTestCase(), charset));292 tc.setTicket(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("ticket"), tc.getTicket(), charset));293 tc.setOrigine(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("origin"), tc.getOrigine(), charset));294 tc.setGroup(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("group"), tc.getGroup(), charset));295 tc.setStatus(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("status"), tc.getStatus(), charset));296 tc.setDescription(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("shortDesc"), tc.getDescription(), charset));297 tc.setBugID(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("bugId"), tc.getBugID(), charset));298 tc.setComment(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("comment"), tc.getComment(), charset));299 tc.setFunction(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("function"), tc.getFunction(), charset));300 // Parameter that we cannot secure as we need the html --> We DECODE them301 tc.setBehaviorOrValueExpected(ParameterParserUtil.parseStringParamAndDecode(request.getParameter("behaviorOrValueExpected"), tc.getBehaviorOrValueExpected(), charset));302 tc.setHowTo(ParameterParserUtil.parseStringParamAndDecode(request.getParameter("howTo"), tc.getHowTo(), charset));303 return tc;304 }305 private List<TestCaseCountry> getCountryList(String targetTest, String targetTestCase, HttpServletRequest request) throws CerberusException, JSONException, UnsupportedEncodingException {306 List<TestCaseCountry> countryList = new ArrayList();307 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());308 IInvariantService invariantService = appContext.getBean(InvariantService.class);309 IFactoryTestCaseCountry testCaseCountryFactory = appContext.getBean(IFactoryTestCaseCountry.class);310 AnswerList answer = invariantService.readByIdname("COUNTRY"); //TODO: handle if the response does not turn ok311 for (Invariant country : (List<Invariant>) answer.getDataList()) {312 String countrySelected = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter(country.getValue()), "");313 if ("".equals(countrySelected)) {314 countryList.add(testCaseCountryFactory.create(targetTest, targetTestCase, country.getValue()));315 }316 }317 return countryList;318 }319}...
Source:UpdateTestCase.java
...94 ServletUtil.servletStart(request);95 /**96 * Parsing and securing all required parameters.97 */98 String test = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("test"), "");99 String testCase = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("testCase"), null);100 String keyTest = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("originalTest"), "");101 String keyTestCase = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("originalTestCase"), null);102 // Prepare the final answer.103 MessageEvent msg1 = new MessageEvent(MessageEventEnum.GENERIC_OK);104 Answer finalAnswer = new Answer(msg1);105 /**106 * Checking all constrains before calling the services.107 */108 if ((StringUtil.isNullOrEmpty(test)) || (StringUtil.isNullOrEmpty(testCase)) || (StringUtil.isNullOrEmpty(keyTest)) || (StringUtil.isNullOrEmpty(keyTestCase))) {109 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);110 msg.setDescription(msg.getDescription().replace("%ITEM%", "Test Case")111 .replace("%OPERATION%", "Update")112 .replace("%REASON%", "mandatory fields (test, testcase) are missing."));113 finalAnswer.setResultMessage(msg);114 } else {115 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());116 testCaseService = appContext.getBean(ITestCaseService.class);117 testCaseLabelService = appContext.getBean(ITestCaseLabelService.class);118 testCaseLabelFactory = appContext.getBean(IFactoryTestCaseLabel.class);119 testCaseCountryService = appContext.getBean(ITestCaseCountryService.class);120 testCaseCountryFactory = appContext.getBean(IFactoryTestCaseCountry.class);121 AnswerItem resp = testCaseService.readByKey(keyTest, keyTestCase);122 TestCase tc = (TestCase) resp.getItem();123 if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem() != null)) {124 /**125 * Object could not be found. We stop here and report the error.126 */127 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);128 msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase")129 .replace("%OPERATION%", "Update")130 .replace("%REASON%", "TestCase does not exist."));131 finalAnswer.setResultMessage(msg);132 } else /**133 * The service was able to perform the query and confirm the object134 * exist, then we can update it.135 */136 {137 if (!testCaseService.hasPermissionsUpdate(tc, request)) { // We cannot update the testcase if the user is not at least in Test role.138 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);139 msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase")140 .replace("%OPERATION%", "Update")141 .replace("%REASON%", "Not enought privilege to update the testcase. You must belong to Test Privilege or even TestAdmin in case the test is in WORKING status."));142 finalAnswer.setResultMessage(msg);143 } else {144 tc = getTestCaseFromRequest(request, tc);145 tc.setTestCaseVersion(tc.getTestCaseVersion()+1);146 // Update testcase147 ans = testCaseService.update(keyTest, keyTestCase, tc);148 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);149 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {150 /**151 * Update was successful. Adding Log entry.152 */153 ILogEventService logEventService = appContext.getBean(LogEventService.class);154 logEventService.createForPrivateCalls("/UpdateTestCase", "UPDATE", "Update testcase : ['" + keyTest + "'|'" + keyTestCase + "'] " + "version : "+tc.getTestCaseVersion(), request);155 // Update labels156 if (request.getParameter("labelList") != null) {157 JSONArray objLabelArray = new JSONArray(request.getParameter("labelList"));158 List<TestCaseLabel> labelList = new ArrayList();159 labelList = getLabelListFromRequest(request, appContext, test, testCase, objLabelArray);160 // Update the Database with the new list.161 ans = testCaseLabelService.compareListAndUpdateInsertDeleteElements(tc.getTest(), tc.getTestCase(), labelList);162 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);163 }164 // Update Countries165 if (request.getParameter("countryList") != null) {166 JSONArray objCountryArray = new JSONArray(request.getParameter("countryList"));167 List<TestCaseCountry> tccList = new ArrayList();168 tccList = getCountryListFromRequest(request, appContext, test, testCase, objCountryArray);169 // Update the Database with the new list.170 ans = testCaseCountryService.compareListAndUpdateInsertDeleteElements(tc.getTest(), tc.getTestCase(), tccList);171 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);172 }173 }174 }175 }176 }177 /**178 * Formating and returning the json result.179 */180 jsonResponse.put("messageType", finalAnswer.getResultMessage().getMessage().getCodeString());181 jsonResponse.put("message", finalAnswer.getResultMessage().getDescription());182 response.getWriter().print(jsonResponse);183 response.getWriter().flush();184 }185 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">186 /**187 * Handles the HTTP <code>GET</code> method.188 *189 * @param request servlet request190 * @param response servlet response191 * @throws ServletException if a servlet-specific error occurs192 * @throws IOException if an I/O error occurs193 */194 @Override195 protected void doGet(HttpServletRequest request, HttpServletResponse response)196 throws ServletException, IOException {197 try {198 try {199 processRequest(request, response);200 } catch (CerberusException ex) {201 LOG.warn(ex);202 }203 } catch (JSONException ex) {204 LOG.warn(ex);205 }206 }207 /**208 * Handles the HTTP <code>POST</code> method.209 *210 * @param request servlet request211 * @param response servlet response212 * @throws ServletException if a servlet-specific error occurs213 * @throws IOException if an I/O error occurs214 */215 @Override216 protected void doPost(HttpServletRequest request, HttpServletResponse response)217 throws ServletException, IOException {218 try {219 try {220 processRequest(request, response);221 } catch (CerberusException ex) {222 LOG.warn(ex);223 }224 } catch (JSONException ex) {225 LOG.warn(ex);226 }227 }228 /**229 * Returns a short description of the servlet.230 *231 * @return a String containing servlet description232 */233 @Override234 public String getServletInfo() {235 return "Short description";236 }// </editor-fold>237 private TestCase getTestCaseFromRequest(HttpServletRequest request, TestCase tc) throws CerberusException, JSONException, UnsupportedEncodingException {238 String charset = request.getCharacterEncoding();239 // Parameter that are already controled by GUI (no need to decode) --> We SECURE them240 tc.setImplementer(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("implementer"), tc.getImplementer()));241 tc.setUsrModif(request.getUserPrincipal().getName());242 if (!Strings.isNullOrEmpty(request.getParameter("project"))) {243 tc.setProject(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("project"), tc.getProject()));244 } else if (request.getParameter("project") != null && request.getParameter("project").isEmpty()) {245 tc.setProject(null);246 } else {247 tc.setProject(tc.getProject());248 }249 tc.setTest(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("test"), tc.getTest()));250 tc.setApplication(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("application"), tc.getApplication()));251 tc.setActiveQA(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("activeQA"), tc.getActiveQA()));252 tc.setActiveUAT(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("activeUAT"), tc.getActiveUAT()));253 tc.setActivePROD(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("activeProd"), tc.getActivePROD()));254 tc.setTcActive(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("active"), tc.getTcActive()));255 tc.setFromBuild(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("fromSprint"), tc.getFromBuild()));256 tc.setFromRev(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("fromRev"), tc.getFromRev()));257 tc.setToBuild(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("toSprint"), tc.getToBuild()));258 tc.setToRev(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("toRev"), tc.getToRev()));259 tc.setTargetBuild(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("targetSprint"), tc.getTargetBuild()));260 tc.setTargetRev(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("targetRev"), tc.getTargetRev()));261 tc.setConditionOper(ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("conditionOper"), tc.getConditionOper()));262 tc.setPriority(ParameterParserUtil.parseIntegerParam(request.getParameter("priority"), tc.getPriority()));263 // Parameter that needs to be secured --> We SECURE+DECODE them264 tc.setTestCase(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("testCase"), tc.getTestCase(), charset));265 tc.setTicket(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("ticket"), tc.getTicket(), charset));266 tc.setOrigine(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("origin"), tc.getOrigine(), charset));267 tc.setGroup(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("group"), tc.getGroup(), charset));268 tc.setStatus(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("status"), tc.getStatus(), charset));269 // Parameter that we cannot secure as we need the html --> We DECODE them270 tc.setDescription(ParameterParserUtil.parseStringParamAndDecode(request.getParameter("shortDesc"), tc.getDescription(), charset));271 tc.setBehaviorOrValueExpected(ParameterParserUtil.parseStringParamAndDecode(request.getParameter("behaviorOrValueExpected"), tc.getBehaviorOrValueExpected(), charset));272 tc.setHowTo(ParameterParserUtil.parseStringParamAndDecode(request.getParameter("howTo"), tc.getHowTo(), charset));273 tc.setBugID(ParameterParserUtil.parseStringParamAndDecode(request.getParameter("bugId"), tc.getBugID(), charset));274 tc.setComment(ParameterParserUtil.parseStringParamAndDecode(request.getParameter("comment"), tc.getComment(), charset));275 tc.setFunction(ParameterParserUtil.parseStringParamAndDecode(request.getParameter("function"), tc.getFunction(), charset));...
parseStringParamAndSanitize
Using AI Code Generation
1package org.cerberus.util;2import org.apache.commons.lang3.StringUtils;3import org.apache.logging.log4j.LogManager;4import org.apache.logging.log4j.Logger;5public class ParameterParserUtil {6 private static final Logger LOG = LogManager.getLogger(ParameterParserUtil.class);7 public static String parseStringParamAndSanitize(String value, String defaultValue) {8 if (StringUtils.isBlank(value)) {9 return defaultValue;10 }11 return value;12 }13}14package org.cerberus.util;15import org.apache.commons.lang3.StringUtils;16import org.apache.logging.log4j.LogManager;17import org.apache.logging.log4j.Logger;18public class ParameterParserUtil {19 private static final Logger LOG = LogManager.getLogger(ParameterParserUtil.class);20 public static String parseStringParamAndSanitize(String value, String defaultValue) {21 if (StringUtils.isBlank(value)) {22 return defaultValue;23 }24 return value;25 }26}27package org.cerberus.util;28import org.apache.commons.lang3.StringUtils;29import org.apache.logging.log4j.LogManager;30import org.apache.logging.log4j.Logger;31public class ParameterParserUtil {32 private static final Logger LOG = LogManager.getLogger(ParameterParserUtil.class);33 public static String parseStringParamAndSanitize(String value, String defaultValue) {34 if (StringUtils.isBlank(value)) {35 return defaultValue;36 }37 return value;38 }39}40package org.cerberus.util;41import org.apache.commons.lang3.StringUtils;42import org.apache.logging.log4j.LogManager;43import org.apache.logging.log4j.Logger;44public class ParameterParserUtil {45 private static final Logger LOG = LogManager.getLogger(ParameterParserUtil.class);46 public static String parseStringParamAndSanitize(String value, String defaultValue) {47 if (StringUtils.isBlank(value)) {48 return defaultValue;49 }50 return value;51 }52}
parseStringParamAndSanitize
Using AI Code Generation
1import org.cerberus.util.ParameterParserUtil;2public class 3 {3 public static void main(String[] args) {4 String result = ParameterParserUtil.parseStringParamAndSanitize("test", "test");5 System.out.println(result);6 }7}
parseStringParamAndSanitize
Using AI Code Generation
1import org.cerberus.util.ParameterParserUtil;2import org.cerberus.util.StringUtil;3import org.springframework.web.util.HtmlUtils;4public class Test {5 public static void main(String[] args) {6 String str = "Hello World";7 System.out.println(ParameterParserUtil.parseStringParamAndSanitize(str, ""));8 }9}
parseStringParamAndSanitize
Using AI Code Generation
1import org.cerberus.util.ParameterParserUtil;2import org.cerberus.util.StringUtil;3public class 3 {4 public static void main(String[] args) {5 String input = "HelloWorld";6 String output = ParameterParserUtil.parseStringParamAndSanitize(input, "");7 System.out.println(output);8 }9}10import org.cerberus.util.ParameterParserUtil;11import org.cerberus.util.StringUtil;12public class 4 {13 public static void main(String[] args) {14 String input = "HelloWorld";15 String output = ParameterParserUtil.parseStringParamAndSanitize(input, "Hello");16 System.out.println(output);17 }18}19import org.cerberus.util.ParameterParserUtil;20import org.cerberus.util.StringUtil;21public class 5 {22 public static void main(String[] args) {23 String input = "HelloWorld";24 String output = ParameterParserUtil.parseStringParamAndSanitize(input, "HelloWorld");25 System.out.println(output);26 }27}28import org.cerberus.util.ParameterParserUtil;29import org.cerberus.util.StringUtil;30public class 6 {31 public static void main(String[] args) {32 String input = "HelloWorld";33 String output = ParameterParserUtil.parseStringParamAndSanitize(input, "HelloWorld");34 System.out.println(output);35 }36}37import org.cerberus.util.ParameterParserUtil;38import org.cerberus.util.StringUtil;39public class 7 {40 public static void main(String[] args) {41 String input = "HelloWorld";42 String output = ParameterParserUtil.parseStringParamAndSanitize(input, "HelloWorld");43 System.out.println(output);44 }45}
parseStringParamAndSanitize
Using AI Code Generation
1import org.cerberus.util.ParameterParserUtil;2import org.springframework.web.bind.annotation.RequestMapping;3import org.springframework.web.bind.annotation.RequestParam;4import org.springframework.web.bind.annotation.RestController;5import org.springframework.web.servlet.ModelAndView;6public class ParameterParserUtilTest {7 @RequestMapping("/test")8 public ModelAndView test(@RequestParam(value = "test") String test) {9 String sanitizedTest = ParameterParserUtil.parseStringParamAndSanitize(test, "");10 System.out.println("Sanitized test: " + sanit
parseStringParamAndSanitize
Using AI Code Generation
1package org.cerberus.util;2import org.apache.commons.lang3.StringUtils;3public class ParameterParserUtil {4 public static String parseStringParamAndSanitize(String parameter) {5 String result = parameter;6 if (StringUtils.isNotEmpty(parameter)) {7 result = StringUtils.trim(parameter);8 }9 return result;10 }11}12package org.cerberus.util;13import org.apache.commons.lang3.StringUtils;14public class ParameterParserUtil {15 public static boolean parseBooleanParam(String parameter) {16 boolean result = false;17 if (StringUtils.isNotEmpty(parameter)) {18 result = Boolean.parseBoolean(parameter);19 }20 return result;21 }22}23package org.cerberus.util;24import org.apache.commons.lang3.StringUtils;25public class ParameterParserUtil {26 public static int parseIntegerParam(String parameter) {27 int result = 0;28 if (StringUtils.isNotEmpty(parameter)) {29 result = Integer.parseInt(parameter);30 }31 return result;32 }33}34package org.cerberus.util;35import org.apache.commons.lang3.StringUtils;36public class ParameterParserUtil {37 public static int parseIntegerParamAndSanitize(String parameter) {38 int result = 0;39 if (StringUtils.isNotEmpty(parameter)) {
parseStringParamAndSanitize
Using AI Code Generation
1import org.cerberus.util.ParameterParserUtil;2import org.apache.commons.lang.StringEscapeUtils;3import java.io.IOException;4import java.io.PrintWriter;5import java.util.HashMap;6import java.util.Map;7import java.util.Set;8import java.util.Iterator;9import javax.servlet.ServletException;10import javax.servlet.http.HttpServlet;11import javax.servlet.http.HttpServletRequest;12import javax.servlet.http.HttpServletResponse;13public class 3 extends HttpServlet {14public void doGet(HttpServletRequest request, HttpServletResponse response)15throws ServletException, IOException {16response.setContentType("text/html");17PrintWriter out = response.getWriter();18String name = request.getParameter("name");19String name1=ParameterParserUtil.parseStringParamAndSanitize(name,"");20out.println("Welcome "+name1);21}22}23Welcome <script>alert('hi');</script>
parseStringParamAndSanitize
Using AI Code Generation
1import org.cerberus.util.ParameterParserUtil;2import java.util.logging.Logger;3import java.util.logging.Level;4public class 3 {5 public static void main(String[] args) {6 String input = "1 OR 1=1";7 String sanitized = ParameterParserUtil.parseStringParamAndSanitize(input, "");8 System.out.println(sanitized);9 }10}11import org.cerberus.util.ParameterParserUtil;12import java.util.logging.Logger;13import java.util.logging.Level;14public class 4 {15 public static void main(String[] args) {16 String input = "1 OR 1=1";17 String sanitized = ParameterParserUtil.parseStringParamAndSanitize(input, "");18 System.out.println(sanitized);19 }20}21import org.cerberus.util.ParameterParserUtil;22import java.util.logging.Logger;23import java.util.logging.Level;24public class 5 {25 public static void main(String[] args) {26 String input = "1 OR 1=1";27 String sanitized = ParameterParserUtil.parseStringParamAndSanitize(input, "");28 System.out.println(sanitized);29 }30}31import org.cerberus.util.ParameterParserUtil;32import java.util.logging.Logger;33import java.util.logging.Level;
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!