def test_get_prompt(self): # We want to get the prompt, not a disclaimer message startup_cfg = StartUpConfig() startup_cfg.accepted_disclaimer = True startup_cfg.save() # The easy way to do this was to simply pass 'python' to Popen # but now that we want to run the tests in virtualenv, we need to # find the "correct" / "virtual" python executable using which and # then pass that one to Popen python_executable = sys.executable p = subprocess.Popen([python_executable, 'w3af_console', '-n'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, shell=False, universal_newlines=True) expected_prompt = 'w3af>>>' stdout, stderr = p.communicate('exit\r\n') msg = 'Failed to find "%s" in "%s" using "%s" as python executable.' msg = msg % (expected_prompt, stdout, python_executable) self.assertIn(expected_prompt, stdout, msg)
def accept_disclaimer(self): """ :return: True/False depending on the user's answer to our disclaimer. Please note that in w3af_console we'll stop if the user does not accept the disclaimer. """ startup_cfg = StartUpConfig() if startup_cfg.accepted_disclaimer: return True QUESTION = 'Do you accept the terms and conditions? [N|y] ' msg = DISCLAIMER + '\n\n' + QUESTION try: user_response = raw_input(msg) except (KeyboardInterrupt, EOFError): print '' user_response = '' user_response = user_response.lower() if user_response == 'y' or user_response == 'yes': startup_cfg.accepted_disclaimer = True startup_cfg.save() return True return False
def tearDown(self): XpresserUnittest.tearDown(self) # Just in case... we don't want to break other tests startup_cfg = StartUpConfig() startup_cfg.accepted_disclaimer = True startup_cfg.save()
def test_save(self): scfg = StartUpConfig(self.CFG_FILE) scfg.last_upd = date.today() scfg.accepted_disclaimer = True scfg.last_commit_id = '3f4808082c1943f964669af1a1c94245bab09c61' scfg.save()
def test_save(self): scfg = StartUpConfig(self.CFG_FILE) scfg.last_upd = date.today() scfg.accepted_disclaimer = True scfg.last_commit_id = '3f4808082c1943f964669af1a1c94245bab09c61' scfg.save()
def test_set_save_use(self): """ This is a unittest for the bug reported by a user where his settings are not saved to the profile. https://github.com/andresriancho/w3af/issues/291 Actually, the settings are saved but not properly displayed, but that's not so important. The important thing is that the user was seeing the old setting instead of the new. """ # We want to get the prompt, not a disclaimer message startup_cfg = StartUpConfig() startup_cfg.accepted_disclaimer = True startup_cfg.save() # Load an existing profile, modify msf_location and save it as unittest commands_to_run = [ 'profiles', 'use OWASP_TOP10', 'back', 'misc-settings', 'set msf_location /tmp/', 'back', 'profiles', 'save_as %s' % self.get_profile_name(), 'exit' ] self.console = ConsoleUI(commands=commands_to_run, do_upd=False) self.console.sh() expected = ('Profile saved.', ) assert_result, msg = self.startswith_expected_in_output(expected) self.assertTrue(assert_result, msg) # The easy way to do this was to simply pass 'python' to Popen # but now that we want to run the tests in virtualenv, we need to # find the "correct" / "virtual" python executable using which and # then pass that one to Popen python_executable = sys.executable p = subprocess.Popen([python_executable, 'w3af_console', '-n'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, shell=False, universal_newlines=True) # Now we run a new ConsoleUI that will load the saved settings. We # should see /tmp/ as the value for msf_location commands_to_run = [ 'profiles', 'use %s' % self.get_profile_name(), 'back', 'misc-settings', 'view', 'back', 'exit' ] expected_output = '/tmp' stdout, stderr = p.communicate('\r'.join(commands_to_run) + '\r') msg = 'Failed to find "%s" in "%s" using "%s" as python executable.' msg = msg % (expected_output, stdout, python_executable) self.assertIn(expected_output, stdout, msg)
def test_disclaimer_shown_not_accept(self): startup_cfg = StartUpConfig() startup_cfg.accepted_disclaimer = False startup_cfg.save() self.find('accept_terms_conditions') self.click('simple_no') self.not_find('owasp_top_10_profile')
def test_load_file_exists(self): """This is a test to verify that the things we saved were persited in the actual file. """ # Save scfg = StartUpConfig(self.CFG_FILE) scfg.last_upd = date.today() scfg.accepted_disclaimer = True scfg.last_commit_id = '3f4808082c1943f964669af1a1c94245bab09c61' scfg.save() # Load scfg = StartUpConfig(self.CFG_FILE) self.assertEqual(scfg.last_upd, date.today()) self.assertEqual(scfg.accepted_disclaimer, True) self.assertEqual(scfg.last_commit_id, '3f4808082c1943f964669af1a1c94245bab09c61') self.assertEqual(scfg.freq, 'D')
def test_load_file_exists(self): """This is a test to verify that the things we saved were persited in the actual file. """ # Save scfg = StartUpConfig(self.CFG_FILE) scfg.last_upd = date.today() scfg.accepted_disclaimer = True scfg.last_commit_id = '3f4808082c1943f964669af1a1c94245bab09c61' scfg.save() # Load scfg = StartUpConfig(self.CFG_FILE) self.assertEqual(scfg.last_upd, date.today()) self.assertEqual(scfg.accepted_disclaimer, True) self.assertEqual(scfg.last_commit_id, '3f4808082c1943f964669af1a1c94245bab09c61') self.assertEqual(scfg.freq, 'D')
def accept_disclaimer(self): """ :return: True/False depending on the user's answer to our disclaimer. Please note that in w3af_gui we'll stop if the user does not accept the disclaimer. """ startup_cfg = StartUpConfig() if startup_cfg.accepted_disclaimer: return True QUESTION = 'Do you accept the terms and conditions?' msg = DISCLAIMER + '\n\n' + QUESTION user_response = ask(msg) if user_response: startup_cfg.accepted_disclaimer = True startup_cfg.save() return True return False
def accept_disclaimer(self): """ :return: True/False depending on the user's answer to our disclaimer. Please note that in w3af_gui we'll stop if the user does not accept the disclaimer. """ startup_cfg = StartUpConfig() if startup_cfg.accepted_disclaimer: return True QUESTION = 'Do you accept the terms and conditions?' msg = DISCLAIMER + '\n\n' + QUESTION user_response = ask(msg) if user_response: startup_cfg.accepted_disclaimer = True startup_cfg.save() return True return False
def setUp(self): super(TestStrategy, self).setUp() startup_cfg = StartUpConfig() startup_cfg.accepted_disclaimer = True startup_cfg.save()
def test_disclaimer_not_shown(self): startup_cfg = StartUpConfig() startup_cfg.accepted_disclaimer = True startup_cfg.save() self.not_find('accept_terms_conditions')
def test_set_save_use(self): """ This is a unittest for the bug reported by a user where his settings are not saved to the profile. https://github.com/andresriancho/w3af/issues/291 Actually, the settings are saved but not properly displayed, but that's not so important. The important thing is that the user was seeing the old setting instead of the new. """ # We want to get the prompt, not a disclaimer message startup_cfg = StartUpConfig() startup_cfg.accepted_disclaimer = True startup_cfg.save() # Load an existing profile, modify msf_location and save it as unittest commands_to_run = ['profiles', 'use OWASP_TOP10', 'back', 'misc-settings', 'set msf_location /tmp/', 'back', 'profiles', 'save_as %s' % self.get_profile_name(), 'exit'] self.console = ConsoleUI(commands=commands_to_run, do_upd=False) self.console.sh() expected = ('Profile saved.',) assert_result, msg = self.startswith_expected_in_output(expected) self.assertTrue(assert_result, msg) # The easy way to do this was to simply pass 'python' to Popen # but now that we want to run the tests in virtualenv, we need to # find the "correct" / "virtual" python executable using which and # then pass that one to Popen python_executable = sys.executable p = subprocess.Popen([python_executable, 'w3af_console', '-n'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, shell=False, universal_newlines=True) # Now we run a new ConsoleUI that will load the saved settings. We # should see /tmp/ as the value for msf_location commands_to_run = ['profiles', 'use %s' % self.get_profile_name(), 'back', 'misc-settings', 'view', 'back', 'exit'] expected_output = '/tmp' stdout, stderr = p.communicate('\r'.join(commands_to_run) + '\r') msg = 'Failed to find "%s" in "%s" using "%s" as python executable.' msg = msg % (expected_output, stdout, python_executable) self.assertIn(expected_output, stdout, msg)
def setUp(self): super(TestStrategy, self).setUp() startup_cfg = StartUpConfig() startup_cfg.accepted_disclaimer = True startup_cfg.save()