yyqdbngt opened a new pull request, #4669:
URL: https://github.com/apache/rocketmq-dashboard/pull/4669

   <!-- Base branch: `rocketmq-studio`, the RocketMQ Studio trunk. -->
   
   ### Which Issue(s) This PR Fixes
   
   - Fixes #4229
   
   ### Brief Description
   
   `MybatisPlusAclRepository` bound the raw search term as a `LIKE` pattern: 
the user search bound
   `username` / `access_key` and the rule query bound `principal` / `resource` 
with the term as typed.
   A term such as `_` or `%` was therefore read as a wildcard and matched every 
row, and a literal
   term containing either character could never be found. The term is now 
escaped (`\`, `%`, `_`)
   before it is bound, using a private helper local to the file and mirroring 
the `escapeLike` helper
   already used by `QueryHistoryService`.
   
   ### How Did You Test This Change?
   
   Two new `MybatisPlusAclRepositoryTest` cases capture the `QueryWrapper` 
handed to the mapper, call
   `getSqlSegment()` before reading `getParamNameValuePairs()` (the parameter 
map is only materialised
   once the SQL segment is built) and assert the bound parameters.
   
   Red - on the unmodified base:
   
   ```
   $ cd server && mvn -B -ntp test -Dtest=MybatisPlusAclRepositoryTest
   [ERROR] Tests run: 25, Failures: 2, Errors: 0, Skipped: 0
   [ERROR]   
MybatisPlusAclRepositoryTest.findUserPageShouldEscapeLikeWildcardsInTheSearchTerm:189
   Expecting ArrayList:
     ["%svc_a%%", "%svc_a%%"]
   to contain only:
     ["%svc\_a\%%"]
   [ERROR]   
MybatisPlusAclRepositoryTest.findRulePageShouldEscapeLikeWildcardsInTheFilterTerms:206
   Expecting ArrayList:
     ["%_orders%", "%svc_a%%"]
   to contain only:
     ["%svc\_a\%%", "%\_orders%"]
   ```
   
   Green - after the fix, including the pre-existing cases of the class and 
checkstyle (0 violations):
   
   ```
   $ cd server && mvn -B -ntp test -Dtest=MybatisPlusAclRepositoryTest
   [INFO] You have 0 Checkstyle violations.
   [INFO] Tests run: 25, Failures: 0, Errors: 0, Skipped: 0
   [INFO] BUILD SUCCESS
   ```
   
   The whole ACL package, to show the neighbouring classes are unaffected:
   
   ```
   $ cd server && mvn -B -ntp test 
-Dtest='org.apache.rocketmq.studio.instance.acl.*Test'
   [INFO] Tests run: 27, Failures: 0, Errors: 0, Skipped: 0 -- AclControllerTest
   [INFO] Tests run: 78, Failures: 0, Errors: 0, Skipped: 0 -- AclServiceTest
   [INFO] Tests run: 25, Failures: 0, Errors: 0, Skipped: 0 -- 
MybatisPlusAclRepositoryTest
   [INFO] Tests run: 28, Failures: 0, Errors: 0, Skipped: 0 -- 
PlainAclRemoteAddressValidatorTest
   [INFO] Tests run: 177, Failures: 0, Errors: 0, Skipped: 0
   [INFO] BUILD SUCCESS
   ```
   
   ### Checklist
   
   - [x] One coherent change; unrelated modifications are not bundled in
   - [x] Commit subject follows Conventional Commits (`feat:` / `fix:` / 
`refactor:` / `chore:` / `docs:` / `perf:`)
   - [x] Tests added or updated for non-trivial changes, test methods named 
`...Test`
   - [x] New UI text has both Chinese and English entries under `web/src/i18n/` 
(no UI text is added)
   - [x] Architecture constraints stay green (`mvn test` runs the ArchUnit 
checks)
   - [x] New source files carry the ASF license header (no new source file)
   - [x] Documentation touched where behaviour changed (no README / `docs/` 
page documents this search)
   


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