View source
<?php
namespace Drupal\Tests\raven\Unit;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Logger\LogMessageParserInterface;
use Drupal\Core\Site\Settings;
use Drupal\raven\Logger\Raven;
use Drupal\Tests\UnitTestCase;
class ProxyConfigTest extends UnitTestCase {
protected $configFactory;
protected $environment;
protected $moduleHandler;
protected $parser;
protected function setUp() : void {
parent::setUp();
$this->parser = $this
->createMock(LogMessageParserInterface::class);
$this->moduleHandler = $this
->createMock(ModuleHandlerInterface::class);
$this->environment = 'testing';
}
public function proxyConfigurationData() {
return [
[
'http://user@sentry.test/123456',
[
'http' => NULL,
'https' => NULL,
'no' => [],
],
'no',
],
[
'http://user@sentry.test/123456',
[
'http' => 'http-proxy.server.test:3129',
'https' => NULL,
'no' => [],
],
'http',
],
[
'http://user@sentry.test/123456',
[
'http' => NULL,
'https' => 'https-proxy.server.test:3129',
'no' => [],
],
'no',
],
[
'http://user@sentry.test/123456',
[
'http' => 'http-proxy.server.test:3129',
'https' => 'https-proxy.server.test:3129',
'no' => [],
],
'http',
],
[
'http://user@sentry.test/123456',
[
'http' => NULL,
'https' => NULL,
'no' => [
'some.server.test',
],
],
'no',
],
[
'http://user@sentry.test/123456',
[
'http' => 'http-proxy.server.test:3129',
'https' => NULL,
'no' => [
'some.server.test',
],
],
'http',
],
[
'http://user@sentry.test/123456',
[
'http' => NULL,
'https' => 'https-proxy.server.test:3129',
'no' => [
'some.server.test',
],
],
'no',
],
[
'http://user@sentry.test/123456',
[
'http' => 'http-proxy.server.test:3129',
'https' => 'https-proxy.server.test:3129',
'no' => [
'some.server.test',
],
],
'http',
],
[
'http://user@sentry.test/123456',
[
'http' => NULL,
'https' => NULL,
'no' => [
'some.server.test',
'sentry.test',
],
],
'no',
],
[
'http://user@sentry.test/123456',
[
'http' => 'http-proxy.server.test:3129',
'https' => NULL,
'no' => [
'some.server.test',
'sentry.test',
],
],
'no',
],
[
'http://user@sentry.test/123456',
[
'http' => NULL,
'https' => 'https-proxy.server.test:3129',
'no' => [
'some.server.test',
'sentry.test',
],
],
'no',
],
[
'http://user@sentry.test/123456',
[
'http' => 'http-proxy.server.test:3129',
'https' => 'https-proxy.server.test:3129',
'no' => [
'some.server.test',
'sentry.test',
],
],
'no',
],
[
'https://user@sentry.test/123456',
[
'http' => NULL,
'https' => NULL,
'no' => [],
],
'no',
],
[
'https://user@sentry.test/123456',
[
'http' => 'http-proxy.server.test:3129',
'https' => NULL,
'no' => [],
],
'no',
],
[
'https://user@sentry.test/123456',
[
'http' => NULL,
'https' => 'https-proxy.server.test:3129',
'no' => [],
],
'https',
],
[
'https://user@sentry.test/123456',
[
'http' => 'http-proxy.server.test:3129',
'https' => 'https-proxy.server.test:3129',
'no' => [],
],
'https',
],
[
'https://user@sentry.test/123456',
[
'http' => NULL,
'https' => NULL,
'no' => [
'some.server.test',
],
],
'no',
],
[
'https://user@sentry.test/123456',
[
'http' => 'http-proxy.server.test:3129',
'https' => NULL,
'no' => [
'some.server.test',
],
],
'no',
],
[
'https://user@sentry.test/123456',
[
'http' => NULL,
'https' => 'https-proxy.server.test:3129',
'no' => [
'some.server.test',
],
],
'https',
],
[
'https://user@sentry.test/123456',
[
'http' => 'http-proxy.server.test:3129',
'https' => 'https-proxy.server.test:3129',
'no' => [
'some.server.test',
],
],
'https',
],
[
'https://user@sentry.test/123456',
[
'http' => NULL,
'https' => NULL,
'no' => [
'some.server.test',
'sentry.test',
],
],
'no',
],
[
'https://user@sentry.test/123456',
[
'http' => 'http-proxy.server.test:3129',
'https' => NULL,
'no' => [
'some.server.test',
'sentry.test',
],
],
'no',
],
[
'https://user@sentry.test/123456',
[
'http' => NULL,
'https' => 'https-proxy.server.test:3129',
'no' => [
'some.server.test',
'sentry.test',
],
],
'no',
],
[
'https://user@sentry.test/123456',
[
'http' => 'http-proxy.server.test:3129',
'https' => 'https-proxy.server.test:3129',
'no' => [
'some.server.test',
'sentry.test',
],
],
'no',
],
];
}
public function testProxyConfiguration($dsn, $config, $proxy) {
$this->configFactory = $this
->getConfigFactoryStub([
'raven.settings' => [
'client_key' => $dsn,
'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
->getClient(TRUE)
->getOptions()
->getHttpProxy(), 'No proxy configured for Sentry\\Client');
}
else {
self::assertSame($config[$proxy], $raven
->getClient(TRUE)
->getOptions()
->getHttpProxy(), strtoupper($proxy) . ' proxy configured for Sentry\\Client');
}
}
}