Skip to content

Commit

Permalink
feat: deprecate query parameter validator
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Jul 4, 2024
1 parent 74986cb commit 14dc536
Show file tree
Hide file tree
Showing 8 changed files with 332 additions and 96 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1333,3 +1333,52 @@ jobs:
name: openapi-docs-php${{ matrix.php }}
path: build/out/openapi
continue-on-error: true

behat_legacy_query_parameter_validator:
name: Behat query parameter validator (PHP ${{ matrix.php }})
env:
QUERY_PARAMETER_VALIDATOR: 1
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
matrix:
php:
- '8.3'
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: pecl, composer
extensions: intl, bcmath, curl, openssl, mbstring, pdo_sqlite
coverage: pcov
ini-values: memory_limit=-1
- name: Get composer cache directory
id: composercache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Update project dependencies
run: composer update --no-interaction --no-progress --ansi
- name: Install PHPUnit
run: vendor/bin/simple-phpunit --version
- name: Clear test app cache
run: tests/Fixtures/app/console cache:clear --ansi
- name: Run Behat tests (PHP 8)
run: |
mkdir -p build/logs/behat
vendor/bin/behat --out=std --format=progress --format=junit --out=build/logs/behat/junit --tags=query_parameter_validator
- name: Upload test artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: behat-logs-php${{ matrix.php }}
path: build/logs/behat
continue-on-error: true
10 changes: 5 additions & 5 deletions behat.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ default:
- 'Behat\MinkExtension\Context\MinkContext'
- 'behatch:context:rest'
filters:
tags: '~@postgres&&~@mongodb&&~@elasticsearch&&~@controller&&~@mercure'
tags: '~@postgres&&~@mongodb&&~@elasticsearch&&~@controller&&~@mercure&&~@query_parameter_validator'
extensions:
'FriendsOfBehat\SymfonyExtension':
bootstrap: 'tests/Fixtures/app/bootstrap.php'
Expand Down Expand Up @@ -52,7 +52,7 @@ postgres:
- 'Behat\MinkExtension\Context\MinkContext'
- 'behatch:context:rest'
filters:
tags: '~@sqlite&&~@mongodb&&~@elasticsearch&&~@controller&&~@mercure'
tags: '~@sqlite&&~@mongodb&&~@elasticsearch&&~@controller&&~@mercure&&~@query_parameter_validator'

mongodb:
suites:
Expand All @@ -73,7 +73,7 @@ mongodb:
- 'Behat\MinkExtension\Context\MinkContext'
- 'behatch:context:rest'
filters:
tags: '~@sqlite&&~@elasticsearch&&~@!mongodb&&~@mercure&&~@controller'
tags: '~@sqlite&&~@elasticsearch&&~@!mongodb&&~@mercure&&~@controller&&~@query_parameter_validator'

mercure:
suites:
Expand Down Expand Up @@ -109,7 +109,7 @@ elasticsearch:
- 'Behat\MinkExtension\Context\MinkContext'
- 'behatch:context:rest'
filters:
tags: '@elasticsearch&&~@mercure'
tags: '@elasticsearch&&~@mercure&&~@query_parameter_validator'

default-coverage:
suites:
Expand Down Expand Up @@ -238,7 +238,7 @@ symfony_listeners:
- 'Behat\MinkExtension\Context\MinkContext'
- 'behatch:context:rest'
filters:
tags: '~@postgres&&~@mongodb&&~@elasticsearch&&~@mercure'
tags: '~@postgres&&~@mongodb&&~@elasticsearch&&~@mercure&&~@query_parameter_validator'
extensions:
'FriendsOfBehat\SymfonyExtension':
bootstrap: 'tests/Fixtures/app/bootstrap.php'
Expand Down
117 changes: 28 additions & 89 deletions features/filter/filter_validation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,161 +10,100 @@ Feature: Validate filters based upon filter description

Scenario: Required filter that does not allow empty value should throw an error if empty
When I am on "/filter_validators?required=&required-allow-empty=&arrayRequired[foo]="
Then the response status code should be 400
And the JSON node "detail" should be equal to 'Query parameter "required" does not allow empty value'
Then the response status code should be 422
And the JSON node "detail" should be equal to 'required: This value should not be blank.'

Scenario: Required filter should throw an error if not set
When I am on "/filter_validators"
Then the response status code should be 400
And the JSON node "detail" should match '/^Query parameter "required" is required\nQuery parameter "required-allow-empty" is required$/'
Then the response status code should be 422
And the JSON node "detail" should be equal to 'required: This value should not be blank.\nrequired-allow-empty: The parameter "required-allow-empty" is required.'

