2018-02-04 13:31:10 +01:00
|
|
|
package com.djrapitops.plan.system.webserver;
|
|
|
|
|
|
|
|
import com.djrapitops.plan.api.exceptions.connection.*;
|
2018-10-13 12:40:18 +02:00
|
|
|
import com.djrapitops.plan.data.WebUser;
|
2018-08-23 12:56:24 +02:00
|
|
|
import com.djrapitops.plan.system.PlanSystem;
|
2018-10-13 12:40:18 +02:00
|
|
|
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
2018-12-08 10:44:10 +01:00
|
|
|
import com.djrapitops.plan.system.settings.paths.WebserverSettings;
|
2018-02-04 13:31:10 +01:00
|
|
|
import com.djrapitops.plan.utilities.Base64Util;
|
2018-10-13 12:40:18 +02:00
|
|
|
import com.djrapitops.plan.utilities.PassEncryptUtil;
|
[Merge] Module split (#786)
* Moved project files to 'common'-module
This is done so that refactoring into multiple smaller modules is easier
as the IDE will not attempt to move tests incorrectly when moving things
between different modules
* Created 'bukkit' module
Following classes were removed during the operation:
- BukkitServerInfo (Renamed to ServerServerInfo)
- SpongeServerInfo (could use ServerServerInfo)
- Hastebin (not viable on every platform, unused)
- HastebinTest
- MockPlayers (unused, bukkit specific)
Changes to classes:
- Renamed Importer to BukkitImporter (contained bukkit related impl.)
- Extracted Importer interface from BukkitImporter
- Turned BukkitPlanModule and BukkitClassBindingModule to interfaces by
using @Binds annotation
- Added Status class since PlayersOnlineListener had a boolean,
that stated if kicks were counted.
This commit completes split partially and was not pushed on commit.
* Created 'sponge' module
Changes to classes:
- Turned ServerSuperClassBindingModule, SuperClassBindingModule,
SpongePlanModule and SpongeClassBindingModule to interfaces by
using @Binds annotation
- Renamed SystemObjectBindingModule to SystemObjectProvidingModule
- Removed sponge related calls in ServerProperties
- Made EmptyImportSystem injectable
This commit completes split partially and was not pushed on commit.
* Changed shade configuration
Further tweaks required.
* Created 'bungeecord' module
Changes to classes:
- Removed use of BungeePingTimerTask in VelocityTaskSystem
- Removed use of RedisBungee in VelocityServerProperties
- Fixed bukkit command.commands.RegisterCommandFilter package
Changes to project structure:
- Dependency versions now in main pom via dependencyManagement
- Repositories now defined in main pom
* Created 'velocity' module
Changes to classes:
- Made RawDataResponse use Gson via reflection since it is no longer
available in dependencies of 'common' module
* Created 'plugin' module
This module is for creating a single deployment artifact and testing of
system interactions.
Fixes to tests:
- Reflection no longer fails to initialize if Bukkit.getServer() is null
- PingCountTimerBukkit no longer fails to be created if Reflection fails
- Removed unnecessary @AfterClass from H2Test
- Jar resource path fixes to Mocker
* Shading configuration
org.slf4j classes are relocated in 'common', 'bukkit' & 'bungeecord'.
In 'sponge' & 'velocity' they are not relocated, allowing injection
as plugin logger, while using slf4j-nop for HikariCP logging.
This allows single release artifact.
* Removed 'Icon' from .gitignore
* Attempt to fix test resources
Because all jar resources are located in 'common', an attempt to fetch
them is made to common/target/Plan-common.jar, which for some reason
is a bad path.
This attempts to remedy that by creating a temporary file from an
InputStream, read with Class#getResourceAsStream
Ignored HTTPSWebServerAuthTest as the certificate path was invalid for
some reason.
2018-11-11 11:55:09 +01:00
|
|
|
import org.junit.*;
|
2018-02-04 13:31:10 +01:00
|
|
|
import org.junit.rules.TemporaryFolder;
|
|
|
|
import org.junit.runner.RunWith;
|
|
|
|
import org.mockito.junit.MockitoJUnitRunner;
|
2018-11-26 10:02:18 +01:00
|
|
|
import rules.BukkitComponentMocker;
|
|
|
|
import rules.ComponentMocker;
|
|
|
|
import utilities.HTTPConnector;
|
2018-12-18 16:16:33 +01:00
|
|
|
import utilities.RandomData;
|
2018-02-04 13:31:10 +01:00
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.security.KeyManagementException;
|
|
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
|
|
|
|
@RunWith(MockitoJUnitRunner.Silent.class)
|
|
|
|
public class HTTPSWebServerAuthTest {
|
|
|
|
|
2018-12-18 16:16:33 +01:00
|
|
|
private static final int TEST_PORT_NUMBER = RandomData.randomInt(9005, 9500);
|
|
|
|
|
2018-02-04 13:31:10 +01:00
|
|
|
@ClassRule
|
|
|
|
public static TemporaryFolder temporaryFolder = new TemporaryFolder();
|
2018-11-26 10:02:18 +01:00
|
|
|
@ClassRule
|
|
|
|
public static ComponentMocker component = new BukkitComponentMocker(temporaryFolder);
|
|
|
|
|
2018-08-23 12:56:24 +02:00
|
|
|
private static PlanSystem bukkitSystem;
|
2018-02-04 13:31:10 +01:00
|
|
|
|
2018-11-26 10:02:18 +01:00
|
|
|
private HTTPConnector connector = new HTTPConnector();
|
|
|
|
|
2018-02-04 13:31:10 +01:00
|
|
|
@BeforeClass
|
|
|
|
public static void setUpClass() throws Exception {
|
|
|
|
URL resource = HTTPSWebServerAuthTest.class.getResource("/Cert.keystore");
|
|
|
|
String keyStore = resource.getPath();
|
|
|
|
String absolutePath = new File(keyStore).getAbsolutePath();
|
|
|
|
|
2018-11-26 10:02:18 +01:00
|
|
|
bukkitSystem = component.getPlanSystem();
|
2018-10-13 12:40:18 +02:00
|
|
|
|
|
|
|
PlanConfig config = bukkitSystem.getConfigSystem().getConfig();
|
|
|
|
|
2018-12-08 10:44:10 +01:00
|
|
|
config.set(WebserverSettings.CERTIFICATE_PATH, absolutePath);
|
|
|
|
config.set(WebserverSettings.CERTIFICATE_KEYPASS, "MnD3bU5HpmPXag0e");
|
|
|
|
config.set(WebserverSettings.CERTIFICATE_STOREPASS, "wDwwf663NLTm73gL");
|
|
|
|
config.set(WebserverSettings.CERTIFICATE_ALIAS, "DefaultPlanCert");
|
2018-10-13 12:40:18 +02:00
|
|
|
|
2018-12-18 16:16:33 +01:00
|
|
|
config.set(WebserverSettings.PORT, TEST_PORT_NUMBER);
|
2018-10-13 12:40:18 +02:00
|
|
|
|
|
|
|
bukkitSystem.enable();
|
|
|
|
|
|
|
|
bukkitSystem.getDatabaseSystem().getDatabase().save()
|
|
|
|
.webUser(new WebUser("test", PassEncryptUtil.createHash("testPass"), 0));
|
2018-02-04 13:31:10 +01:00
|
|
|
}
|
|
|
|
|
2018-04-01 12:53:33 +02:00
|
|
|
@AfterClass
|
|
|
|
public static void tearDownClass() {
|
2018-02-04 13:31:10 +01:00
|
|
|
if (bukkitSystem != null) {
|
|
|
|
bukkitSystem.disable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test case against "Perm level 0 required, got 0".
|
|
|
|
*/
|
|
|
|
@Test
|
[Merge] Module split (#786)
* Moved project files to 'common'-module
This is done so that refactoring into multiple smaller modules is easier
as the IDE will not attempt to move tests incorrectly when moving things
between different modules
* Created 'bukkit' module
Following classes were removed during the operation:
- BukkitServerInfo (Renamed to ServerServerInfo)
- SpongeServerInfo (could use ServerServerInfo)
- Hastebin (not viable on every platform, unused)
- HastebinTest
- MockPlayers (unused, bukkit specific)
Changes to classes:
- Renamed Importer to BukkitImporter (contained bukkit related impl.)
- Extracted Importer interface from BukkitImporter
- Turned BukkitPlanModule and BukkitClassBindingModule to interfaces by
using @Binds annotation
- Added Status class since PlayersOnlineListener had a boolean,
that stated if kicks were counted.
This commit completes split partially and was not pushed on commit.
* Created 'sponge' module
Changes to classes:
- Turned ServerSuperClassBindingModule, SuperClassBindingModule,
SpongePlanModule and SpongeClassBindingModule to interfaces by
using @Binds annotation
- Renamed SystemObjectBindingModule to SystemObjectProvidingModule
- Removed sponge related calls in ServerProperties
- Made EmptyImportSystem injectable
This commit completes split partially and was not pushed on commit.
* Changed shade configuration
Further tweaks required.
* Created 'bungeecord' module
Changes to classes:
- Removed use of BungeePingTimerTask in VelocityTaskSystem
- Removed use of RedisBungee in VelocityServerProperties
- Fixed bukkit command.commands.RegisterCommandFilter package
Changes to project structure:
- Dependency versions now in main pom via dependencyManagement
- Repositories now defined in main pom
* Created 'velocity' module
Changes to classes:
- Made RawDataResponse use Gson via reflection since it is no longer
available in dependencies of 'common' module
* Created 'plugin' module
This module is for creating a single deployment artifact and testing of
system interactions.
Fixes to tests:
- Reflection no longer fails to initialize if Bukkit.getServer() is null
- PingCountTimerBukkit no longer fails to be created if Reflection fails
- Removed unnecessary @AfterClass from H2Test
- Jar resource path fixes to Mocker
* Shading configuration
org.slf4j classes are relocated in 'common', 'bukkit' & 'bungeecord'.
In 'sponge' & 'velocity' they are not relocated, allowing injection
as plugin logger, while using slf4j-nop for HikariCP logging.
This allows single release artifact.
* Removed 'Icon' from .gitignore
* Attempt to fix test resources
Because all jar resources are located in 'common', an attempt to fetch
them is made to common/target/Plan-common.jar, which for some reason
is a bad path.
This attempts to remedy that by creating a temporary file from an
InputStream, read with Class#getResourceAsStream
Ignored HTTPSWebServerAuthTest as the certificate path was invalid for
some reason.
2018-11-11 11:55:09 +01:00
|
|
|
@Ignore("HTTPS Start fails due to paths being bad for some reason")
|
2018-02-04 13:31:10 +01:00
|
|
|
public void testHTTPSAuthForPages() throws IOException, WebException, KeyManagementException, NoSuchAlgorithmException {
|
2018-12-18 16:16:33 +01:00
|
|
|
String address = "https://localhost:" + TEST_PORT_NUMBER;
|
2018-02-04 13:31:10 +01:00
|
|
|
URL url = new URL(address);
|
2018-11-26 10:02:18 +01:00
|
|
|
HttpURLConnection connection = connector.getConnection("HET", address);
|
2018-02-04 13:31:10 +01:00
|
|
|
|
|
|
|
String user = Base64Util.encode("test:testPass");
|
|
|
|
connection.setRequestProperty("Authorization", "Basic " + user);
|
|
|
|
|
|
|
|
int responseCode = connection.getResponseCode();
|
|
|
|
|
|
|
|
switch (responseCode) {
|
|
|
|
case 200:
|
2018-10-13 12:40:18 +02:00
|
|
|
case 302:
|
2018-02-04 13:31:10 +01:00
|
|
|
return;
|
|
|
|
case 400:
|
|
|
|
throw new BadRequestException("Bad Request: " + url.toString());
|
|
|
|
case 403:
|
|
|
|
throw new ForbiddenException(url.toString() + " returned 403");
|
|
|
|
case 404:
|
|
|
|
throw new NotFoundException(url.toString() + " returned a 404, ensure that your server is connected to an up to date Plan server.");
|
|
|
|
case 412:
|
|
|
|
throw new UnauthorizedServerException(url.toString() + " reported that it does not recognize this server. Make sure '/plan m setup' was successful.");
|
|
|
|
case 500:
|
|
|
|
throw new InternalErrorException();
|
|
|
|
default:
|
|
|
|
throw new WebException(url.toString() + "| Wrong response code " + responseCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|