jamesfredley commented on code in PR #16492:
URL: https://github.com/apache/grails-core/pull/16492#discussion_r4174533294
##########
grails-test-examples/views-functional-tests/src/integration-test/groovy/functional/tests/ModelInterceptorIntSpec.groovy:
##########
@@ -75,4 +75,28 @@ class ModelInterceptorIntSpec extends Specification
implements HttpClientSupport
and: "the interceptor's after() received the model argument without
the bean"
modelInterceptor.latestModel == [title: 'x']
}
+
+ @Issue('https://github.com/apache/grails-core/issues/12081')
+ void "TEMPLATE_MODEL does not leak into the interceptor of a forwarded
action"() {
+ given: "a controller that renders a template (setting TEMPLATE_MODEL)
then forwards to another action"
+ def response = http('/renderTemplate/forwardAfterTemplate')
+
+ expect: "the HTTP response succeeds"
+ response.assertStatus(200)
+
+ and: "the interceptor's after() for the forwarded action
(forwardTarget) sees no model"
+ modelInterceptor.latestModel == null
+ }
+
+ @Issue('https://github.com/apache/grails-core/issues/12081')
+ void "TEMPLATE_MODEL does not leak into the interceptor of an included
action"() {
+ given: "a controller that renders a template (setting TEMPLATE_MODEL)
then includes another action"
+ def response = http('/renderTemplate/includeAfterTemplate')
+
+ expect: "the HTTP response succeeds"
+ response.assertStatus(200)
+
+ and: "the interceptor's after() for the included action
(includeTarget) sees no model"
+ modelInterceptor.modelByAction['includeTarget'] == null
Review Comment:
Non-blocking. `modelByAction['includeTarget'] == null` is also true when the
key was never set, so this passes if the included interceptor did not run.
Assert `containsKey('includeTarget')` and that the recorded model is null.
##########
grails-test-examples/views-functional-tests/src/integration-test/groovy/functional/tests/ModelInterceptorIntSpec.groovy:
##########
@@ -75,4 +75,28 @@ class ModelInterceptorIntSpec extends Specification
implements HttpClientSupport
and: "the interceptor's after() received the model argument without
the bean"
modelInterceptor.latestModel == [title: 'x']
}
+
+ @Issue('https://github.com/apache/grails-core/issues/12081')
+ void "TEMPLATE_MODEL does not leak into the interceptor of a forwarded
action"() {
+ given: "a controller that renders a template (setting TEMPLATE_MODEL)
then forwards to another action"
+ def response = http('/renderTemplate/forwardAfterTemplate')
+
+ expect: "the HTTP response succeeds"
+ response.assertStatus(200)
+
+ and: "the interceptor's after() for the forwarded action
(forwardTarget) sees no model"
+ modelInterceptor.latestModel == null
Review Comment:
Non-blocking. `latestModel == null` does not prove the forwarded action's
interceptor ran. The enclosing dispatch can overwrite `latestModel` after
`forwardTarget`. Reset the observations before the request, then assert
`modelByAction.containsKey('forwardTarget')` and that the recorded model is
null, and assert the target response content.
##########
grails-controllers/src/test/groovy/grails/artefact/controller/support/RequestForwarderSpec.groovy:
##########
@@ -73,6 +73,49 @@ class RequestForwarderSpec extends Specification {
+ cleanup:
+ RequestContextHolder.setRequestAttributes(null)
+ }
+
+ void "test request forward clears TEMPLATE_MODEL before and after the
forward"() {
Review Comment:
Non-blocking. This covers a successful forward. It does not cover a
dispatcher that throws after setting a new `TEMPLATE_MODEL`. The `finally`
removal should still clear it. A throwing dispatcher would lock that in. Not
required for this approval.
##########
grails-test-examples/hibernate7/views-functional-tests/src/integration-test/groovy/functional/tests/ModelInterceptorIntSpec.groovy:
##########
@@ -75,4 +75,28 @@ class ModelInterceptorIntSpec extends Specification
implements HttpClientSupport
and: "the interceptor's after() received the model argument without
the bean"
modelInterceptor.latestModel == [title: 'x']
}
+
+ @Issue('https://github.com/apache/grails-core/issues/12081')
+ void "TEMPLATE_MODEL does not leak into the interceptor of a forwarded
action"() {
+ given: "a controller that renders a template (setting TEMPLATE_MODEL)
then forwards to another action"
+ def response = http('/renderTemplate/forwardAfterTemplate')
+
+ expect: "the HTTP response succeeds"
+ response.assertStatus(200)
+
+ and: "the interceptor's after() for the forwarded action
(forwardTarget) sees no model"
+ modelInterceptor.latestModel == null
Review Comment:
Non-blocking. Same gap as the views-functional-tests copy. `latestModel ==
null` does not prove `forwardTarget`'s interceptor ran, because the enclosing
dispatch can overwrite it. Assert `containsKey('forwardTarget')` and the
recorded model.
##########
grails-web-url-mappings/src/test/groovy/org/grails/web/mapping/UrlMappingUtilsSpec.groovy:
##########
@@ -92,4 +92,71 @@ class UrlMappingUtilsSpec extends Specification {
and:
includedContent
}
+
+ void "test includeForUrlMappingInfo clears TEMPLATE_MODEL during include
and restores it after"() {
Review Comment:
Non-blocking. This covers the success path. The `finally` restore is not
directly tested when the include throws, or when the included action replaces
an existing outer model. A dispatcher that sets a distinct inner model and
throws, then an identity comparison against the saved outer map, would lock
that in. Not required for this approval.
##########
grails-test-examples/hibernate7/views-functional-tests/src/integration-test/groovy/functional/tests/ModelInterceptorIntSpec.groovy:
##########
@@ -75,4 +75,28 @@ class ModelInterceptorIntSpec extends Specification
implements HttpClientSupport
and: "the interceptor's after() received the model argument without
the bean"
modelInterceptor.latestModel == [title: 'x']
}
+
+ @Issue('https://github.com/apache/grails-core/issues/12081')
+ void "TEMPLATE_MODEL does not leak into the interceptor of a forwarded
action"() {
+ given: "a controller that renders a template (setting TEMPLATE_MODEL)
then forwards to another action"
+ def response = http('/renderTemplate/forwardAfterTemplate')
+
+ expect: "the HTTP response succeeds"
+ response.assertStatus(200)
+
+ and: "the interceptor's after() for the forwarded action
(forwardTarget) sees no model"
+ modelInterceptor.latestModel == null
+ }
+
+ @Issue('https://github.com/apache/grails-core/issues/12081')
+ void "TEMPLATE_MODEL does not leak into the interceptor of an included
action"() {
+ given: "a controller that renders a template (setting TEMPLATE_MODEL)
then includes another action"
+ def response = http('/renderTemplate/includeAfterTemplate')
+
+ expect: "the HTTP response succeeds"
+ response.assertStatus(200)
+
+ and: "the interceptor's after() for the included action
(includeTarget) sees no model"
+ modelInterceptor.modelByAction['includeTarget'] == null
Review Comment:
Non-blocking. Same gap as the views-functional-tests copy. A missing
`includeTarget` key also compares equal to null. Assert
`containsKey('includeTarget')`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]