imbajin commented on code in PR #2966: URL: https://github.com/apache/hugegraph/pull/2966#discussion_r2930102211
########## 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() { Review Comment: ⚠️ The new standalone tests only exercise the `ADMIN` branch, so they don't actually lock down the regression described in the PR body. The problematic path was that `validGraphSpace()` could still succeed in standalone mode because `manager.graphSpace(name)` returns a synthetic `DEFAULT` space, and that only happens in the `SPACE` / `SPACE_MEMBER` branches. ASCII view: ```text checkPdModeEnabled() | +-- ADMIN <- covered here +-- SPACE <- regression path \-- SPACE_MEMBER <- regression path ``` Please add at least one standalone test with `type=SPACE` or `type=SPACE_MEMBER` against a non-`DEFAULT` graphspace, so this PR verifies the branch that used to fall through. ```suggestion @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)); } ``` -- 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]
