Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add max_request_body_size option #249

Merged
merged 7 commits into from Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fix Hub initialization for `ErrorListener` (#243, thanks to @teohhanhui)
- Fix compatibility with sentry/sentry 2.2+ (#244)
- Add support for `class_serializers` option (#245)
- Add support for `max_request_body_size` option (#249)

## 3.1.0 - 2019-07-02
- Add support for Symfony 2.8 (#233, thanks to @nocive)
Expand Down
21 changes: 20 additions & 1 deletion src/DependencyInjection/Configuration.php
Expand Up @@ -93,6 +93,15 @@ public function getConfigTreeBuilder(): TreeBuilder
})
->thenInvalid('Expecting service reference, got "%s"');
$optionsChildNodes->scalarNode('logger');
if ($this->maxRequestBodySizeIsSupported()) {
$optionsChildNodes->enumNode('max_request_body_size')
->values([
'none',
'small',
'medium',
'always',
]);
}
$optionsChildNodes->integerNode('max_breadcrumbs')
->min(1);
$optionsChildNodes->integerNode('max_value_length')
Expand Down Expand Up @@ -170,9 +179,19 @@ private function isNotAValidCallback(): \Closure
}

private function classSerializersAreSupported(): bool
{
return $this->optionIsSupported('class_serializers', []);
}

private function maxRequestBodySizeIsSupported(): bool
{
return $this->optionIsSupported('max_request_body_size', 'none');
}

private function optionIsSupported(string $name, $defaultValue): bool
{
try {
new Options(['class_serializers' => []]);
new Options([$name => $defaultValue]);
Jean85 marked this conversation as resolved.
Show resolved Hide resolved

return true;
} catch (\Throwable $throwable) {
Expand Down
1 change: 1 addition & 0 deletions src/DependencyInjection/SentryExtension.php
Expand Up @@ -67,6 +67,7 @@ private function passConfigurationToOptions(ContainerBuilder $container, array $
'excluded_exceptions',
'http_proxy',
'logger',
'max_request_body_size',
'max_breadcrumbs',
'max_value_length',
'prefixes',
Expand Down
35 changes: 24 additions & 11 deletions test/BaseTestCase.php
Expand Up @@ -4,29 +4,42 @@

use PHPUnit\Framework\TestCase;
use Sentry\Options;
use Sentry\SentryBundle\Test\DependencyInjection\ConfigurationTest;

abstract class BaseTestCase extends TestCase
{
public const SUPPORTED_SENTRY_OPTIONS_COUNT = 23;

protected function classSerializersAreSupported(): bool
{
try {
new Options(['class_serializers' => []]);
return $this->optionIsSupported('class_serializers', []);
}

return true;
} catch (\Throwable $throwable) {
return false;
}
protected function maxRequestBodySizeIsSupported(): bool
{
return $this->optionIsSupported('max_request_body_size', 'none');
}

protected function getSupportedOptionsCount(): int
{
$count = 23;

if ($this->classSerializersAreSupported()) {
return ConfigurationTest::SUPPORTED_SENTRY_OPTIONS_COUNT + 1;
++$count;
}

if ($this->maxRequestBodySizeIsSupported()) {
++$count;
}

return ConfigurationTest::SUPPORTED_SENTRY_OPTIONS_COUNT;
return $count;
}

private function optionIsSupported(string $name, $defaultValue): bool
{
try {
new Options([$name => $defaultValue]);

return true;
} catch (\Throwable $throwable) {
return false;
}
}
}
6 changes: 6 additions & 0 deletions test/DependencyInjection/ConfigurationTest.php
Expand Up @@ -112,6 +112,10 @@ public function optionValuesProvider(): array
['excluded_exceptions', [\Throwable::class]],
['logger', 'some-logger'],
['max_breadcrumbs', 15],
['max_request_body_size', 'none'],
['max_request_body_size', 'small'],
['max_request_body_size', 'medium'],
['max_request_body_size', 'always'],
['max_value_length', 1000],
['prefixes', ['some-string']],
['project_root', '/some/dir'],
Expand Down Expand Up @@ -174,6 +178,8 @@ public function invalidValuesProvider(): array
['integrations', [1]],
['integrations', 'a string'],
['logger', []],
['max_request_body_size', null],
['max_request_body_size', 'invalid'],
['max_breadcrumbs', -1],
['max_breadcrumbs', 'string'],
['max_value_length', -1],
Expand Down
1 change: 1 addition & 0 deletions test/DependencyInjection/SentryExtensionTest.php
Expand Up @@ -122,6 +122,7 @@ public function optionsValueProvider(): array
['excluded_exceptions', [\Throwable::class]],
['http_proxy', '1.2.3.4'],
['logger', 'sentry-logger'],
['max_request_body_size', 'always'],
['max_breadcrumbs', 15],
['max_value_length', 1000],
['prefixes', ['/some/path/prefix/']],
Expand Down