This is an automated email from the ASF dual-hosted git repository.
jin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hugegraph.git
The following commit(s) were added to refs/heads/master by this push:
new 5f91d8b5c refactor(server): disable GraphSpaceAPI and ManagerAPI in
standalone mode (#2966)
5f91d8b5c is described below
commit 5f91d8b5c6be1dffc3e6dd8fd84ae561f7fb6b53
Author: contrueCT <[email protected]>
AuthorDate: Fri Mar 20 16:27:15 2026 +0800
refactor(server): disable GraphSpaceAPI and ManagerAPI in standalone mode
(#2966)
* feat(api): disable GraphSpaceAPI and ManagerAPI in standalone mode
- Add public isUsePD() accessor to GraphManager to expose PD status
- Add checkPdModeEnabled() helper in API base class
- Call checkPdModeEnabled() in all public methods of GraphSpaceAPI
(list/get/create/manage/delete)
- Call checkPdModeEnabled() in all public methods of ManagerAPI
(createManager/delete/list/checkRole/getRolesInGs)
- Returns HTTP 400 with message 'GraphSpace management is not supported in
standalone mode'
- Add standalone-mode rejection tests in GraphSpaceApiTest and
ManagerApiTest
---------
Co-authored-by: Copilot Autofix powered by AI
<[email protected]>
Co-authored-by: imbajin <[email protected]>
---
.../main/java/org/apache/hugegraph/api/API.java | 16 +++
.../org/apache/hugegraph/api/auth/ManagerAPI.java | 7 +-
.../apache/hugegraph/api/space/GraphSpaceAPI.java | 8 +-
.../org/apache/hugegraph/core/GraphManager.java | 14 +--
.../org/apache/hugegraph/api/ApiTestSuite.java | 2 +
.../java/org/apache/hugegraph/api/BaseApiTest.java | 45 +++++---
.../hugegraph/api/GraphSpaceApiStandaloneTest.java | 91 +++++++++++++++
.../apache/hugegraph/api/GraphSpaceApiTest.java | 2 +-
.../hugegraph/api/ManagerApiStandaloneTest.java | 128 +++++++++++++++++++++
.../org/apache/hugegraph/api/ManagerApiTest.java | 48 ++++----
10 files changed, 312 insertions(+), 49 deletions(-)
diff --git
a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/API.java
b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/API.java
index c47686471..3220cf6b0 100644
---
a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/API.java
+++
b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/API.java
@@ -86,6 +86,8 @@ public class API {
MetricsUtil.registerMeter(API.class, "expected-error");
private static final Meter unknownErrorMeter =
MetricsUtil.registerMeter(API.class, "unknown-error");
+ private static final String STANDALONE_ERROR =
+ "GraphSpace management is not supported in standalone mode";
public static HugeGraph graph(GraphManager manager, String graphSpace,
String graph) {
@@ -241,6 +243,20 @@ public class API {
}
}
+ /**
+ * Ensures the graph manager is available and PD mode is enabled.
+ *
+ * @param manager the graph manager of current request
+ * @throws IllegalArgumentException if the graph manager is null
+ * @throws HugeException if PD mode is disabled
+ */
+ protected static void ensurePdModeEnabled(GraphManager manager) {
+ E.checkArgumentNotNull(manager, "Graph manager can't be null");
+ if (!manager.isPDEnabled()) {
+ throw new HugeException(STANDALONE_ERROR);
+ }
+ }
+
public static boolean hasAdminPerm(GraphManager manager, String user) {
return manager.authManager().isAdminManager(user);
}
diff --git
a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/auth/ManagerAPI.java
b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/auth/ManagerAPI.java
index 81da1b058..071e4b8a6 100644
---
a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/auth/ManagerAPI.java
+++
b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/auth/ManagerAPI.java
@@ -68,6 +68,7 @@ public class ManagerAPI extends API {
@PathParam("graphspace") String graphSpace,
JsonManager jsonManager) {
LOG.debug("Create manager: {}", jsonManager);
+ ensurePdModeEnabled(manager);
String user = jsonManager.user;
HugePermission type = jsonManager.type;
// graphSpace now comes from @PathParam instead of JsonManager
@@ -123,6 +124,7 @@ public class ManagerAPI extends API {
@Parameter(description = "The manager type: SPACE,
SPACE_MEMBER, or ADMIN")
@QueryParam("type") HugePermission type) {
LOG.debug("Delete graph manager: {} {} {}", user, type, graphSpace);
+ ensurePdModeEnabled(manager);
E.checkArgument(!"admin".equals(user) ||
type != HugePermission.ADMIN,
"User 'admin' can't be removed from ADMIN");
@@ -168,7 +170,7 @@ public class ManagerAPI extends API {
@Parameter(description = "The manager type: SPACE,
SPACE_MEMBER or ADMIN")
@QueryParam("type") HugePermission type) {
LOG.debug("list graph manager: {} {}", type, graphSpace);
-
+ ensurePdModeEnabled(manager);
AuthManager authManager = manager.authManager();
validType(type);
List<String> adminManagers;
@@ -201,7 +203,7 @@ public class ManagerAPI extends API {
"SPACE, SPACE_MEMBER, or
ADMIN")
@QueryParam("type") HugePermission type) {
LOG.debug("check if current user is graph manager: {} {}", type,
graphSpace);
-
+ ensurePdModeEnabled(manager);
validType(type);
AuthManager authManager = manager.authManager();
String user = HugeGraphAuthProxy.username();
@@ -235,6 +237,7 @@ public class ManagerAPI extends API {
@Parameter(description = "The user name")
@QueryParam("user")
String user) {
LOG.debug("get user [{}]'s role in graph space [{}]", user,
graphSpace);
+ ensurePdModeEnabled(manager);
AuthManager authManager = manager.authManager();
List<HugePermission> result = new ArrayList<>();
validGraphSpace(manager, graphSpace);
diff --git
a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/space/GraphSpaceAPI.java
b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/space/GraphSpaceAPI.java
index 85894cacd..35bc40aed 100644
---
a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/space/GraphSpaceAPI.java
+++
b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/space/GraphSpaceAPI.java
@@ -78,6 +78,7 @@ public class GraphSpaceAPI extends API {
@Produces(APPLICATION_JSON_WITH_CHARSET)
public Object list(@Context GraphManager manager,
@Context SecurityContext sc) {
+ ensurePdModeEnabled(manager);
Set<String> spaces = manager.graphSpaces();
return ImmutableMap.of("graphSpaces", spaces);
}
@@ -89,6 +90,7 @@ public class GraphSpaceAPI extends API {
public Object get(@Context GraphManager manager,
@Parameter(description = "The name of the graph space")
@PathParam("graphspace") String graphSpace) {
+ ensurePdModeEnabled(manager);
manager.getSpaceStorage(graphSpace);
GraphSpace gs = space(manager, graphSpace);
@@ -111,6 +113,7 @@ public class GraphSpaceAPI extends API {
"name or nickname
prefix")
@QueryParam("prefix") String prefix,
@Context SecurityContext sc) {
+ ensurePdModeEnabled(manager);
Set<String> spaces = manager.graphSpaces();
List<Map<String, Object>> spaceList = new ArrayList<>();
List<Map<String, Object>> result = new ArrayList<>();
@@ -160,7 +163,7 @@ public class GraphSpaceAPI extends API {
@RolesAllowed({"admin"})
public String create(@Context GraphManager manager,
JsonGraphSpace jsonGraphSpace) {
-
+ ensurePdModeEnabled(manager);
jsonGraphSpace.checkCreate(false);
String creator = HugeGraphAuthProxy.username();
@@ -192,7 +195,7 @@ public class GraphSpaceAPI extends API {
@Parameter(description = "The name of
the graph space")
@PathParam("name") String name,
Map<String, Object> actionMap) {
-
+ ensurePdModeEnabled(manager);
E.checkArgument(actionMap != null && actionMap.size() == 2 &&
actionMap.containsKey(GRAPH_SPACE_ACTION),
"Invalid request body '%s'", actionMap);
@@ -322,6 +325,7 @@ public class GraphSpaceAPI extends API {
public void delete(@Context GraphManager manager,
@Parameter(description = "The name of the graph space")
@PathParam("name") String name) {
+ ensurePdModeEnabled(manager);
manager.dropGraphSpace(name);
}
diff --git
a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/core/GraphManager.java
b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/core/GraphManager.java
index eda050e16..770e75cc7 100644
---
a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/core/GraphManager.java
+++
b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/core/GraphManager.java
@@ -276,7 +276,7 @@ public final class GraphManager {
.replace("_", "-").toLowerCase();
}
- private boolean usePD() {
+ public boolean isPDEnabled() {
return this.PDExist;
}
@@ -1227,7 +1227,7 @@ public final class GraphManager {
public HugeGraph createGraph(String graphSpace, String name, String
creator,
Map<String, Object> configs, boolean init) {
- if (!usePD()) {
+ if (!isPDEnabled()) {
// Extract nickname from configs
String nickname;
if (configs.get("nickname") != null) {
@@ -1937,7 +1937,7 @@ public final class GraphManager {
public HugeGraph graph(String graphSpace, String name) {
String key = String.join(DELIMITER, graphSpace, name);
Graph graph = this.graphs.get(key);
- if (graph == null && usePD()) {
+ if (graph == null && isPDEnabled()) {
Map<String, Map<String, Object>> configs =
this.metaManager.graphConfigs(graphSpace);
// If current server registered graph space is not DEFAULT, only
load graph creation
@@ -1981,7 +1981,7 @@ public final class GraphManager {
}
public void dropGraph(String graphSpace, String name, boolean clear) {
- if (!usePD()) {
+ if (!isPDEnabled()) {
dropGraphLocal(name);
return;
}
@@ -2086,7 +2086,7 @@ public final class GraphManager {
public Set<String> graphs(String graphSpace) {
Set<String> graphs = new HashSet<>();
- if (!usePD()) {
+ if (!isPDEnabled()) {
for (String key : this.graphs.keySet()) {
String[] parts = key.split(DELIMITER);
if (parts[0].equals(graphSpace)) {
@@ -2103,7 +2103,7 @@ public final class GraphManager {
}
public GraphSpace graphSpace(String name) {
- if (!usePD()) {
+ if (!isPDEnabled()) {
return new GraphSpace("DEFAULT");
}
GraphSpace space = this.graphSpaces.get(name);
@@ -2152,7 +2152,7 @@ public final class GraphManager {
public void graphReadMode(String graphSpace, String graphName,
GraphReadMode readMode) {
- if (!usePD()) {
+ if (!isPDEnabled()) {
HugeGraph g = this.graph(spaceGraphName(graphSpace, graphName));
g.readMode(readMode);
return;
diff --git
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java
index 07eb608ad..1fe8fc45f 100644
---
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java
+++
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java
@@ -42,6 +42,8 @@ import org.junit.runners.Suite;
CypherApiTest.class,
ArthasApiTest.class,
GraphSpaceApiTest.class,
+ GraphSpaceApiStandaloneTest.class,
+ ManagerApiStandaloneTest.class,
})
public class ApiTestSuite {
diff --git
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/BaseApiTest.java
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/BaseApiTest.java
index f88c134ab..a6f84de33 100644
---
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/BaseApiTest.java
+++
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/BaseApiTest.java
@@ -39,6 +39,7 @@ import org.glassfish.jersey.message.GZipEncoder;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
+import org.junit.Assume;
import org.junit.BeforeClass;
import com.fasterxml.jackson.databind.JavaType;
@@ -61,9 +62,9 @@ public class BaseApiTest {
protected static final String BASE_URL = "http://127.0.0.1:8080";
private static final String GRAPH = "hugegraph";
private static final String GRAPHSPACE = "DEFAULT";
- private static final String USERNAME = "admin";
protected static final String URL_PREFIX = "graphspaces/" + GRAPHSPACE +
"/graphs/" + GRAPH;
protected static final String TRAVERSERS_API = URL_PREFIX + "/traversers";
+ private static final String USERNAME = "admin";
private static final String PASSWORD = "pa";
private static final int NO_LIMIT = -1;
private static final String SCHEMA_PKS = "/schema/propertykeys";
@@ -73,6 +74,8 @@ public class BaseApiTest {
private static final String GRAPH_VERTEX = "/graph/vertices";
private static final String GRAPH_EDGE = "/graph/edges";
private static final String BATCH = "/batch";
+ static final String STANDALONE_ERROR =
+ "GraphSpace management is not supported in standalone mode";
private static final String ROCKSDB_CONFIG_TEMPLATE =
"{ \"gremlin.graph\": \"org.apache.hugegraph.HugeFactory\"," +
@@ -82,10 +85,8 @@ public class BaseApiTest {
"\"rocksdb.wal_path\": \"rocksdbtest-data-%s\"," +
"\"search.text_analyzer\": \"jieba\"," +
"\"search.text_analyzer_mode\": \"INDEX\" }";
-
- protected static RestClient client;
-
private static final ObjectMapper MAPPER = new ObjectMapper();
+ protected static RestClient client;
@BeforeClass
public static void init() {
@@ -99,19 +100,10 @@ public class BaseApiTest {
client = null;
}
- @After
- public void teardown() throws Exception {
- BaseApiTest.clearData();
- }
-
public static String baseUrl() {
return BASE_URL;
}
- public RestClient client() {
- return client;
- }
-
public static RestClient newClient() {
return new RestClient(BASE_URL);
}
@@ -193,7 +185,8 @@ public class BaseApiTest {
Assert.fail(String.format("Failed to wait for task %s " +
"due to timeout", task));
}
- } while (!expectedStatus.contains(status));
+ }
+ while (!expectedStatus.contains(status));
}
protected static void initVertexLabel() {
@@ -748,6 +741,30 @@ public class BaseApiTest {
return analystClient;
}
+ /**
+ * Skips the current test when the server backend is not known to be in
+ * standalone mode. Treats both {@code "hstore"} and {@code null}
+ * (i.e. the backend property is not provided/unknown) as PD/distributed
+ * mode and skips the test for safety.
+ * Call this from a {@code @Before} method in standalone-only test classes.
+ */
+ public static void assumeStandaloneMode() {
+ String backend = System.getProperty("backend");
+ boolean isPdMode = backend == null || "hstore".equals(backend);
+ Assume.assumeFalse(
+ "Skip when backend is hstore (PD/distributed) or not
specified",
+ isPdMode);
+ }
+
+ @After
+ public void teardown() throws Exception {
+ BaseApiTest.clearData();
+ }
+
+ public RestClient client() {
+ return client;
+ }
+
public static class RestClient {
private final Client client;
diff --git
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/GraphSpaceApiStandaloneTest.java
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/GraphSpaceApiStandaloneTest.java
new file mode 100644
index 000000000..21e3975a2
--- /dev/null
+++
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/GraphSpaceApiStandaloneTest.java
@@ -0,0 +1,91 @@
+/*
+ * 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 com.google.common.collect.ImmutableMap;
+
+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";
+
+ @Before
+ public void skipForPdMode() {
+ assumeStandaloneMode();
+ }
+
+ @Test
+ public void testProfileReturnsFriendlyError() {
+ Response r = this.client().get(PATH + "/profile");
+ String content = assertResponseStatus(400, r);
+ Assert.assertTrue(content.contains(STANDALONE_ERROR));
+ }
+
+ @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,
ImmutableMap.of());
+ String content = assertResponseStatus(400, r);
+ Assert.assertTrue(content.contains(STANDALONE_ERROR));
+ }
+
+ @Test
+ public void testDeleteReturnsFriendlyError() {
+ Response r = this.client().delete(PATH, "nonexistent");
+ String content = assertResponseStatus(400, r);
+ Assert.assertTrue(content.contains(STANDALONE_ERROR));
+ }
+}
diff --git
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/GraphSpaceApiTest.java
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/GraphSpaceApiTest.java
index 01782e7e0..1c3eb7799 100644
---
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/GraphSpaceApiTest.java
+++
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/GraphSpaceApiTest.java
@@ -42,7 +42,7 @@ public class GraphSpaceApiTest extends BaseApiTest {
Response r = this.client().get(PATH);
String result = r.readEntity(String.class);
Map<String, Object> resultMap = JsonUtil.fromJson(result, Map.class);
- List<String> spaces = (List<String>) resultMap.get("graphSpaces");
+ List<String> spaces = (List<String>)resultMap.get("graphSpaces");
for (String space : spaces) {
if (!"DEFAULT".equals(space)) {
this.client().delete(PATH, space);
diff --git
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ManagerApiStandaloneTest.java
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ManagerApiStandaloneTest.java
new file mode 100644
index 000000000..4c0e17815
--- /dev/null
+++
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ManagerApiStandaloneTest.java
@@ -0,0 +1,128 @@
+/*
+ * 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 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));
+ }
+
+ @Test
+ public void testCheckRoleReturnsFriendlyError() {
+ Response r = this.client().get(managerPath("DEFAULT") + "/check",
+ Map.of("type",
(Object)HugePermission.ADMIN));
+ String content = assertResponseStatus(400, r);
+ Assert.assertTrue(content.contains(STANDALONE_ERROR));
+ }
+
+ @Test
+ public void testGetRolesInGsReturnsFriendlyError() {
+ Response r = this.client().get(managerPath("DEFAULT") + "/role",
+ Map.of("user", (Object)"admin"));
+ String content = assertResponseStatus(400, r);
+ Assert.assertTrue(content.contains(STANDALONE_ERROR));
+ }
+
+ @Test
+ public void testCreateSpaceManagerReturnsFriendlyError() {
+ String body = "{\"user\":\"admin\",\"type\":\"SPACE\"}";
+ Response r = this.client().post(managerPath("nonexistent"), body);
+ String content = assertResponseStatus(400, r);
+ Assert.assertTrue(content.contains(STANDALONE_ERROR));
+ }
+
+ @Test
+ public void testDeleteSpaceManagerReturnsFriendlyError() {
+ Response r = this.client().delete(managerPath("nonexistent"),
+ Map.of("user", "admin",
+ "type",
HugePermission.SPACE));
+ String content = assertResponseStatus(400, r);
+ Assert.assertTrue(content.contains(STANDALONE_ERROR));
+ }
+
+ @Test
+ public void testListSpaceManagerReturnsFriendlyError() {
+ Response r = this.client().get(managerPath("nonexistent"),
+ Map.of("type", (Object)
HugePermission.SPACE));
+ String content = assertResponseStatus(400, r);
+ Assert.assertTrue(content.contains(STANDALONE_ERROR));
+ }
+
+ @Test
+ public void testCheckRoleSpaceReturnsFriendlyError() {
+ Response r = this.client().get(managerPath("nonexistent") + "/check",
+ Map.of("type", (Object)
HugePermission.SPACE));
+ String content = assertResponseStatus(400, r);
+ Assert.assertTrue(content.contains(STANDALONE_ERROR));
+ }
+
+ @Test
+ public void testGetRolesInGsNonExistentReturnsFriendlyError() {
+ Response r = this.client().get(managerPath("nonexistent") + "/role",
+ Map.of("user", (Object) "admin"));
+ String content = assertResponseStatus(400, r);
+ Assert.assertTrue(content.contains(STANDALONE_ERROR));
+ }
+}
diff --git
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ManagerApiTest.java
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ManagerApiTest.java
index afae0c94a..095361f43 100644
---
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ManagerApiTest.java
+++
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ManagerApiTest.java
@@ -68,13 +68,13 @@ public class ManagerApiTest extends BaseApiTest {
Response r1 = this.client().get("/graphspaces");
String result = r1.readEntity(String.class);
Map<String, Object> resultMap = JsonUtil.fromJson(result, Map.class);
- List<String> spaces = (List<String>) resultMap.get("graphSpaces");
+ List<String> spaces = (List<String>)resultMap.get("graphSpaces");
for (String space : spaces) {
Response r = this.client().get(managerPath(space),
ImmutableMap.of("type",
HugePermission.SPACE_MEMBER));
result = r.readEntity(String.class);
resultMap = JsonUtil.fromJson(result, Map.class);
- List<String> spaceAdmins = (List<String>) resultMap.get("admins");
+ List<String> spaceAdmins = (List<String>)resultMap.get("admins");
for (String user : spaceAdmins) {
this.client().delete(managerPath(space),
ImmutableMap.of("user", user,
@@ -89,7 +89,7 @@ public class ManagerApiTest extends BaseApiTest {
ImmutableMap.of("type",
HugePermission.ADMIN));
String result = r.readEntity(String.class);
Map<String, Object> resultMap = JsonUtil.fromJson(result, Map.class);
- List<String> admins = (List<String>) resultMap.get("admins");
+ List<String> admins = (List<String>)resultMap.get("admins");
for (String user : admins) {
if ("admin".equals(user)) {
continue;
@@ -103,13 +103,13 @@ public class ManagerApiTest extends BaseApiTest {
Response r1 = this.client().get("/graphspaces");
String result = r1.readEntity(String.class);
Map<String, Object> resultMap = JsonUtil.fromJson(result, Map.class);
- List<String> spaces = (List<String>) resultMap.get("graphSpaces");
+ List<String> spaces = (List<String>)resultMap.get("graphSpaces");
for (String space : spaces) {
Response r = this.client().get(managerPath(space),
ImmutableMap.of("type",
HugePermission.SPACE));
result = r.readEntity(String.class);
resultMap = JsonUtil.fromJson(result, Map.class);
- List<String> spaceAdmins = (List<String>) resultMap.get("admins");
+ List<String> spaceAdmins = (List<String>)resultMap.get("admins");
for (String user : spaceAdmins) {
this.client().delete(managerPath(space),
ImmutableMap.of("user", user,
@@ -124,7 +124,7 @@ public class ManagerApiTest extends BaseApiTest {
if (user.get("user_name").equals("admin")) {
continue;
}
- this.client().delete(USER_PATH, (String) user.get("id"));
+ this.client().delete(USER_PATH, (String)user.get("id"));
}
}
@@ -153,10 +153,8 @@ public class ManagerApiTest extends BaseApiTest {
client().get(managerPath("testspace") + "/check",
ImmutableMap.of("type", HugePermission.SPACE_MEMBER));
- RestClient member1Client =
- new RestClient(baseUrl(), "test_member1", "password1");
- RestClient member2Client =
- new RestClient(baseUrl(), "test_member2", "password1");
+ RestClient member1Client = new RestClient(baseUrl(), "test_member1",
"password1");
+ RestClient member2Client = new RestClient(baseUrl(), "test_member2",
"password1");
String res1 = member1Client.get(managerPath("testspace") + "/check",
ImmutableMap.of("type",
@@ -214,10 +212,8 @@ public class ManagerApiTest extends BaseApiTest {
r = client().post(managerPath("testspace"), spaceManager);
assertResponseStatus(201, r);
- RestClient spaceMemberClient =
- new RestClient(baseUrl(), "perm_member", "password1");
- RestClient spaceManagerClient =
- new RestClient(baseUrl(), "perm_manager", "password1");
+ RestClient spaceMemberClient = new RestClient(baseUrl(),
"perm_member", "password1");
+ RestClient spaceManagerClient = new RestClient(baseUrl(),
"perm_manager", "password1");
String userPath = "graphspaces/testspace/graphs/testgraph/auth/users";
String user = "{\"user_name\":\"" + "test_perm_user" +
@@ -326,15 +322,17 @@ public class ManagerApiTest extends BaseApiTest {
Response r = this.client().get(userPath, ImmutableMap.of("limit",
NO_LIMIT));
String result = assertResponseStatus(200, r);
- Map<String, List<Map<String, Object>>> resultMap =
- JsonUtil.fromJson(result, new TypeReference<Map<String,
- List<Map<String, Object>>>>() {
- });
+ TypeReference<Map<String, List<Map<String, Object>>>> typeRef =
+ new TypeReference<Map<String, List<Map<String, Object>>>>() {
+ };
+ Map<String, List<Map<String, Object>>> resultMap =
JsonUtil.fromJson(result,
+
typeRef);
return resultMap.get("users");
}
/**
- * Test space manager boundary: SpaceA's manager cannot operate SpaceB's
resources
+ * Test space manager boundary: SpaceA's manager cannot operate SpaceB's
+ * resources
*/
@Test
public void testSpaceManagerBoundary() {
@@ -491,9 +489,11 @@ public class ManagerApiTest extends BaseApiTest {
response.contains("no permission"));
// Verify: manageralpha CAN promote usertest to be spacealpha's member
- // But this will fail because manageralpha doesn't have permission to
read user from
+ // But this will fail because manageralpha doesn't have permission to
read user
+ // from
// DEFAULT space
- // This is expected behavior - space managers should only manage users
already in their
+ // This is expected behavior - space managers should only manage users
already
+ // in their
// space
// or admin should assign users to spaces first
@@ -640,7 +640,8 @@ public class ManagerApiTest extends BaseApiTest {
String vertexJson =
"{\"label\":\"person\",\"properties\":{\"age\":30}}";
r = managerClient.post(vertexPath, vertexJson);
String response2 = r.readEntity(String.class);
- // Note: Vertex write might require specific permissions depending on
configuration
+ // Note: Vertex write might require specific permissions depending on
+ // configuration
// We check if it's either allowed (201) or forbidden (403)
int status = r.getStatus();
Assert.assertTrue("Status should be 201 or 403, but was: " + status,
@@ -659,7 +660,8 @@ public class ManagerApiTest extends BaseApiTest {
r = outsiderClient.post(vertexPath, vertexJson3);
Assert.assertEquals(403, r.getStatus());
- // Test 7: Space manager can manage space members (already tested in
other tests)
+ // Test 7: Space manager can manage space members (already tested in
other
+ // tests)
// Test 8: Space member cannot manage space members
this.createUser("newuser");
String addMemberJson =
"{\"user\":\"newuser\",\"type\":\"SPACE_MEMBER\"}";