Пример #1
0
    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 = ['label']

        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(['label'], bug.labels)
        self.assertEqual('2', self.testcase.key.get().bug_information)
Пример #2
0
    def test_security_severity_security_bug_with_severity_set(
            self, project_name):
        """Test security severity label is set when testcase is a security bug and
    has a security severity."""
        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-')))
Пример #3
0
    def setUp(self):
        test_helpers.patch(self, [
            'libs.access._is_domain_allowed',
            'libs.auth.get_current_user',
            'config.db_config.get',
            'issue_management.issue_tracker_utils.get_issue_tracker_for_testcase',
            'issue_management.monorail.issue_tracker_manager.IssueTrackerManager',
        ])
        itm = issue_tracker_manager.IssueTrackerManager('test')
        self.mock.get_issue_tracker_for_testcase.return_value = (
            monorail.IssueTracker(itm))
        self.get_issue = itm.get_issue
        self.get_original_issue = itm.get_original_issue

        self.email = '*****@*****.**'
        self.mock.get_current_user.return_value = auth.User(self.email)

        self.bug = issue.Issue()
        self.bug.id = 1234
        self.original_bug = issue.Issue()
        self.original_bug.id = 5678

        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
Пример #4
0
 def test_testcase_metadata_invalid(self):
     """Tests issue filing with invalid metadata."""
     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)
Пример #5
0
    def test_memory_tool_used(self, project_name):
        """Test memory tool label is correctly set."""
        for entry in label_utils.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(entry['label'], issue_tracker._itm.last_issue.labels)
Пример #6
0
    def test_security_severity_functional_bug(self, project_name):
        """Test security severity label is not set for a functional bug."""
        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-'))
Пример #7
0
def get_issue_tracker(tracker_type, project_name=None, use_cache=False):
    """Get the issue tracker with the given type and name."""
    # TODO(ochang): Actually use `tracker_type`.
    assert tracker_type == 'monorail'
    if not project_name:
        from datastore import data_handler
        project_name = data_handler.get_issue_tracker_name()

    itm = _get_issue_tracker_manager_for_project(project_name,
                                                 use_cache=use_cache)
    if itm is None:
        return None

    return monorail.IssueTracker(itm)
    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',
            '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)

        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()
Пример #9
0
    def setUp(self):
        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 = 'name'
        mock_issue_merged.closed = datetime.datetime(2019, 1, 1)

        mock_issues = {
            1337: mock_issue,
            1338: mock_issue_merged,
        }

        self.itm = IssueTrackerManager('name', mock_issues)
        self.issue_tracker = monorail.IssueTracker(self.itm)
Пример #10
0
    def test_security_severity_security_bug_default_severity(
            self, project_name):
        """Test security severity label is set when testcase is a security bug and
    no severity can be determined."""
        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-')))
Пример #11
0
    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, [
        'metrics.logs.log_error',
        'base.utils.utcnow',
        'issue_management.issue_tracker_utils.get_issue_tracker',
        'handlers.base_handler.Handler.is_cron',
        '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
Пример #13
0
    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'])
Пример #14
0
    def test_security_severity_security_bug_severity_override(
            self, project_name):
        """Test security severity label is set correct when testcase has its own
    severity but there is an override provided."""
        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-')))
Пример #15
0
    def test_filed_issues_oss_fuzz(self):
        """Tests issue filing for oss-fuzz."""
        issue_tracker = monorail.IssueTracker(IssueTrackerManager('oss-fuzz'))
        issue_filer.file_issue(self.testcase1, 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(issue_filer.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(issue_filer.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(issue_filer.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(issue_filer.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(issue_filer.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(issue_filer.DEADLINE_NOTE,
                         issue_tracker._itm.last_issue.body)
Пример #16
0
 def test_filed_issues_chromium(self):
     """Tests issue filing for chromium."""
     issue_tracker = monorail.IssueTracker(IssueTrackerManager('chromium'))
     issue_filer.file_issue(self.testcase4, issue_tracker)
     self.assertIn('OS-Chrome', issue_tracker._itm.last_issue.labels)