コード例 #1
0
  def setUp(self):
    self.mox = mox.Mox()
    self.testbed = testbed.Testbed()
    self.testbed.activate()
    self.testbed.init_memcache_stub()
    self.testbed.init_datastore_v3_stub()
    self.testbed.init_user_stub()

    self.cnxn = fake.MonorailConnection()
    self.services = service_manager.Services(
        user=fake.UserService(),
        usergroup=fake.UserGroupService(),
        project=fake.ProjectService(),
        cache_manager=fake.CacheManager())
    self.project = self.services.project.TestAddProject(
        'proj', project_id=789, owner_ids=[111])
    self.user = self.services.user.TestAddUser('*****@*****.**', 222)
    self.svcr = TestableServicer(self.services)
    self.token = xsrf.GenerateToken(222, xsrf.XHR_SERVLET_PATH)
    self.request = UpdateSomethingRequest(exc_class=None)
    self.prpc_context = context.ServicerContext()
    self.prpc_context.set_code(codes.StatusCode.OK)
    self.auth = authdata.AuthData(user_id=222, email='*****@*****.**')

    self.oauth_patcher = mock.patch(
        'google.appengine.api.oauth.get_current_user')
    self.mock_oauth_gcu = self.oauth_patcher.start()
    self.mock_oauth_gcu.return_value = None
コード例 #2
0
ファイル: authdata_test.py プロジェクト: xinghun61/infra
 def testFinishInitialization_ComputedUserGroup(self):
     """effective_ids should be {user_id, group_id...}."""
     self.services.usergroup.TestAddGroupSettings(888,
                                                  '*****@*****.**')
     auth = authdata.AuthData(user_id=111, email='*****@*****.**')
     authdata.AuthData._FinishInitialization(self.cnxn, auth, self.services)
     self.assertEqual(auth.user_id, 111)
     self.assertEqual(auth.effective_ids, {111, 888})
コード例 #3
0
ファイル: authdata_test.py プロジェクト: xinghun61/infra
    def testFinishInitialization_AccountHasParent(self):
        """The parent's effective_ids are added to child's."""
        child = self.services.user.TestAddUser('*****@*****.**', 111)
        child.linked_parent_id = 222
        parent = self.services.user.TestAddUser('*****@*****.**', 222)
        parent.linked_child_ids = [111]
        auth = authdata.AuthData(user_id=111, email='*****@*****.**')
        authdata.AuthData._FinishInitialization(self.cnxn, auth, self.services)
        self.assertEqual(auth.user_id, 111)
        self.assertEqual(auth.effective_ids, {111, 222})

        self.services.usergroup.TestAddMembers(888, [111])
        self.services.usergroup.TestAddMembers(999, [222])
        auth = authdata.AuthData(user_id=111, email='*****@*****.**')
        authdata.AuthData._FinishInitialization(self.cnxn, auth, self.services)
        self.assertEqual(auth.user_id, 111)
        self.assertEqual(auth.effective_ids, {111, 222, 888, 999})
コード例 #4
0
ファイル: authdata_test.py プロジェクト: xinghun61/infra
 def testFinishInitialization_NormalMemberships(self):
     """effective_ids should be {user_id, group_id...}."""
     self.services.usergroup.TestAddMembers(888, [111])
     self.services.usergroup.TestAddMembers(999, [111])
     auth = authdata.AuthData(user_id=111, email='*****@*****.**')
     authdata.AuthData._FinishInitialization(self.cnxn, auth, self.services)
     self.assertEqual(auth.user_id, 111)
     self.assertEqual(auth.effective_ids, {111, 888, 999})
コード例 #5
0
    def testGatherPageData(self):
        mr = testing_helpers.MakeMonorailRequest(
            path='/p/proj/people/list',
            project=self.project,
            perms=permissions.OWNER_ACTIVE_PERMISSIONSET)
        mr.auth = authdata.AuthData()
        page_data = self.servlet.GatherPageData(mr)

        self.assertEqual(1, page_data['total_num_owners'])
コード例 #6
0
 def testGatherPageData(self):
     mr = testing_helpers.MakeMonorailRequest(
         path='/p/proj/people/detail?u=111',
         project=self.project,
         perms=permissions.OWNER_ACTIVE_PERMISSIONSET)
     mr.auth = authdata.AuthData()
     page_data = self.servlet.GatherPageData(mr)
     self.assertFalse(page_data['warn_abandonment'])
     self.assertEquals(2, page_data['total_num_owners'])
