Copilot commented on code in PR #875:
URL: 
https://github.com/apache/rocketmq-dashboard/pull/875#discussion_r3705228720


##########
server/src/main/java/org/apache/rocketmq/studio/instance/acl/CreateAclUserDTO.java:
##########
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.rocketmq.studio.instance.acl;
+
+import jakarta.validation.constraints.NotBlank;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class CreateAclUserDTO {
+    @NotBlank(message = "username is required")
+    private String username;
+    private boolean admin;
+    private List<String> clusters;

Review Comment:
   Switching the request type from `AclUserVO` to `CreateAclUserDTO` can change 
how unknown JSON properties are handled (e.g., clients sending extra fields 
like `accessKey`/`secretKey` that used to bind may now cause a 400 depending on 
the Jackson configuration). If backward compatibility is desired, consider 
explicitly ignoring unknown properties on `CreateAclUserDTO` (e.g., via a 
Jackson annotation) so existing clients don’t break.



##########
server/src/test/java/org/apache/rocketmq/studio/instance/acl/AclControllerTest.java:
##########
@@ -221,11 +223,39 @@ void createUserShouldReturnGeneratedCredentials() throws 
Exception {
 
         mockMvc.perform(post("/api/acl/users/create")
                         .contentType(MediaType.APPLICATION_JSON)
-                        .content("{\"username\":\"new-user\"}"))
+                        .content("""
+                                {
+                                  "username": "new-user",
+                                  "admin": true,
+                                  "clusters": ["cluster-a"]
+                                }
+                                """))
                 .andExpect(status().isOk())
                 .andExpect(jsonPath("$.code").value(200))
                 
.andExpect(jsonPath("$.data.accessKey").value("access-key-123456"))
                 
.andExpect(jsonPath("$.data.secretKey").value("secret-key-987654"));
+
+        ArgumentCaptor<AclUserVO> captor = 
ArgumentCaptor.forClass(AclUserVO.class);
+        verify(aclService).createUser(captor.capture());
+        assertThat(captor.getValue().getUsername()).isEqualTo("new-user");
+        assertThat(captor.getValue().isAdmin()).isTrue();
+        
assertThat(captor.getValue().getClusters()).containsExactly("cluster-a");
+    }
+
+    @Test
+    void createUserShouldRejectMissingUsername() throws Exception {
+        mockMvc.perform(post("/api/acl/users/create")
+                        .contentType(MediaType.APPLICATION_JSON)
+                        .content("""
+                                {
+                                  "admin": false
+                                }
+                                """))
+                .andExpect(status().isBadRequest())
+                .andExpect(jsonPath("$.code").value(400))
+                .andExpect(jsonPath("$.message").value("username is 
required"));

Review Comment:
   `@NotBlank` rejects both missing and blank/whitespace values, but the added 
test only covers the missing-field case. Add a regression test for `"username": 
""` (and/or whitespace) to ensure the blank-path continues to be rejected with 
the expected error shape/message.



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