diff --git a/LaunchServer/build.gradle b/LaunchServer/build.gradle index d948cc3d..8288f840 100644 --- a/LaunchServer/build.gradle +++ b/LaunchServer/build.gradle @@ -40,6 +40,13 @@ ) } +test { + useJUnitPlatform() + testLogging { + events "passed", "skipped", "failed" + } +} + task sourcesJar(type: Jar) { from sourceSets.main.allJava archiveClassifier = 'sources' @@ -107,6 +114,7 @@ pack project(':LauncherAPI') compileOnlyA 'com.google.guava:guava:26.0-jre' compileOnlyA 'log4j:log4j:1.2.17' // Do not update (laggy dep). compileOnlyA 'org.apache.logging.log4j:log4j-core:2.11.2' + testCompile 'org.junit.jupiter:junit-jupiter:5.4.1' } task hikari(type: Copy) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java index dae1f39b..fbcdf705 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java @@ -312,7 +312,10 @@ public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env) , "std")}; newConfig.auth[0].displayName = "Default"; newConfig.protectHandler = new StdProtectHandler(); - newConfig.permissionsHandler = new JsonFilePermissionsHandler(); + if(env.equals(LaunchServer.LaunchServerEnv.TEST)) + newConfig.permissionsHandler = new DefaultPermissionsHandler(); + else + newConfig.permissionsHandler = new JsonFilePermissionsHandler(); newConfig.binaryName = "Launcher"; newConfig.whitelistRejectString = "Вас нет в белом списке"; diff --git a/LaunchServer/src/test/java/pro/gravit/launchserver/StartLaunchServerTest.java b/LaunchServer/src/test/java/pro/gravit/launchserver/StartLaunchServerTest.java new file mode 100644 index 00000000..d0dc375f --- /dev/null +++ b/LaunchServer/src/test/java/pro/gravit/launchserver/StartLaunchServerTest.java @@ -0,0 +1,78 @@ +package pro.gravit.launchserver; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; +import pro.gravit.launcher.Launcher; +import pro.gravit.launcher.managers.SimpleModulesConfigManager; +import pro.gravit.launchserver.config.LaunchServerConfig; +import pro.gravit.launchserver.config.LaunchServerRuntimeConfig; +import pro.gravit.launchserver.manangers.LaunchServerGsonManager; +import pro.gravit.launchserver.modules.impl.LaunchServerModulesManager; +import pro.gravit.utils.command.StdCommandHandler; +import pro.gravit.utils.helper.SecurityHelper; + +import java.io.IOException; +import java.nio.file.Path; +import java.security.KeyPair; +import java.security.interfaces.RSAPrivateKey; +import java.security.interfaces.RSAPublicKey; + +public class StartLaunchServerTest { + @TempDir + public static Path modulesDir; + @TempDir + public static Path configDir; + @TempDir + public static Path dir; + public static LaunchServer launchServer; + @BeforeAll + public static void prepare() throws Exception + { + LaunchServerModulesManager modulesManager = new LaunchServerModulesManager(modulesDir, configDir); + SimpleModulesConfigManager configManager = new SimpleModulesConfigManager(configDir); + LaunchServerConfig config = LaunchServerConfig.getDefault(LaunchServer.LaunchServerEnv.TEST); + Launcher.gsonManager = new LaunchServerGsonManager(modulesManager); + Launcher.gsonManager.initGson(); + LaunchServerRuntimeConfig runtimeConfig = new LaunchServerRuntimeConfig(); + LaunchServerBuilder builder = new LaunchServerBuilder(); + KeyPair pair = SecurityHelper.genRSAKeyPair(); + RSAPublicKey publicKey = (RSAPublicKey) pair.getPublic(); + RSAPrivateKey privateKey = (RSAPrivateKey) pair.getPrivate(); + builder.setDir(dir) + .setEnv(LaunchServer.LaunchServerEnv.TEST) + .setConfig(config) + .setRuntimeConfig(runtimeConfig) + .setPublicKey(publicKey) + .setPrivateKey(privateKey) + .setLaunchServerConfigManager(new LaunchServer.LaunchServerConfigManager() { + @Override + public LaunchServerConfig readConfig() throws IOException { + return null; + } + + @Override + public LaunchServerRuntimeConfig readRuntimeConfig() throws IOException { + return null; + } + + @Override + public void writeConfig(LaunchServerConfig config) throws IOException { + + } + + @Override + public void writeRuntimeConfig(LaunchServerRuntimeConfig config) throws IOException { + + } + }) + .setModulesManager(modulesManager) + .setCommandHandler(new StdCommandHandler(false)); + launchServer = builder.build(); + } + @Test + public void start() throws Exception + { + launchServer.run(); + } +}