From fd0ed36e67de7a00d198b92203b80826e71ef81e Mon Sep 17 00:00:00 2001 From: Joscha Schmiedt <joscha@schmiedt.dev> Date: Wed, 26 Mar 2025 17:12:34 +0100 Subject: [PATCH] Remove attempts for integration tests for SSS in gRPC --- .../grpc/ServerSideScriptingGrpcTest.java | 196 ------------------ 1 file changed, 196 deletions(-) diff --git a/src/test/java/org/caosdb/server/grpc/ServerSideScriptingGrpcTest.java b/src/test/java/org/caosdb/server/grpc/ServerSideScriptingGrpcTest.java index 7e24f9d4..013b2397 100644 --- a/src/test/java/org/caosdb/server/grpc/ServerSideScriptingGrpcTest.java +++ b/src/test/java/org/caosdb/server/grpc/ServerSideScriptingGrpcTest.java @@ -22,180 +22,14 @@ package org.caosdb.server.grpc; import static org.junit.jupiter.api.Assertions.assertEquals; -import java.io.IOException; import java.util.ArrayList; -import java.util.HashSet; -import org.apache.shiro.SecurityUtils; -import org.apache.shiro.subject.Subject; import org.caosdb.api.scripting.v1alpha1.ExecuteServerSideScriptRequest; -import org.caosdb.api.scripting.v1alpha1.ExecuteServerSideScriptResponse; import org.caosdb.api.scripting.v1alpha1.NamedArgument; -import org.caosdb.api.scripting.v1alpha1.ServerSideScriptExecutionResult; -import org.caosdb.server.CaosDBServer; -import org.caosdb.server.ServerProperties; -import org.caosdb.server.accessControl.AnonymousAuthenticationToken; -import org.caosdb.server.accessControl.CredentialsValidator; -import org.caosdb.server.accessControl.Principal; -import org.caosdb.server.accessControl.Role; -import org.caosdb.server.accessControl.UserSources; -import org.caosdb.server.database.BackendTransaction; -import org.caosdb.server.database.access.Access; -import org.caosdb.server.database.backend.interfaces.RetrievePasswordValidatorImpl; -import org.caosdb.server.database.backend.interfaces.RetrievePermissionRulesImpl; -import org.caosdb.server.database.backend.interfaces.RetrieveRoleImpl; -import org.caosdb.server.database.backend.interfaces.RetrieveUserImpl; -import org.caosdb.server.database.exceptions.TransactionException; -import org.caosdb.server.database.misc.TransactionBenchmark; -import org.caosdb.server.database.proto.ProtoUser; import org.caosdb.server.entity.Message; -import org.caosdb.server.permissions.PermissionRule; -import org.caosdb.server.scripting.ScriptingPermissions; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; public class ServerSideScriptingGrpcTest { - public static class RetrieveRoleMockup implements RetrieveRoleImpl { - - public RetrieveRoleMockup(Access a) {} - - @Override - public Role retrieve(String role) throws TransactionException { - Role ret = new Role(); - ret.name = "anonymous"; - ret.description = "bla"; - return ret; - } - - @Override - public TransactionBenchmark getBenchmark() { - return null; - } - - @Override - public void setTransactionBenchmark(TransactionBenchmark b) {} - } - - public static class RetrievePermissionRules implements RetrievePermissionRulesImpl { - - public RetrievePermissionRules(Access a) {} - - @Override - public HashSet<PermissionRule> retrievePermissionRule(String role) throws TransactionException { - HashSet<PermissionRule> result = new HashSet<>(); - result.add( - new PermissionRule( - true, false, ScriptingPermissions.PERMISSION_EXECUTION("anonymous_ok"))); - return result; - } - - @Override - public TransactionBenchmark getBenchmark() { - return null; - } - - @Override - public void setTransactionBenchmark(TransactionBenchmark b) {} - } - - public static class RetrieveUserMockUp implements RetrieveUserImpl { - - public RetrieveUserMockUp(Access a) {} - - @Override - public ProtoUser execute(Principal principal) throws TransactionException { - return new ProtoUser(); - } - - @Override - public TransactionBenchmark getBenchmark() { - return null; - } - - @Override - public void setTransactionBenchmark(TransactionBenchmark b) {} - } - - public static class RetrievePasswordValidator implements RetrievePasswordValidatorImpl { - - public RetrievePasswordValidator(Access a) {} - - @Override - public CredentialsValidator<String> execute(String name) throws TransactionException { - return new CredentialsValidator<String>() { - @Override - public boolean isValid(String credential) { - return true; - } - }; - } - - @Override - public void setTransactionBenchmark(TransactionBenchmark b) {} - - @Override - public TransactionBenchmark getBenchmark() { - return null; - } - } - - @BeforeAll - public static void setupShiro() throws IOException { - CaosDBServer.initServerProperties(); - CaosDBServer.initShiro(); - - BackendTransaction.setImpl(RetrieveRoleImpl.class, RetrieveRoleMockup.class); - BackendTransaction.setImpl(RetrievePermissionRulesImpl.class, RetrievePermissionRules.class); - BackendTransaction.setImpl(RetrieveUserImpl.class, RetrieveUserMockUp.class); - BackendTransaction.setImpl( - RetrievePasswordValidatorImpl.class, RetrievePasswordValidator.class); - - UserSources.getDefaultRealm(); - } - - @Test - public void testAnonymousWithOutPermission() { - Subject user = SecurityUtils.getSubject(); - CaosDBServer.setProperty(ServerProperties.KEY_AUTH_OPTIONAL, "true"); - user.login(AnonymousAuthenticationToken.getInstance()); - - // TODO: implement this test - - // Form form = new Form("call=anonymous_no_permission"); - // Representation entity = form.getWebRepresentation(); - // Request request = new Request(Method.POST, "../test", entity); - // request.setRootRef(new Reference("bla")); - // request.getAttributes().put("SRID", "asdf1234"); - // request.setDate(new Date()); - // request.setHostRef("bla"); - // resource.init(null, request, new Response(null)); - - // resource.handle(); - // assertEquals(Status.CLIENT_ERROR_FORBIDDEN, - // resource.getResponse().getStatus()); - } - - @Test - public void testAnonymousWithPermission() { - Subject user = SecurityUtils.getSubject(); - CaosDBServer.setProperty(ServerProperties.KEY_AUTH_OPTIONAL, "true"); - user.login(AnonymousAuthenticationToken.getInstance()); - - // TODO: implement this test - - // Form form = new Form("call=anonymous_ok"); - // Representation entity = form.getWebRepresentation(); - // Request request = new Request(Method.POST, "../test", entity); - // request.setRootRef(new Reference("bla")); - // request.getAttributes().put("SRID", "asdf1234"); - // request.setDate(new Date()); - // request.setHostRef("bla"); - // resource.init(null, request, new Response(null)); - - // resource.handle(); - // assertEquals(Status.SUCCESS_OK, resource.getResponse().getStatus()); - } - @Test public void testExecuteServerSideScriptRequestToCommandline() throws Message { ExecuteServerSideScriptRequest request = @@ -218,34 +52,4 @@ public class ServerSideScriptingGrpcTest { assertEquals(commandline.get(3), "pos0"); assertEquals(commandline.get(4), "pos1"); } - - @Test - public void testCallScript() throws Message { - - // TODO: Implement this test - - // ServerSideScriptingServiceImpl service = new ServerSideScriptingServiceImpl(); - // ExecuteServerSideScriptRequest request = - // ExecuteServerSideScriptRequest.newBuilder() - // .setScriptFilename("my_script.py") - // .addPositionalArguments("pos0") - // .addPositionalArguments("pos1") - // .addNamedArguments( - // NamedArgument.newBuilder().setName("option1").setValue("val1").build()) - // .addNamedArguments( - // NamedArgument.newBuilder().setName("option2").setValue("val2").build()) - // .setTimeoutMs(1000) - // .build(); - - // ExecuteServerSideScriptResponse response = service.callScript(request); - - // assertEquals(response.getCall(), "my_script.py"); - // assertEquals( - // response.getResult(), - // ServerSideScriptExecutionResult.SERVER_SIDE_SCRIPT_EXECUTION_RESULT_SUCCESS); - // assertEquals(response.getStdout(), ""); // Assuming the script does not produce any output - // assertEquals(response.getStderr(), ""); // Assuming the script does not produce any error output - // assertEquals(response.getReturnCode(), 0); // Assuming the script returns 0 - // assertEquals(response.getDurationMs() > 0, true); // Check if duration is greater than 0 - } } -- GitLab