def testUpdateUser(self):
     self.SetUpUpdateUser()
     user_a = user_pb2.User(email='*****@*****.**', banned='Turned spammer')
     self.mox.ReplayAll()
     self.user_service.UpdateUser(self.cnxn, 111L, user_a)
     self.mox.VerifyAll()
     self.assertFalse(self.user_service.user_2lc.HasItem(111L))
 def testDeletedUserOld(self):
   deleted_user = user_pb2.User(user_id=0)
   user_view = framework_views.UserView(deleted_user)
   self.assertEqual(
       user_view.display_name, framework_constants.DELETED_USER_NAME)
   self.assertEqual(user_view.email, '')
   self.assertEqual(user_view.obscure_email, '')
   self.assertEqual(user_view.profile_url, '')
 def testGetUser(self):
     SetUpGetUsers(self.user_service, self.cnxn)
     user_a = user_pb2.User(email='*****@*****.**')
     self.user_service.user_2lc.CacheItem(111L, user_a)
     self.mox.ReplayAll()
     user = self.user_service.GetUser(self.cnxn, 333L)
     self.mox.VerifyAll()
     self.assertEqual('*****@*****.**', user.email)
 def testUpdateUserSettings(self):
   self.SetUpUpdateUser()
   user_a = user_pb2.User(email='*****@*****.**')
   self.mox.ReplayAll()
   self.user_service.UpdateUserSettings(
       self.cnxn, 111, user_a, is_banned=True,
       banned_reason='Turned spammer')
   self.mox.VerifyAll()
Exemple #5
0
    def testNeedCaptcha_AuthUserLifetimeExcessiveActivityException(self):
        action = actionlimit.ISSUE_COMMENT
        user = user_pb2.User()
        life_max = actionlimit.ACTION_LIMITS[action][3]

        for _i in range(0, life_max):
            actionlimit.CountAction(user, action)

        self.assertRaises(actionlimit.ExcessiveActivityException,
                          actionlimit.NeedCaptcha, user, action)
Exemple #6
0
 def setUp(self):
     parent = user_pb2.User(user_id=111,
                            email='*****@*****.**',
                            linked_child_ids=[222])
     child = user_pb2.User(user_id=222,
                           email='*****@*****.**',
                           linked_parent_id=111)
     user_3 = user_pb2.User(user_id=333, email='*****@*****.**')
     user_4 = user_pb2.User(user_id=444, email='*****@*****.**')
     self.addr_perm_parent = notify_reasons.AddrPerm(
         False, parent.email, parent, notify_reasons.REPLY_NOT_ALLOWED)
     self.addr_perm_child = notify_reasons.AddrPerm(
         False, child.email, child, notify_reasons.REPLY_NOT_ALLOWED)
     self.addr_perm_3 = notify_reasons.AddrPerm(
         False, user_3.email, user_3, notify_reasons.REPLY_NOT_ALLOWED)
     self.addr_perm_4 = notify_reasons.AddrPerm(
         False, user_4.email, user_4, notify_reasons.REPLY_NOT_ALLOWED)
     self.addr_perm_5 = notify_reasons.AddrPerm(
         False, '*****@*****.**', None, notify_reasons.REPLY_NOT_ALLOWED)
 def setUp(self):
   project = project_pb2.Project()
   project.owner_ids.append(111)
   project.committer_ids.append(222)
   project.contributor_ids.append(333)
   project.contributor_ids.append(888)
   user = user_pb2.User()
   user.is_site_admin = False
   self.mr = monorailrequest.MonorailRequest(None)
   self.mr.project = project
   self.mr.auth.user_pb = user
Exemple #8
0
  def setUp(self):
    self.testbed = testbed.Testbed()
    self.testbed.activate()
    self.testbed.init_memcache_stub()

    self.mox = mox.Mox()
    self.cnxn = self.mox.CreateMock(sql.MonorailConnection)
    self.services = service_manager.Services()
    self.services.chart = MakeChartService(self.mox, self.services.config)
    self.config_service = fake.ConfigService()
    self.user = user_pb2.User()
