You are here

class ProxyConfigTest in Raven: Sentry Integration 8.2

Same name and namespace in other branches
  1. 3.x tests/src/Unit/ProxyConfigTest.php \Drupal\Tests\raven\Unit\ProxyConfigTest

Test proxy configuration.

@group raven

Hierarchy

Expanded class hierarchy of ProxyConfigTest

File

tests/src/Unit/ProxyConfigTest.php, line 16

Namespace

Drupal\Tests\raven\Unit
View source
class ProxyConfigTest extends UnitTestCase {

  /**
   * Config factory.
   *
   * @var \PHPUnit\Framework\MockObject\MockBuilder
   */
  protected $configFactory;

  /**
   * Environment.
   *
   * @var string
   */
  protected $environment;

  /**
   * The module handler.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * The message's placeholders parser.
   *
   * @var \Drupal\Core\Logger\LogMessageParserInterface
   */
  protected $parser;

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $this->parser = $this
      ->createMock(LogMessageParserInterface::class);
    $this->moduleHandler = $this
      ->createMock(ModuleHandlerInterface::class);
    $this->environment = 'testing';
  }

  /**
   * Data provider for testProxyConfiguration().
   */
  public function proxyConfigurationData() {
    return [
      // HTTP DSN, Empty proxy white-list.
      [
        'http://user:password@sentry.test/123456',
        [
          'http' => NULL,
          'https' => NULL,
          'no' => [],
        ],
        'no',
      ],
      [
        'http://user:password@sentry.test/123456',
        [
          'http' => 'http-proxy.server.test:3129',
          'https' => NULL,
          'no' => [],
        ],
        'http',
      ],
      [
        'http://user:password@sentry.test/123456',
        [
          'http' => NULL,
          'https' => 'https-proxy.server.test:3129',
          'no' => [],
        ],
        'no',
      ],
      [
        'http://user:password@sentry.test/123456',
        [
          'http' => 'http-proxy.server.test:3129',
          'https' => 'https-proxy.server.test:3129',
          'no' => [],
        ],
        'http',
      ],
      // HTTP DSN, Not empty proxy white-list.
      [
        'http://user:password@sentry.test/123456',
        [
          'http' => NULL,
          'https' => NULL,
          'no' => [
            'some.server.test',
          ],
        ],
        'no',
      ],
      [
        'http://user:password@sentry.test/123456',
        [
          'http' => 'http-proxy.server.test:3129',
          'https' => NULL,
          'no' => [
            'some.server.test',
          ],
        ],
        'http',
      ],
      [
        'http://user:password@sentry.test/123456',
        [
          'http' => NULL,
          'https' => 'https-proxy.server.test:3129',
          'no' => [
            'some.server.test',
          ],
        ],
        'no',
      ],
      [
        'http://user:password@sentry.test/123456',
        [
          'http' => 'http-proxy.server.test:3129',
          'https' => 'https-proxy.server.test:3129',
          'no' => [
            'some.server.test',
          ],
        ],
        'http',
      ],
      // HTTP DSN, Not empty proxy white-list, Sentry white-listed.
      [
        'http://user:password@sentry.test/123456',
        [
          'http' => NULL,
          'https' => NULL,
          'no' => [
            'some.server.test',
            'sentry.test',
          ],
        ],
        'no',
      ],
      [
        'http://user:password@sentry.test/123456',
        [
          'http' => 'http-proxy.server.test:3129',
          'https' => NULL,
          'no' => [
            'some.server.test',
            'sentry.test',
          ],
        ],
        'no',
      ],
      [
        'http://user:password@sentry.test/123456',
        [
          'http' => NULL,
          'https' => 'https-proxy.server.test:3129',
          'no' => [
            'some.server.test',
            'sentry.test',
          ],
        ],
        'no',
      ],
      [
        'http://user:password@sentry.test/123456',
        [
          'http' => 'http-proxy.server.test:3129',
          'https' => 'https-proxy.server.test:3129',
          'no' => [
            'some.server.test',
            'sentry.test',
          ],
        ],
        'no',
      ],
      // HTTPS DSN, Empty proxy white-list.
      [
        'https://user:password@sentry.test/123456',
        [
          'http' => NULL,
          'https' => NULL,
          'no' => [],
        ],
        'no',
      ],
      [
        'https://user:password@sentry.test/123456',
        [
          'http' => 'http-proxy.server.test:3129',
          'https' => NULL,
          'no' => [],
        ],
        'no',
      ],
      [
        'https://user:password@sentry.test/123456',
        [
          'http' => NULL,
          'https' => 'https-proxy.server.test:3129',
          'no' => [],
        ],
        'https',
      ],
      [
        'https://user:password@sentry.test/123456',
        [
          'http' => 'http-proxy.server.test:3129',
          'https' => 'https-proxy.server.test:3129',
          'no' => [],
        ],
        'https',
      ],
      // HTTPS DSN, Not empty proxy white-list.
      [
        'https://user:password@sentry.test/123456',
        [
          'http' => NULL,
          'https' => NULL,
          'no' => [
            'some.server.test',
          ],
        ],
        'no',
      ],
      [
        'https://user:password@sentry.test/123456',
        [
          'http' => 'http-proxy.server.test:3129',
          'https' => NULL,
          'no' => [
            'some.server.test',
          ],
        ],
        'no',
      ],
      [
        'https://user:password@sentry.test/123456',
        [
          'http' => NULL,
          'https' => 'https-proxy.server.test:3129',
          'no' => [
            'some.server.test',
          ],
        ],
        'https',
      ],
      [
        'https://user:password@sentry.test/123456',
        [
          'http' => 'http-proxy.server.test:3129',
          'https' => 'https-proxy.server.test:3129',
          'no' => [
            'some.server.test',
          ],
        ],
        'https',
      ],
      // HTTPS DSN, Not empty proxy white-list, Sentry white-listed.
      [
        'https://user:password@sentry.test/123456',
        [
          'http' => NULL,
          'https' => NULL,
          'no' => [
            'some.server.test',
            'sentry.test',
          ],
        ],
        'no',
      ],
      [
        'https://user:password@sentry.test/123456',
        [
          'http' => 'http-proxy.server.test:3129',
          'https' => NULL,
          'no' => [
            'some.server.test',
            'sentry.test',
          ],
        ],
        'no',
      ],
      [
        'https://user:password@sentry.test/123456',
        [
          'http' => NULL,
          'https' => 'https-proxy.server.test:3129',
          'no' => [
            'some.server.test',
            'sentry.test',
          ],
        ],
        'no',
      ],
      [
        'https://user:password@sentry.test/123456',
        [
          'http' => 'http-proxy.server.test:3129',
          'https' => 'https-proxy.server.test:3129',
          'no' => [
            'some.server.test',
            'sentry.test',
          ],
        ],
        'no',
      ],
    ];
  }

  /**
   * Test proxy configuration.
   *
   * @dataProvider proxyConfigurationData
   */
  public function testProxyConfiguration($dsn, $config, $proxy) {
    $this->configFactory = $this
      ->getConfigFactoryStub([
      'raven.settings' => [
        'client_key' => $dsn,
        // We need this to avoid registering error handlers in
        // \Drupal\raven\Logger\Raven constructor.
        'fatal_error_handler' => FALSE,
      ],
    ]);
    new Settings([
      'http_client_config' => [
        'proxy' => $config,
      ],
    ]);
    $raven = new Raven($this->configFactory, $this->parser, $this->moduleHandler, $this->environment);
    if ($proxy === 'no') {
      self::assertEmpty($raven->client->http_proxy, 'No proxy configured for Raven_Client');
    }
    else {
      self::assertSame($config[$proxy], $raven->client->http_proxy, strtoupper($proxy) . ' proxy configured for Raven_Client');
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
ProxyConfigTest::$configFactory protected property Config factory.
ProxyConfigTest::$environment protected property Environment.
ProxyConfigTest::$moduleHandler protected property The module handler.
ProxyConfigTest::$parser protected property The message's placeholders parser.
ProxyConfigTest::proxyConfigurationData public function Data provider for testProxyConfiguration().
ProxyConfigTest::setUp protected function Overrides UnitTestCase::setUp
ProxyConfigTest::testProxyConfiguration public function Test proxy configuration.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.