def test_srd_sd_weakness_extendedsearchtab_tc(self): driver = self.driver driver.get(self.base_url + "/search.php?extended&tree") el = driver.find_element_by_xpath("//select[@id='flaw_sel']") common_sd_methods.select_option_dropdow(el, "--+ CWE-843: Access of Resource Using Incompatible Type (Type Confusion)") numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_weakness(driver, numOfTestCases, "CWE-843: Access of Resource Using Incompatible Type (Type Confusion)") driver.get(self.base_url + "/search.php?extended&tree") el = driver.find_element_by_xpath("//select[@id='flaw_sel']") common_sd_methods.select_option_dropdow(el, "--+ CWE-835: Loop with Unreachable Exit Condition (Infinite Loop)") numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_weakness(driver, numOfTestCases, "CWE-835: Loop with Unreachable Exit Condition (Infinite Loop)") driver.get(self.base_url + "/search.php?extended&tree") el = driver.find_element_by_xpath("//select[@id='flaw_sel']") common_sd_methods.select_option_dropdow(el, "--+ CWE-506: Embedded Malicious Code") numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_weakness(driver, numOfTestCases, "CWE-506: Embedded Malicious Code") driver.get(self.base_url + "/search.php?extended&tree") el = driver.find_element_by_xpath("//select[@id='flaw_sel']") common_sd_methods.select_option_dropdow(el, "--+ CWE-170: Improper Null Termination") numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_weakness(driver, numOfTestCases, "CWE-170: Improper Null Termination") driver.get(self.base_url + "/search.php?extended&tree") el = driver.find_element_by_xpath("//select[@id='flaw_sel']") common_sd_methods.select_option_dropdow(el, "--+ CWE-336: Same Seed in PRNG") numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_weakness(driver, numOfTestCases, "CWE-336: Same Seed in PRNG")
def test_srd_sd_filename_sourcecodesearchtab(self): i = 0 while (i < 88720): self.driver.get(self.base_url + "/view.php?count=20&first=%s&sort=asc" %i) self.grab_files_names(common_sd_methods.count_test_cases_in_page(self.driver)) i+=20 for name in self.fileNames: self.driver.get(self.base_url + "/search.php?code") self.driver.find_element_by_xpath("//input[@id='fileName']").send_keys(name) self.driver.find_element_by_xpath("//input[@name='Submit']").click() #must have only one test case with the same ID and the same file foundTestCases = common_sd_methods.count_test_cases_in_page(self.driver) if foundTestCases > 1: j = 2 tcID = [] while j < foundTestCases: tcID.append(self.driver.find_element_by_xpath("//div[@id='content']/form/table/tbody/tr[%s]/td[2]/a" %j).text) j +=1 try: self.assertFalse(len(tcID)!=len(set(tcID))) except AssertionError as e: self.verificationErrors.append(("Duplicated test cases in the search by file name %s" %name)) self.driver.find_element_by_xpath("//div[@id='content']/form/table/tbody/tr[2]/td[2]/a").click() #the test case file name must be the same as the file name searched try: self.assertEqual((self.driver.find_element_by_xpath("//div[@id='content']/table/tbody/tr[14]/td[2]/ul/li/a").text), name) except AssertionError as e: self.verificationErrors.append(("The file name %s is not the same in the test case page" %name))
def search_for_inserted_files(self): #verify if searching by a line present in the source file previously inserted the result returns the same number as the number of inserterd test cases self.driver.get(self.base_url + "/search.php?code") self.driver.find_element_by_xpath("//input[@id='fileName']").clear() #line = open(os.getcwd() + "/srd_db_tcs/example_files/example_file_selenium.py", "r").readlines()[72] #This line doesn't work because of some weird issue with the webdriver API #self.driver.find_element_by_xpath("//input[@id='function']").send_keys(unicode(line, errors='ignore')) self.driver.find_element_by_xpath("//input[@id='fileName']").send_keys("selenium") self.driver.find_element_by_xpath("//input[@name='Submit']").click() numberOfTestCases = common_sd_methods.count_test_cases_in_page(self.driver) #verify if the source file present in each test case returned as result of the search is the same as the source file previously inserted if numberOfTestCases > 0: i = 0 while i < numberOfTestCases: self.driver.find_element_by_xpath("//div[@id='content']/form/table/tbody/tr[%s]/td[2]/a" %(i+2)).click() try: self.assertEqual("example_file_selenium.py",self.driver.find_element_by_xpath("//div[@id='content']/table/tbody/tr[14]/td[2]/ul/li/a").text) except AssertionError as e: self.verificationErrors.append("File is not the same as the inserted previously in the test case %s." %self.driver.find_element_by_xpath("//span[@id='TestCaseID']").text) self.driver.back() i += 1 else: self.verificationErrors.append("Test case not found when looking for 'selenium' using the 'File Contains' search.")
def test_srd_sd_numfiles_light_tc_max_value(self): driver = self.driver driver.get(self.base_url + "/search.php?code") # 11 is the max number of files in a test case i = 0 while True: j = 0 testCase = 2 # send the value to the max field driver.find_element_by_xpath("//input[@name='maxFiles']").send_keys("%s" % i) driver.find_element_by_xpath("//input[@name='Submit']").click() time.sleep(2) # count the number of test cases per search numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) if numOfTestCases == 0: driver.back() else: while j < numOfTestCases: # for each element driver.find_element_by_xpath( "//div[@id='content']/form/table/tbody/tr[%s]/td[2]/a" % testCase ).click() time.sleep(10) # take the number of files fileString = driver.find_element_by_xpath("//div[@id='content']/table/tbody/tr[14]/td[2]").text # and verify if it's right try: numOfFiles = re.search( "\d+", re.search("The test case contains \d+ files.", fileString).group(0) ).group(0) except: numOfFiles = 1 if numOfFiles == 1: try: self.assertTrue(int(numOfFiles) <= i) except AssertionError as e: self.verificationErrors.append(("Number of files is not <= then %s as expected" % i)) else: try: self.assertTrue(int(numOfFiles) <= i) except AssertionError as e: self.verificationErrors.append(("Number of files is not <= then %s as expected" % i)) j += 1 testCase += 1 driver.back() driver.back() if i == 11: break i += 11
def search_for_tc(self): i = 0 #3 is the size of the dropdown_options lists while i < 3: self.driver.get(self.base_url + "/search.php?extended&tree") #take the test case ID self.driver.find_element_by_xpath("//input[@name='reference']").send_keys("%s" %self.insertedTestCasesID[i]) #insert keywords in the description field self.driver.find_element_by_xpath("//input[@name='description']").send_keys("selenium") #fill the dropdown menus el = self.driver.find_element_by_xpath("//select[@name='flawed[]']") common_sd_methods.select_option_dropdow(el, common_db_test_methods.dropdown_options.get('flawed')[i]) el = self.driver.find_element_by_xpath("//select[@name='languages[]']") common_sd_methods.select_option_dropdow(el, common_db_test_methods.dropdown_options.get('languages')[i]) el = self.driver.find_element_by_xpath("//select[@name='typesofartifacts[]']") common_sd_methods.select_option_dropdow(el, common_db_test_methods.dropdown_options.get('artifact')[i]) el = self.driver.find_element_by_xpath("//select[@id='flaw_sel']") common_sd_methods.select_option_dropdow(el, common_db_test_methods.dropdown_options.get('type_flaw')[i]) el = self.driver.find_element_by_xpath("//select[@id='complex_sel']") common_sd_methods.select_option_dropdow(el, common_db_test_methods.dropdown_options.get('ccplx')[i]) self.driver.find_element_by_xpath("//input[@name='Submit']").click() time.sleep(3) numberOfTestCases = common_sd_methods.count_test_cases_in_page(self.driver) if numberOfTestCases > 0: #verify the search results self.driver.find_element_by_xpath("//div[@id='content']/form/table/tbody/tr[2]/td[2]/a").click() try: self.assertEqual(self.user, self.driver.find_element_by_xpath("//div[@id='content']/table/tbody/tr[3]/td[2]/span").text) except AssertionError as e: self.verificationErrors.append("Test case not found or author is not the same when searching for author '%s'" %(self.author)) try: self.assertEqual(common_db_test_methods.dropdown_options.get('languages')[i], self.driver.find_element_by_xpath("//div[@id='content']/table/tbody/tr[6]/td[2]/span").text) except AssertionError as e: self.verificationErrors.append("Test case not found or language is not the same when searching for language '%s'" %(common_db_test_methods.dropdown_options.get('languages')[i])) try: self.assertEqual(common_db_test_methods.dropdown_options.get('artifact')[i], self.driver.find_element_by_xpath("//div[@id='content']/table/tbody/tr[7]/td[2]/span").text) except AssertionError as e: self.verificationErrors.append("Test case not found or the artifact is not the same when searching for artifact '%s'" %(common_db_test_methods.dropdown_options.get('artifact')[i])) try: self.assertEqual(re.search('\d+', common_db_test_methods.dropdown_options.get('type_flaw')[i]).group(0), re.search('\d+', self.driver.find_element_by_xpath("//div[@id='content']/table/tbody/tr[15]/td[2]/ul/li/span").text).group(0)) except AssertionError as e: self.verificationErrors.append("Test case not found or the type flaw is not the same when searching for type flaw '%s'" %(common_db_test_methods.dropdown_options.get('type_flaw')[i])) else: self.verificationErrors.append("Test case not found when searching for the test cases previously inserted!") i += 1
def test_srd_sd_numfiles_light_tc_same_values(self): driver = self.driver driver.get(self.base_url + "/search.php?code") #11 is the max number of files in a test case i = 0 while True: j = 0 testCase = 2 #send the same value for max and min driver.find_element_by_xpath("//input[@name='minFiles']").send_keys("%s" %i) driver.find_element_by_xpath("//input[@name='maxFiles']").send_keys("%s" %i) driver.find_element_by_xpath("//input[@name='Submit']").click() time.sleep(2) #count the number of test cases per search numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) if (numOfTestCases == 0): driver.back() else: while(j < numOfTestCases): #for each test case driver.find_element_by_xpath("//div[@id='content']/form/table/tbody/tr[%s]/td[2]/a" %testCase).click() time.sleep(10) #take the number o files fileString = driver.find_element_by_xpath("//div[@id='content']/table/tbody/tr[14]/td[2]").text #and verify if it's correct try: numOfFiles = re.search('\d+', re.search('The test case contains \d+ files.', fileString).group(0)).group(0) except: numOfFiles = 1 if(numOfFiles == 1): try: self.assertTrue(i==1) except AssertionError as e: self.verificationErrors.append(("Number of files is not the same as %s as expected" %i)) else: try: self.assertEqual(i, int(numOfFiles)) except AssertionError as e: self.verificationErrors.append(("Number of files is not the same as %s as expected" %i)) j += 1 testCase += 1 driver.back() driver.back() if (i == 11): break i += 11
def test_srd_sd_file_contains_sourcecodesearchtab(self): key_words = ["null", "string", "memory", "buffer", "stack", "heap", "integer", "race", "error", "switch", "break", "pointer", "CWE", "injection", "command"] for word in key_words: self.driver.get(self.base_url + "/search.php?code") self.driver.find_element_by_xpath("//input[@id='function']").send_keys(word) self.driver.find_element_by_xpath("//input[@name='Submit']").click() foundTestCases = common_sd_methods.count_test_cases_in_page(self.driver) j = 2 found_word = None while j < (foundTestCases+2): testCaseID = self.driver.find_element_by_xpath(("//div[@id='content']/form/table/tbody/tr[%s]/td[2]/a" %j)).text self.driver.find_element_by_xpath(("//div[@id='content']/form/table/tbody/tr[%s]/td[2]/a" %j)).click() #try to find the word on the first tab if(re.search(word, self.driver.find_element_by_xpath("//div[@id='code']").text, re.IGNORECASE)): found_word = True #search for the word on the other tabs else: i = 1 while(True): try: driver.find_element_by_xpath("//div[@id='mainTabContainer']/div/div[%s]/span" %(i+1)).click() except: break if(re.search(word, driver.find_element_by_css_selector("div[id='tab%s']" %i).text, re.IGNORECASE)): found_word = True i +=1 try: self.assertTrue(found_word) except AssertionError as e: self.verificationErrors.append(("Source code doesn't have the term '%s' searched but the test case %s still apearing in the results" %(word, testCaseID))) j += 1 self.driver.back()
def test_srd_sd_numfiles_extendedsearchtab_tc_max_value(self): driver = self.driver driver.get(self.base_url + "/search.php?code") #11 is the max number of files in a test case for i in range(12): j = 0 testCase = 2 #send the same value for max and min driver.find_element_by_xpath("//input[@name='maxFiles']").send_keys("%s" %i) driver.find_element_by_xpath("//input[@name='Submit']").click() time.sleep(2) #count the number of test cases per search numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) if (numOfTestCases == 0): driver.back() else: while(j < numOfTestCases): driver.find_element_by_xpath("//div[@id='content']/form/table/tbody/tr[%s]/td[2]/a" %testCase).click() time.sleep(2) fileString = driver.find_element_by_xpath("//div[@id='content']/table/tbody/tr[14]/td[2]").text try: numOfFiles = re.search('\d+', re.search('The test case contains \d+ files.', fileString).group(0)).group(0) except: numOfFiles = 1 if(numOfFiles == 1): try: self.assertTrue(int(numOfFiles) <= i) except AssertionError as e: self.verificationErrors.append(("Number of files is not <= then %s " %i) + str(e)) else: try: self.assertTrue(int(numOfFiles) <= i) except AssertionError as e: self.verificationErrors.append(("Number of files is not <= then %s " %i) +str(e)) j += 1 testCase += 1 driver.back() driver.back()
def test_srd_sd_filesize_sourcecodesearchtab_tc_min_value(self): driver = self.driver driver.get(self.base_url + "/search.php?code") #494975 is the max number of bytes in a test case for i in range(494975): j = 0 testCase = 2 driver.find_element_by_xpath("//input[@name='minFileSize']").send_keys("%s" %i) driver.find_element_by_xpath("//input[@name='Submit']").click() time.sleep(2) #count the number of test cases per search numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) if (numOfTestCases == 0): driver.back() else: while(j < numOfTestCases): testCaseID = driver.find_element_by_xpath("//div[@id='content']/form/table/tbody/tr[%s]/td[2]/a" %testCase).text driver.find_element_by_xpath("//div[@id='content']/form/table/tbody/tr[%s]/td[2]/a" %testCase).click() time.sleep(2) fileString = driver.find_element_by_xpath("//div[@id='content']/table/tbody/tr[14]/td[2]").text try: numOfFiles = re.search('\d+', re.search('The test case contains \d+ files.', fileString).group(0)).group(0) except: numOfFiles = 1 if(numOfFiles == 1): try: self.assertTrue(int(numOfFiles) <= i) except AssertionError as e: self.verificationErrors.append("The tes case %s has the wrong number " %(testCaseID)) else: try: self.assertTrue(int(numOfFiles) <= i) except AssertionError as e: self.verificationErrors.append(str(e)) j += 1 testCase += 1 driver.back() driver.back()
def test_srd_sd_dropdown_tc(self): driver = self.driver driver.get(self.base_url + "/search.php?simple") el = driver.find_element_by_xpath("//select[@name='flawed[]']") common_sd_methods.select_option_dropdow(el, "Bad") numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_flawed_element(driver, numOfTestCases, "Bad test case") if common_sd_methods.go_last_page(driver): numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_flawed_element(driver, numOfTestCases, "Bad test case") driver.get(self.base_url + "/search.php?simple") el = driver.find_element_by_xpath("//select[@name='flawed[]']") common_sd_methods.select_option_dropdow(el, "Good") numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_flawed_element(driver, numOfTestCases, "Good test case") if common_sd_methods.go_last_page(driver): numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_flawed_element(driver, numOfTestCases, "Good test case") driver.get(self.base_url + "/search.php?simple") el = driver.find_element_by_xpath("//select[@name='flawed[]']") common_sd_methods.select_option_dropdow(el, "Mixed") numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_flawed_element(driver, numOfTestCases, "Mixed test case") if common_sd_methods.go_last_page(driver): numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_flawed_element(driver, numOfTestCases, "Mixed test case") driver.get(self.base_url + "/search.php?simple") el = driver.find_element_by_xpath("//select[@name='languages[]']") common_sd_methods.select_option_dropdow(el, "C") numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_language_element(driver, numOfTestCases, "C") if common_sd_methods.go_last_page(driver): numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_language_element(driver, numOfTestCases, "C") driver.get(self.base_url + "/search.php?simple") el = driver.find_element_by_xpath("//select[@name='languages[]']") common_sd_methods.select_option_dropdow(el, "Java") numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_language_element(driver, numOfTestCases, "Java") if common_sd_methods.go_last_page(driver): numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_language_element(driver, numOfTestCases, "Java") driver.get(self.base_url + "/search.php?simple") el = driver.find_element_by_xpath("//select[@name='languages[]']") common_sd_methods.select_option_dropdow(el, "C++") numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_language_element(driver, numOfTestCases, "C++") if common_sd_methods.go_last_page(driver): numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_language_element(driver, numOfTestCases, "C++") driver.get(self.base_url + "/search.php?simple") el = driver.find_element_by_xpath("//select[@name='languages[]']") common_sd_methods.select_option_dropdow(el, "PHP") numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_language_element(driver, numOfTestCases, "PHP") if common_sd_methods.go_last_page(driver): numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_language_element(driver, numOfTestCases, "PHP") driver.get(self.base_url + "/search.php?simple") el = driver.find_element_by_xpath("//select[@name='typesofartifacts[]']") common_sd_methods.select_option_dropdow(el, "Source Code") numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_artifact_element(driver, numOfTestCases, "Source Code") if common_sd_methods.go_last_page(driver): numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_artifact_element(driver, numOfTestCases, "Source Code") driver.get(self.base_url + "/search.php?simple") el = driver.find_element_by_xpath("//select[@name='typesofartifacts[]']") common_sd_methods.select_option_dropdow(el, "Mix Of Artifact") numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_artifact_element(driver, numOfTestCases, "Mix Of Artifact") if common_sd_methods.go_last_page(driver): numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_artifact_element(driver, numOfTestCases, "Mix Of Artifact")
def test_srd_sd_query_date_extendedsearchtab_tc(self): driver = self.driver #on date tests driver.get(self.base_url + "/search.php?extended") driver.find_element_by_xpath("//input[@name='date']").send_keys("10/21/2005") driver.find_element_by_xpath("//div[@id='cleaner_1']/span/label[3]/input").click() driver.find_element_by_xpath("//input[@name='Submit']").click() numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_query_date_on_date(driver, numOfTestCases, "2005-10-21") if common_sd_methods.go_last_page(driver): numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_query_date_on_date(driver, numOfTestCases, "2005-10-21") driver.get(self.base_url + "/search.php?extended") driver.find_element_by_xpath("//input[@name='date']").send_keys("05/22/2013") driver.find_element_by_xpath("//div[@id='cleaner_1']/span/label[3]/input").click() driver.find_element_by_xpath("//input[@name='Submit']").click() numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_query_date_on_date(driver, numOfTestCases, "2013-05-22") if common_sd_methods.go_last_page(driver): numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_query_date_on_date(driver, numOfTestCases, "2013-05-22") #before date tests driver.get(self.base_url + "/search.php?extended") driver.find_element_by_xpath("//input[@name='date']").send_keys("10/21/2005") driver.find_element_by_xpath("//div[@id='cleaner_1']/span/label[2]/input").click() driver.find_element_by_xpath("//input[@name='Submit']").click() numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_query_date_before_date(driver, numOfTestCases, "2005-10-21") if common_sd_methods.go_last_page(driver): numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_query_date_before_date(driver, numOfTestCases, "2005-10-21") driver.get(self.base_url + "/search.php?extended") driver.find_element_by_xpath("//input[@name='date']").send_keys("05/22/2013") driver.find_element_by_xpath("//div[@id='cleaner_1']/span/label[2]/input").click() driver.find_element_by_xpath("//input[@name='Submit']").click() numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_query_date_before_date(driver, numOfTestCases, "2013-05-22") if common_sd_methods.go_last_page(driver): numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_query_date_before_date(driver, numOfTestCases, "2013-05-22") #after date tests driver.get(self.base_url + "/search.php?extended") driver.find_element_by_xpath("//input[@name='date']").send_keys("10/21/2005") driver.find_element_by_xpath("//div[@id='cleaner_1']/span/label[4]/input").click() driver.find_element_by_xpath("//input[@name='Submit']").click() numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_query_date_after_date(driver, numOfTestCases, "2005-10-21") if common_sd_methods.go_last_page(driver): numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_query_date_after_date(driver, numOfTestCases, "2005-10-21") driver.get(self.base_url + "/search.php?extended") driver.find_element_by_xpath("//input[@name='date']").send_keys("05/22/2013") driver.find_element_by_xpath("//div[@id='cleaner_1']/span/label[4]/input").click() driver.find_element_by_xpath("//input[@name='Submit']").click() numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_query_date_after_date(driver, numOfTestCases, "2013-05-22") if common_sd_methods.go_last_page(driver): numOfTestCases = common_sd_methods.count_test_cases_in_page(driver) self.verify_query_date_after_date(driver, numOfTestCases, "2013-05-22")