Exemple #9
0
    def testCountAction_IncrementsRecentCount(self):
        action = actionlimit.ISSUE_COMMENT
        user = user_pb2.User()
        (_period, soft_limit, _hard_limit,
         _life_max) = actionlimit.ACTION_LIMITS[action]

        for i in range(1, soft_limit):
            actionlimit.CountAction(user, action)
            limit = actionlimit.GetLimitPB(user, action)
            self.assertEqual(i, limit.recent_count)
            self.assertEqual(i, limit.lifetime_count)
Exemple #10
0
    def testNeedCaptcha_AuthUserHardLimitExcessiveActivityException(self):
        action = actionlimit.ISSUE_COMMENT
        user = user_pb2.User()
        (_period, _soft_limit, hard_limit,
         _life_max) = actionlimit.ACTION_LIMITS[action]

        for _i in range(0, hard_limit):
            actionlimit.CountAction(user, action)

        self.assertRaises(actionlimit.ExcessiveActivityException,
                          actionlimit.NeedCaptcha, user, action)
    async def authenticate(self, request):
        if not request.session.get('user'):
            return AuthCredentials([]), UnauthenticatedUser()

        if '_connection' not in request.scope:
            return AuthCredentials([
                'authenticated'
            ]), user_pb2.User(email=request.session['user'])

        user = await _get_user(request, request.session['user'])

        if user is None:
            return AuthCredentials([]), UnauthenticatedUser()

        user = ParseDict(user, user_pb2.User())
        credentials = {
            'authenticated',
        }

        if user.confirmed:
            credentials.add('email_confirmed')

        target = getattr(request.scope['_parsed'],
                         get_check_attr(request.url.path), None)

        if target:
            if isinstance(target, str):
                for permission in user.permissions:
                    if str(permission.service_id
                           ) == target or permission.organization_id == target:
                        credentials |= PERMISSIONS_MAP[
                            permission.permission_type].permissions

            elif isiterable(target):
                for permission in user.permissions:
                    if str(permission.service_id
                           ) in target or permission.organization_id in target:
                        credentials |= PERMISSIONS_MAP[
                            permission.permission_type].permissions

        return AuthCredentials(list(credentials)), user
Exemple #12
0
 def setUp(self):
     self.hotlist = fake.Hotlist('hotlistName',
                                 123,
                                 hotlist_item_fields=[
                                     (2, 0, None, None, ''),
                                     (1, 0, None, None, ''),
                                     (5, 0, None, None, '')
                                 ],
                                 is_private=False,
                                 owner_ids=[111])
     self.user1 = user_pb2.User(user_id=111)
     self.user1_view = framework_views.UserView(self.user1)
  def testGatherHelpData_NewUser(self):
    mr = testing_helpers.MakeMonorailRequest(
        path='/p/proj/issues/entry', project=self.project)
    mr.auth.user_pb = user_pb2.User(user_id=111)
    mr.auth.user_id = 111

    help_data = self.servlet.GatherHelpData(mr, {})
    self.assertEqual(
        {'account_cue': None,
         'cue': 'privacy_click_through',
         'is_privileged_domain_user': None},
        help_data)
 def testGetUsersByIDs(self):
     SetUpGetUsers(self.user_service, self.cnxn)
     user_a = user_pb2.User(email='*****@*****.**')
     self.user_service.user_2lc.CacheItem(111L, user_a)
     self.mox.ReplayAll()
     user_dict = self.user_service.GetUsersByIDs(self.cnxn, [111L, 333L])
     self.mox.VerifyAll()
     self.assertEqual(2, len(user_dict))
     self.assertEqual('*****@*****.**', user_dict[111L].email)
     self.assertFalse(user_dict[111L].is_site_admin)
     self.assertFalse(user_dict[111L].banned)
     self.assertTrue(user_dict[111L].notify_issue_change)
     self.assertEqual('*****@*****.**', user_dict[333L].email)
