Copilot commented on code in PR #2966:
URL: https://github.com/apache/hugegraph/pull/2966#discussion_r2917501717


##########
hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/space/GraphSpaceAPI.java:
##########
@@ -76,6 +76,7 @@ public class GraphSpaceAPI extends API {
     @Produces(APPLICATION_JSON_WITH_CHARSET)
     public Object list(@Context GraphManager manager,
                        @Context SecurityContext sc) {
+        checkPdModeEnabled(manager);
         Set<String> spaces = manager.graphSpaces();
         return ImmutableMap.of("graphSpaces", spaces);

Review Comment:
   GraphSpaceAPI is intended to be disabled in standalone mode, but only some 
endpoints call checkPdModeEnabled(). The /graphspaces/profile endpoint 
(listProfile) is still reachable without the guard, so standalone mode can 
still access GraphSpace-related management data. Consider adding the same 
checkPdModeEnabled(manager) at the start of listProfile (and any other 
GraphSpaceAPI endpoints) to fully enforce the standalone restriction.



##########
hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ManagerApiStandaloneTest.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * 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.hugegraph.api;
+
+import java.util.Map;
+
+import org.apache.hugegraph.auth.HugePermission;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import jakarta.ws.rs.core.Response;
+
+/**
+ * Tests that ManagerAPI returns a friendly HTTP 400 error in standalone mode
+ * (i.e. when the server is started without PD / hstore backend).
+ * <p>
+ * This class intentionally does NOT have a class-level Assume guard so that
+ * the tests are actually executed in non-hstore CI runs.
+ */
+public class ManagerApiStandaloneTest extends BaseApiTest {
+
+    private static final String STANDALONE_ERROR =
+            "GraphSpace management is not supported in standalone mode";
+
+    private static String managerPath(String graphSpace) {
+        return String.format("graphspaces/%s/auth/managers", graphSpace);
+    }
+
+    @Before
+    public void skipForPdMode() {
+        assumeStandaloneMode();
+    }
+
+    @Test
+    public void testCreateManagerReturnsFriendlyError() {
+        String body = "{\"user\":\"admin\",\"type\":\"ADMIN\"}";
+        Response r = this.client().post(managerPath("DEFAULT"), body);
+        String content = assertResponseStatus(400, r);
+        Assert.assertTrue(content.contains(STANDALONE_ERROR));
+    }
+
+    @Test
+    public void testDeleteManagerReturnsFriendlyError() {
+        Response r = this.client().delete(managerPath("DEFAULT"),
+                                          Map.of("user", "admin",
+                                                 "type", 
HugePermission.ADMIN));
+        String content = assertResponseStatus(400, r);
+        Assert.assertTrue(content.contains(STANDALONE_ERROR));
+    }
+
+    @Test
+    public void testListManagerReturnsFriendlyError() {
+        Response r = this.client().get(managerPath("DEFAULT"),
+                                       Map.of("type", 
(Object)HugePermission.ADMIN));
+        String content = assertResponseStatus(400, r);
+        Assert.assertTrue(content.contains(STANDALONE_ERROR));

Review Comment:
   This test uses java.util.Map.of(...) for query params, but other API tests 
in this module consistently use Guava ImmutableMap.of(...). Using ImmutableMap 
here would avoid the extra (Object) casts needed for type inference and keep 
parameter-map construction consistent across the test suite.



##########
hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/core/GraphManager.java:
##########
@@ -280,6 +280,10 @@ private boolean usePD() {
         return this.PDExist;
     }
 
+    public boolean isUsePD() {
+        return this.PDExist;

Review Comment:
   GraphManager already has a private usePD() helper used internally; adding a 
separate public isUsePD() with the same implementation duplicates the source of 
truth and risks divergence over time. Consider either making usePD() public (or 
package-private) and using it consistently, or having isUsePD() delegate to 
usePD().
   ```suggestion
           return this.usePD();
   ```



##########
hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/GraphSpaceApiStandaloneTest.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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.hugegraph.api;
+
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import jakarta.ws.rs.core.Response;
+
+/**
+ * Tests that GraphSpaceAPI returns a friendly HTTP 400 error in standalone
+ * mode (i.e. when the server is started without PD / hstore backend).
+ * <p>
+ * This class intentionally does NOT have a class-level Assume guard so that
+ * the tests are actually executed in non-hstore CI runs.
+ */
+public class GraphSpaceApiStandaloneTest extends BaseApiTest {
+
+    private static final String PATH = "graphspaces";
+    private static final String STANDALONE_ERROR =
+            "GraphSpace management is not supported in standalone mode";
+
+    @Before
+    public void skipForPdMode() {
+        assumeStandaloneMode();
+    }
+
+    @Test
+    public void testListReturnsFriendlyError() {
+        Response r = this.client().get(PATH);
+        String content = assertResponseStatus(400, r);
+        Assert.assertTrue(content.contains(STANDALONE_ERROR));
+    }
+
+    @Test
+    public void testGetReturnsFriendlyError() {
+        Response r = this.client().get(PATH, "DEFAULT");
+        String content = assertResponseStatus(400, r);
+        Assert.assertTrue(content.contains(STANDALONE_ERROR));
+    }
+
+    @Test
+    public void testCreateReturnsFriendlyError() {
+        String body = "{\"name\":\"test_standalone\",\"nickname\":\"test\","
+                      + "\"description\":\"test\",\"cpu_limit\":10,"
+                      + "\"memory_limit\":10,\"storage_limit\":10,"
+                      + "\"max_graph_number\":10,\"max_role_number\":10,"
+                      + "\"auth\":false,\"configs\":{}}";
+        Response r = this.client().post(PATH, body);
+        String content = assertResponseStatus(400, r);
+        Assert.assertTrue(content.contains(STANDALONE_ERROR));
+    }
+
+    @Test
+    public void testManageReturnsFriendlyError() {
+        String body = 
"{\"action\":\"update\",\"update\":{\"name\":\"DEFAULT\"}}";
+        Response r = this.client().put(PATH, "DEFAULT", body, Map.of());
+        String content = assertResponseStatus(400, r);

Review Comment:
   This test uses Map.of() for the (empty) query-params map, while other API 
tests in this module use ImmutableMap.of(). Consider switching to 
ImmutableMap.of() for consistency with the rest of the test suite.



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