mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-04-11 22:56:08 +02:00
Fixed HTTPSWebServerAuthTest
This commit is contained in:
parent
6dcc02ebb6
commit
31986644f9
@ -22,6 +22,8 @@ import java.io.*;
|
|||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class TestResources {
|
public class TestResources {
|
||||||
|
|
||||||
private TestResources() {
|
private TestResources() {
|
||||||
@ -35,11 +37,13 @@ public class TestResources {
|
|||||||
public static void copyResourceIntoFile(File toFile, String resourcePath) {
|
public static void copyResourceIntoFile(File toFile, String resourcePath) {
|
||||||
createEmptyFile(toFile);
|
createEmptyFile(toFile);
|
||||||
writeResourceToFile(toFile, resourcePath);
|
writeResourceToFile(toFile, resourcePath);
|
||||||
|
assertTrue("Failed to copy resource: '" + resourcePath + "'", toFile.exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void copyTestResourceIntoFile(File toFile, InputStream testResource) {
|
public static void copyTestResourceIntoFile(File toFile, InputStream testResource) {
|
||||||
createEmptyFile(toFile);
|
createEmptyFile(toFile);
|
||||||
copyResourceToFile(toFile, testResource);
|
copyResourceToFile(toFile, testResource);
|
||||||
|
assertTrue("Failed to copy resource: '" + toFile.getAbsolutePath() + "'", toFile.exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void copyResourceToFile(File toFile, InputStream testResource) {
|
private static void copyResourceToFile(File toFile, InputStream testResource) {
|
||||||
|
@ -7,14 +7,18 @@ import com.djrapitops.plan.system.settings.config.PlanConfig;
|
|||||||
import com.djrapitops.plan.system.settings.paths.WebserverSettings;
|
import com.djrapitops.plan.system.settings.paths.WebserverSettings;
|
||||||
import com.djrapitops.plan.utilities.Base64Util;
|
import com.djrapitops.plan.utilities.Base64Util;
|
||||||
import com.djrapitops.plan.utilities.PassEncryptUtil;
|
import com.djrapitops.plan.utilities.PassEncryptUtil;
|
||||||
import org.junit.*;
|
import org.junit.AfterClass;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.ClassRule;
|
||||||
|
import org.junit.Test;
|
||||||
import org.junit.rules.TemporaryFolder;
|
import org.junit.rules.TemporaryFolder;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
import org.mockito.junit.MockitoJUnitRunner;
|
||||||
import rules.BukkitComponentMocker;
|
|
||||||
import rules.ComponentMocker;
|
import rules.ComponentMocker;
|
||||||
|
import rules.PluginComponentMocker;
|
||||||
import utilities.HTTPConnector;
|
import utilities.HTTPConnector;
|
||||||
import utilities.RandomData;
|
import utilities.RandomData;
|
||||||
|
import utilities.TestResources;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -23,6 +27,8 @@ import java.net.URL;
|
|||||||
import java.security.KeyManagementException;
|
import java.security.KeyManagementException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
@RunWith(MockitoJUnitRunner.Silent.class)
|
@RunWith(MockitoJUnitRunner.Silent.class)
|
||||||
public class HTTPSWebServerAuthTest {
|
public class HTTPSWebServerAuthTest {
|
||||||
|
|
||||||
@ -31,21 +37,21 @@ public class HTTPSWebServerAuthTest {
|
|||||||
@ClassRule
|
@ClassRule
|
||||||
public static TemporaryFolder temporaryFolder = new TemporaryFolder();
|
public static TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||||
@ClassRule
|
@ClassRule
|
||||||
public static ComponentMocker component = new BukkitComponentMocker(temporaryFolder);
|
public static ComponentMocker component = new PluginComponentMocker(temporaryFolder);
|
||||||
|
|
||||||
private static PlanSystem bukkitSystem;
|
private static PlanSystem system;
|
||||||
|
|
||||||
private HTTPConnector connector = new HTTPConnector();
|
private HTTPConnector connector = new HTTPConnector();
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUpClass() throws Exception {
|
public static void setUpClass() throws Exception {
|
||||||
URL resource = HTTPSWebServerAuthTest.class.getResource("/Cert.keystore");
|
File file = temporaryFolder.newFile();
|
||||||
String keyStore = resource.getPath();
|
TestResources.copyResourceIntoFile(file, "/Cert.keystore");
|
||||||
String absolutePath = new File(keyStore).getAbsolutePath();
|
String absolutePath = file.getAbsolutePath();
|
||||||
|
|
||||||
bukkitSystem = component.getPlanSystem();
|
system = component.getPlanSystem();
|
||||||
|
|
||||||
PlanConfig config = bukkitSystem.getConfigSystem().getConfig();
|
PlanConfig config = system.getConfigSystem().getConfig();
|
||||||
|
|
||||||
config.set(WebserverSettings.CERTIFICATE_PATH, absolutePath);
|
config.set(WebserverSettings.CERTIFICATE_PATH, absolutePath);
|
||||||
config.set(WebserverSettings.CERTIFICATE_KEYPASS, "MnD3bU5HpmPXag0e");
|
config.set(WebserverSettings.CERTIFICATE_KEYPASS, "MnD3bU5HpmPXag0e");
|
||||||
@ -54,28 +60,30 @@ public class HTTPSWebServerAuthTest {
|
|||||||
|
|
||||||
config.set(WebserverSettings.PORT, TEST_PORT_NUMBER);
|
config.set(WebserverSettings.PORT, TEST_PORT_NUMBER);
|
||||||
|
|
||||||
bukkitSystem.enable();
|
system.enable();
|
||||||
|
|
||||||
bukkitSystem.getDatabaseSystem().getDatabase().save()
|
system.getDatabaseSystem().getDatabase().save()
|
||||||
.webUser(new WebUser("test", PassEncryptUtil.createHash("testPass"), 0));
|
.webUser(new WebUser("test", PassEncryptUtil.createHash("testPass"), 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterClass
|
||||||
public static void tearDownClass() {
|
public static void tearDownClass() {
|
||||||
if (bukkitSystem != null) {
|
if (system != null) {
|
||||||
bukkitSystem.disable();
|
system.disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test case against "Perm level 0 required, got 0".
|
* Test case against "Perm level 0 required, got 0".
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test(timeout = 5000)
|
||||||
@Ignore("HTTPS Start fails due to paths being bad for some reason")
|
// @Ignore("HTTPS Start fails due to paths being bad for some reason")
|
||||||
public void testHTTPSAuthForPages() throws IOException, WebException, KeyManagementException, NoSuchAlgorithmException {
|
public void testHTTPSAuthForPages() throws IOException, WebException, KeyManagementException, NoSuchAlgorithmException {
|
||||||
|
assertTrue("WebServer is not using https", system.getWebServerSystem().getWebServer().isUsingHTTPS());
|
||||||
|
|
||||||
String address = "https://localhost:" + TEST_PORT_NUMBER;
|
String address = "https://localhost:" + TEST_PORT_NUMBER;
|
||||||
URL url = new URL(address);
|
URL url = new URL(address);
|
||||||
HttpURLConnection connection = connector.getConnection("HET", address);
|
HttpURLConnection connection = connector.getConnection("GET", address);
|
||||||
|
|
||||||
String user = Base64Util.encode("test:testPass");
|
String user = Base64Util.encode("test:testPass");
|
||||||
connection.setRequestProperty("Authorization", "Basic " + user);
|
connection.setRequestProperty("Authorization", "Basic " + user);
|
||||||
|
Loading…
Reference in New Issue
Block a user