コード例 #1
0
 def testGatherPageData_DownloadBadFilename(self):
   aid = self.attachment.attachment_id
   path = '/p/proj/issues/attachment?aid=%s&signed_aid=signed_%d' % (
       aid, aid)
   self.attachment.filename = '<script>alert("xsrf")</script>.txt';
   safe_filename = 'attachment-%d.dat' % aid
   self.mox.StubOutWithMock(gcs_helpers, 'MaybeCreateDownload')
   gcs_helpers.MaybeCreateDownload(
       'app_default_bucket',
       '/pid/attachments/object_id',
       safe_filename).AndReturn(True)
   self.mox.StubOutWithMock(gcs_helpers, 'SignUrl')
   gcs_helpers.SignUrl(
       'app_default_bucket',
       '/pid/attachments/object_id-download'
       ).AndReturn('googleusercontent.com/...-download...')
   self.mox.StubOutWithMock(self.servlet, 'redirect')
   _request, mr = testing_helpers.GetRequestObjects(
       project=self.project,
       path=path,
       perms=permissions.READ_ONLY_PERMISSIONSET)  # includes VIEW
   self.servlet.redirect(mox.And(
       mox.Not(mox.StrContains(self.attachment.filename)),
       mox.StrContains('googleusercontent.com')), abort=True)
   self.mox.ReplayAll()
   self.servlet.GatherPageData(mr)
   self.mox.VerifyAll()
コード例 #2
0
 def test_run_notifications_with_routing_keys(self):
     mock_logger = self._create_mock_logger()
     stacklog.get_logger('verifier', is_parent=False).AndReturn(mock_logger)
     self._mock_exchange_create_and_connect(
         self.verifier_with_notifications)
     self.mox.StubOutWithMock(self.verifier_with_notifications, '_run')
     self.verifier_with_notifications._run(callback=mox.Not(mox.Is(None)))
     self.mox.ReplayAll()
     self.verifier_with_notifications.run()
     self.mox.VerifyAll()
コード例 #3
0
 def testGatherPageData_DownloadBadFilename(self):
   aid = self.attachment.attachment_id
   self.attachment.filename = '<script>alert("xsrf")</script>.txt';
   self.mox.StubOutWithMock(self.servlet, 'redirect')
   _request, mr = testing_helpers.GetRequestObjects(
       project=self.project,
       path='/p/proj/issues/attachment?aid=%s' % aid,
       perms=permissions.READ_ONLY_PERMISSIONSET)  # includes VIEW
   self.servlet.redirect(mox.And(
       mox.Not(mox.StrContains(self.attachment.filename)),
       mox.StrContains('attachment-%d.dat' % aid)), abort=True)
   self.mox.ReplayAll()
   self.servlet.GatherPageData(mr)
   self.mox.VerifyAll()
コード例 #4
0
    def testLuksAsOwnerBarcodeTooLong(self):
        self.mox.StubOutWithMock(self.c, 'VerifyXsrfToken')
        self.c.VerifyXsrfToken('RetrieveSecret')

        mock_user = self.mox.CreateMockAnything()
        mock_user.email = '*****@*****.**'
        mock_user.__getitem__('email').AndReturn(mock_user.email)
        self.mox.StubOutWithMock(models, 'GetCurrentUser')
        models.GetCurrentUser().AndReturn(mock_user)
        models.GetCurrentUser().AndReturn(mock_user)

        self.mox.StubOutWithMock(self.c, 'VerifyPermissions')
        self.c.VerifyPermissions(
            permissions.RETRIEVE, user=mock_user).AndRaise(
                models.AccessDeniedError('user is not an admin'))
        self.c.VerifyPermissions(permissions.RETRIEVE_OWN, user=mock_user)

        volume_uuid = 'foovolumeuuid'
        passphrase = '676ffb71232f71ee0ddf643876907f17' * 20

        self.c.request = {'json': '0'}
        self.c.response = self.mox.CreateMockAnything()
        self.c.response.out = self.mox.CreateMockAnything()
        self.c.response.out.write(
            mox.And(mox.Not(mox.Regex(r'<img class="qr_code" ')),
                    mox.Regex(passphrase)))

        mock_entity = self.mox.CreateMockAnything()
        mock_entity.passphrase = passphrase
        mock_entity.owner = '*****@*****.**'

        self.mox.StubOutWithMock(models.LuksVolume, 'get_by_key_name')
        models.LuksVolume.get_by_key_name(volume_uuid).AndReturn(mock_entity)

        mock_user.user = self.mox.CreateMockAnything()
        self.mox.StubOutWithMock(mock_user.user, 'nickname')
        mock_user.user.nickname().AndReturn('mock_user_foo')

        self.mox.StubOutWithMock(models.LuksAccessLog, 'Log')
        models.LuksAccessLog.Log(message='GET',
                                 entity=mock_entity,
                                 request=self.c.request)

        self.mox.StubOutWithMock(self.c, 'SendRetrievalEmail')
        self.c.SendRetrievalEmail(mock_entity, mock_user).AndReturn(None)

        self.mox.ReplayAll()
        self.c.RetrieveSecret(volume_uuid)
        self.mox.VerifyAll()
