Esempio n. 1
0
 def test_should_send_report_request_if_check_fails(self):
     wrappee = _DummyWsgiApp()
     control_client = mock.MagicMock(spec=client.Client)
     given = {
         u'wsgi.url_scheme': u'http',
         u'PATH_INFO': u'/any',
         u'REMOTE_ADDR': u'192.168.0.3',
         u'HTTP_HOST': u'localhost',
         u'HTTP_REFERER': u'example.myreferer.com',
         u'REQUEST_METHOD': u'GET'}
     dummy_response = sc_messages.CheckResponse(
         operationId = u'fake_operation_id',
         checkErrors = [
             sc_messages.CheckError(
                 code=sc_messages.CheckError.CodeValueValuesEnum.PROJECT_DELETED)
         ]
     )
     wrapped = wsgi.add_all(wrappee,
                            self.PROJECT_ID,
                            control_client,
                            loader=service.Loaders.SIMPLE)
     control_client.check.return_value = dummy_response
     wrapped(given, _dummy_start_response)
     expect(control_client.check.called).to(be_true)
     expect(control_client.report.called).to(be_true)
     expect(control_client.allocate_quota.called).to(be_false)
Esempio n. 2
0
    def test_signals_resend_on_1st_call_after_flush_interval_with_errors(self):
        req = _make_test_request(self.SERVICE_NAME)
        failure_code = sc_messages.CheckError.CodeValueValuesEnum.NOT_FOUND
        fake_response = sc_messages.CheckResponse(
            operationId=self.FAKE_OPERATION_ID, checkErrors=[
                sc_messages.CheckError(code=failure_code)
            ])
        agg = self.agg
        expect(agg.check(req)).to(be_none)
        agg.add_response(req, fake_response)
        expect(agg.check(req)).to(equal(fake_response))

        # Now flush interval is reached, but not the response expiry
        self.timer.tick() # now past the flush_interval
        expect(agg.check(req)).to(be_none)  # first response is null

        # until expiry, the response will continue to be returned
        expect(agg.check(req)).to(equal(fake_response))
        expect(agg.check(req)).to(equal(fake_response))

        # expire
        self.timer.tick()
        self.timer.tick() # now expired
        expect(agg.check(req)).to(be_none)
        expect(agg.check(req)).to(be_none) # 2nd check is None as well
Esempio n. 3
0
 def test_should_include_project_id_in_error_text_when_needed(self):
     resp = sc_messages.CheckResponse(
         checkErrors = [
             sc_messages.CheckError(
                 code=sc_messages.CheckError.CodeValueValuesEnum.PROJECT_DELETED)
         ]
     )
     code, got, _ = check_request.convert_response(resp, self.PROJECT_ID)
     want = u'Project %s has been deleted' % (self.PROJECT_ID,)
     expect(code).to(equal(httplib.FORBIDDEN))
     expect(got).to(equal(want))
Esempio n. 4
0
 def test_should_include_detail_in_error_text_when_needed(self):
     detail = u'details, details, details'
     resp = sc_messages.CheckResponse(
         checkErrors = [
             sc_messages.CheckError(
                 code=sc_messages.CheckError.CodeValueValuesEnum.IP_ADDRESS_BLOCKED,
                 detail=detail)
         ]
     )
     code, got, _ = check_request.convert_response(resp, self.PROJECT_ID)
     expect(code).to(equal(httplib.FORBIDDEN))
     expect(got).to(equal(detail))