def setUp(self): test_helpers.patch_environ(self) flaskapp = flask.Flask('testflask') flaskapp.add_url_rule( '/apply-ccs', view_func=oss_fuzz_apply_ccs.Handler.as_view('/apply-ccs')) self.app = webtest.TestApp(flaskapp) data_types.ExternalUserPermission( email='*****@*****.**', entity_name='job', entity_kind=data_types.PermissionEntityKind.JOB, is_prefix=False, auto_cc=data_types.AutoCCType.ALL).put() data_types.ExternalUserPermission( email='*****@*****.**', entity_name='job', entity_kind=data_types.PermissionEntityKind.JOB, is_prefix=False, auto_cc=data_types.AutoCCType.ALL).put() test_helpers.patch(self, [ 'clusterfuzz._internal.base.utils.utcnow', 'handlers.base_handler.Handler.is_cron', 'libs.issue_management.issue_tracker.IssueTracker.get_original_issue', 'libs.issue_management.issue_tracker_policy.get', 'libs.issue_management.issue_tracker_utils.' 'get_issue_tracker_for_testcase', ]) self.itm = IssueTrackerManager('oss-fuzz') self.mock.get_issue_tracker_for_testcase.return_value = ( monorail.IssueTracker(self.itm)) self.mock.utcnow.return_value = datetime.datetime(2016, 1, 1) self.mock.get.return_value = OSS_FUZZ_POLICY self.mock.get_original_issue.side_effect = get_original_issue self.job = data_types.Job(name='job', environment_string='') self.job.put() data_types.Testcase(open=True, status='Processed', bug_information='1337', job_type='job').put() data_types.Testcase(open=True, status='Processed', bug_information='1338', job_type='job').put() data_types.Testcase(open=True, status='Processed', bug_information='1339', job_type='job').put() data_types.Testcase(open=True, status='Processed', bug_information='1340', job_type='job').put()
def test_security_severity_security_bug_with_severity_set( self, project_name, policy): """Test security severity label is set when testcase is a security bug and has a security severity.""" self.mock.get.return_value = policy security_severity_string_map = { data_types.SecuritySeverity.HIGH: 'Security_Severity-High', data_types.SecuritySeverity.MEDIUM: 'Security_Severity-Medium', data_types.SecuritySeverity.LOW: 'Security_Severity-Low', } for security_severity in security_severity_string_map: issue_tracker = monorail.IssueTracker( IssueTrackerManager(project_name)) self.testcase1.security_flag = True self.testcase1.security_severity = security_severity self.testcase1.put() issue_filer.file_issue(self.testcase1, issue_tracker) self.assertIn(security_severity_string_map[security_severity], issue_tracker._itm.last_issue.labels) self.assertEqual( 1, len( issue_tracker._itm.last_issue.get_labels_by_prefix( 'Security_Severity-')))
def test_succeed(self): """Update an issue.""" bug = issue.Issue() bug.open = True itm = mock.Mock(project_name='chromium') itm.get_issue.return_value = bug self.mock.get_issue_tracker_for_testcase.return_value = ( monorail.IssueTracker(itm)) self.mock.get_issue_description.return_value = 'description' self.mock.get_issue_summary.return_value = 'summary' self.mock.get_stacktrace.return_value = 'stacktrace' self.mock.get_memory_tool_labels.return_value = ['tool'] resp = self.app.post_json( '/', { 'testcaseId': self.testcase.key.id(), 'issueId': '2', 'needsSummaryUpdate': 'true', 'csrf_token': form.generate_csrf_token(), }, expect_errors=True) self.assertEqual(200, resp.status_int) self.assertEqual('yes', resp.json['testcase']) self.assertEqual('description', bug.comment) self.assertEqual('summary', bug.summary) self.assertListEqual(['Stability-tool'], bug.labels) self.assertEqual('2', self.testcase.key.get().bug_information)
def setUp(self): test_helpers.patch(self, [ 'libs.access._is_domain_allowed', 'libs.auth.get_current_user', 'clusterfuzz._internal.config.db_config.get', 'libs.issue_management.issue_tracker.IssueTracker.get_original_issue', 'libs.issue_management.issue_tracker_utils.' 'get_issue_tracker_for_testcase', 'libs.issue_management.monorail.issue_tracker_manager.' 'IssueTrackerManager', ]) self.itm = issue_tracker_manager.IssueTrackerManager('test') self.itm.project_name = 'test-project' self.mock.get_issue_tracker_for_testcase.return_value = ( monorail.IssueTracker(self.itm)) self.get_issue = self.itm.get_issue self.email = '*****@*****.**' self.mock.get_current_user.return_value = auth.User(self.email) self.bug = issue.Issue() self.bug.id = 1234 self.bug.itm = self.itm self.original_bug = issue.Issue() self.original_bug.id = 5678 self.original_bug.itm = self.itm self.testcase = data_types.Testcase() self.mock.get.return_value = (data_types.Config( relax_testcase_restrictions=True)) self.mock._is_domain_allowed.return_value = False
def test_testcase_metadata_invalid(self): """Tests issue filing with invalid metadata.""" self.mock.get.return_value = CHROMIUM_POLICY issue_tracker = monorail.IssueTracker(IssueTrackerManager('chromium')) issue_filer.file_issue(self.testcase6, issue_tracker) self.assertItemsEqual( ['ClusterFuzz', 'Reproducible', 'Pri-1', 'Stability-Crash', 'Type-Bug'], issue_tracker._itm.last_issue.labels)
def test_filed_issues_oss_fuzz(self): """Tests issue filing for oss-fuzz.""" self.mock.get.return_value = OSS_FUZZ_POLICY issue_tracker = monorail.IssueTracker(IssueTrackerManager('oss-fuzz')) issue_filer.file_issue(self.testcase1, issue_tracker) self.assertEqual('New', issue_tracker._itm.last_issue.status) self.assertTrue( issue_tracker._itm.last_issue.has_label_matching( 'restrict-view-commit')) self.assertFalse( issue_tracker._itm.last_issue.has_label_matching( 'reported-2016-01-01')) self.assertNotIn(DEADLINE_NOTE, issue_tracker._itm.last_issue.body) issue_filer.file_issue(self.testcase1_security, issue_tracker) self.assertTrue( issue_tracker._itm.last_issue.has_label_matching( 'restrict-view-commit')) self.assertFalse( issue_tracker._itm.last_issue.has_label_matching( 'reported-2016-01-01')) self.assertNotIn(DEADLINE_NOTE, issue_tracker._itm.last_issue.body) issue_filer.file_issue(self.testcase2, issue_tracker) self.assertFalse( issue_tracker._itm.last_issue.has_label_matching( 'restrict-view-commit')) self.assertTrue( issue_tracker._itm.last_issue.has_label_matching( 'reported-2016-01-01')) self.assertNotIn(DEADLINE_NOTE, issue_tracker._itm.last_issue.body) issue_filer.file_issue(self.testcase2_security, issue_tracker) self.assertTrue( issue_tracker._itm.last_issue.has_label_matching( 'restrict-view-commit')) self.assertTrue( issue_tracker._itm.last_issue.has_label_matching( 'reported-2016-01-01')) self.assertIn(DEADLINE_NOTE, issue_tracker._itm.last_issue.body) issue_filer.file_issue(self.testcase3, issue_tracker) self.assertFalse( issue_tracker._itm.last_issue.has_label_matching( 'restrict-view-commit')) self.assertFalse( issue_tracker._itm.last_issue.has_label_matching( 'reported-2016-01-01')) self.assertNotIn(DEADLINE_NOTE, issue_tracker._itm.last_issue.body) issue_filer.file_issue(self.testcase3_security, issue_tracker) self.assertFalse( issue_tracker._itm.last_issue.has_label_matching( 'restrict-view-commit')) self.assertTrue( issue_tracker._itm.last_issue.has_label_matching( 'reported-2016-01-01')) self.assertNotIn(DEADLINE_NOTE, issue_tracker._itm.last_issue.body)
def test_filed_issues_chromium(self): """Tests issue filing for chromium.""" self.mock.get.return_value = CHROMIUM_POLICY issue_tracker = monorail.IssueTracker(IssueTrackerManager('chromium')) issue_filer.file_issue(self.testcase4, issue_tracker) self.assertIn('OS-Chrome', issue_tracker._itm.last_issue.labels) self.assertEqual('Untriaged', issue_tracker._itm.last_issue.status) self.assertNotIn('Restrict-View-SecurityTeam', issue_tracker._itm.last_issue.labels)
def setUp(self): helpers.patch(self, [ 'libs.issue_management.monorail.issue_tracker_manager.' 'IssueTrackerManager.get_issues', ]) mock_issue = MonorailIssue() mock_issue.id = 1337 mock_issue.summary = 'summary' mock_issue.body = 'body' mock_issue.owner = 'owner' mock_issue.reporter = 'reporter' mock_issue.status = 'New' mock_issue.add_label('label1') mock_issue.add_label('label2') mock_issue.add_component('A>B') mock_issue.add_component('C>D') mock_issue.add_cc('*****@*****.**') mock_comment0 = MonorailComment() mock_comment0.author = 'author' mock_comment0.cc = ['*****@*****.**', '*****@*****.**'] mock_comment0.labels = ['-label0', 'label1'] mock_comment0.components = ['-E>F', 'A>B'] mock_comment0.comment = 'comment' mock_comment0.summary = 'summary' mock_comment0.status = 'status' mock_comment0.owner = 'owner' mock_comment1 = MonorailComment() mock_comment1.author = 'author' mock_comment1.comment = 'comment' mock_issue.comments = [ mock_comment0, mock_comment1, ] mock_issue_merged = MonorailIssue() mock_issue_merged.id = 1338 mock_issue_merged.merged_into = 1337 mock_issue_merged.merged_into_project = 'project' mock_issue_merged.closed = datetime.datetime(2019, 1, 1) mock_issue_merged_another_project = MonorailIssue() mock_issue_merged_another_project.id = 1339 mock_issue_merged_another_project.merged_into = 1 mock_issue_merged_another_project.merged_into_project = 'different-project' mock_issues = { 1337: mock_issue, 1338: mock_issue_merged, 1339: mock_issue_merged_another_project, } self.itm = IssueTrackerManager('project', mock_issues) self.issue_tracker = monorail.IssueTracker(self.itm)
def test_memory_tool_used(self, project_name, policy): """Test memory tool label is correctly set.""" self.mock.get.return_value = policy for entry in issue_filer.MEMORY_TOOLS_LABELS: issue_tracker = monorail.IssueTracker(IssueTrackerManager(project_name)) self.testcase1.crash_stacktrace = '\n\n%s\n' % entry['token'] self.testcase1.put() issue_filer.file_issue(self.testcase1, issue_tracker) self.assertIn('Stability-' + entry['label'], issue_tracker._itm.last_issue.labels)
def test_security_severity_functional_bug(self, project_name, policy): """Test security severity label is not set for a functional bug.""" self.mock.get.return_value = policy issue_tracker = monorail.IssueTracker(IssueTrackerManager(project_name)) self.testcase1.security_flag = False self.testcase1.security_severity = None self.testcase1.put() issue_filer.file_issue(self.testcase1, issue_tracker) self.assertFalse( issue_tracker._itm.last_issue.has_label_by_prefix('Security_Severity-'))
def setUp(self): test_helpers.patch_environ(self) self.app = webtest.TestApp( webapp2.WSGIApplication([('/apply-ccs', oss_fuzz_apply_ccs.Handler) ])) data_types.ExternalUserPermission( email='*****@*****.**', entity_name='job', entity_kind=data_types.PermissionEntityKind.JOB, is_prefix=False, auto_cc=data_types.AutoCCType.ALL).put() data_types.ExternalUserPermission( email='*****@*****.**', entity_name='job', entity_kind=data_types.PermissionEntityKind.JOB, is_prefix=False, auto_cc=data_types.AutoCCType.ALL).put() test_helpers.patch(self, [ 'base.utils.utcnow', 'handlers.base_handler.Handler.is_cron', 'libs.issue_management.issue_tracker_policy.get', 'libs.issue_management.issue_tracker_utils.' 'get_issue_tracker_for_testcase', ]) self.itm = IssueTrackerManager('oss-fuzz') self.mock.get_issue_tracker_for_testcase.return_value = ( monorail.IssueTracker(self.itm)) self.mock.utcnow.return_value = datetime.datetime(2016, 1, 1) self.mock.get.return_value = OSS_FUZZ_POLICY data_types.Testcase(open=True, status='Processed', bug_information='1337', job_type='job').put() data_types.Testcase(open=True, status='Processed', bug_information='1338', job_type='job').put() data_types.Testcase(open=True, status='Processed', bug_information='1339', job_type='job').put() data_types.Testcase(open=True, status='Processed', bug_information='1340', job_type='job').put()
def test_reproducible_flag(self): """Test (un)reproducible flag is correctly set.""" self.mock.get.return_value = CHROMIUM_POLICY issue_tracker = monorail.IssueTracker(IssueTrackerManager('chromium')) self.testcase1.one_time_crasher_flag = True self.testcase1.put() issue_filer.file_issue(self.testcase1, issue_tracker) self.assertIn('Unreproducible', issue_tracker._itm.last_issue.labels) self.testcase1.one_time_crasher_flag = False self.testcase1.put() issue_filer.file_issue(self.testcase1, issue_tracker) self.assertIn('Reproducible', issue_tracker._itm.last_issue.labels)
def test_testcase_save_exception(self): """Tests issue filing when issue.save exception""" self.mock.get.return_value = CHROMIUM_POLICY_FALLBACK original_save = monorail.issue.Issue.save helpers.patch(self, ['libs.issue_management.monorail.issue.Issue.save']) def my_save(*args, **kwargs): if getattr(my_save, 'raise_exception', True): setattr(my_save, 'raise_exception', False) raise Exception("Boom!") return original_save(*args, **kwargs) self.mock.save.side_effect = my_save issue_tracker = monorail.IssueTracker(IssueTrackerManager('chromium')) _, exception = issue_filer.file_issue(self.testcase5, issue_tracker) self.assertIsInstance(exception, Exception) six.assertCountEqual( self, ['fallback>component', '-component1', '-component2'], issue_tracker._itm.last_issue.components) self.assertIn( '**NOTE**: This bug was filed into this component due to permission or ' 'configuration issues with the specified component(s) component1 component2', issue_tracker._itm.last_issue.body) # call without fallback_component in policy # Expected result: no issue is added to itm setattr(my_save, 'raise_exception', True) issue_tracker = monorail.IssueTracker(IssueTrackerManager('chromium')) self.mock.get.return_value = CHROMIUM_POLICY with self.assertRaises(Exception): issue_filer.file_issue(self.testcase1, issue_tracker) self.assertIsNone(issue_tracker._itm.last_issue)
def test_crash_labels(self): """Test crash label setting.""" self.mock.get.return_value = CHROMIUM_POLICY issue_tracker = monorail.IssueTracker(IssueTrackerManager('chromium')) self.testcase1.crash_type = 'UNKNOWN' self.testcase1.put() issue_filer.file_issue(self.testcase1, issue_tracker) self.assertIn('Pri-1', issue_tracker._itm.last_issue.labels) self.assertIn('Stability-Crash', issue_tracker._itm.last_issue.labels) self.testcase1.crash_type = 'Undefined-shift' self.testcase1.put() issue_filer.file_issue(self.testcase1, issue_tracker) self.assertIn('Pri-2', issue_tracker._itm.last_issue.labels) self.assertNotIn('Stability-Crash', issue_tracker._itm.last_issue.labels)
def test_security_severity_security_bug_default_severity( self, project_name, policy): """Test security severity label is set when testcase is a security bug and no severity can be determined.""" self.mock.get.return_value = policy issue_tracker = monorail.IssueTracker(IssueTrackerManager(project_name)) self.testcase1.security_flag = True self.testcase1.security_severity = None self.testcase1.put() issue_filer.file_issue(self.testcase1, issue_tracker) self.assertIn('Security_Severity-High', issue_tracker._itm.last_issue.labels) self.assertEqual( 1, len( issue_tracker._itm.last_issue.get_labels_by_prefix( 'Security_Severity-')))
def test_testcase_metadata_labels_and_components(self): """Tests issue filing with additional labels and components.""" self.mock.get.return_value = CHROMIUM_POLICY issue_tracker = monorail.IssueTracker(IssueTrackerManager('chromium')) issue_filer.file_issue(self.testcase5, issue_tracker) six.assertCountEqual(self, [ 'ClusterFuzz', 'Reproducible', 'Pri-1', 'Stability-Crash', 'Type-Bug', 'label1', 'label2', ], issue_tracker._itm.last_issue.labels) six.assertCountEqual(self, [ 'component1', 'component2', ], issue_tracker._itm.last_issue.components)
def test_filed_issues_oss_fuzz_disable_disclose(self): """Test filing oss-fuzz issues with disclosure disabled.""" self.job2.environment_string += 'DISABLE_DISCLOSURE = True\n' self.job2.put() self.mock.get.return_value = OSS_FUZZ_POLICY issue_tracker = monorail.IssueTracker(IssueTrackerManager('oss-fuzz')) issue_filer.file_issue(self.testcase2_security, issue_tracker) self.assertTrue( issue_tracker._itm.last_issue.has_label_matching( 'restrict-view-commit')) self.assertFalse( issue_tracker._itm.last_issue.has_label_matching( 'reported-2016-01-01')) self.assertNotIn(DEADLINE_NOTE, issue_tracker._itm.last_issue.body) self.assertIn(FIX_NOTE, issue_tracker._itm.last_issue.body) self.assertIn(QUESTIONS_NOTE, issue_tracker._itm.last_issue.body)
def test_issue_not_found(self): """Issue is not found.""" itm = mock.Mock(spec_set=issue_tracker_manager.IssueTrackerManager) self.mock.get_issue_tracker_for_testcase.return_value = ( monorail.IssueTracker(itm)) itm.get_issue.return_value = None resp = self.app.post_json('/', { 'testcaseId': self.testcase.key.id(), 'issueId': '2', 'needsSummaryUpdate': '', 'csrf_token': form.generate_csrf_token(), }, expect_errors=True) self.assertEqual(404, resp.status_int) self.assertEqual('Issue (id=2) is not found!', resp.json['message']) self.assertEqual('*****@*****.**', resp.json['email'])
def setUp(self): self.app = webtest.TestApp( webapp2.WSGIApplication([('/build-status', oss_fuzz_build_status.Handler)])) test_helpers.patch(self, [ 'base.utils.utcnow', 'handlers.base_handler.Handler.is_cron', 'libs.issue_management.issue_tracker_utils.get_issue_tracker', 'metrics.logs.log_error', 'requests.get', ]) self.mock.utcnow.return_value = datetime.datetime(2018, 2, 1) self.mock.is_cron.return_value = True self.itm = IssueTrackerManager('oss-fuzz') self.mock.get_issue_tracker.return_value = monorail.IssueTracker(self.itm) self.maxDiff = None # pylint: disable=invalid-name
def test_issue_not_open(self): """Issue is not open.""" itm = mock.Mock(spec_set=issue_tracker_manager.IssueTrackerManager) bug = issue.Issue() bug.open = False self.mock.get_issue_tracker_for_testcase.return_value = ( monorail.IssueTracker(itm)) itm.get_issue.return_value = bug resp = self.app.post_json('/', { 'testcaseId': self.testcase.key.id(), 'issueId': '2', 'needsSummaryUpdate': '', 'csrf_token': form.generate_csrf_token(), }, expect_errors=True) self.assertEqual(400, resp.status_int) self.assertIn('file a new issue', resp.json['message']) self.assertEqual('*****@*****.**', resp.json['email'])
def test_security_severity_security_bug_severity_override( self, project_name, policy): """Test security severity label is set correct when testcase has its own severity but there is an override provided.""" self.mock.get.return_value = policy issue_tracker = monorail.IssueTracker(IssueTrackerManager(project_name)) self.testcase1.security_flag = True self.testcase1.security_severity = data_types.SecuritySeverity.HIGH self.testcase1.put() issue_filer.file_issue( self.testcase1, issue_tracker, security_severity=data_types.SecuritySeverity.MEDIUM) self.assertNotIn('Security_Severity-High', issue_tracker._itm.last_issue.labels) self.assertIn('Security_Severity-Medium', issue_tracker._itm.last_issue.labels) self.assertEqual( 1, len( issue_tracker._itm.last_issue.get_labels_by_prefix( 'Security_Severity-')))
def setUp(self): flaskapp = flask.Flask('testflask') flaskapp.add_url_rule( '/build-status', view_func=oss_fuzz_build_status.Handler.as_view('/build-status')) self.app = webtest.TestApp(flaskapp) test_helpers.patch(self, [ 'base.utils.utcnow', 'handlers.base_handler.Handler.is_cron', 'libs.issue_management.issue_tracker_utils.get_issue_tracker', 'metrics.logs.log_error', 'requests.get', ]) self.mock.utcnow.return_value = datetime.datetime(2018, 2, 1) self.mock.is_cron.return_value = True self.itm = IssueTrackerManager('oss-fuzz') self.mock.get_issue_tracker.return_value = monorail.IssueTracker( self.itm) self.maxDiff = None # pylint: disable=invalid-name
def test_footer_formatting(self): """Test footer message with formatting.""" policy = issue_tracker_policy.IssueTrackerPolicy({ 'status': { 'assigned': 'Assigned', 'duplicate': 'Duplicate', 'verified': 'Verified', 'new': 'Untriaged', 'wontfix': 'WontFix', 'fixed': 'Fixed' }, 'all': { 'status': 'new', 'issue_body_footer': 'Target: %FUZZ_TARGET%, Project: %PROJECT%' }, 'non_security': {}, 'labels': {}, 'security': {}, 'existing': {}, }) self.mock.get.return_value = policy issue_tracker = monorail.IssueTracker(IssueTrackerManager('chromium')) self.testcase1.project_name = 'proj' self.testcase1.fuzzer_name = 'libFuzzer' self.testcase1.overridden_fuzzer_name = 'libFuzzer_proj_target' data_types.FuzzTarget( id='libFuzzer_proj_target', project='proj', engine='libFuzzer', binary='target').put() issue_filer.file_issue(self.testcase1, issue_tracker) self.assertIn('Target: target, Project: proj', issue_tracker._itm.last_issue.body)
def test_filed_issues_chromium_ios(self): """Tests issue filing for chromium iOS.""" self.mock.get.return_value = CHROMIUM_POLICY issue_tracker = monorail.IssueTracker(IssueTrackerManager('chromium')) issue_filer.file_issue(self.testcase7, issue_tracker) self.assertIn('OS-iOS', issue_tracker._itm.last_issue.labels)