Exemplo n.º 1
0
    def test_raw_post_data_partial_read(self):
        if django.VERSION[:2] < (1, 3):
            return
        v = six.b('{"foo": "bar"}')
        request = WSGIRequest(
            environ={
                'wsgi.input': six.BytesIO(v + six.b('\r\n\r\n')),
                'REQUEST_METHOD': 'POST',
                'SERVER_NAME': 'testserver',
                'SERVER_PORT': '80',
                'CONTENT_TYPE': 'application/octet-stream',
                'CONTENT_LENGTH': len(v),
                'ACCEPT': 'application/json',
            })
        request.read(1)

        self.opbeat.capture('Message', message='foo', request=request)

        self.assertEquals(len(self.opbeat.events), 1)
        event = self.opbeat.events.pop(0)

        self.assertTrue('http' in event)
        http = event['http']
        self.assertEquals(http['method'], 'POST')
        self.assertEquals(http['data'], '<unavailable>')
Exemplo n.º 2
0
 def test_non_utf8_encoding(self):
     data = {
         'http': {
             'query_string': six.b('broken=') + u"aéöüa".encode('latin-1')
         }
     }
     proc = SanitizePasswordsProcessor(Mock())
     result = proc.process(data)
     assert result['http']['query_string'] == u'broken=a\ufffd\ufffd\ufffda'
Exemplo n.º 3
0
    def test_post_raw_data(self):
        request = WSGIRequest(environ={
            'wsgi.input': six.BytesIO(six.b('foobar')),
            'REQUEST_METHOD': 'POST',
            'SERVER_NAME': 'testserver',
            'SERVER_PORT': '80',
            'CONTENT_TYPE': 'application/octet-stream',
            'ACCEPT': 'application/json',
            'CONTENT_LENGTH': '6',
        })
        self.opbeat.capture('Message', message='foo', request=request)

        self.assertEquals(len(self.opbeat.events), 1)
        event = self.opbeat.events.pop(0)

        self.assertTrue('http' in event)
        http = event['http']
        self.assertEquals(http['method'], 'POST')
        self.assertEquals(http['data'], six.b('foobar'))
Exemplo n.º 4
0
 def test_post_as_string(self):
     data = {
         'http': {
             'data': six.b('password=evil&api_key=evil&harmless=bar'),
         }
     }
     proc = SanitizePasswordsProcessor(Mock())
     result = proc.process(data)
     self.assertTrue('http' in result)
     http = result['http']
     assert 'evil' not in force_text(http['data'])
Exemplo n.º 5
0
 def test_post_as_string(self):
     data = {
         'http': {
             'data': six.b('password=evil&api_key=evil&harmless=bar'),
         }
     }
     proc = SanitizePasswordsProcessor(Mock())
     result = proc.process(data)
     self.assertTrue('http' in result)
     http = result['http']
     assert 'evil' not in force_text(http['data'])
Exemplo n.º 6
0
    def test_raw_post_data_partial_read(self):
        if django.VERSION[:2] < (1, 3):
            return
        v = six.b('{"foo": "bar"}')
        request = WSGIRequest(environ={
            'wsgi.input': six.BytesIO(v + six.b('\r\n\r\n')),
            'REQUEST_METHOD': 'POST',
            'SERVER_NAME': 'testserver',
            'SERVER_PORT': '80',
            'CONTENT_TYPE': 'application/octet-stream',
            'CONTENT_LENGTH': len(v),
            'ACCEPT': 'application/json',
        })
        request.read(1)

        self.opbeat.capture('Message', message='foo', request=request)

        self.assertEquals(len(self.opbeat.events), 1)
        event = self.opbeat.events.pop(0)

        self.assertTrue('http' in event)
        http = event['http']
        self.assertEquals(http['method'], 'POST')
        self.assertEquals(http['data'], '<unavailable>')
