Plugin Directory

Changeset 1418133


Ignore:
Timestamp:
05/16/2016 08:30:17 PM (10 years ago)
Author:
rmb185
Message:

Version 1.1

Location:
getsentry-client/trunk
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • getsentry-client/trunk/raven/AUTHORS

    r1098247 r1418133  
    1 The Raven PHP client was originally written by Michael van Tellingen
     1The Sentry PHP SDK was originally written by Michael van Tellingen
    22and is maintained by the Sentry Team.
    33
    4 http://github.com/getsentry/raven-php/contributors
     4http://github.com/getsentry/sentry-php/contributors
  • getsentry-client/trunk/raven/CHANGES

    r1098363 r1418133  
     10.15.0
     2------
     3
     4- Fixed some cases where serialization wouldn't happen.
     5- Added sdk attribute.
     6
     70.14.0
     8------
     9
     10- Added ``prefixes`` option for stripping absolute paths.
     11- Removed ``abs_path`` from stacktraces.
     12- Added ``app_path`` to specify application root for resolving ``in_app` on frames.
     13- Moved Laravel support to ``sentry-laravel`` project.
     14- Fixed duplicate stack computation.
     15- Added ``dsn`` option to ease configuration.
     16- Fixed an issue with the curl async transport.
     17- Improved serialization of values.
     18
     190.13.0
     20------
     21
     22- Updated API to use new style interfaces.
     23- Remove session cookie in default processor.
     24- Expand docs for Laravel, Symfony2, and Monolog.
     25- Default error types can now be set as part of ErrorHandler configuration.
     26
     270.12.1
     28------
     29
     30- Dont send empty values for various context.
     31
     320.12.0
     33------
     34
     35- Bumped protocol version to 6.
     36- Fixed an issue with the async curl handler (GH-216).
     37- Removed UDP transport.
     38
     390.11.0
     40------
     41
     42- New configuration parameter: 'release'
     43- New configuration parameter: 'message_limit'
     44- New configuration parameter: 'curl_ssl_version'
     45- New configuration parameter: 'curl_ipv4'
     46- New configuration parameter: 'verify_ssl'
     47- Updated remote endpoint to use modern project-based path.
     48- Expanded default sanitizer support to include 'auth_pw' attribute.
     49
    1500.10.0
    251------
  • getsentry-client/trunk/raven/LICENSE

    r1098247 r1418133  
    88    2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    99
    10     3. Neither the name of the Raven nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
     10    3. Neither the name of the Raven, Sentry, nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
    1111
    1212THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  • getsentry-client/trunk/raven/Makefile

    r1098247 r1418133  
    11.PHONY: test
    22
    3 develop:
     3develop: update-submodules
    44    composer install --dev
    55    make setup-git
    66
    7 test:
     7update-submodules:
     8    git submodule init
     9    git submodule update
     10
     11cs:
     12    vendor/bin/php-cs-fixer fix --config-file=.php_cs --verbose --diff
     13
     14cs-dry-run:
     15    vendor/bin/php-cs-fixer fix --config-file=.php_cs --verbose --diff --dry-run
     16
     17test: cs-dry-run
    818    vendor/bin/phpunit
    919
  • getsentry-client/trunk/raven/README.rst

    r1098363 r1418133  
    1 raven-php
    2 =========
    3 
    4 .. image:: https://secure.travis-ci.org/getsentry/raven-php.png?branch=master
    5    :target: http://travis-ci.org/getsentry/raven-php
    6 
    7 
    8 raven-php is a PHP client for `Sentry <http://aboutsentry.com/>`_.
     1sentry-php
     2==========
     3
     4.. image:: https://secure.travis-ci.org/getsentry/sentry-php.png?branch=master
     5   :target: http://travis-ci.org/getsentry/sentry-php
     6
     7
     8The official PHP SDK for `Sentry <https://getsentry.com/>`_.
    99
    1010.. code-block:: php
     
    4848dependencies, you can add Raven with it.
    4949
    50 .. code-block:: json
    51 
    52     {
    53         "require": {
    54             "raven/raven": "$VERSION"
    55         }
    56     }
    57 
    58 (replace ``$VERSION`` with one of the available versions on `Packagist <https://packagist.org/packages/raven/raven>`_)
     50::
     51
     52    $ composer require sentry/sentry:$VERSION
     53
     54(replace ``$VERSION`` with one of the available versions on `Packagist <https://packagist.org/packages/sentry/sentry>`_)
    5955or to get the latest version off the master branch:
    6056
    61 .. code-block:: json
    62 
    63     {
    64         "require": {
    65             "raven/raven": "dev-master"
    66         }
    67     }
     57::
     58
     59    $ composer require sentry/sentry:dev-master
    6860
    6961Note that using unstable versions is not recommended and should be avoided. Also
    7062you should define a maximum version, e.g. by doing ``>=0.6,<1.0`` or ``~0.6``.
    7163
     64Alternatively, use the ``^`` operator for specifying a version, e.g.,
     65
     66::
     67
     68    $ composer require sentry/sentry:^0.11.0
     69
    7270Composer will take care of the autoloading for you, so if you require the
    7371``vendor/autoload.php``, you're good to go.
     
    8179::
    8280
    83     $ git clone git://github.com/getsentry/raven-php.git
     81    $ git clone git://github.com/getsentry/sentry-php.git
    8482
    8583And including it using the autoloader:
     
    9896.. code-block:: bash
    9997
    100     $ bin/raven test https://public:secret@app.getsentry.com/1
     98    $ bin/sentry test https://public:secret@app.getsentry.com/1
    10199    Client configuration:
    102     -> servers: [https://sentry.example.com/api/store/]
     100    -> server: [https://sentry.example.com/api/store/]
    103101    -> project: 1
    104102    -> public_key: public
     
    263261::
    264262
    265     $ bin/phpunit
     263    $ vendor/bin/phpunit
    266264
    267265
     
    270268---------
    271269
    272 * `Bug Tracker <http://github.com/getsentry/raven-php/issues>`_
    273 * `Code <http://github.com/getsentry/raven-php>`_
     270* `Bug Tracker <http://github.com/getsentry/sentry-php/issues>`_
     271* `Code <http://github.com/getsentry/sentry-php>`_
    274272* `Mailing List <https://groups.google.com/group/getsentry>`_
    275273* `IRC <irc://irc.freenode.net/sentry>`_  (irc.freenode.net, #sentry)
  • getsentry-client/trunk/raven/composer.json

    r1098247 r1418133  
    11{
    2     "name": "raven/raven",
     2    "name": "sentry/sentry",
    33    "type": "library",
    44    "description": "A PHP client for Sentry (http://getsentry.com)",
    55    "keywords": ["log", "logging"],
    66    "homepage": "http://getsentry.com",
    7     "license": "BSD",
     7    "license": "BSD-3-Clause",
    88    "authors": [
    99        {
     
    1313    ],
    1414    "require-dev": {
    15         "phpunit/phpunit": "3.7.*"
     15        "fabpot/php-cs-fixer": "^1.8.0",
     16        "phpunit/phpunit": "^4.6.6"
    1617    },
    1718    "require": {
    18         "php": ">=5.2.4"
     19        "php": ">=5.2.4",
     20        "ext-curl": "*",
     21        "monolog/monolog": "*"
    1922    },
    2023    "bin": [
    21         "bin/raven"
     24        "bin/sentry"
    2225    ],
    23     "config": {
    24         "bin-dir": "bin"
    25     },
    2626    "autoload": {
    2727        "psr-0" : {
     
    3131    "extra": {
    3232        "branch-alias": {
    33             "dev-master": "0.8.x-dev"
     33            "dev-master": "0.17.x-dev"
    3434        }
    3535    }
  • getsentry-client/trunk/raven/lib/Raven/Client.php

    r1098363 r1418133  
    1717class Raven_Client
    1818{
    19     const VERSION = '0.10.0';
    20     const PROTOCOL = '5';
     19    const VERSION = '0.17.0';
     20    const PROTOCOL = '6';
    2121
    2222    const DEBUG = 'debug';
     
    2929    const MESSAGE_LIMIT = 1024;
    3030
    31     var $severity_map;
    32     var $extra_data;
    33 
    34     var $store_errors_for_bulk_send = false;
     31    public $severity_map;
     32    public $extra_data;
     33
     34    public $store_errors_for_bulk_send = false;
    3535
    3636    public function __construct($options_or_dsn=null, $options=array())
    3737    {
    38         if (is_null($options_or_dsn) && !empty($_SERVER['SENTRY_DSN'])) {
    39             // Read from environment
    40             $options_or_dsn = $_SERVER['SENTRY_DSN'];
    41         }
    42         if (!is_array($options_or_dsn)) {
    43             if (!empty($options_or_dsn)) {
    44                 // Must be a valid DSN
    45                 $options_or_dsn = self::parseDSN($options_or_dsn);
    46             } else {
    47                 $options_or_dsn = array();
    48             }
    49         }
    50         $options = array_merge($options_or_dsn, $options);
     38        if (is_array($options_or_dsn)) {
     39            $options = array_merge($options_or_dsn, $options);
     40        }
     41
     42        if (!is_array($options_or_dsn) && !empty($options_or_dsn)) {
     43            $dsn = $options_or_dsn;
     44        } elseif (!empty($_SERVER['SENTRY_DSN'])) {
     45            $dsn = @$_SERVER['SENTRY_DSN'];
     46        } elseif (!empty($options['dsn'])) {
     47            $dsn = $options['dsn'];
     48        } else {
     49            $dsn = null;
     50        }
     51
     52        if (!empty($dsn)) {
     53            $options = array_merge($options, self::parseDSN($dsn));
     54        }
    5155
    5256        $this->logger = Raven_Util::get($options, 'logger', 'php');
    53         $this->servers = Raven_Util::get($options, 'servers');
     57        $this->server = Raven_Util::get($options, 'server');
    5458        $this->secret_key = Raven_Util::get($options, 'secret_key');
    5559        $this->public_key = Raven_Util::get($options, 'public_key');
     
    5963        $this->site = Raven_Util::get($options, 'site', $this->_server_variable('SERVER_NAME'));
    6064        $this->tags = Raven_Util::get($options, 'tags', array());
     65        $this->release = Raven_Util::get($options, 'release', null);
     66        $this->environment = Raven_Util::get($options, 'environment', null);
    6167        $this->trace = (bool) Raven_Util::get($options, 'trace', true);
    6268        $this->timeout = Raven_Util::get($options, 'timeout', 2);
    6369        $this->message_limit = Raven_Util::get($options, 'message_limit', self::MESSAGE_LIMIT);
    6470        $this->exclude = Raven_Util::get($options, 'exclude', array());
    65         $this->severity_map = NULL;
     71        $this->severity_map = null;
    6672        $this->shift_vars = (bool) Raven_Util::get($options, 'shift_vars', true);
    6773        $this->http_proxy = Raven_Util::get($options, 'http_proxy');
     
    7177        $this->curl_path = Raven_Util::get($options, 'curl_path', 'curl');
    7278        $this->curl_ipv4 = Raven_util::get($options, 'curl_ipv4', true);
    73         $this->ca_cert = Raven_util::get($options, 'ca_cert', $this->get_default_ca_cert());
    74         $this->curl_ssl_version = Raven_Util::get($options, 'curl_ssl_version');
     79        $this->ca_cert = Raven_Util::get($options, 'ca_cert', $this->get_default_ca_cert());
     80        $this->verify_ssl = Raven_Util::get($options, 'verify_ssl', true);
     81        $this->curl_ssl_version = Raven_Util::get($options, 'curl_ssl_version');
     82        $this->trust_x_forwarded_proto = Raven_Util::get($options, 'trust_x_forwarded_proto');
     83        // a list of prefixes used to coerce absolute paths into relative
     84        $this->prefixes = Raven_Util::get($options, 'prefixes', null);
     85        // app path is used to determine if code is part of your application
     86        $this->app_path = Raven_Util::get($options, 'app_path', null);
    7587
    7688        $this->processors = $this->setProcessorsFromOptions($options);
    7789
    7890        $this->_lasterror = null;
     91        $this->_last_event_id = null;
    7992        $this->_user = null;
    8093        $this->context = new Raven_Context();
     94        $this->breadcrumbs = new Raven_Breadcrumbs();
     95        $this->sdk = Raven_Util::get($options, 'sdk', array(
     96            'name' => 'sentry-php',
     97            'version' => self::VERSION,
     98        ));
    8199
    82100        if ($this->curl_method == 'async') {
     
    99117     * @return array
    100118     */
    101     public function setProcessorsFromOptions($options){
     119    public function setProcessorsFromOptions($options)
     120    {
    102121        $processors = array();
    103122        foreach (Raven_util::get($options, 'processors', self::getDefaultProcessors()) as $processor) {
    104123            $new_processor = new $processor($this);
    105124
    106             if( isset($options['processorOptions']) && is_array($options['processorOptions']) ){
    107                 if( isset($options['processorOptions'][$processor]) && method_exists($processor, 'setProcessorOptions') ){
     125            if (isset($options['processorOptions']) && is_array($options['processorOptions'])) {
     126                if (isset($options['processorOptions'][$processor]) && method_exists($processor, 'setProcessorOptions')) {
    108127                    $new_processor->setProcessorOptions($options['processorOptions'][$processor]);
    109128                }
     
    124143        $url = parse_url($dsn);
    125144        $scheme = (isset($url['scheme']) ? $url['scheme'] : '');
    126         if (!in_array($scheme, array('http', 'https', 'udp'))) {
     145        if (!in_array($scheme, array('http', 'https'))) {
    127146            throw new InvalidArgumentException('Unsupported Sentry DSN scheme: ' . (!empty($scheme) ? $scheme : '<not set>'));
    128147        }
     
    150169
    151170        return array(
    152             'servers'    => array(sprintf('%s://%s%s/api/store/', $scheme, $netloc, $path)),
     171            'server'     => sprintf('%s://%s%s/api/%s/store/', $scheme, $netloc, $path, $project),
    153172            'project'    => $project,
    154173            'public_key' => $username,
     
    204223        if ($level_or_options === null) {
    205224            $data = array();
    206         } else if (!is_array($level_or_options)) {
     225        } elseif (!is_array($level_or_options)) {
    207226            $data = array(
    208227                'level' => $level_or_options,
     
    255274            );
    256275
    257             /**'sentry.interfaces.Exception'
     276            /**'exception'
    258277             * Exception::getTrace doesn't store the point at where the exception
    259278             * was thrown, so we have to stuff it in ourselves. Ugh.
     
    274293            $exc_data['stacktrace'] = array(
    275294                'frames' => Raven_Stacktrace::get_stack_info(
    276                     $trace, $this->trace, $this->shift_vars, $vars, $this->message_limit
     295                    $trace, $this->trace, $this->shift_vars, $vars, $this->message_limit, $this->prefixes,
     296                    $this->app_path
    277297                ),
    278298            );
    279299
    280300            $exceptions[] = $exc_data;
    281 
    282301        } while ($has_chained_exceptions && $exc = $exc->getPrevious());
    283302
    284303        $data['message'] = $message;
    285         $data['sentry.interfaces.Exception'] = array(
     304        $data['exception'] = array(
    286305            'values' => array_reverse($exceptions),
    287306        );
     
    320339    }
    321340
     341    /**
     342     * Return the last captured event's ID or null if none available.
     343     */
     344    public function getLastEventID()
     345    {
     346        return $this->_last_event_id;
     347    }
     348
    322349    protected function is_http_request()
    323350    {
     
    331358        foreach ($_SERVER as $key => $value) {
    332359            if (0 === strpos($key, 'HTTP_')) {
    333                 if (in_array($key, array('HTTP_CONTENT_TYPE', 'HTTP_CONTENT_LENGTH'))) {
    334                     continue;
    335                 }
    336360                $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($key, 5)))))] = $value;
    337             } elseif (in_array($key, array('CONTENT_TYPE', 'CONTENT_LENGTH'))) {
     361            } elseif (in_array($key, array('CONTENT_TYPE', 'CONTENT_LENGTH')) && $value !== '') {
    338362                $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', $key))))] = $value;
    339363            } else {
     
    364388
    365389        return array(
    366             'sentry.interfaces.Http' => $result,
     390            'request' => $result,
    367391        );
    368392    }
     
    383407        }
    384408        return array(
    385             'sentry.interfaces.User' => $user,
     409            'user' => $user,
    386410        );
    387411    }
     
    401425            'tags' => $this->tags,
    402426            'platform' => 'php',
    403         );
    404     }
    405 
    406     public function capture($data, $stack, $vars = null)
    407     {
    408         if (!isset($data['timestamp'])) $data['timestamp'] = gmdate('Y-m-d\TH:i:s\Z');
    409         if (!isset($data['level'])) $data['level'] = self::ERROR;
    410         if (!isset($data['tags'])) $data['tags'] = array();
    411         if (!isset($data['extra'])) $data['extra'] = array();
    412         if (!isset($data['event_id'])) $data['event_id'] = $this->uuid4();
     427            'sdk' => $this->sdk,
     428        );
     429    }
     430
     431    public function capture($data, $stack = null, $vars = null)
     432    {
     433        if (!isset($data['timestamp'])) {
     434            $data['timestamp'] = gmdate('Y-m-d\TH:i:s\Z');
     435        }
     436        if (!isset($data['level'])) {
     437            $data['level'] = self::ERROR;
     438        }
     439        if (!isset($data['tags'])) {
     440            $data['tags'] = array();
     441        }
     442        if (!isset($data['extra'])) {
     443            $data['extra'] = array();
     444        }
     445        if (!isset($data['event_id'])) {
     446            $data['event_id'] = $this->uuid4();
     447        }
    413448
    414449        if (isset($data['message'])) {
     
    423458
    424459        $data = array_merge($this->get_user_data(), $data);
     460
     461        if ($this->release) {
     462            $data['release'] = $this->release;
     463        }
     464        if ($this->environment) {
     465            $data['environment'] = $this->environment;
     466        }
    425467
    426468        $data['tags'] = array_merge(
     
    434476            $data['extra']);
    435477
    436         if ((!$stack && $this->auto_log_stacks) || $stack === True) {
     478        if (empty($data['extra'])) {
     479            unset($data['extra']);
     480        } else {
     481            $data['extra'] = $data['extra'];
     482        }
     483
     484        if (empty($data['tags'])) {
     485            unset($data['tags']);
     486        } else {
     487            $data['tags'] = $data['tags'];
     488        }
     489        if (!empty($data['user'])) {
     490            $data['user'] = $data['user'];
     491        }
     492        if (!empty($data['request'])) {
     493            $data['request'] = $data['request'];
     494        }
     495
     496        if (!$this->breadcrumbs->is_empty()) {
     497            $data['breadcrumbs'] = $this->breadcrumbs->fetch();
     498        }
     499
     500        if ((!$stack && $this->auto_log_stacks) || $stack === true) {
    437501            $stack = debug_backtrace();
    438502
     
    447511            }
    448512
    449             if (!isset($data['sentry.interfaces.Stacktrace'])) {
    450                 $data['sentry.interfaces.Stacktrace'] = array(
     513            if (!isset($data['stacktrace']) && !isset($data['exception'])) {
     514                $data['stacktrace'] = array(
    451515                    'frames' => Raven_Stacktrace::get_stack_info(
    452                         $stack, $this->trace, $this->shift_vars, $vars, $this->message_limit
     516                        $stack, $this->trace, $this->shift_vars, $vars, $this->message_limit,
     517                        $this->prefixes, $this->app_path
    453518                    ),
    454519                );
     
    459524        $this->process($data);
    460525
    461         if(!$this->store_errors_for_bulk_send){
     526        if (!$this->store_errors_for_bulk_send) {
    462527            $this->send($data);
    463         }else{
    464             if(empty($this->error_data)){
     528        } else {
     529            if (empty($this->error_data)) {
    465530                $this->error_data = array();
    466531            }
     
    468533        }
    469534
     535        $this->_last_event_id = $data['event_id'];
     536
    470537        return $data['event_id'];
    471538    }
     
    473540    public function sanitize(&$data)
    474541    {
    475         // manually trigger autoloading, as it's not done in some edge cases due to PHP bugs (see #60149)
    476         if (!class_exists('Raven_Serializer')) {
    477             spl_autoload_call('Raven_Serializer');
    478         }
    479 
    480         $data = Raven_Serializer::serialize($data);
    481542    }
    482543
     
    493554    }
    494555
    495     public function sendUnsentErrors(){
    496         if(!empty($this->error_data)){
    497             foreach($this->error_data as $data){
     556    public function sendUnsentErrors()
     557    {
     558        if (!empty($this->error_data)) {
     559            foreach ($this->error_data as $data) {
    498560                $this->send($data);
    499561            }
    500562            unset($this->error_data);
    501563        }
    502         if($this->store_errors_for_bulk_send){
     564        if ($this->store_errors_for_bulk_send) {
    503565            //in case an error occurs after this is called, on shutdown, send any new errors.
    504566            $this->store_errors_for_bulk_send = !defined('RAVEN_CLIENT_END_REACHED');
     
    507569
    508570    /**
    509      * Wrapper to handle encoding and sending data to all defined Sentry servers
     571     * Wrapper to handle encoding and sending data to the Sentry API server.
    510572     *
    511573     * @param array     $data       Associative array of data to log
     
    518580        }
    519581
    520         if (!$this->servers) {
     582        if (!$this->server) {
    521583            return;
    522584        }
     
    529591        $message = base64_encode($message); // PHP's builtin curl_* function are happy without this, but the exec method requires it
    530592
    531         foreach ($this->servers as $url) {
    532             $client_string = 'raven-php/' . self::VERSION;
    533             $timestamp = microtime(true);
    534             $headers = array(
    535                 'User-Agent' => $client_string,
    536                 'X-Sentry-Auth' => $this->get_auth_header(
    537                     $timestamp, $client_string, $this->public_key,
    538                     $this->secret_key),
    539                 'Content-Type' => 'application/octet-stream'
    540             );
    541 
    542             $this->send_remote($url, $message, $headers);
    543         }
     593        $client_string = 'sentry-php/' . self::VERSION;
     594        $timestamp = microtime(true);
     595        $headers = array(
     596            'User-Agent' => $client_string,
     597            'X-Sentry-Auth' => $this->get_auth_header(
     598                $timestamp, $client_string, $this->public_key,
     599                $this->secret_key),
     600            'Content-Type' => 'application/octet-stream'
     601        );
     602
     603        $this->send_remote($this->server, $message, $headers);
    544604    }
    545605
     
    555615        $parts = parse_url($url);
    556616        $parts['netloc'] = $parts['host'].(isset($parts['port']) ? ':'.$parts['port'] : null);
    557 
    558         if ($parts['scheme'] === 'udp') {
    559             $this->send_udp($parts['netloc'], $data, $headers['X-Sentry-Auth']);
    560         }
    561         else {
    562             $this->send_http($url, $data, $headers);
    563         }
    564     }
    565 
    566     /**
    567      * Send data to Sentry via udp socket
    568      *
    569      * @param string    $netloc     host:port || host
    570      * @param array     $data       Associative array of data to log
    571      * @param array     $headers    Associative array of headers
    572      */
    573     private function send_udp($netloc, $data, $headers)
    574     {
    575         list($host, $port) = explode(':', $netloc);
    576         $raw_data = $headers."\n\n".$data;
    577 
    578         $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
    579         socket_sendto($sock, $raw_data, strlen($raw_data), 0, $host, $port);
    580         socket_close($sock);
    581     }
    582 
    583     protected function get_default_ca_cert() {
     617        $this->send_http($url, $data, $headers);
     618    }
     619
     620    protected function get_default_ca_cert()
     621    {
    584622        return dirname(__FILE__) . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'cacert.pem';
    585623    }
     
    590628            CURLOPT_VERBOSE => false,
    591629            CURLOPT_SSL_VERIFYHOST => 2,
    592             CURLOPT_SSL_VERIFYPEER => true,
     630            CURLOPT_SSL_VERIFYPEER => $this->verify_ssl,
    593631            CURLOPT_CAINFO => $this->ca_cert,
    594             CURLOPT_USERAGENT => 'raven-php/' . self::VERSION,
     632            CURLOPT_USERAGENT => 'sentry-php/' . self::VERSION,
    595633        );
    596634        if ($this->http_proxy) {
     
    598636        }
    599637        if ($this->curl_ssl_version) {
    600             $options[CURLOPT_SSLVERSION] = $this->curl_ssl_version;
     638            $options[CURLOPT_SSLVERSION] = $this->curl_ssl_version;
    601639        }
    602640        if ($this->curl_ipv4) {
     
    606644            // MS is available in curl >= 7.16.2
    607645            $timeout = max(1, ceil(1000 * $this->timeout));
     646
     647            // some versions of PHP 5.3 don't have this defined correctly
     648            if (!defined('CURLOPT_CONNECTTIMEOUT_MS')) {
     649                //see http://stackoverflow.com/questions/9062798/php-curl-timeout-is-not-working/9063006#9063006
     650                define('CURLOPT_CONNECTTIMEOUT_MS', 156);
     651            }
     652
    608653            $options[CURLOPT_CONNECTTIMEOUT_MS] = $timeout;
    609654            $options[CURLOPT_TIMEOUT_MS] = $timeout;
     
    643688     * @return bool
    644689     */
    645     private function send_http_asynchronous_curl_exec($url, $data, $headers) {
     690    private function send_http_asynchronous_curl_exec($url, $data, $headers)
     691    {
    646692        // TODO(dcramer): support ca_cert
    647693        $cmd = $this->curl_path.' -X POST ';
     
    652698        $cmd .= '\''. $url .'\' ';
    653699        $cmd .= '-m 5 ';  // 5 second timeout for the whole process (connect + send)
     700        if (!$this->verify_ssl) {
     701            $cmd .= '-k ';
     702        }
    654703        $cmd .= '> /dev/null 2>&1 &'; // ensure exec returns immediately while curl runs in the background
    655704
     
    673722            array_push($new_headers, $key .': '. $value);
    674723        }
     724        // XXX(dcramer): Prevent 100-continue response form server (Fixes GH-216)
     725        $new_headers[] = 'Expect:';
    675726
    676727        $curl = curl_init($url);
     
    745796        $uuid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
    746797            // 32 bits for "time_low"
    747             mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
     798            mt_rand(0, 0xffff), mt_rand(0, 0xffff),
    748799
    749800            // 16 bits for "time_mid"
    750             mt_rand( 0, 0xffff ),
     801            mt_rand(0, 0xffff),
    751802
    752803            // 16 bits for "time_hi_and_version",
    753804            // four most significant bits holds version number 4
    754             mt_rand( 0, 0x0fff ) | 0x4000,
     805            mt_rand(0, 0x0fff) | 0x4000,
    755806
    756807            // 16 bits, 8 bits for "clk_seq_hi_res",
    757808            // 8 bits for "clk_seq_low",
    758809            // two most significant bits holds zero and one for variant DCE1.1
    759             mt_rand( 0, 0x3fff ) | 0x8000,
     810            mt_rand(0, 0x3fff) | 0x8000,
    760811
    761812            // 48 bits for "node"
    762             mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
     813            mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
    763814        );
    764815
     
    771822     * @return string|null
    772823     */
    773     private function get_current_url()
     824    protected function get_current_url()
    774825    {
    775826        // When running from commandline the REQUEST_URI is missing.
     
    778829        }
    779830
    780         $schema = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'
    781             || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
    782 
    783         return $schema . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     831        // HTTP_HOST is a client-supplied header that is optional in HTTP 1.0
     832        $host = (!empty($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST']
     833            : (!empty($_SERVER['LOCAL_ADDR'])  ? $_SERVER['LOCAL_ADDR']
     834            : (!empty($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '')));
     835
     836        $httpS = $this->isHttps() ? 's' : '';
     837        return "http{$httpS}://{$host}{$_SERVER['REQUEST_URI']}";
     838    }
     839
     840    /**
     841     * Was the current request made over https?
     842     *
     843     * @return bool
     844     */
     845    protected function isHttps()
     846    {
     847        if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') {
     848            return true;
     849        }
     850
     851        if (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443) {
     852            return true;
     853        }
     854
     855        if (!empty($this->trust_x_forwarded_proto) &&
     856            !empty($_SERVER['X-FORWARDED-PROTO']) &&
     857            $_SERVER['X-FORWARDED-PROTO'] === 'https') {
     858            return true;
     859        }
     860
     861        return false;
    784862    }
    785863
     
    805883     * @return string           Sentry log level group
    806884     */
    807     public function translateSeverity($severity) {
     885    public function translateSeverity($severity)
     886    {
    808887        if (is_array($this->severity_map) && isset($this->severity_map[$severity])) {
    809888            return $this->severity_map[$severity];
     
    825904        }
    826905        if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
    827           switch ($severity) {
     906            switch ($severity) {
    828907            case E_DEPRECATED:         return Raven_Client::WARN;
    829908            case E_USER_DEPRECATED:    return Raven_Client::WARN;
     
    839918     * @param array $map
    840919     */
    841     public function registerSeverityMap($map) {
     920    public function registerSeverityMap($map)
     921    {
    842922        $this->severity_map = $map;
    843923    }
     
    850930     * @param array $data           Additional user data
    851931     */
    852     public function set_user_data($id, $email=null, $data=array()) {
    853         $this->user_context(array_merge(array(
    854             'id'    => $id,
    855             'email' => $email,
    856         ), $data));
     932    public function set_user_data($id, $email=null, $data=array())
     933    {
     934        $user = array('id' => $id);
     935        if (isset($email)) {
     936            $user['email'] = $email;
     937        }
     938        $this->user_context(array_merge($user, $data));
    857939    }
    858940
     
    862944     * @param array $data   Associative array of user data
    863945     */
    864     public function user_context($data) {
     946    public function user_context($data)
     947    {
    865948        $this->context->user = $data;
    866949    }
     
    871954     * @param array $data   Associative array of tags
    872955     */
    873     public function tags_context($data) {
     956    public function tags_context($data)
     957    {
    874958        $this->context->tags = array_merge($this->context->tags, $data);
    875959    }
     
    880964     * @param array $data   Associative array of extra data
    881965     */
    882     public function extra_context($data) {
     966    public function extra_context($data)
     967    {
    883968        $this->context->extra = array_merge($this->context->extra, $data);
    884969    }
     
    887972     * @param array $processors
    888973     */
    889     public function setProcessors(array $processors){
     974    public function setProcessors(array $processors)
     975    {
    890976        $this->processors = $processors;
    891977    }
  • getsentry-client/trunk/raven/lib/Raven/Compat.php

    r1098247 r1418133  
    1212class Raven_Compat
    1313{
    14 
    1514    public static function gethostname()
    1615    {
  • getsentry-client/trunk/raven/lib/Raven/CurlHandler.php

    r1098363 r1418133  
    4646            array_push($new_headers, $key .': '. $value);
    4747        }
     48        // XXX(dcramer): Prevent 100-continue response form server (Fixes GH-216)
     49        $new_headers[] = 'Expect:';
    4850
    4951        curl_setopt($ch, CURLOPT_HTTPHEADER, $new_headers);
     
    7072    public function join($timeout=null)
    7173    {
    72         if (!isset($timeout)) {
    73             $timeout = $this->join_timeout;
    74         }
     74        if (!isset($timeout)) {
     75            $timeout = $this->join_timeout;
     76        }
    7577        $start = time();
    7678        do {
     
    8082            }
    8183            usleep(10000);
    82         } while ($timeout !== 0 && time() - $start > $timeout);
     84        } while ($timeout !== 0 && time() - $start < $timeout);
    8385    }
    8486
     
    9597                    $mrc = curl_multi_exec($this->multi_handle, $active);
    9698                } while ($mrc == CURLM_CALL_MULTI_PERFORM);
    97             }
    98             else {
     99            } else {
    99100                return;
    100101            }
  • getsentry-client/trunk/raven/lib/Raven/ErrorHandler.php

    r1098247 r1418133  
    2222 */
    2323
     24// TODO(dcramer): deprecate default error types in favor of runtime configuration
     25// unless a reason can be determined that making them dynamic is better. They
     26// currently are not used outside of the fatal handler.
    2427class Raven_ErrorHandler
    2528{
     
    3033    private $reservedMemory;
    3134    private $send_errors_last = false;
    32     private $error_types = -1;
    33 
    34     public function __construct($client, $send_errors_last = false)
     35
     36    /**
     37     * @var array
     38     * Error types which should be processed by the handler.
     39     * A 'null' value implies "whatever error_reporting is at time of error".
     40     */
     41    private $error_types = null;
     42
     43    /**
     44     * @deprecated
     45     * @var array
     46     * Error types that can be processed by the handler
     47     */
     48    private $validErrorTypes = array(
     49        E_ERROR,
     50        E_WARNING,
     51        E_PARSE,
     52        E_NOTICE,
     53        E_CORE_ERROR,
     54        E_CORE_WARNING,
     55        E_COMPILE_ERROR,
     56        E_COMPILE_WARNING,
     57        E_USER_ERROR,
     58        E_USER_WARNING,
     59        E_USER_NOTICE,
     60        E_STRICT,
     61        E_RECOVERABLE_ERROR,
     62        E_DEPRECATED,
     63        E_USER_DEPRECATED,
     64    );
     65
     66    /**
     67     * @deprecated
     68     * @var array
     69     * The default Error types that are always processed by the handler. Can be set during construction.
     70     */
     71    private $defaultErrorTypes = array(
     72        E_ERROR,
     73        E_PARSE,
     74        E_CORE_ERROR,
     75        E_CORE_WARNING,
     76        E_COMPILE_ERROR,
     77        E_COMPILE_WARNING,
     78        E_STRICT,
     79    );
     80
     81    public function __construct($client, $send_errors_last = false, $default_error_types = null,
     82                                $error_types = null)
    3583    {
    3684        $this->client = $client;
     85        if ($default_error_types !== null) {
     86            $this->defaultErrorTypes = $default_error_types;
     87        }
     88        $this->error_types = $error_types;
    3789        register_shutdown_function(array($this, 'detectShutdown'));
    3890        if ($send_errors_last) {
     
    54106    public function handleError($code, $message, $file = '', $line = 0, $context=array())
    55107    {
    56         if ($this->error_types & $code & error_reporting()) {
    57           $e = new ErrorException($message, 0, $code, $file, $line);
    58           $this->handleException($e, true, $context);
    59         }
    60 
    61         if ($this->call_existing_error_handler && $this->old_error_handler) {
    62             call_user_func($this->old_error_handler, $code, $message, $file, $line, $context);
    63         }
     108        if (error_reporting() !== 0) {
     109            $error_types = $this->error_types;
     110            if ($error_types === null) {
     111                $error_types = error_reporting();
     112            }
     113            if ($error_types & $code) {
     114                $e = new ErrorException($message, 0, $code, $file, $line);
     115                $this->handleException($e, true, $context);
     116            }
     117        }
     118        if ($this->call_existing_error_handler) {
     119            if ($this->old_error_handler !== null) {
     120                return call_user_func($this->old_error_handler, $code, $message, $file, $line, $context);
     121            } else {
     122                return false;
     123            }
     124        }
     125    }
     126
     127    /**
     128     * Nothing by default, use it in child classes for catching other types of errors
     129     * Only constants from $this->validErrorTypes can be used
     130     *
     131     * @deprecated
     132     * @return array
     133     */
     134
     135    protected function getAdditionalErrorTypesToProcess()
     136    {
     137        return array();
     138    }
     139
     140    /**
     141     * @deprecated
     142     * @return array
     143     */
     144    private function getErrorTypesToProcess()
     145    {
     146        $additionalErrorTypes = array_intersect($this->getAdditionalErrorTypesToProcess(), $this->validErrorTypes);
     147        // array_unique so bitwise "or" operation wouldn't fail if some error type gets repeated
     148        return array_unique(array_merge($this->defaultErrorTypes, $additionalErrorTypes));
    64149    }
    65150
     
    72157        unset($this->reservedMemory);
    73158
    74         $errors = E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING | E_STRICT;
     159        $errors = 0;
     160        foreach ($this->getErrorTypesToProcess() as $errorType) {
     161            $errors |= $errorType;
     162        }
    75163
    76164        if ($lastError['type'] & $errors) {
     
    87175        $this->old_exception_handler = set_exception_handler(array($this, 'handleException'));
    88176        $this->call_existing_exception_handler = $call_existing_exception_handler;
    89     }
    90 
    91     public function registerErrorHandler($call_existing_error_handler = true, $error_types = -1)
    92     {
    93         $this->error_types = $error_types;
    94         $this->old_error_handler = set_error_handler(array($this, 'handleError'), error_reporting());
     177        return $this;
     178    }
     179
     180    /**
     181     * Register a handler which will intercept standard PHP errors and report them to the
     182     * associated Sentry client.
     183     *
     184     * @return array
     185     */
     186    //
     187    public function registerErrorHandler($call_existing_error_handler = true, $error_types = null)
     188    {
     189        if ($error_types !== null) {
     190            $this->error_types = $error_types;
     191        }
     192        $this->old_error_handler = set_error_handler(array($this, 'handleError'), E_ALL);
    95193        $this->call_existing_error_handler = $call_existing_error_handler;
     194        return $this;
    96195    }
    97196
     
    101200
    102201        $this->reservedMemory = str_repeat('x', 1024 * $reservedMemorySize);
    103     }
    104 
    105     public function detectShutdown() {
     202        return $this;
     203    }
     204
     205    public function detectShutdown()
     206    {
    106207        if (!defined('RAVEN_CLIENT_END_REACHED')) {
    107208            define('RAVEN_CLIENT_END_REACHED', true);
  • getsentry-client/trunk/raven/lib/Raven/SanitizeDataProcessor.php

    r1098363 r1418133  
    99{
    1010    const MASK = '********';
    11     const FIELDS_RE = '/(authorization|password|passwd|secret|password_confirmation|card_number)/i';
     11    const FIELDS_RE = '/(authorization|password|passwd|secret|password_confirmation|card_number|auth_pw)/i';
    1212    const VALUES_RE = '/^(?:\d[ -]*?){13,16}$/';
    1313
     
    2020        $this->client       = $client;
    2121        $this->fields_re    = self::FIELDS_RE;
    22         $this->values_re   = self::VALUES_RE;
     22        $this->values_re    = self::VALUES_RE;
     23        $this->session_cookie_name = ini_get('session.name');
    2324    }
    2425
     
    2829     * @param array $options    Associative array of processor options
    2930     */
    30     public function setProcessorOptions(array $options){
    31         if( isset($options['fields_re']) ){
     31    public function setProcessorOptions(array $options)
     32    {
     33        if (isset($options['fields_re'])) {
    3234            $this->fields_re = $options['fields_re'];
    3335        }
    3436
    35         if( isset($options['values_re']) ){
     37        if (isset($options['values_re'])) {
    3638            $this->values_re = $options['values_re'];
    3739        }
     
    6365    }
    6466
     67    public function sanitizeHttp(&$data)
     68    {
     69        if (empty($data['request'])) {
     70            return;
     71        }
     72        $http = &$data['request'];
     73        if (empty($http['cookies'])) {
     74            return;
     75        }
     76
     77        $cookies = &$http['cookies'];
     78        if (!empty($cookies[$this->session_cookie_name])) {
     79            $cookies[$this->session_cookie_name] = self::MASK;
     80        }
     81    }
     82
    6583    public function process(&$data)
    6684    {
    6785        array_walk_recursive($data, array($this, 'sanitize'));
     86        $this->sanitizeHttp($data);
    6887    }
    6988
  • getsentry-client/trunk/raven/lib/Raven/Serializer.php

    r1098247 r1418133  
    3131     * sanitization and encoding.
    3232     */
    33     public static function serialize($value, $max_depth=9, $_depth=0)
     33    public function serialize($value, $max_depth=3, $_depth=0)
    3434    {
    3535        if (is_object($value) || is_resource($value)) {
    36             return self::serializeValue($value);
     36            return $this->serializeValue($value);
    3737        } elseif ($_depth < $max_depth && is_array($value)) {
    3838            $new = array();
    3939            foreach ($value as $k => $v) {
    40                 $new[self::serializeValue($k)] = self::serialize($v, $max_depth, $_depth + 1);
     40                $new[$this->serializeValue($k)] = $this->serialize($v, $max_depth, $_depth + 1);
    4141            }
    4242
    4343            return $new;
    4444        } else {
    45             return self::serializeValue($value);
     45            return $this->serializeValue($value);
    4646        }
    4747    }
    4848
    49     public static function serializeValue($value)
     49    protected function serializeValue($value)
    5050    {
    51         if ($value === null) {
    52             return 'null';
    53         } elseif ($value === false) {
    54             return 'false';
    55         } elseif ($value === true) {
    56             return 'true';
    57         } elseif (is_float($value) && (int) $value == $value) {
    58             return $value.'.0';
     51        if (is_null($value) || is_bool($value) || is_float($value) || is_integer($value)) {
     52            return $value;
    5953        } elseif (is_object($value) || gettype($value) == 'object') {
    6054            return 'Object '.get_class($value);
     
    6357        } elseif (is_array($value)) {
    6458            return 'Array of length ' . count($value);
    65         } elseif (is_integer($value)) {
    66             return (integer) $value;
    6759        } else {
    6860            $value = (string) $value;
    6961
    7062            if (function_exists('mb_convert_encoding')) {
    71                 $value = mb_convert_encoding($value, 'UTF-8', 'UTF-8');
     63                $value = mb_convert_encoding($value, 'UTF-8', 'auto');
    7264            }
    7365
  • getsentry-client/trunk/raven/lib/Raven/Stacktrace.php

    r1098363 r1418133  
    1515
    1616    public static function get_stack_info($frames, $trace = false, $shiftvars = true, $errcontext = null,
    17                             $frame_var_limit = Raven_Client::MESSAGE_LIMIT)
     17                                          $frame_var_limit = Raven_Client::MESSAGE_LIMIT, $strip_prefixes = null,
     18                                          $app_path = null)
    1819    {
    1920        /**
     
    5455                $context = self::read_source_file($frame['file'], $frame['line']);
    5556                $abs_path = $frame['file'];
    56                 $filename = basename($frame['file']);
    57             }
    58 
    59             $module = $filename;
     57            }
     58
     59            // strip base path if present
     60            $context['filename'] = self::strip_prefixes($context['filename'], $strip_prefixes);
     61
     62            $module = basename($abs_path);
    6063            if (isset($nextframe['class'])) {
    6164                $module .= ':' . $nextframe['class'];
     
    7780            }
    7881
    79             $frame = array(
    80                 'abs_path' => $abs_path,
     82            $data = array(
     83                // abs_path isn't overly useful, wastes space, and exposes
     84                // filesystem internals
     85                // 'abs_path' => $abs_path,
    8186                'filename' => $context['filename'],
    8287                'lineno' => (int) $context['lineno'],
     
    8792                'post_context' => $context['suffix'],
    8893            );
     94
     95            // detect in_app based on app path
     96            if ($app_path) {
     97                $data['in_app'] = (bool)(substr($abs_path, 0, strlen($app_path)) === $app_path);
     98            }
     99
    89100            // dont set this as an empty array as PHP will treat it as a numeric array
    90101            // instead of a mapping which goes against the defined Sentry spec
    91102            if (!empty($vars)) {
     103                $serializer = new Raven_ReprSerializer();
     104                $cleanVars = array();
    92105                foreach ($vars as $key => $value) {
     106                    $value = $serializer->serialize($value);
    93107                    if (is_string($value) || is_numeric($value)) {
    94                         $vars[$key] = substr($value, 0, $frame_var_limit);
     108                        $cleanVars[$key] = substr($value, 0, $frame_var_limit);
     109                    } else {
     110                        $cleanVars[$key] = $value;
    95111                    }
    96112                }
    97                 $frame['vars'] = $vars;
    98             }
    99 
    100             $result[] = $frame;
     113                $data['vars'] = $cleanVars;
     114            }
     115
     116            $result[] = $data;
    101117        }
    102118
     
    117133        }
    118134        return $args;
    119 
    120135    }
    121136
     
    150165            }
    151166        }
    152         if (isset($frame['class'])) {
    153             if (method_exists($frame['class'], $frame['function'])) {
    154                 $reflection = new ReflectionMethod($frame['class'], $frame['function']);
    155             } elseif ($frame['type'] === '::') {
    156                 $reflection = new ReflectionMethod($frame['class'], '__callStatic');
    157             } else {
    158                 $reflection = new ReflectionMethod($frame['class'], '__call');
    159             }
    160         } else {
    161             $reflection = new ReflectionFunction($frame['function']);
     167        try {
     168            if (isset($frame['class'])) {
     169                if (method_exists($frame['class'], $frame['function'])) {
     170                    $reflection = new ReflectionMethod($frame['class'], $frame['function']);
     171                } elseif ($frame['type'] === '::') {
     172                    $reflection = new ReflectionMethod($frame['class'], '__callStatic');
     173                } else {
     174                    $reflection = new ReflectionMethod($frame['class'], '__call');
     175                }
     176            } else {
     177                $reflection = new ReflectionFunction($frame['function']);
     178            }
     179        } catch (ReflectionException $e) {
     180            return array();
    162181        }
    163182
     
    169188                // Assign the argument by the parameter name
    170189                if (is_array($arg)) {
    171                   foreach ($arg as $key => $value) {
    172                     if (is_string($value) || is_numeric($value)) {
    173                       $arg[$key] = substr($value, 0, $frame_arg_limit);
     190                    foreach ($arg as $key => $value) {
     191                        if (is_string($value) || is_numeric($value)) {
     192                            $arg[$key] = substr($value, 0, $frame_arg_limit);
     193                        }
    174194                    }
    175                   }
    176195                }
    177196                $args[$params[$i]->name] = $arg;
     
    184203
    185204        return $args;
     205    }
     206
     207    private static function strip_prefixes($filename, $prefixes)
     208    {
     209        if ($prefixes === null) {
     210            return;
     211        }
     212        foreach ($prefixes as $prefix) {
     213            if (substr($filename, 0, strlen($prefix)) === $prefix) {
     214                return substr($filename, strlen($prefix) + 1);
     215            }
     216        }
     217        return $filename;
    186218    }
    187219
     
    240272                }
    241273                $file->next();
    242              }
     274            }
    243275        } catch (RuntimeException $exc) {
    244276            return $frame;
  • getsentry-client/trunk/raven/test/Raven/Tests/ClientTest.php

    r1098363 r1418133  
    4242        return parent::get_user_data();
    4343    }
     44
     45    /**
     46     * Expose the current url method to test it
     47     *
     48     * @return string
     49     */
     50    public function test_get_current_url()
     51    {
     52        return $this->get_current_url();
     53    }
    4454}
    4555
     
    7383
    7484        $this->assertEquals($result['project'], 1);
    75         $this->assertEquals($result['servers'], array('http://example.com/api/store/'));
     85        $this->assertEquals($result['server'], 'http://example.com/api/1/store/');
    7686        $this->assertEquals($result['public_key'], 'public');
    7787        $this->assertEquals($result['secret_key'], 'secret');
     
    8393
    8494        $this->assertEquals($result['project'], 1);
    85         $this->assertEquals($result['servers'], array('https://example.com/api/store/'));
     95        $this->assertEquals($result['server'], 'https://example.com/api/1/store/');
    8696        $this->assertEquals($result['public_key'], 'public');
    8797        $this->assertEquals($result['secret_key'], 'secret');
     
    93103
    94104        $this->assertEquals($result['project'], 1);
    95         $this->assertEquals($result['servers'], array('http://example.com/app/api/store/'));
     105        $this->assertEquals($result['server'], 'http://example.com/app/api/1/store/');
    96106        $this->assertEquals($result['public_key'], 'public');
    97107        $this->assertEquals($result['secret_key'], 'secret');
     
    103113
    104114        $this->assertEquals($result['project'], 1);
    105         $this->assertEquals($result['servers'], array('http://example.com:9000/app/api/store/'));
     115        $this->assertEquals($result['server'], 'http://example.com:9000/app/api/1/store/');
    106116        $this->assertEquals($result['public_key'], 'public');
    107117        $this->assertEquals($result['secret_key'], 'secret');
     
    158168
    159169        $this->assertEquals($client->project, 1);
    160         $this->assertEquals($client->servers, array('http://example.com/api/store/'));
     170        $this->assertEquals($client->server, 'http://example.com/api/1/store/');
    161171        $this->assertEquals($client->public_key, 'public');
    162172        $this->assertEquals($client->secret_key, 'secret');
     
    170180
    171181        $this->assertEquals($client->project, 1);
    172         $this->assertEquals($client->servers, array('http://example.com/api/store/'));
     182        $this->assertEquals($client->server, 'http://example.com/api/1/store/');
    173183        $this->assertEquals($client->public_key, 'public');
    174184        $this->assertEquals($client->secret_key, 'secret');
     
    179189    {
    180190        $client = new Raven_Client(array(
    181             'servers' => array('http://example.com/api/store/'),
    182         ));
    183 
    184         $this->assertEquals($client->servers, array('http://example.com/api/store/'));
     191            'server' => 'http://example.com/api/1/store/',
     192            'project' => 1,
     193        ));
     194
     195        $this->assertEquals($client->server, 'http://example.com/api/1/store/');
     196    }
     197
     198
     199    public function testDsnInOptionsFirstArg()
     200    {
     201        $client = new Raven_Client(array(
     202            'dsn' => 'http://public:secret@example.com/1',
     203        ));
     204
     205        $this->assertEquals($client->project, 1);
     206        $this->assertEquals($client->server, 'http://example.com/api/1/store/');
     207        $this->assertEquals($client->public_key, 'public');
     208        $this->assertEquals($client->secret_key, 'secret');
     209    }
     210
     211    public function testDsnInOptionsSecondArg()
     212    {
     213        $client = new Raven_Client(null, array(
     214            'dsn' => 'http://public:secret@example.com/1',
     215        ));
     216
     217        $this->assertEquals($client->project, 1);
     218        $this->assertEquals($client->server, 'http://example.com/api/1/store/');
     219        $this->assertEquals($client->public_key, 'public');
     220        $this->assertEquals($client->secret_key, 'secret');
    185221    }
    186222
     
    188224    {
    189225        $client = new Raven_Client(array(
    190             'servers' => array('http://example.com/api/store/'),
     226            'server' => 'http://example.com/api/1/store/',
     227            'project' => 1,
    191228        ), array(
    192229            'site' => 'foo',
    193230        ));
    194231
    195         $this->assertEquals($client->servers, array('http://example.com/api/store/'));
     232        $this->assertEquals($client->server, 'http://example.com/api/1/store/');
    196233        $this->assertEquals($client->site, 'foo');
    197234    }
     
    206243        $event = array_pop($events);
    207244        $this->assertEquals($event['extra']['foo'], 'bar');
     245    }
     246
     247    public function testEmptyExtraData()
     248    {
     249        $client = new Dummy_Raven_Client(array('extra' => array()));
     250
     251        $client->captureMessage('Test Message %s', array('foo'));
     252        $events = $client->getSentEvents();
     253        $this->assertEquals(count($events), 1);
     254        $event = array_pop($events);
     255        $this->assertEquals(array_key_exists('extra', $event), false);
    208256    }
    209257
     
    281329        $event = array_pop($events);
    282330
    283         $exc = $event['sentry.interfaces.Exception'];
     331        $exc = $event['exception'];
    284332        $this->assertEquals(count($exc['values']), 1);
    285333        $this->assertEquals($exc['values'][0]['value'], 'Foo bar');
     
    314362        $event = array_pop($events);
    315363
    316         $exc = $event['sentry.interfaces.Exception'];
     364        $exc = $event['exception'];
    317365        $this->assertEquals(count($exc['values']), 2);
    318366        $this->assertEquals($exc['values'][0]['value'], 'Foo bar');
    319367        $this->assertEquals($exc['values'][1]['value'], 'Child exc');
    320 
    321     }
    322 
    323     public function testCaptureExceptionDifferentLevelsInChainedExceptionsBug() {
     368    }
     369
     370    public function testCaptureExceptionDifferentLevelsInChainedExceptionsBug()
     371    {
    324372        if (version_compare(PHP_VERSION, '5.3.0', '<')) {
    325373            $this->markTestSkipped('PHP 5.3 required for chained exceptions.');
     
    417465    }
    418466
    419     public function testGetDefaultData() {
     467    public function testGetDefaultData()
     468    {
    420469        $client = new Dummy_Raven_Client();
    421470        $expected = array(
     
    426475            'logger' => $client->logger,
    427476            'tags' => $client->tags,
     477            'sdk' => array(
     478                'name' => 'sentry-php',
     479                'version' => $client::VERSION,
     480            ),
    428481        );
    429482        $this->assertEquals($expected, $client->get_default_data());
     
    443496            'HTTP_ACCEPT_CHARSET' => 'utf-8',
    444497            'HTTP_COOKIE'         => 'cupcake: strawberry',
    445             'HTTP_CONTENT_TYPE'   => 'text/html',
    446             'HTTP_CONTENT_LENGTH' => '1000',
    447498            'SERVER_PORT'         => '443',
    448499            'SERVER_PROTOCOL'     => 'HTTP/1.1',
     
    460511
    461512        $expected = array(
    462             'sentry.interfaces.Http' => array(
     513            'request' => array(
    463514                'method' => 'PATCH',
    464515                'url' => 'https://getsentry.com/welcome/',
     
    494545    }
    495546
    496     public function testGetUserDataWithSetUser() {
     547    public function testGetUserDataWithSetUser()
     548    {
    497549        $client = new Dummy_Raven_Client();
    498550
     
    507559
    508560        $expected = array(
    509             'sentry.interfaces.User' => array(
     561            'user' => array(
    510562                'id' => 'unique_id',
    511563                'username' => 'my_user',
     
    517569    }
    518570
    519     public function testGetUserDataWithNoUser() {
     571    public function testGetUserDataWithNoUser()
     572    {
    520573        $client = new Dummy_Raven_Client();
    521574
    522575        $expected = array(
    523             'sentry.interfaces.User' => array(
     576            'user' => array(
    524577                'id' => session_id(),
    525578            )
     
    528581    }
    529582
    530     public function testGetAuthHeader() {
    531         $client = new Dummy_Raven_Client();
    532 
    533         $clientstring = 'raven-php/test';
     583    public function testGetAuthHeader()
     584    {
     585        $client = new Dummy_Raven_Client();
     586
     587        $clientstring = 'sentry-php/test';
    534588        $timestamp = '1234341324.340000';
    535589
     
    538592                    "sentry_key=publickey, sentry_secret=secretkey";
    539593
    540         $this->assertEquals($expected, $client->get_auth_header($timestamp, 'raven-php/test', 'publickey', 'secretkey'));
     594        $this->assertEquals($expected, $client->get_auth_header($timestamp, 'sentry-php/test', 'publickey', 'secretkey'));
    541595    }
    542596
     
    553607        $this->assertEquals(array(
    554608            'email' => 'foo@example.com',
    555         ), $event['sentry.interfaces.User']);
     609        ), $event['user']);
    556610    }
    557611
     
    592646    }
    593647
    594     public function cb1($data) {
     648    public function testGetLastEventID()
     649    {
     650        $client = new Dummy_Raven_Client();
     651        $client->capture(array('message' => 'test', 'event_id' => 'abc'));
     652        $this->assertEquals($client->getLastEventID(), 'abc');
     653    }
     654
     655    public function cb1($data)
     656    {
    595657        $this->assertEquals('test', $data['message']);
    596658        return false;
    597659    }
    598660
    599     public function cb2($data) {
     661    public function cb2($data)
     662    {
    600663        $this->assertEquals('test', $data['message']);
    601664        return true;
     
    604667    public function testSendCallback()
    605668    {
    606 
    607669        $client = new Dummy_Raven_Client(array('send_callback' => array($this, 'cb1')));
    608670        $client->captureMessage('test');
     
    615677        $this->assertEquals(1, count($events));
    616678    }
     679
     680    /**
     681     * Set the server array to the test values, check the current url
     682     *
     683     * @dataProvider currentUrlProvider
     684     * @param array $serverData
     685     * @param array $options
     686     * @param string $expected - the url expected
     687     * @param string $message - fail message
     688     */
     689    public function testCurrentUrl($serverVars, $options, $expected, $message)
     690    {
     691        $_SERVER = $serverVars;
     692
     693        $client = new Dummy_Raven_Client($options);
     694        $result = $client->test_get_current_url();
     695
     696        $this->assertSame($expected, $result, $message);
     697    }
     698
     699    /**
     700     * Arrays of:
     701     *  $_SERVER data
     702     *  config
     703     *  expected url
     704     *  Fail message
     705     *
     706     * @return array
     707     */
     708    public function currentUrlProvider()
     709    {
     710        return array(
     711            array(
     712                array(),
     713                array(),
     714                null,
     715                'No url expected for empty REQUEST_URI'
     716            ),
     717            array(
     718                array(
     719                    'REQUEST_URI' => '/',
     720                    'HTTP_HOST' => 'example.com',
     721                ),
     722                array(),
     723                'http://example.com/',
     724                'The url is expected to be http with the request uri'
     725            ),
     726            array(
     727                array(
     728                    'REQUEST_URI' => '/',
     729                    'HTTP_HOST' => 'example.com',
     730                    'HTTPS' => 'on'
     731                ),
     732                array(),
     733                'https://example.com/',
     734                'The url is expected to be https because of HTTPS on'
     735            ),
     736            array(
     737                array(
     738                    'REQUEST_URI' => '/',
     739                    'HTTP_HOST' => 'example.com',
     740                    'SERVER_PORT' => '443'
     741                ),
     742                array(),
     743                'https://example.com/',
     744                'The url is expected to be https because of the server port'
     745            ),
     746            array(
     747                array(
     748                    'REQUEST_URI' => '/',
     749                    'HTTP_HOST' => 'example.com',
     750                    'X-FORWARDED-PROTO' => 'https'
     751                ),
     752                array(),
     753                'http://example.com/',
     754                'The url is expected to be http because the X-Forwarded header is ignored'
     755            ),
     756            array(
     757                array(
     758                    'REQUEST_URI' => '/',
     759                    'HTTP_HOST' => 'example.com',
     760                    'X-FORWARDED-PROTO' => 'https'
     761                ),
     762                array('trust_x_forwarded_proto' => true),
     763                'https://example.com/',
     764                'The url is expected to be https because the X-Forwarded header is trusted'
     765            )
     766        );
     767    }
    617768}
  • getsentry-client/trunk/raven/test/Raven/Tests/ErrorHandlerTest.php

    r1098247 r1418133  
    1717    {
    1818        $this->errorLevel = error_reporting();
     19        $this->errorHandlerCalled = false;
     20        $this->existingErrorHandler = set_error_handler(array($this, 'errorHandler'), -1);
     21    }
     22
     23    public function errorHandler()
     24    {
     25        $this->errorHandlerCalled = true;
    1926    }
    2027
    2128    public function tearDown()
    2229    {
     30        // XXX(dcramer): this isn't great as it doesnt restore the old error reporting level
     31        set_error_handler(array($this, 'errorHandler'), error_reporting());
    2332        error_reporting($this->errorLevel);
    2433    }
     
    2635    public function testErrorsAreLoggedAsExceptions()
    2736    {
    28         $client = $this->getMock('Client', array('captureException', 'getIdent'));
     37        $client = $this->getMock('Client', array('captureException', 'getIdent', 'sendUnsentErrors'));
    2938        $client->expects($this->once())
    3039               ->method('captureException')
    3140               ->with($this->isInstanceOf('ErrorException'));
    3241
    33         $handler = new Raven_ErrorHandler($client);
     42        $handler = new Raven_ErrorHandler($client, E_ALL);
    3443        $handler->handleError(E_WARNING, 'message');
    3544    }
     
    4857    }
    4958
    50     public function testErrorHandlerCheckSilentReporting()
     59    public function testErrorHandlerPassErrorReportingPass()
     60    {
     61        $client = $this->getMock('Client', array('captureException', 'getIdent'));
     62        $client->expects($this->once())
     63               ->method('captureException');
     64
     65        $handler = new Raven_ErrorHandler($client);
     66        $handler->registerErrorHandler(false, -1);
     67
     68        error_reporting(E_USER_WARNING);
     69        trigger_error('Warning', E_USER_WARNING);
     70    }
     71
     72    public function testErrorHandlerPropagates()
    5173    {
    5274        $client = $this->getMock('Client', array('captureException', 'getIdent'));
    5375        $client->expects($this->never())
    5476               ->method('captureException');
     77
     78        $handler = new Raven_ErrorHandler($client);
     79        $handler->registerErrorHandler(true, E_DEPRECATED);
     80
     81        error_reporting(E_USER_WARNING);
     82        trigger_error('Warning', E_USER_WARNING);
     83
     84        $this->assertEquals($this->errorHandlerCalled, 1);
     85    }
     86
     87    public function testErrorHandlerRespectsErrorReportingDefault()
     88    {
     89        $client = $this->getMock('Client', array('captureException', 'getIdent'));
     90        $client->expects($this->once())
     91               ->method('captureException');
     92
     93        error_reporting(E_DEPRECATED);
     94
     95        $handler = new Raven_ErrorHandler($client);
     96        $handler->registerErrorHandler(true);
     97
     98        error_reporting(E_ALL);
     99        trigger_error('Warning', E_USER_WARNING);
     100
     101        $this->assertEquals($this->errorHandlerCalled, 1);
     102    }
     103
     104    // Because we cannot **know** that a user silenced an error, we always
     105    // defer to respecting the error reporting settings.
     106    public function testSilentErrorsAreReported()
     107    {
     108        $client = $this->getMock('Client', array('captureException', 'getIdent'));
     109        $client->expects($this->never())
     110               ->method('captureException');
     111
     112        error_reporting(E_USER_WARNING);
    55113
    56114        $handler = new Raven_ErrorHandler($client);
     
    60118    }
    61119
    62     public function testErrorHandlerBlockErrorReporting()
     120    public function testErrorHandlerDefaultsErrorReporting()
    63121    {
    64122        $client = $this->getMock('Client', array('captureException', 'getIdent'));
     
    66124               ->method('captureException');
    67125
    68         $handler = new Raven_ErrorHandler($client);
    69         $handler->registerErrorHandler(false);
    70 
    71126        error_reporting(E_USER_ERROR);
    72         trigger_error('Warning', E_USER_WARNING);
    73     }
    74 
    75     public function testErrorHandlerPassErrorReportingPass()
    76     {
    77         $client = $this->getMock('Client', array('captureException', 'getIdent'));
    78         $client->expects($this->once())
    79                ->method('captureException');
    80127
    81128        $handler = new Raven_ErrorHandler($client);
    82129        $handler->registerErrorHandler(false);
    83130
    84         error_reporting(E_USER_WARNING);
    85131        trigger_error('Warning', E_USER_WARNING);
    86132    }
     133
     134    public function testFluidInterface()
     135    {
     136        $client = $this->getMock('Client', array('captureException', 'getIdent'));
     137        $handler = new Raven_ErrorHandler($client);
     138        $result = $handler->registerErrorHandler();
     139        $this->assertEquals($result, $handler);
     140        $result = $handler->registerExceptionHandler();
     141        $this->assertEquals($result, $handler);
     142        // TODO(dcramer): cant find a great way to test resetting the shutdown
     143        // handler
     144        // $result = $handler->registerShutdownHandler();
     145        // $this->assertEquals($result, $handler);
     146    }
    87147}
  • getsentry-client/trunk/raven/test/Raven/Tests/SanitizeDataProcessorTest.php

    r1098363 r1418133  
    1515    {
    1616        $data = array(
    17             'sentry.interfaces.Http' => array(
     17            'request' => array(
    1818                'data' => array(
    1919                    'foo' => 'bar',
     
    3737        $processor->process($data);
    3838
    39         $vars = $data['sentry.interfaces.Http']['data'];
     39        $vars = $data['request']['data'];
    4040        $this->assertEquals($vars['foo'], 'bar');
    4141        $this->assertEquals(Raven_SanitizeDataProcessor::MASK, $vars['password']);
     
    4848
    4949        $this->assertEquals(Raven_SanitizeDataProcessor::MASK, $vars['card_number']['0']);
     50    }
     51
     52    public function testDoesFilterSessionId()
     53    {
     54        $data = array(
     55            'request' => array(
     56                'cookies' => array(
     57                    ini_get('session.name') => 'abc',
     58                ),
     59            )
     60        );
     61
     62        $client = new Raven_Client();
     63        $processor = new Raven_SanitizeDataProcessor($client);
     64        $processor->process($data);
     65
     66        $cookies = $data['request']['cookies'];
     67        $this->assertEquals($cookies[ini_get('session.name')], Raven_SanitizeDataProcessor::MASK);
    5068    }
    5169
     
    6785     *
    6886     */
    69     public function testSettingProcessorOptions(){
     87    public function testSettingProcessorOptions()
     88    {
    7089        $client     = new Raven_Client();
    7190        $processor  = new Raven_SanitizeDataProcessor($client);
    7291
    73         $this->assertEquals($processor->getFieldsRe(), '/(authorization|password|passwd|secret|password_confirmation|card_number)/i','got default fields');
    74         $this->assertEquals($processor->getValuesRe(),'/^(?:\d[ -]*?){13,16}$/','got default values');
     92        $this->assertEquals($processor->getFieldsRe(), '/(authorization|password|passwd|secret|password_confirmation|card_number|auth_pw)/i', 'got default fields');
     93        $this->assertEquals($processor->getValuesRe(), '/^(?:\d[ -]*?){13,16}$/', 'got default values');
    7594
    7695        $options = array(
     
    81100        $processor->setProcessorOptions($options);
    82101
    83         $this->assertEquals($processor->getFieldsRe(), '/(api_token)/i','overwrote fields');
    84         $this->assertEquals($processor->getValuesRe(), '/^(?:\d[ -]*?){15,16}$/','overwrote values');
     102        $this->assertEquals($processor->getFieldsRe(), '/(api_token)/i', 'overwrote fields');
     103        $this->assertEquals($processor->getValuesRe(), '/^(?:\d[ -]*?){15,16}$/', 'overwrote values');
    85104    }
    86105
     
    92111     * @param $dsn
    93112     */
    94     public function testOverrideOptions($processorOptions, $client_options, $dsn){
     113    public function testOverrideOptions($processorOptions, $client_options, $dsn)
     114    {
    95115        $client = new Raven_Client($dsn, $client_options);
    96116        $processor = $client->processors[0];
    97117
    98118        $this->assertInstanceOf('Raven_SanitizeDataProcessor', $processor);
    99         $this->assertEquals($processor->getFieldsRe(), $processorOptions['Raven_SanitizeDataProcessor']['fields_re'],'overwrote fields');
    100         $this->assertEquals($processor->getValuesRe(), $processorOptions['Raven_SanitizeDataProcessor']['values_re'],'overwrote values');
     119        $this->assertEquals($processor->getFieldsRe(), $processorOptions['Raven_SanitizeDataProcessor']['fields_re'], 'overwrote fields');
     120        $this->assertEquals($processor->getValuesRe(), $processorOptions['Raven_SanitizeDataProcessor']['values_re'], 'overwrote values');
    101121    }
    102122
     
    109129     * @param $dsn
    110130     */
    111     public function testOverridenSanitize($processorOptions, $client_options, $dsn){
     131    public function testOverridenSanitize($processorOptions, $client_options, $dsn)
     132    {
    112133        $data = array(
    113             'sentry.interfaces.Http' => array(
     134            'request' => array(
    114135                'data' => array(
    115136                    'foo'               => 'bar',
     
    132153
    133154        $this->assertInstanceOf('Raven_SanitizeDataProcessor', $processor);
    134         $this->assertEquals($processor->getFieldsRe(), $processorOptions['Raven_SanitizeDataProcessor']['fields_re'],'overwrote fields');
    135         $this->assertEquals($processor->getValuesRe(), $processorOptions['Raven_SanitizeDataProcessor']['values_re'],'overwrote values');
     155        $this->assertEquals($processor->getFieldsRe(), $processorOptions['Raven_SanitizeDataProcessor']['fields_re'], 'overwrote fields');
     156        $this->assertEquals($processor->getValuesRe(), $processorOptions['Raven_SanitizeDataProcessor']['values_re'], 'overwrote values');
    136157
    137158        $processor->process($data);
    138159
    139         $vars = $data['sentry.interfaces.Http']['data'];
    140         $this->assertEquals($vars['foo'], 'bar','did not alter foo');
    141         $this->assertEquals($vars['password'], 'hello','did not alter password');
    142         $this->assertEquals($vars['the_secret'],'hello','did not alter the_secret');
    143         $this->assertEquals($vars['a_password_here'],'hello','did not alter a_password_here');
    144         $this->assertEquals($vars['mypasswd'],'hello','did not alter mypasswd');
    145         $this->assertEquals($vars['authorization'],'Basic dXNlcm5hbWU6cGFzc3dvcmQ=','did not alter authorization');
    146         $this->assertEquals(Raven_SanitizeDataProcessor::MASK, $vars['api_token'],'masked api_token');
     160        $vars = $data['request']['data'];
     161        $this->assertEquals($vars['foo'], 'bar', 'did not alter foo');
     162        $this->assertEquals($vars['password'], 'hello', 'did not alter password');
     163        $this->assertEquals($vars['the_secret'], 'hello', 'did not alter the_secret');
     164        $this->assertEquals($vars['a_password_here'], 'hello', 'did not alter a_password_here');
     165        $this->assertEquals($vars['mypasswd'], 'hello', 'did not alter mypasswd');
     166        $this->assertEquals($vars['authorization'], 'Basic dXNlcm5hbWU6cGFzc3dvcmQ=', 'did not alter authorization');
     167        $this->assertEquals(Raven_SanitizeDataProcessor::MASK, $vars['api_token'], 'masked api_token');
    147168
    148169        $this->assertEquals(Raven_SanitizeDataProcessor::MASK, $vars['card_number']['0'], 'masked card_number[0]');
    149         $this->assertEquals($vars['card_number']['1'], $vars['card_number']['1'],'did not alter card_number[1]');
     170        $this->assertEquals($vars['card_number']['1'], $vars['card_number']['1'], 'did not alter card_number[1]');
    150171    }
    151172
     
    155176     * @return array
    156177     */
    157     public static function overrideDataProvider(){
     178    public static function overrideDataProvider()
     179    {
    158180        $processorOptions = array(
    159181            'Raven_SanitizeDataProcessor' => array(
  • getsentry-client/trunk/raven/test/Raven/Tests/SerializerTest.php

    r1098247 r1418133  
    1919    public function testArraysAreArrays()
    2020    {
     21        $serializer = new Raven_Serializer();
    2122        $input = array(1, 2, 3);
    22         $result = Raven_Serializer::serialize($input);
     23        $result = $serializer->serialize($input);
    2324        $this->assertEquals(array('1', '2', '3'), $result);
    2425    }
     
    2627    public function testObjectsAreStrings()
    2728    {
     29        $serializer = new Raven_Serializer();
    2830        $input = new Raven_StacktraceTestObject();
    29         $result = Raven_Serializer::serialize($input);
     31        $result = $serializer->serialize($input);
    3032        $this->assertEquals('Object Raven_StacktraceTestObject', $result);
    3133    }
     
    3335    public function testIntsAreInts()
    3436    {
     37        $serializer = new Raven_Serializer();
    3538        $input = 1;
    36         $result = Raven_Serializer::serialize($input);
     39        $result = $serializer->serialize($input);
    3740        $this->assertTrue(is_integer($result));
    3841        $this->assertEquals(1, $result);
    3942    }
    4043
     44    public function testFloats()
     45    {
     46        $serializer = new Raven_Serializer();
     47        $input = 1.5;
     48        $result = $serializer->serialize($input);
     49        $this->assertTrue(is_float($result));
     50        $this->assertEquals(1.5, $result);
     51    }
     52
     53    public function testBooleans()
     54    {
     55        $serializer = new Raven_Serializer();
     56        $input = true;
     57        $result = $serializer->serialize($input);
     58        $this->assertTrue(is_bool($result));
     59        $this->assertEquals(true, $result);
     60
     61        $input = false;
     62        $result = $serializer->serialize($input);
     63        $this->assertTrue(is_bool($result));
     64        $this->assertEquals(false, $result);
     65    }
     66
     67    public function testNull()
     68    {
     69        $serializer = new Raven_Serializer();
     70        $input = null;
     71        $result = $serializer->serialize($input);
     72        $this->assertTrue(is_null($result));
     73        $this->assertEquals(null, $result);
     74    }
     75
    4176    public function testRecursionMaxDepth()
    4277    {
     78        $serializer = new Raven_Serializer();
    4379        $input = array();
    4480        $input[] = &$input;
    45         $result = Raven_Serializer::serialize($input, 3);
     81        $result = $serializer->serialize($input, 3);
    4682        $this->assertEquals(array(array(array('Array of length 1'))), $result);
    4783    }
    48 
    4984}
  • getsentry-client/trunk/raven/test/Raven/Tests/StacktraceTest.php

    r1098247 r1418133  
    7070        $this->assertEquals('include_once', $frame["function"]);
    7171        $this->assertEquals('a_test($foo);', $frame["context_line"]);
    72 
    73 
    7472    }
    7573
     
    109107        $this->assertEquals('friend', $frame['vars']['param1']);
    110108        $this->assertEquals('a_test($foo);', $frame["context_line"]);
    111 
    112 
    113109    }
    114110
     
    153149        $this->assertEquals('a_test($foo);', $frame["context_line"]);
    154150        $this->assertEquals($vars, $frame['vars']);
    155 
    156 
     151    }
     152
     153    public function testDoesNotModifyCaptureVars()
     154    {
     155        $stack = array(
     156            array(
     157                "file" => dirname(__FILE__) . "/resources/a.php",
     158                "line" => 11,
     159                "function" => "a_test",
     160                "args"=> array(
     161                    "friend",
     162                ),
     163            ),
     164            array(
     165                "file" => dirname(__FILE__) . "/resources/b.php",
     166                "line" => 3,
     167                "args"=> array(
     168                    "/tmp/a.php",
     169                ),
     170                "function" => "include_once",
     171            ),
     172        );
     173
     174        // PHP's errcontext as passed to the error handler contains REFERENCES to any vars that were in the global scope.
     175        // Modification of these would be really bad, since if control is returned (non-fatal error) we'll have altered the state of things!
     176        $originalFoo = "bloopblarp";
     177        $iAmFoo = $originalFoo;
     178        $vars = array(
     179            "foo" => &$iAmFoo
     180        );
     181
     182        $frames = Raven_Stacktrace::get_stack_info($stack, true, true, $vars, 5);
     183
     184        // Check we haven't modified our vars.
     185        $this->assertEquals($originalFoo, $vars["foo"]);
     186
     187        $frame = $frames[1];
     188        // Check that we did truncate the variable in our output
     189        $this->assertEquals(5, strlen($frame['vars']['foo']));
    157190    }
    158191
     
    197230        $this->assertEquals($vars, $frame['vars']);
    198231        $this->assertEquals('a_test($foo);', $frame["context_line"]);
    199 
    200 
    201232    }
    202233
     
    229260        $this->assertEquals('raven_test_recurse', $frame['function']);
    230261    }
     262
     263    public function testInApp()
     264    {
     265        $stack = array(
     266            array(
     267                "file" => dirname(__FILE__) . "/resources/a.php",
     268                "line" => 11,
     269                "function" => "a_test",
     270            ),
     271            array(
     272                "file" => dirname(__FILE__) . "/resources/b.php",
     273                "line" => 3,
     274                "function" => "include_once",
     275            ),
     276        );
     277
     278        $frames = Raven_Stacktrace::get_stack_info($stack, true, null, null, 0, null, dirname(__FILE__));
     279
     280        $this->assertEquals($frames[0]['in_app'], true);
     281        $this->assertEquals($frames[1]['in_app'], true);
     282    }
     283
     284    public function testBasePath()
     285    {
     286        $stack = array(
     287            array(
     288                "file" => dirname(__FILE__) . "/resources/a.php",
     289                "line" => 11,
     290                "function" => "a_test",
     291            ),
     292            array(
     293                "file" => dirname(__FILE__) . "/resources/b.php",
     294                "line" => 3,
     295                "function" => "include_once",
     296            ),
     297        );
     298
     299        $frames = Raven_Stacktrace::get_stack_info($stack, true, null, null, 0, array(dirname(__FILE__)));
     300
     301        $this->assertEquals($frames[0]['filename'], 'resources/b.php');
     302        $this->assertEquals($frames[1]['filename'], 'resources/a.php');
     303    }
    231304}
  • getsentry-client/trunk/readme.txt

    r1344226 r1418133  
    55Requires at least: 3.0.1
    66Tested up to: 3.4
    7 Stable tag: 1.0
     7Stable tag: 1.1
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    2828
    2929== Changelog ==
     30
     31= 1.1 =
     32
     33Upgrade raven php client to v0.15.0
    3034
    3135= 1.0 =
Note: See TracChangeset for help on using the changeset viewer.