コード例 #7
0
ファイル: authdata_test.py プロジェクト: xinghun61/infra
    def testFinishInitialization_AccountHasChildren(self):
        """All linked child effective_ids are added to parent's."""
        child1 = self.services.user.TestAddUser('*****@*****.**', 111)
        child1.linked_parent_id = 333
        child2 = self.services.user.TestAddUser('*****@*****.**', 222)
        child2.linked_parent_id = 333
        parent = self.services.user.TestAddUser('*****@*****.**', 333)
        parent.linked_child_ids = [111, 222]

        auth = authdata.AuthData(user_id=333, email='*****@*****.**')
        authdata.AuthData._FinishInitialization(self.cnxn, auth, self.services)
        self.assertEqual(auth.user_id, 333)
        self.assertEqual(auth.effective_ids, {111, 222, 333})

        self.services.usergroup.TestAddMembers(888, [111])
        self.services.usergroup.TestAddMembers(999, [222])
        auth = authdata.AuthData(user_id=333, email='*****@*****.**')
        authdata.AuthData._FinishInitialization(self.cnxn, auth, self.services)
        self.assertEqual(auth.user_id, 333)
        self.assertEqual(auth.effective_ids, {111, 222, 333, 888, 999})
コード例 #8
0
 def testRepr(self):
     """We get nice debugging strings."""
     auth = authdata.AuthData(user_id=111, email='*****@*****.**')
     mc = monorailcontext.MonorailContext(
         None,
         cnxn=self.cnxn,
         auth=auth,
         perms=permissions.USER_PERMISSIONSET)
     repr_str = '%r' % mc
     self.assertTrue(repr_str.startswith('MonorailContext('))
     self.assertIn('*****@*****.**', repr_str)
     self.assertIn('view', repr_str)
コード例 #9
0
    def testProcessAlert_NewIssue(self, fake_pasicn, fake_pasibn):
        """When an alert for a new incident comes in, create a new issue."""
        self.mox.StubOutWithMock(tracker_helpers, 'LookupComponentIDs')
        tracker_helpers.LookupComponentIDs(['Infra'],
                                           mox.IgnoreArg()).AndReturn([1])

        self.mox.StubOutWithMock(self.services.config, 'LookupLabelID')
        self.services.config.LookupLabelID(
            self.cnxn, self.project.project_id,
            'Incident-Id-incident-1').AndReturn(None)

        # Mock command parsing.
        mock_uia = commitlogcommands.UpdateIssueAction(101)
        self.mox.StubOutWithMock(commitlogcommands, 'UpdateIssueAction')
        commitlogcommands.UpdateIssueAction(101).AndReturn(mock_uia)

        self.mox.StubOutWithMock(mock_uia, 'Parse')
        mock_uia.Parse(self.cnxn,
                       self.project.project_name,
                       111, ['issue body'],
                       self.services,
                       strip_quoted_lines=True)

        self.mox.ReplayAll()

        auth = authdata.AuthData(user_id=111, email='*****@*****.**')
        ret = self.inbound.ProcessAlert(self.cnxn, self.project,
                                        self.project_addr, '*****@*****.**',
                                        auth, 'issue title', 'issue body',
                                        'incident-1')

        self.mox.VerifyAll()
        self.assertIsNone(ret)

        actual_issue = self.services.issue.GetIssueByLocalID(
            self.cnxn, self.project.project_id, 101)
        actual_comments = self.services.issue.GetCommentsForIssue(
            self.cnxn, actual_issue.issue_id)
        self.assertEqual('issue title', actual_issue.summary)
        self.assertEqual('Available', actual_issue.status)
        self.assertEqual(111, actual_issue.reporter_id)
        self.assertEqual([1], actual_issue.component_ids)
        self.assertEqual(None, actual_issue.owner_id)
        self.assertEqual([
            'Infra-Troopers-Alerts', 'Restrict-View-Google', 'Pri-2',
            'Incident-Id-incident-1'
        ], actual_issue.labels)
        self.assertEqual(
            'Filed by [email protected] on behalf of [email protected]\n\nissue body',
            actual_comments[0].content)
        self.assertEqual(1, len(fake_pasicn.mock_calls))
        self.assertEqual(1, len(fake_pasibn.mock_calls))
