Frun1na opened a new pull request, #6786:
URL: https://github.com/apache/rocketmq-dashboard/pull/6786
### Which Issue(s) This PR Fixes
- Fixes #6785
### Brief Description
In mock-data mode the cluster page's test-connection form accepted a
whitespace-only NameServer address and the mock branch answered a successful
probe for it: `testClusterConnection(' ')` trimmed to `''`, then returned
`connected: true` with an empty `namesrvAddr` and the demo broker list, so the
page toasted a success and rendered a probe result
(`web/src/pages/cluster/index.tsx:507-510`). The endpoint refuses that request
- `TestConnectionDTO` declares `@NotBlank namesrvAddr` and answers 400
`namesrvAddr is required` - and the form's `required` rule does not catch it
because the Ant validator rejects only the empty string, not whitespace.
The mock branch now rejects a blank address with the endpoint's own message
before probing, which is the check its sibling
`connectionsService.listConnections` already performs for the same parameter.
Non-blank addresses keep answering the demo probe unchanged; the endpoint path
is untouched.
### How Did You Test This Change?
```
$ cd web && npx vitest run src/services/clusterService.test.ts
✓ src/services/clusterService.test.ts (9 tests) 12ms
Test Files 1 passed (1)
Tests 9 passed (9)
```
The mapped checks for the two changed web files:
```
$ npx eslint src/services/clusterService.test.ts
src/services/clusterService.ts # clean
$ npx prettier --check src/services/clusterService.test.ts
src/services/clusterService.ts
Checking formatting...
All matched files use Prettier code style!
$ npx vitest related --run src/services/clusterService.test.ts
src/services/clusterService.ts
Test Files 8 passed (8) # includes the cluster page suite
Tests 135 passed (135)
$ npx tsc -b # clean
```
The new test fails without the fix (only the mock file reverted, test kept):
```
$ git checkout -- web/src/services/clusterService.ts
$ npx vitest run src/services/clusterService.test.ts
FAIL src/services/clusterService.test.ts > clusterService mock clusters >
requires the NameServer address the endpoint requires
AssertionError: promise resolved "{ connected: true, …(6) }" instead of
rejecting
- Expected
+ Received
- Error {
- "message": "rejected promise",
+ {
+ "brokerCount": 8,
+ "brokerNames": [
+ "rocketmq-prod-0",
...
Test Files 1 failed (1)
Tests 1 failed | 8 passed (9)
```
The assertion is that a blank address rejects and a non-blank one still
resolves, so it goes red exactly while the mock answers a probe for input the
endpoint refuses; restoring the guard turns it green again.
### 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`
- [ ] New UI text has both Chinese and English entries under `web/src/i18n/`
- [ ] Architecture constraints stay green (`mvn test` runs the ArchUnit
checks)
- [ ] New source files carry the ASF license header
- [ ] Documentation touched where behaviour changed (README / `docs/` /
in-app help)
--
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]