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 151cbc9e6 fix(acl): reject the blank ACL fields the mock store 
accepted (#6820)
151cbc9e6 is described below

commit 151cbc9e6c3504622a0f48c40661086c1f6b56f3
Author: Apulupie <[email protected]>
AuthorDate: Fri Nov 27 12:44:01 2026 +0800

    fix(acl): reject the blank ACL fields the mock store accepted (#6820)
---
 web/src/services/aclService.test.ts | 27 +++++++++++++++++++++++++++
 web/src/services/aclService.ts      | 14 ++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/web/src/services/aclService.test.ts 
b/web/src/services/aclService.test.ts
index 5a40e1487..61aa2f67f 100644
--- a/web/src/services/aclService.test.ts
+++ b/web/src/services/aclService.test.ts
@@ -156,6 +156,33 @@ describe('ACL service mock data', () => {
     );
   });
 
+  it('rejects the blank ACL fields the backend requires text for', async () => 
{
+    // AclService guards every ACL write with StringUtils.hasText and answers 
400; the ACL
+    // dialogs' `required` rules accept a whitespace-only value, so the mock 
used to store the
+    // blank field as if the write had succeeded.
+    const usersBefore = await listAclUsers();
+
+    await expect(createAclUser({ username: '   ' })).rejects.toThrow('ACL 
username is required');
+    await expect(createAclRule({ principal: '   ', resource: 'topic-a' 
})).rejects.toThrow(
+      'ACL principal is required',
+    );
+    await expect(createAclRule({ principal: 'user-admin', resource: '  ' 
})).rejects.toThrow(
+      'ACL resource is required',
+    );
+    await expect(
+      createAndUpdatePlainAccessConfig({ accessKey: '', secretKey: 'svc-blank' 
}),
+    ).rejects.toThrow('accessKey is required');
+
+    await expect(listAclUsers()).resolves.toEqual(usersBefore);
+  });
+
+  it('keeps accepting an identity whose text is not blank', async () => {
+    // The backend checks hasText, it does not trim: only a value that is 
blank after trimming
+    // is a 400, so a padded username is still stored as sent.
+    const created = await createAclUser({ username: '  user-padded  ' });
+    expect(created.username).toBe('  user-padded  ');
+  });
+
   it('rejects deletion of missing ACL records', async () => {
     const rulesBefore = await listAclRules();
     const usersBefore = await listAclUsers();
diff --git a/web/src/services/aclService.ts b/web/src/services/aclService.ts
index 7bb99eff3..bdb59f613 100644
--- a/web/src/services/aclService.ts
+++ b/web/src/services/aclService.ts
@@ -58,6 +58,16 @@ function copyAclUser(user: AclUser): AclUser {
   };
 }
 
+// AclService guards the ACL write fields with StringUtils.hasText and answers 
400; a
+// whitespace-only value must not reach the mock store either (the dialogs' 
`required` rules
+// accept it). Only a value that is blank after trimming is rejected; what is 
stored is the
+// value as sent, like the backend.
+function requireAclText(value: string | null | undefined, field: string): void 
{
+  if (!(value ?? '').trim()) {
+    throw new Error(`${field} is required`);
+  }
+}
+
 export async function listAclRules(params?: AclRuleQuery): 
Promise<PageResult<AclRule>> {
   if (isMockMode()) {
     let result = [...aclRulesState];
@@ -145,6 +155,8 @@ export async function createAclRule(
   data: Partial<AclRule> & { instanceId?: string },
 ): Promise<AclRule> {
   if (isMockMode()) {
+    requireAclText(data.principal, 'ACL principal');
+    requireAclText(data.resource, 'ACL resource');
     const rule: AclRule = {
       id: Date.now(),
       principal: '',
@@ -194,6 +206,7 @@ export async function createAclUser(
   data: Partial<AclUser> & { instanceId?: string },
 ): Promise<AclUser> {
   if (isMockMode()) {
+    requireAclText(data.username, 'ACL username');
     const user: AclUser = {
       id: Date.now(),
       username: '',
@@ -270,6 +283,7 @@ export async function createAndUpdatePlainAccessConfig(
 ): Promise<PlainAccessConfig> {
   if (isMockMode()) {
     const accessKey = (data.accessKey ?? '').trim();
+    requireAclText(accessKey, 'accessKey');
     const providedSecret = (data.secretKey ?? '').trim();
     const existing = aclPlainAccessState.find((a) => a.accessKey === 
accessKey);
     if (!providedSecret && !existing) {

Reply via email to