コード例 #10
0
    def testProcessAlert_ExistingIssue(self):
        """When an alert for an ongoing incident comes in, add a comment."""
        self.issue.labels = ['Incident-Id-incident-1']
        self.mox.StubOutWithMock(self.services.config, 'LookupLabelID')
        self.services.config.LookupLabelID(
            self.cnxn, self.project.project_id,
            'Incident-Id-incident-1').AndReturn(1234)

        self.mox.StubOutWithMock(self.services.issue, 'GetIIDsByLabelIDs')
        self.services.issue.GetIIDsByLabelIDs(self.cnxn, [1234],
                                              self.project.project_id,
                                              None).AndReturn([1])

        self.mox.StubOutWithMock(self.services.issue, 'GetOpenAndClosedIssues')
        self.services.issue.GetOpenAndClosedIssues(self.cnxn, [1]).AndReturn(
            ([self.issue], []))

        self.mox.StubOutWithMock(self.services.issue, 'GetComments')
        self.services.issue.GetComments(self.cnxn,
                                        issue_id=[self.issue.issue_id],
                                        commenter_id=[111]).AndReturn([])

        self.mox.StubOutWithMock(self.services.issue, 'CreateIssueComment')
        self.services.issue.CreateIssueComment(
            self.cnxn, self.issue, 111,
            'Filed by [email protected] on behalf of [email protected]\n\nissue body'
        ).AndReturn(None)

        # Mock command parsing.
        mock_uia = commitlogcommands.UpdateIssueAction(self.issue.local_id)
        self.mox.StubOutWithMock(commitlogcommands, 'UpdateIssueAction')
        commitlogcommands.UpdateIssueAction(
            self.issue.local_id).AndReturn(mock_uia)

        self.mox.StubOutWithMock(mock_uia, 'Parse')
        mock_uia.Parse(self.cnxn,
                       self.project.project_name,
                       111, ['issue body'],
                       self.services,
                       strip_quoted_lines=True)

        self.mox.ReplayAll()

        auth = authdata.AuthData(user_id=111, email='*****@*****.**')
        ret = self.inbound.ProcessAlert(self.cnxn, self.project,
                                        self.project_addr, '*****@*****.**',
                                        auth, 'issue title', 'issue body',
                                        'incident-1')

        self.mox.VerifyAll()
        self.assertIsNone(ret)
コード例 #11
0
ファイル: monorailrequest.py プロジェクト: xinghun61/infra
    def __init__(self, services, params=None):
        """Initialize the MonorailRequest object."""
        # Note: mr starts off assuming anon until ParseRequest() is called.
        super(MonorailRequest, self).__init__(services)
        self.form_overrides = {}
        if params:
            self.form_overrides.update(params)
        self.debug_enabled = False
        self.use_cached_searches = True

        self.hotlist_id = None
        self.hotlist = None
        self.hotlist_name = None

        self.viewed_username = None
        self.viewed_user_auth = authdata.AuthData()
コード例 #12
0
    def testProcessAlert_NonWhitelistedSender(self):
        self.assertTrue(self.inbound.IsWhitelisted('*****@*****.**'))
        self.assertFalse(self.inbound.IsWhitelisted('*****@*****.**'))

        self.mox.StubOutWithMock(self.inbound, 'IsWhitelisted')
        self.inbound.IsWhitelisted('*****@*****.**').AndReturn(False)

        self.mox.ReplayAll()
        auth = authdata.AuthData(user_id=111, email='*****@*****.**')
        ret = self.inbound.ProcessAlert(self.cnxn, self.project,
                                        self.project_addr,
                                        '*****@*****.**', auth,
                                        'issue title', 'issue body',
                                        'incident')

        self.mox.VerifyAll()
        self.assertIsNone(ret)
コード例 #13
0
    def testConstructor_PassingAuthAndPerms(self):
        """We can easily make an mc for testing."""
        auth = authdata.AuthData(user_id=111, email='*****@*****.**')
        mc = monorailcontext.MonorailContext(
            None,
            cnxn=self.cnxn,
            auth=auth,
            perms=permissions.USER_PERMISSIONSET)
        self.assertEqual(self.cnxn, mc.cnxn)
        self.assertEqual(auth, mc.auth)
        self.assertEqual(permissions.USER_PERMISSIONSET, mc.perms)
        self.assertTrue(isinstance(mc.profiler, profiler.Profiler))
        self.assertEqual([], mc.warnings)
        self.assertTrue(isinstance(mc.errors, template_helpers.EZTError))

        mc.CleanUp()
        self.assertIsNone(mc.cnxn)
コード例 #14
0
    def setUp(self):
        # services
        self.services = service_manager.Services(
            config=fake.ConfigService(),
            issue=fake.IssueService(),
            user=fake.UserService(),
            usergroup=fake.UserGroupService(),
            project=fake.ProjectService())

        # project
        self.project = self.services.project.TestAddProject(
            self.project_name,
            project_id=self.project_id,
            process_inbound_email=True,
            contrib_ids=[self.user_id])

        # sender
        self.auth = authdata.AuthData(user_id=self.user_id,
                                      email=self.from_addr)

        # issue
        self.issue = tracker_pb2.Issue(
            project_id=self.project_id,
            local_id=self.test_issue_local_id,
            summary=self.msg_subject,
            reporter_id=self.user_id,
            component_ids=[self.component_id],
            status=self.alert_props['status'],
            labels=self.alert_props['labels'],
        )
        self.services.issue.TestAddIssue(self.issue)

        # Patch send_notifications functions.
        self.notification_patchers = [
            patch('features.send_notifications.%s' % func, spec=True)
            for func in [
                'PrepareAndSendIssueBlockingNotification',
                'PrepareAndSendIssueChangeNotification',
            ]
        ]
        self.blocking_notification = self.notification_patchers[0].start()
        self.blocking_notification = self.notification_patchers[1].start()

        self.mox = mox.Mox()