Scenario: Required filter should not throw an error if set
When I am on "/array_filter_validators?arrayRequired[]=foo&indexedArrayRequired[foo]=foo"
Then the response status code should be 200

Scenario: Required filter should throw an error if not set
When I am on "/array_filter_validators"
Then the response status code should be 400
And the JSON node "detail" should match '/^Query parameter "arrayRequired\[\]" is required\nQuery parameter "indexedArrayRequired\[foo\]" is required$/'

When I am on "/array_filter_validators?arrayRequired=foo&indexedArrayRequired[foo]=foo"
Then the response status code should be 400
And the JSON node "detail" should be equal to 'Query parameter "arrayRequired[]" is required'
Then the response status code should be 422
And the JSON node "detail" should be equal to 'arrayRequired: This value should not be blank.\nindexedArrayRequired: This value should not be blank.'

When I am on "/array_filter_validators?arrayRequired[foo]=foo"
Then the response status code should be 400
And the JSON node "detail" should match '/^Query parameter "arrayRequired\[\]" is required\nQuery parameter "indexedArrayRequired\[foo\]" is required$/'
Then the response status code should be 422
And the JSON node "detail" should be equal to 'indexedArrayRequired: This value should not be blank.'

When I am on "/array_filter_validators?arrayRequired[]=foo"
Then the response status code should be 400
And the JSON node "detail" should be equal to 'Query parameter "indexedArrayRequired[foo]" is required'

When I am on "/array_filter_validators?arrayRequired[]=foo&indexedArrayRequired[bar]=bar"
Then the response status code should be 400
And the JSON node "detail" should be equal to 'Query parameter "indexedArrayRequired[foo]" is required'
Then the response status code should be 422
And the JSON node "detail" should be equal to 'indexedArrayRequired: This value should not be blank.'

Scenario: Test filter bounds: maximum
When I am on "/filter_validators?required=foo&required-allow-empty&maximum=10"
Then the response status code should be 200

When I am on "/filter_validators?required=foo&required-allow-empty&maximum=11"
Then the response status code should be 400
And the JSON node "detail" should be equal to 'Query parameter "maximum" must be less than or equal to 10'
Then the response status code should be 422
And the JSON node "detail" should be equal to 'maximum: This value should be less than or equal to 10.'

Scenario: Test filter bounds: exclusiveMaximum
When I am on "/filter_validators?required=foo&required-allow-empty&exclusiveMaximum=9"
Then the response status code should be 200

When I am on "/filter_validators?required=foo&required-allow-empty&exclusiveMaximum=10"
Then the response status code should be 400
And the JSON node "detail" should be equal to 'Query parameter "exclusiveMaximum" must be less than 10'
Then the response status code should be 422
And the JSON node "detail" should be equal to 'maximum: This value should be less than 10.'

Scenario: Test filter bounds: minimum
When I am on "/filter_validators?required=foo&required-allow-empty&minimum=5"
Then the response status code should be 200

When I am on "/filter_validators?required=foo&required-allow-empty&minimum=0"
Then the response status code should be 400
And the JSON node "detail" should be equal to 'Query parameter "minimum" must be greater than or equal to 5'
Then the response status code should be 422
And the JSON node "detail" should be equal to 'minimum: This value should be greater than or equal to 5.'

Scenario: Test filter bounds: exclusiveMinimum
When I am on "/filter_validators?required=foo&required-allow-empty&exclusiveMinimum=6"
Then the response status code should be 200

When I am on "/filter_validators?required=foo&required-allow-empty&exclusiveMinimum=5"
Then the response status code should be 400
And the JSON node "detail" should be equal to 'Query parameter "exclusiveMinimum" must be greater than 5'
Then the response status code should be 422
And the JSON node "detail" should be equal to 'exclusiveMinimum: This value should be greater than 5.'

Scenario: Test filter bounds: max length
When I am on "/filter_validators?required=foo&required-allow-empty&max-length-3=123"
Then the response status code should be 200

When I am on "/filter_validators?required=foo&required-allow-empty&max-length-3=1234"
Then the response status code should be 400
And the JSON node "detail" should be equal to 'Query parameter "max-length-3" length must be lower than or equal to 3'

Scenario: Do not throw an error if value is not an array
When I am on "/filter_validators?required=foo&required-allow-empty&max-length-3[]=12345"
Then the response status code should be 200
Then the response status code should be 422
And the JSON node "detail" should be equal to 'max-length-3: This value is too long. It should have 3 characters or less.'