Exemple #15
0
 def to_protobuf(self,
                 with_permissions=True,
                 permission_type='') -> user_pb2.User:
     return user_pb2.User(
         name=self.name,
         surname=self.surname,
         email=self.email,
         id=str(self.id),
         data=self.data,
         permissions=[
             permission.to_protobuf() for permission in self.permissions
         ] if with_permissions else [],
         permission_type=permission_type,
         confirmed=self.confirmed,
     )
Exemple #16
0
    def testNeedCaptcha_AuthUserHardLimitRespectsTimeout(self):
        action = actionlimit.ISSUE_COMMENT
        user = user_pb2.User()
        (period, _soft_limit, hard_limit,
         _life_max) = actionlimit.ACTION_LIMITS[action]
        now = int(time.time())
        later = now + period + 1  # a future in which our timestamp is expired

        for _i in range(0, hard_limit):
            actionlimit.CountAction(user, action, now=now)

        self.assertRaises(actionlimit.ExcessiveActivityException,
                          actionlimit.NeedCaptcha, user, action)
        # if we didn't pass later, we'd get an exception
        self.assertFalse(actionlimit.NeedCaptcha(user, action, now=later))
  def testGatherHelpData_AlreadyClickedThroughPrivacy(self):
    mr = testing_helpers.MakeMonorailRequest(
        path='/p/proj/issues/entry', project=self.project)
    mr.auth.user_pb = user_pb2.User(user_id=111)
    mr.auth.user_id = 111
    self.services.user.SetUserPrefs(
        self.cnxn, 111,
        [user_pb2.UserPrefValue(name='privacy_click_through', value='true')])

    help_data = self.servlet.GatherHelpData(mr, {})
    self.assertEqual(
        {'account_cue': None,
         'cue': 'code_of_conduct',
         'is_privileged_domain_user': None},
        help_data)
Exemple #18
0
    def testNeedCaptcha_AuthUserLifetimeIgnoresTimeout(self):
        action = actionlimit.ISSUE_COMMENT
        user = user_pb2.User()
        (period, _soft_limit, _hard_limit,
         life_max) = actionlimit.ACTION_LIMITS[action]
        now = int(time.time())
        later = now + period + 1  # a future in which our timestamp is expired

        for _i in range(0, life_max):
            actionlimit.CountAction(user, action, now=now)

        self.assertRaises(actionlimit.ExcessiveActivityException,
                          actionlimit.NeedCaptcha,
                          user,
                          action,
                          now=later)
Exemple #19
0
    def testCountAction_ResetRecentActions(self):
        action = actionlimit.ISSUE_COMMENT
        user = user_pb2.User()
        limit = actionlimit.GetLimitPB(user, action)
        limit.recent_count = 10
        limit.reset_timestamp = 11

        limit = actionlimit.GetLimitPB(user, action)
        self.assertEqual(10, limit.recent_count)
        self.assertEqual(11, limit.reset_timestamp)

        actionlimit.ResetRecentActions(user, action)

        limit = actionlimit.GetLimitPB(user, action)
        self.assertEqual(0, limit.recent_count)
        self.assertEqual(0, limit.reset_timestamp)
