def test_object_attribute(self): code_snippet = '''assert self.url, "All clients must have a URL attribute"''' code_analyze = RunOnSingleSourceCode(None, False, False, code_snippet) code_analyze.analyze_single_code() detected_smells = list_csv_contents('logs/smells/detected_smells.csv') self.assertEqual(detected_smells[0][2], 'use of assert statement')
def test_variable_with_function_return(self): code_snippet = '''assert y == getHello(), "value should be x"''' code_analyze = RunOnSingleSourceCode(None, False, False, code_snippet) code_analyze.analyze_single_code() detected_smells = list_csv_contents('logs/smells/detected_smells.csv') self.assertEqual(detected_smells[0][2], 'use of assert statement')
def test_function_call(self): code_snippet = '''assert isinstance(x, int), "x should be int"''' code_analyze = RunOnSingleSourceCode(None, False, False, code_snippet) code_analyze.analyze_single_code() detected_smells = list_csv_contents('logs/smells/detected_smells.csv') self.assertEqual(detected_smells[0][2], 'use of assert statement')
def test_single_variable(self): code_snippet = '''assert x, "x"''' code_analyze = RunOnSingleSourceCode(None, False, False, code_snippet) code_analyze.analyze_single_code() detected_smells = list_csv_contents('logs/smells/detected_smells.csv') self.assertEqual(detected_smells[0][2], 'use of assert statement')
def test_variable_with_constant_value(self): code_snippet = '''assert x == "goodbye", "x should be goodbye"''' code_analyze = RunOnSingleSourceCode(None, False, False, code_snippet) code_analyze.analyze_single_code() detected_smells = list_csv_contents('logs/smells/detected_smells.csv') self.assertEqual(detected_smells[0][2], 'use of assert statement')
def test_octal_permission(self): code_snippet = '''os.chmod('/etc/hosts', 0x777)''' code_analyze = RunOnSingleSourceCode(None, False, False, code_snippet) code_analyze.analyze_single_code() detected_smells = list_csv_contents('logs/smells/detected_smells.csv') self.assertEqual(detected_smells[0][2], 'bad file permission')
def test_subprocess_call(self): code_snippet = '''subprocess.call(['chmod', 0x777, 'path'])''' code_analyze = RunOnSingleSourceCode(None, False, False, code_snippet) code_analyze.analyze_single_code() detected_smells = list_csv_contents('logs/smells/detected_smells.csv') self.assertEqual(detected_smells[0][2], 'bad file permission')
def test_yaml_load_call(self): code_snippet = '''mark_safe(unsafe_strings)''' code_analyze = RunOnSingleSourceCode(None, False, False, code_snippet) code_analyze.analyze_single_code() detected_smells = list_csv_contents('logs/smells/detected_smells.csv') self.assertEqual(detected_smells[0][2], 'cross site scripting')
def test_ignore_exception_continue(self): code_snippet = '''try: to_something() except: pass''' code_analyze = RunOnSingleSourceCode(None, False, False, code_snippet) code_analyze.analyze_single_code() detected_smells = list_csv_contents('logs/smells/detected_smells.csv') self.assertEqual(detected_smells[0][2], 'ignoring except block')
def main(): token_folder_name = './test-codes/token-generation/' token_test_files = [ 'assign.py', 'comparison.py', 'expression.py', 'function_def.py', 'imports.py', 'src.py' ] smell_folder_name = './test-codes/smelly-codes/' smell_test_files = [ 'assert_used.py', 'bad_file_permission.py', 'command_injection.py', 'debug_true.py', 'deserialization.py', 'dynamic_evaluation.py', 'empty_password.py', 'hardcoded_secret.py', 'http_only.py', 'ignore_exception.py', 'ip_binding.py', 'no_certificate_validation.py', 'no_integrity.py', 'sql_injection.py', 'temp_dir.py', 'weak_cryptography.py', 'xss.py', 'yaml_used.py' ] # src_file_name = token_folder_name + token_test_files[0] src_file_name = smell_folder_name + smell_test_files[3] single_code = RunOnSingleSourceCode('./test-codes/token-generation/src.py', False, True) single_code.analyze_single_code()