Scenario: Test filter bounds: min length
When I am on "/filter_validators?required=foo&required-allow-empty&min-length-3=123"
Then the response status code should be 200

When I am on "/filter_validators?required=foo&required-allow-empty&min-length-3=12"
Then the response status code should be 400
And the JSON node "detail" should be equal to 'Query parameter "min-length-3" length must be greater than or equal to 3'
Then the response status code should be 422
And the JSON node "detail" should be equal to 'min-length-3: This value is too short. It should have 3 characters or more.'

Scenario: Test filter pattern
When I am on "/filter_validators?required=foo&required-allow-empty&pattern=pattern"
When I am on "/filter_validators?required=foo&required-allow-empty&pattern=nrettap"
Then the response status code should be 200

When I am on "/filter_validators?required=foo&required-allow-empty&pattern=not-pattern"
Then the response status code should be 400
And the JSON node "detail" should be equal to 'Query parameter "pattern" must match pattern /^(pattern|nrettap)$/'
Then the response status code should be 422
And the JSON node "detail" should be equal to 'pattern: This value is not valid.'

Scenario: Test filter enum
When I am on "/filter_validators?required=foo&required-allow-empty&enum=in-enum"
Then the response status code should be 200

When I am on "/filter_validators?required=foo&required-allow-empty&enum=not-in-enum"
Then the response status code should be 400
And the JSON node "detail" should be equal to 'Query parameter "enum" must be one of "in-enum, mune-ni"'
Then the response status code should be 422
And the JSON node "detail" should be equal to 'enum: The value you selected is not a valid choice.'

Scenario: Test filter multipleOf
When I am on "/filter_validators?required=foo&required-allow-empty&multiple-of=4"
Then the response status code should be 200

When I am on "/filter_validators?required=foo&required-allow-empty&multiple-of=3"
Then the response status code should be 400
And the JSON node "detail" should be equal to 'Query parameter "multiple-of" must multiple of 2'

Scenario: Test filter array items csv format minItems
When I am on "/filter_validators?required=foo&required-allow-empty&csv-min-2=a,b"
Then the response status code should be 200

When I am on "/filter_validators?required=foo&required-allow-empty&csv-min-2=a"
Then the response status code should be 400
And the JSON node "detail" should be equal to 'Query parameter "csv-min-2" must contain more than 2 values'

Scenario: Test filter array items csv format maxItems
When I am on "/filter_validators?required=foo&required-allow-empty&csv-max-3=a,b,c"
Then the response status code should be 200

When I am on "/filter_validators?required=foo&required-allow-empty&csv-max-3=a,b,c,d"
Then the response status code should be 400
And the JSON node "detail" should be equal to 'Query parameter "csv-max-3" must contain less than 3 values'

Scenario: Test filter array items tsv format minItems
When I am on "/filter_validators?required=foo&required-allow-empty&tsv-min-2=a\tb"
Then the response status code should be 200

When I am on "/filter_validators?required=foo&required-allow-empty&tsv-min-2=a,b"
Then the response status code should be 400
And the JSON node "detail" should be equal to 'Query parameter "tsv-min-2" must contain more than 2 values'

Scenario: Test filter array items pipes format minItems
When I am on "/filter_validators?required=foo&required-allow-empty&pipes-min-2=a|b"
Then the response status code should be 200

When I am on "/filter_validators?required=foo&required-allow-empty&pipes-min-2=a,b"
Then the response status code should be 400
And the JSON node "detail" should be equal to 'Query parameter "pipes-min-2" must contain more than 2 values'

Scenario: Test filter array items ssv format minItems
When I am on "/filter_validators?required=foo&required-allow-empty&ssv-min-2=a b"
Then the response status code should be 200

When I am on "/filter_validators?required=foo&required-allow-empty&ssv-min-2=a,b"
Then the response status code should be 400
And the JSON node "detail" should be equal to 'Query parameter "ssv-min-2" must contain more than 2 values'

@dropSchema
Scenario: Test filter array items unique items
When I am on "/filter_validators?required=foo&required-allow-empty&csv-uniques=a,b"
Then the response status code should be 200

When I am on "/filter_validators?required=foo&required-allow-empty&csv-uniques=a,a"
Then the response status code should be 400
And the JSON node "detail" should be equal to 'Query parameter "csv-uniques" must contain unique values'
Then the response status code should be 422
And the JSON node "detail" should be equal to 'multiple-of: This value should be a multiple of 2.'
Loading

0 comments on commit 14dc536

Please sign in to comment.