コード例 #5
0
    def test_run_full(self):
        mock_logger = self._create_mock_logger()
        mock_logger.info('exchange: N: None, P: 0, S: 2, E: 0')
        stacklog.get_logger('verifier', is_parent=False).AndReturn(mock_logger)
        stacklog.get_logger('verifier', is_parent=False).AndReturn(mock_logger)

        self.mox.StubOutWithMock(transaction, 'commit_on_success')
        tran = self.mox.CreateMockAnything()
        tran.__enter__().AndReturn(tran)
        tran.__exit__(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
        transaction.commit_on_success().AndReturn(tran)
        self._mock_exchange_create_and_connect(
            self.verifier_with_notifications)
        self.verifier_with_notifications.exchange().AndReturn('exchange')
        self.mox.StubOutWithMock(self.verifier_with_notifications,
                                 '_keep_running')
        self.verifier_with_notifications._keep_running().AndReturn(True)
        start = datetime.datetime.utcnow()
        self.mox.StubOutWithMock(self.verifier_with_notifications, '_utcnow')
        self.verifier_with_notifications._utcnow().AndReturn(start)
        self.verifier_with_notifications._utcnow().AndReturn(start)
        settle_offset = {SETTLE_UNITS: SETTLE_TIME}
        ending_max = start - datetime.timedelta(**settle_offset)
        self.mox.StubOutWithMock(self.verifier_with_notifications,
                                 'verify_for_range')
        self.verifier_with_notifications.verify_for_range(ending_max,
                                                          callback=mox.Not(
                                                              mox.Is(None)))
        self.mox.StubOutWithMock(self.verifier_with_notifications,
                                 'reconcile_failed')
        result1 = self.mox.CreateMockAnything()
        result2 = self.mox.CreateMockAnything()
        self.verifier_with_notifications.results = [result1, result2]
        result1.ready().AndReturn(True)
        result1.successful().AndReturn(True)
        result1.get().AndReturn((True, None))
        result2.ready().AndReturn(True)
        result2.successful().AndReturn(True)
        result2.get().AndReturn((True, None))
        self.verifier_with_notifications.reconcile_failed()
        self.mox.StubOutWithMock(time, 'sleep', use_mock_anything=True)
        time.sleep(TICK_TIME)
        self.verifier_with_notifications._keep_running().AndReturn(False)
        self.mox.ReplayAll()

        self.verifier_with_notifications.run()

        self.mox.VerifyAll()
コード例 #6
0
    def testUpdateStateful(self):
        """Tests that we call the stateful update script with the correct args.
        """
        self.mox.StubOutWithMock(autoupdater.ChromiumOSUpdater, '_run')
        self.mox.StubOutWithMock(autoupdater.ChromiumOSUpdater,
                                 '_get_stateful_update_script')
        update_url = ('http://172.22.50.205:8082/update/lumpy-chrome-perf/'
                      'R28-4444.0.0-b2996')
        static_update_url = ('http://172.22.50.205:8082/static/'
                             'lumpy-chrome-perf/R28-4444.0.0-b2996')
        update_script = '/usr/local/bin/stateful_update'

        # Test with clobber=False.
        autoupdater.ChromiumOSUpdater._get_stateful_update_script().AndReturn(
                update_script)
        autoupdater.ChromiumOSUpdater._run(
                mox.And(
                        mox.StrContains(update_script),
                        mox.StrContains(static_update_url),
                        mox.Not(mox.StrContains('--stateful_change=clean'))),
                timeout=mox.IgnoreArg())

        self.mox.ReplayAll()
        updater = autoupdater.ChromiumOSUpdater(update_url)
        updater.update_stateful(clobber=False)
        self.mox.VerifyAll()

        # Test with clobber=True.
        self.mox.ResetAll()
        autoupdater.ChromiumOSUpdater._get_stateful_update_script().AndReturn(
                update_script)
        autoupdater.ChromiumOSUpdater._run(
                mox.And(
                        mox.StrContains(update_script),
                        mox.StrContains(static_update_url),
                        mox.StrContains('--stateful_change=clean')),
                timeout=mox.IgnoreArg())
        self.mox.ReplayAll()
        updater = autoupdater.ChromiumOSUpdater(update_url)
        updater.update_stateful(clobber=True)
        self.mox.VerifyAll()
コード例 #7
0
 def testInvalidKeyWithNot(self):
   """Should return False if they key is NOT in the dict."""
   self.assert_(mox.Not(mox.ContainsKeyValue("qux", 1)) == {"key": 2})
コード例 #8
0
 def testKeyInDict(self):
   """Should return True if the item is NOT a key in a dict."""
   self.assert_(mox.Not(mox.In("foo")) == {"key" : 42})
コード例 #9
0
 def testItemInList(self):
   """Should return True if the item is NOT in the list."""
   self.assert_(mox.Not(mox.In(42)) == [1, 2, 3])