Exemple #20
0
 def to_protobuf(self,
                 with_user=False,
                 with_permissions=False) -> ticket_pb2.Ticket:
     return ticket_pb2.Ticket(
         id=str(self.id),
         user_id=str(self.user_id),
         service_id=str(self.service_id),
         organization_id=self.service.organization_id,
         ticket_id=self.ticket_id,
         enqueue_at=self.enqueue_at.timestamp(),
         accepted_at=self.accepted_at.timestamp()
         if self.accepted_at else 0,
         state=ticket_pb2.Ticket.State[self.state],
         window=self.window,
         resolution=ticket_pb2.Ticket.Resolution[self.resolution],
         user=self.user.to_protobuf(with_permissions=with_permissions)
         if with_user else user_pb2.User())
    def testShouldPreviewOnHover(self):
        saved_flag = settings.enable_quick_edit
        user = user_pb2.User()

        settings.enable_quick_edit = True
        user.preview_on_hover = True
        self.assertTrue(issuelist._ShouldPreviewOnHover(user))
        user.preview_on_hover = False
        self.assertFalse(issuelist._ShouldPreviewOnHover(user))

        settings.enable_quick_edit = False
        user.preview_on_hover = True
        self.assertFalse(issuelist._ShouldPreviewOnHover(user))
        user.preview_on_hover = False
        self.assertFalse(issuelist._ShouldPreviewOnHover(user))

        settings.enable_quick_edit = saved_flag
Exemple #22
0
    def testGetVisibleLiveProjects_AnyoneAccessWithUser(self):
        project_rows = [(234, 'proj2', 'test proj 2', 'test project', 'live',
                         'anyone', '', '', None, '', 0, 50 * 1024 * 1024, NOW,
                         NOW, None, True, False, False, None, None, None)]

        self.project_service.project_tbl.Select(
            self.cnxn,
            cols=['project_id'],
            state=project_pb2.ProjectState.LIVE).AndReturn(project_rows)
        self.SetUpGetProjects()
        self.mox.ReplayAll()
        user_a = user_pb2.User(email='*****@*****.**')
        project_ids = self.project_service.GetVisibleLiveProjects(
            self.cnxn, user_a, set([111]))

        self.mox.VerifyAll()
        self.assertItemsEqual([234], project_ids)
Exemple #23
0
    def testCustomizeLimit(self):
        user = user_pb2.User()

        self.assertIsNone(user.get_assigned_value('issue_comment_limit'))
        actionlimit.CustomizeLimit(user, actionlimit.ISSUE_COMMENT, 10, 100,
                                   500)
        self.assertIsNotNone(user.get_assigned_value('issue_comment_limit'))
        limit = user.issue_comment_limit

        # sets the specified limit
        self.assertIsNotNone(limit.get_assigned_value('lifetime_limit'))
        self.assertEqual(500, limit.lifetime_limit)
        self.assertEqual(10, limit.period_soft_limit)
        self.assertEqual(100, limit.period_hard_limit)

        # sets initial values to zero
        self.assertEqual(0, limit.recent_count)
        self.assertEqual(0, limit.reset_timestamp)
Exemple #24
0
    def testNeedCaptcha_NoLifetimeLimit(self):
        action = actionlimit.ISSUE_COMMENT
        user = user_pb2.User()
        life_max = actionlimit.ACTION_LIMITS[action][3]
        actionlimit.GetLimitPB(user, action).lifetime_count = life_max + 1

        self.assertRaises(actionlimit.ExcessiveActivityException,
                          actionlimit.NeedCaptcha,
                          user,
                          action,
                          skip_lifetime_check=False)
        self.assertFalse(
            actionlimit.NeedCaptcha(user, action, skip_lifetime_check=True))
        actionlimit.GetLimitPB(user, action).recent_count = 1
        actionlimit.GetLimitPB(user,
                               action).reset_timestamp = int(time.time()) + 5
        self.assertFalse(
            actionlimit.NeedCaptcha(user, action, skip_lifetime_check=True))