Exemplo n.º 7
0
 def test_send_with_auth_header(self, time, send_remote):
     time.return_value = 1328055286.51
     client = Client(
         servers=["http://example.com"], organization_id="organization_id", app_id="app_id", secret_token="secret"
     )
     client.send(auth_header="foo", **{"foo": "bar"})
     send_remote.assert_called_once_with(
         url="http://example.com",
         data=six.b("x\x9c\xabVJ\xcb\xcfW\xb2RPJJ,R\xaa\x05\x00 \x98\x04T"),
         headers={
             "Content-Type": "application/octet-stream",
             "Authorization": "foo",
             "User-Agent": "opbeat-python/%s" % opbeat.VERSION,
             "X-Opbeat-Platform": self.client.get_platform_info(),
         },
     )
Exemplo n.º 8
0
 def test_send_with_auth_header(self, time, send_remote):
     time.return_value = 1328055286.51
     client = Client(
         servers=['http://example.com'],
         organization_id='organization_id',
         app_id='app_id',
         secret_token='secret',
     )
     client.send(auth_header='foo', **{
         'foo': 'bar',
     })
     send_remote.assert_called_once_with(
         url='http://example.com',
         data=six.b('x\x9c\xabVJ\xcb\xcfW\xb2RPJJ,R\xaa\x05\x00 \x98\x04T'),
         headers={
             'Content-Type': 'application/octet-stream',
             'Authorization': 'foo',
             'User-Agent': 'opbeat-python/%s' % opbeat.VERSION
         },
     )
Exemplo n.º 9
0
 def test_send_with_auth_header(self, time, send_remote):
     time.return_value = 1328055286.51
     client = Client(
         servers=['http://example.com'],
         organization_id='organization_id',
         app_id='app_id',
         secret_token='secret',
     )
     client.send(auth_header='foo', **{
         'foo': 'bar',
     })
     send_remote.assert_called_once_with(
         url='http://example.com',
         data=six.b('x\x9c\xabVJ\xcb\xcfW\xb2RPJJ,R\xaa\x05\x00 \x98\x04T'),
         headers={
             'Content-Type': 'application/octet-stream',
             'Authorization': 'foo',
             'User-Agent': 'opbeat-python/%s' % opbeat.VERSION,
             'X-Opbeat-Platform': self.client.get_platform_info(),
         },
     )
Exemplo n.º 10
0
 def test_send(self, time, send_remote):
     time.return_value = 1328055286.51
     public = "public"
     access_token = "secret"
     client = Client(
         servers=['http://example.com'],
         organization_id='organization_id',
         app_id='app_id',
         secret_token='secret',
     )
     client.send(**{
         'foo': 'bar',
     })
     send_remote.assert_called_once_with(
         url='http://example.com',
         data=six.b('x\x9c\xabVJ\xcb\xcfW\xb2RPJJ,R\xaa\x05\x00 \x98\x04T'),
         headers={
             'Content-Type': 'application/octet-stream',
             'Authorization': 'Bearer %s' % (access_token),
             'User-Agent': 'opbeat-python/%s' % opbeat.VERSION
         },
     )
Exemplo n.º 11
0
 def test_send(self, time, send_remote):
     time.return_value = 1328055286.51
     public = "public"
     access_token = "secret"
     client = Client(
         servers=['http://example.com'],
         organization_id='organization_id',
         app_id='app_id',
         secret_token='secret',
     )
     client.send(**{
         'foo': 'bar',
     })
     send_remote.assert_called_once_with(
         url='http://example.com',
         data=six.b('x\x9c\xabVJ\xcb\xcfW\xb2RPJJ,R\xaa\x05\x00 \x98\x04T'),
         headers={
             'Content-Type': 'application/octet-stream',
             'Authorization': 'Bearer %s' % (access_token),
             'User-Agent': 'opbeat-python/%s' % opbeat.VERSION,
             'X-Opbeat-Platform': self.client.get_platform_info(),
         },
     )
Exemplo n.º 12
0
    def test_bad_string(self):
        x = six.b('The following character causes problems: \xd4')

        result = transform(x)
        self.assertEquals(type(result), six.binary_type)
        self.assertEquals(result, six.b('(Error decoding value)'))
Exemplo n.º 13
0
    def test_bad_string(self):
        x = six.b('The following character causes problems: \xd4')

        result = transform(x)
        self.assertEquals(type(result), six.binary_type)
        self.assertEquals(result, six.b('(Error decoding value)'))