This is an automated email from the ASF dual-hosted git repository.
lizhimins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git
The following commit(s) were added to refs/heads/master by this push:
new e33fa1a80 fix(instance): reject the blank name and endpoint the mock
create accepted (#6825)
e33fa1a80 is described below
commit e33fa1a80d79f0fa2bb129451a8dd0c387c39dba
Author: Apulupie <[email protected]>
AuthorDate: Fri Nov 27 12:43:22 2026 +0800
fix(instance): reject the blank name and endpoint the mock create accepted
(#6825)
---
web/src/services/instanceService.test.ts | 28 ++++++++++++++++++++++++++++
web/src/services/instanceService.ts | 18 ++++++++++++++++--
2 files changed, 44 insertions(+), 2 deletions(-)
diff --git a/web/src/services/instanceService.test.ts
b/web/src/services/instanceService.test.ts
index f8d6132ee..003dbf8c7 100644
--- a/web/src/services/instanceService.test.ts
+++ b/web/src/services/instanceService.test.ts
@@ -141,6 +141,34 @@ describe('instanceService mock instances', () => {
await expect(listInstances()).resolves.toEqual(before);
});
+ it('rejects the blank name and endpoint the API requires', async () => {
+ // The registration dialog's `required` rules do not reject whitespace, so
both fields can
+ // arrive blank; InstanceService.createApacheInstance answers 400 for them
(requireInstanceName
+ // -> "InstanceVO name is required", requireValidEndpoint -> "InstanceVO
endpoint is required").
+ const before = await listInstances();
+
+ await expect(
+ createInstance({ name: ' ', type: 'DIRECT', endpoint: '10.0.1.90:9876'
}),
+ ).rejects.toThrow('InstanceVO name is required');
+ await expect(
+ createInstance({ name: 'mock-blank-endpoint', type: 'DIRECT', endpoint:
' ' }),
+ ).rejects.toThrow('InstanceVO endpoint is required');
+
+ await expect(listInstances()).resolves.toEqual(before);
+ });
+
+ it('stores the trimmed name and endpoint the API stores', async () => {
+ const created = await createInstance({
+ name: ' mock-trimmed-create ',
+ type: 'DIRECT',
+ endpoint: ' 10.0.1.91:9876 ',
+ remark: 'trimmed',
+ });
+
+ expect(created.name).toBe('mock-trimmed-create');
+ expect(created.endpoint).toBe('10.0.1.91:9876');
+ });
+
it('returns provider-specific mock capabilities without sharing mutable
arrays', async () => {
const first = await getInstanceCapabilities('instance-direct-1');
expect(first.instanceId).toBe('instance-direct-1');
diff --git a/web/src/services/instanceService.ts
b/web/src/services/instanceService.ts
index 546c95f94..9cb61b3e8 100644
--- a/web/src/services/instanceService.ts
+++ b/web/src/services/instanceService.ts
@@ -111,6 +111,18 @@ export async function getInstanceCapabilities(instanceId:
string): Promise<Insta
};
}
+// InstanceService.createApacheInstance registers a manually created instance
through
+// requireInstanceName/requireValidEndpoint: neither field may be blank and
both are stored
+// trimmed. The registration dialog's `required` rules accept whitespace, so
the mock store has
+// to run the same checks instead of keeping the raw value.
+function requireMockInstanceText(value: string | undefined, field: 'name' |
'endpoint'): string {
+ const trimmed = (value ?? '').trim();
+ if (!trimmed) {
+ throw new Error(`InstanceVO ${field} is required`);
+ }
+ return trimmed;
+}
+
export async function createInstance(data: CreateInstanceRequest):
Promise<Instance> {
if (isMockMode()) {
const requestedName = data.name?.trim();
@@ -121,9 +133,11 @@ export async function createInstance(data:
CreateInstanceRequest): Promise<Insta
const instance: Instance = {
id: Date.now(),
...data,
- name: data.name || '',
+ name: cloudManaged ? data.name || '' :
requireMockInstanceText(data.name, 'name'),
type: cloudManaged ? 'CLOUD' : data.type || 'PROXY_CLUSTER',
- endpoint: data.endpoint || '',
+ endpoint: cloudManaged
+ ? data.endpoint || ''
+ : requireMockInstanceText(data.endpoint, 'endpoint'),
vendor: data.vendor || 'APACHE',
remark: data.remark || '',
topicCount: 0,