klT45 opened a new pull request, #7874:
URL: https://github.com/apache/shenyu/pull/7874

   Fixes #7873
   
   ## Changes
   
   - `shenyu-common`: new `RewriteHandleUtils#unapplicableReason(regex, 
replace)`, the applicability check that `RewritePluginDataHandler` used inline. 
In plain-regex mode the regex is compiled and the replacement is dry-run 
against the empty input, which validates both parts; placeholder mode (`regex` 
and `replace` both contain `{`) and incomplete expressions stay accepted 
because the plugin substitutes them literally or skips them.
   - `shenyu-admin`: new `RewriteRuleHandleValidator` (same shape as the 
existing `AgentGatewayRuleHandleValidator`) parses the handle, rejects handles 
that are not a JSON object, and rejects handles the gateway could never apply 
with a message that names the reason, e.g. `rewrite rule handle can not be 
applied, invalid replacement template: No group 1`.
   - `RuleServiceImpl#validateRuleHandle`: validate handles of the `rewrite` 
plugin next to the `agentGateway` ones, so create, update, batch import and 
namespace import are all covered.
   - `RewritePluginDataHandler#canRewrite` delegates to the shared util; the 
behaviour and the log message are unchanged, the log now additionally carries 
the reason. An unparsable handle JSON is also rejected at the write boundary 
now, instead of throwing inside the gateway data-sync thread.
   
   Handles that work today keep working: `(test)` + `/new/$1`, `/shenyu/test` + 
`/new`, `/shenyu/{id}` + `/target/{id}`, blank or incomplete expressions; 
unknown extra fields inside the handle are still accepted. The runtime 
fail-safe from #7854 stays as the last line of defence for rules already stored 
or written by another sync source.
   
   ## Tests
   
   New tests, all of which fail before the change:
   
   - `RewriteHandleUtilsTest` - applicable expressions, missing group 
reference, bare `$`, invalid regex.
   - `RewriteRuleHandleValidatorTest` - 8 accepted handles and 9 rejected 
handles (`not-json`, `[]`, JSON `null`, missing group, `$$`, trailing `$`, 
invalid regex) plus a message assertion for the missing group case.
   - `RuleServiceTest#testRewriteCreateRejectsUnapplicableHandleBeforeWrite`, 
`#testRewriteUpdateRejectsUnapplicableHandleBeforeWrite`, 
`#testRewriteImportRejectsUnapplicableHandleBeforeWrite` - the rule is rejected 
before any DB write or event is published; 
`#testRewriteCreateAcceptsApplicableHandle` is the regression guard that valid 
handles still save.
   
   ## Verifying
   
   - `./mvnw -pl shenyu-admin -am install -Dmaven.test.skip=true 
-Djacoco.skip=true -Dmaven.javadoc.skip=true`
   - `./mvnw -pl shenyu-common test -Dtest=RewriteHandleUtilsTest` - 4 tests 
pass
   - `./mvnw -pl shenyu-plugin/shenyu-plugin-rewrite test` - 23 tests pass
   - `./mvnw -pl shenyu-admin test 
-Dtest=RewriteRuleHandleValidatorTest,RuleServiceTest` - 39 tests pass
   - `./mvnw -pl shenyu-common,shenyu-plugin/shenyu-plugin-rewrite,shenyu-admin 
verify -DskipTests` - checkstyle and Apache RAT pass, 0 unapproved licenses


-- 
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]

Reply via email to