コード例 #15
0
    def testProcessAlert_NewIssue_Codesearch(self, fake_pasicn, fake_pasibn):
        """When an alert for a new incident comes in, create a new issue.

    If the body contains the string 'codesearch' then we should auto-assign to
    the Infra>Codesearch component."""
        self.mox.StubOutWithMock(tracker_helpers, 'LookupComponentIDs')
        tracker_helpers.LookupComponentIDs(['Infra>Codesearch'],
                                           mox.IgnoreArg()).AndReturn([2])

        self.mox.StubOutWithMock(self.services.config, 'LookupLabelID')
        self.services.config.LookupLabelID(
            self.cnxn, self.project.project_id,
            'Incident-Id-incident-1').AndReturn(None)

        # Mock command parsing.
        mock_uia = commitlogcommands.UpdateIssueAction(101)
        self.mox.StubOutWithMock(commitlogcommands, 'UpdateIssueAction')
        commitlogcommands.UpdateIssueAction(101).AndReturn(mock_uia)

        self.mox.StubOutWithMock(mock_uia, 'Parse')
        mock_uia.Parse(self.cnxn,
                       self.project.project_name,
                       111, ['issue body codesearch'],
                       self.services,
                       strip_quoted_lines=True)

        self.mox.ReplayAll()

        auth = authdata.AuthData(user_id=111, email='*****@*****.**')
        ret = self.inbound.ProcessAlert(self.cnxn, self.project,
                                        self.project_addr, '*****@*****.**',
                                        auth, 'issue title',
                                        'issue body codesearch', 'incident-1')

        self.mox.VerifyAll()
        self.assertIsNone(ret)

        actual_issue = self.services.issue.GetIssueByLocalID(
            self.cnxn, self.project.project_id, 101)
        self.assertEqual([2], actual_issue.component_ids)
        self.assertEqual(1, len(fake_pasicn.mock_calls))
        self.assertEqual(1, len(fake_pasibn.mock_calls))
コード例 #16
0
    def testProcessAlert_ExistingIssueTimeDelay(self):
        """Don't add a comment if it's been less than 24 hours."""
        self.issue.labels = ['Incident-Id-incident-1']
        self.mox.StubOutWithMock(self.services.config, 'LookupLabelID')
        self.services.config.LookupLabelID(
            self.cnxn, self.project.project_id,
            'Incident-Id-incident-1').AndReturn(1234)

        self.mox.StubOutWithMock(self.services.issue, 'GetIIDsByLabelIDs')
        self.services.issue.GetIIDsByLabelIDs(self.cnxn, [1234],
                                              self.project.project_id,
                                              None).AndReturn([1])

        self.mox.StubOutWithMock(self.services.issue, 'GetOpenAndClosedIssues')
        self.services.issue.GetOpenAndClosedIssues(self.cnxn, [1]).AndReturn(
            ([self.issue], []))

        comment = tracker_pb2.IssueComment()
        comment.timestamp = int(time.time())

        self.mox.StubOutWithMock(self.services.issue, 'GetComments')
        self.services.issue.GetComments(self.cnxn,
                                        issue_id=[self.issue.issue_id],
                                        commenter_id=[111
                                                      ]).AndReturn([comment])

        # CreateIssueComment should not be called.
        self.mox.StubOutWithMock(self.services.issue, 'CreateIssueComment')

        self.mox.ReplayAll()

        auth = authdata.AuthData(user_id=111, email='*****@*****.**')
        ret = self.inbound.ProcessAlert(self.cnxn, self.project,
                                        self.project_addr, '*****@*****.**',
                                        auth, 'issue title', 'issue body',
                                        'incident-1')

        self.mox.VerifyAll()
        self.assertIsNone(ret)
コード例 #17
0
ファイル: authdata_test.py プロジェクト: xinghun61/infra
 def testFinishInitialization_NoMemberships(self):
     """No user groups means effective_ids == {user_id}."""
     auth = authdata.AuthData(user_id=111, email='*****@*****.**')
     authdata.AuthData._FinishInitialization(self.cnxn, auth, self.services)
     self.assertEqual(auth.user_id, 111)
     self.assertEqual(auth.effective_ids, {111})