Repository navigation
Fix dispatcher GrailsWebRequest publication after late filters #16873
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
Open
ruthst00
wants to merge
1
commit into
apache:7.0.x
Choose a base branch
from
ruthst00:fix/15819-dispatcher-grailswebrequest
base: 7.0.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+709
−10
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| <!-- | ||
| SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| Licensed to the Apache Software Foundation (ASF) under one or more | ||
| contributor license agreements. See the NOTICE file distributed with | ||
| this work for additional information regarding copyright ownership. | ||
| The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| (the "License"); you may not use this file except in compliance with | ||
| the License. You may obtain a copy of the License at | ||
|
|
||
| https://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| --> | ||
|
|
||
| # Response rendering regression (#15819) | ||
|
|
||
| Functional coverage based on the | ||
| [end-application reproducer](https://github.com/ruthst00/15819-response-renderer-overloads). | ||
| The application registers a Spring `RequestContextFilter` at order `-100`, after | ||
| Grails' request filter, and serves a small GSP fragment from `/search/results`. | ||
| Keep the fragment small and do not flush the response: committing it can mask | ||
| the unwanted conventional view resolution that caused the original failure. | ||
|
|
||
| There is deliberately no `results.gsp` or `upload.gsp`. The tests cover template | ||
| rendering with AJAX and normal GET requests and multipart uploads behind a late | ||
| request-context filter. `/search/upload` reads a `title` form field and a `file` | ||
| upload, and renders the title, original filename and uploaded content in the fragment. | ||
|
|
||
| `GrailsDispatcherServletRequestBindingSpec` provides the dispatcher regression | ||
| coverage on `7.0.x`, including multipart resolution, request publication, nested | ||
| dispatches and asynchronous processing. It has a distinct name so merge-up can | ||
| retain the existing dispatcher and hidden-method specs on `8.0.x`. | ||
|
|
||
| The tests use real HTTP requests against the embedded application; no browser, | ||
| database, or Docker container is needed. From the repository root, run: | ||
|
|
||
| ```bash | ||
| ./gradlew :grails-test-examples-issue-15819:integrationTest | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| plugins { | ||
| id 'org.apache.grails.buildsrc.properties' | ||
| id 'org.apache.grails.buildsrc.dependency-validator' | ||
| id 'org.apache.grails.buildsrc.compile' | ||
| id 'org.apache.grails.buildsrc.vulnerability-scan' | ||
| } | ||
|
|
||
| version = '0.1' | ||
| group = 'issue15819' | ||
|
|
||
| apply plugin: 'org.apache.grails.gradle.grails-web' | ||
| apply plugin: 'org.apache.grails.gradle.grails-gsp' | ||
|
|
||
| dependencies { | ||
| implementation platform(project(':grails-bom')) | ||
| implementation 'org.apache.grails:grails-dependencies-starter-web' | ||
|
|
||
| integrationTestImplementation 'org.apache.grails.testing:grails-testing-support-core' | ||
| integrationTestImplementation 'org.apache.grails:grails-testing-support-http-client' | ||
| } | ||
|
|
||
| apply { | ||
| from rootProject.layout.projectDirectory.file('gradle/functional-test-config.gradle') | ||
| from rootProject.layout.projectDirectory.file('gradle/grails-extension-gradle-config.gradle') | ||
| } |
23 changes: 23 additions & 0 deletions
23
grails-test-examples/issue-15819/grails-app/conf/application.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| grails: | ||
| profile: web | ||
| views: | ||
| gsp: | ||
| encoding: UTF-8 | ||
| info: | ||
| app: | ||
| name: issue-15819 |
30 changes: 30 additions & 0 deletions
30
grails-test-examples/issue-15819/grails-app/conf/spring/resources.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package spring | ||
|
|
||
| import org.springframework.boot.web.servlet.FilterRegistrationBean | ||
| import org.springframework.web.filter.RequestContextFilter | ||
|
|
||
| beans = { | ||
| // Reproduce an application filter replacing the thread binding after Grails' request filter. | ||
| lateRequestContextFilter(FilterRegistrationBean) { | ||
| filter = new RequestContextFilter() | ||
| order = -100 | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
grails-test-examples/issue-15819/grails-app/controllers/issue15819/SearchController.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package issue15819 | ||
|
|
||
| import grails.compiler.GrailsCompileStatic | ||
| import org.springframework.web.multipart.MultipartHttpServletRequest | ||
|
|
||
| @GrailsCompileStatic | ||
| class SearchController { | ||
|
|
||
| def results() { | ||
| render(template: 'results', model: [results: ['Grails', 'Groovy', 'Spring Boot']]) | ||
| } | ||
|
|
||
| def upload() { | ||
| def file = ((MultipartHttpServletRequest) request).getFile('file') | ||
| render(template: 'results', model: [results: [params.title, file.originalFilename, new String(file.bytes, 'UTF-8')]]) | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
grails-test-examples/issue-15819/grails-app/controllers/issue15819/UrlMappings.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package issue15819 | ||
|
|
||
| class UrlMappings { | ||
|
|
||
| static mappings = { | ||
| "/search/$action"(controller: 'search') | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
grails-test-examples/issue-15819/grails-app/init/issue15819/Application.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package issue15819 | ||
|
|
||
| import groovy.transform.CompileStatic | ||
|
|
||
| import grails.boot.GrailsApp | ||
| import grails.boot.config.GrailsAutoConfiguration | ||
|
|
||
| @CompileStatic | ||
| class Application extends GrailsAutoConfiguration { | ||
|
|
||
| static void main(String[] args) { | ||
| GrailsApp.run(Application, args) | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
grails-test-examples/issue-15819/grails-app/views/search/_results.gsp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <%-- | ||
| Licensed to the Apache Software Foundation (ASF) under one | ||
| or more contributor license agreements. See the NOTICE file | ||
| distributed with this work for additional information | ||
| regarding copyright ownership. The ASF licenses this file | ||
| to you under the Apache License, Version 2.0 (the | ||
| "License"); you may not use this file except in compliance | ||
| with the License. You may obtain a copy of the License at | ||
|
|
||
| https://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, | ||
| software distributed under the License is distributed on an | ||
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| KIND, either express or implied. See the License for the | ||
| specific language governing permissions and limitations | ||
| under the License. | ||
| --%> | ||
| <ul id="results"> | ||
| <g:each in="${results}" var="result"> | ||
| <li>${result}</li> | ||
| </g:each> | ||
| </ul> |
72 changes: 72 additions & 0 deletions
72
.../issue-15819/src/integration-test/groovy/issue15819/ResponseRendererFunctionalSpec.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package issue15819 | ||
|
|
||
| import spock.lang.Issue | ||
| import spock.lang.Specification | ||
| import spock.lang.Tag | ||
| import spock.lang.Unroll | ||
|
|
||
| import grails.testing.mixin.integration.Integration | ||
| import org.apache.grails.testing.http.client.HttpClientSupport | ||
| import org.apache.grails.testing.http.client.MultipartBody | ||
|
|
||
| @Integration | ||
| @Tag('http-client') | ||
| @Issue('https://github.com/apache/grails-core/issues/15819') | ||
| class ResponseRendererFunctionalSpec extends Specification implements HttpClientSupport { | ||
|
|
||
| @Unroll | ||
| void 'an upload renders only the template fragment with ajax=#ajax'() { | ||
| given: | ||
| def multipart = MultipartBody.builder() | ||
| .addPart('title', 'Upload title') | ||
| .addPart('file', 'results.txt', 'text/plain', 'Uploaded content') | ||
| .build() | ||
|
|
||
| when: | ||
| def response = httpPostMultipart(ajax ? ['X-Requested-With': 'XMLHttpRequest'] : [:], '/search/upload', multipart) | ||
|
|
||
| then: | ||
| response.assertStatus(200) | ||
| response.headerValue('Content-Type').startsWith('text/html') | ||
| response.body().replaceAll(/\s+/, ' ').trim() == | ||
| '<ul id="results"> <li>Upload title</li> <li>results.txt</li> <li>Uploaded content</li> </ul>' | ||
|
|
||
| where: | ||
| ajax << [false, true] | ||
| } | ||
|
|
||
| @Unroll | ||
| void '#action renders only the _results.gsp template fragment with ajax=#ajax'() { | ||
| when: | ||
| def response = http(ajax ? ['X-Requested-With': 'XMLHttpRequest'] : [:], "/search/$action") | ||
|
|
||
| then: 'no conventional action view is resolved and no layout or error page is appended' | ||
| response.assertStatus(200) | ||
| response.headerValue('Content-Type').startsWith('text/html') | ||
| response.body().replaceAll(/\s+/, ' ').trim() == | ||
| '<ul id="results"> <li>Grails</li> <li>Groovy</li> <li>Spring Boot</li> </ul>' | ||
|
|
||
| where: | ||
| action | ajax | ||
| 'results' | false | ||
| 'results' | true | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Request tags are raw and unchanged. A filter sets params.tags[0] to filter. A later wrapper supplies wrapped and values, and a late filter replaces the thread binding. The controller should receive filter and values. It receives wrapped and values, because the new request is published without the filter's edit. Carry that edit onto the published request.