Exemple #25
0
    def testGetVisibleLiveProjects_ArchivedProject(self):
        project_rows = [
            (234, 'proj2', 'test proj 2', 'test project', 'archived', 'anyone',
             '', '', None, '', 0, 50 * 1024 * 1024, NOW, NOW, None, True,
             False, False, None, None, None, None, None, None)
        ]
        self.proj2.state = project_pb2.ProjectState.ARCHIVED
        self.project_service.project_2lc.CacheItem(234, self.proj2)

        self.project_service.project_tbl.Select(
            self.cnxn,
            cols=['project_id'],
            state=project_pb2.ProjectState.LIVE).AndReturn(project_rows)
        self.mox.ReplayAll()
        user_a = user_pb2.User(email='*****@*****.**')
        project_ids = self.project_service.GetVisibleLiveProjects(
            self.cnxn, user_a, set([111]))

        self.mox.VerifyAll()
        self.assertItemsEqual([], project_ids)
Exemple #26
0
    def testGetVisibleLiveProjects_RestrictedAccessWithNonMember(self):
        project_rows = [
            (234, 'proj2', 'test proj 2', 'test project', 'live',
             'members_only', '', '', None, '', 0, 50 * 1024 * 1024, NOW, NOW,
             None, True, False, False, None, None, None, None, None, None)
        ]
        self.proj2.access = project_pb2.ProjectAccess.MEMBERS_ONLY
        self.project_service.project_2lc.CacheItem(234, self.proj2)

        self.project_service.project_tbl.Select(
            self.cnxn,
            cols=['project_id'],
            state=project_pb2.ProjectState.LIVE).AndReturn(project_rows)
        self.mox.ReplayAll()
        user_a = user_pb2.User(email='*****@*****.**')
        project_ids = self.project_service.GetVisibleLiveProjects(
            self.cnxn, user_a, set([111]))

        self.mox.VerifyAll()
        self.assertItemsEqual([], project_ids)
Exemple #27
0
    def testCountAction_PeriodExpiration(self):
        action = actionlimit.ISSUE_COMMENT
        user = user_pb2.User()
        (period, soft_limit, _hard_limit,
         _life_max) = actionlimit.ACTION_LIMITS[action]
        now = int(time.time())
        later = now + period + 1  # a future in which our timestamp is expired

        for i in range(1, soft_limit):
            actionlimit.CountAction(user, action, now=now)
            limit = actionlimit.GetLimitPB(user, action)
            self.assertEqual(i, limit.recent_count)
            self.assertEqual(i, limit.lifetime_count)

        actionlimit.CountAction(user, action, now=now)
        self.assertEqual(soft_limit, limit.recent_count)
        self.assertEqual(soft_limit, limit.lifetime_count)

        actionlimit.CountAction(user, action, now=later)
        self.assertEqual(1, limit.recent_count)
        self.assertEqual(soft_limit + 1, limit.lifetime_count)
 def setUp(self):
     self.user_prefs = user_pb2.UserPrefs()
     self.user = user_pb2.User()
     self.issue = fake.MakeTestIssue(789, 1, 'summary one', 'New', 111)
     self.rvg_issue = fake.MakeTestIssue(789,
                                         2,
                                         'summary two',
                                         'New',
                                         111,
                                         labels=['Restrict-View-Google'])
     self.more_restricted_issue = fake.MakeTestIssue(
         789, 3, 'summary three', 'New', 111, labels=['Restrict-View-Core'])
     self.both_restricted_issue = fake.MakeTestIssue(
         789,
         4,
         'summary four',
         'New',
         111,
         labels=['Restrict-View-Google', 'Restrict-View-Core'])
     self.addr_perm = notify_reasons.AddrPerm(
         False, '*****@*****.**', self.user,
         notify_reasons.REPLY_MAY_COMMENT, self.user_prefs)
Exemple #29
0
import grpc

from proto import user_pb2
from proto import user_pb2_grpc

channel = grpc.insecure_channel('localhost:4001')

stub = user_pb2_grpc.HelloStub(channel)

# create a valid request message
user_name = user_pb2.User(first_name='Snehil', last_name='Banerjee')

response = stub.hello_user(user_name)

# et voilà
print(response.resp)
 def setUp(self):
   self.user = user_pb2.User(user_id=111)