mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-02-15 03:41:38 +01:00
Test file extensions supported by public html
This commit is contained in:
parent
7ccc957929
commit
d25d013b75
@ -18,6 +18,7 @@ package com.djrapitops.plan.delivery;
|
||||
|
||||
import com.djrapitops.plan.delivery.formatting.Formatters;
|
||||
import com.djrapitops.plan.delivery.rendering.json.graphs.Graphs;
|
||||
import com.djrapitops.plan.delivery.webserver.Addresses;
|
||||
import com.djrapitops.plan.storage.file.PublicHtmlFiles;
|
||||
import dagger.Lazy;
|
||||
|
||||
@ -27,20 +28,27 @@ import javax.inject.Singleton;
|
||||
@Singleton
|
||||
public class DeliveryUtilities {
|
||||
|
||||
private final Lazy<Addresses> addresses;
|
||||
private final Lazy<Formatters> formatters;
|
||||
private final Lazy<Graphs> graphs;
|
||||
private final Lazy<PublicHtmlFiles> publicHtmlFiles;
|
||||
|
||||
@Inject
|
||||
public DeliveryUtilities(
|
||||
Lazy<Addresses> addresses,
|
||||
Lazy<Formatters> formatters,
|
||||
Lazy<Graphs> graphs,
|
||||
Lazy<PublicHtmlFiles> publicHtmlFiles) {
|
||||
this.addresses = addresses;
|
||||
this.formatters = formatters;
|
||||
this.graphs = graphs;
|
||||
this.publicHtmlFiles = publicHtmlFiles;
|
||||
}
|
||||
|
||||
public Addresses getAddresses() {
|
||||
return addresses.get();
|
||||
}
|
||||
|
||||
public Formatters getFormatters() {
|
||||
return formatters.get();
|
||||
}
|
||||
|
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan.delivery.webserver;
|
||||
|
||||
import com.djrapitops.plan.PlanSystem;
|
||||
import com.djrapitops.plan.delivery.DeliveryUtilities;
|
||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||
import extension.FullSystemExtension;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
import utilities.HTTPConnector;
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* @author AuroraLS3
|
||||
*/
|
||||
@ExtendWith(FullSystemExtension.class)
|
||||
class PublicHtmlTest {
|
||||
|
||||
private static final HTTPConnector CONNECTOR = new HTTPConnector();
|
||||
|
||||
@BeforeAll
|
||||
static void setupSystem(PlanSystem system) {
|
||||
system.enable();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
static void teardownSystem(PlanSystem system) {
|
||||
system.disable();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"avif", "bin", "bmp",
|
||||
"css", "csv", "eot",
|
||||
"gif", "html", "htm",
|
||||
"ico", "ics", "js",
|
||||
"jpeg", "jpg", "json",
|
||||
"jsonld", "mjs", "otf",
|
||||
"pdf", "php", "png",
|
||||
"rtf", "svg", "tif",
|
||||
"tiff", "ttf", "txt",
|
||||
"woff", "woff2", "xml",
|
||||
})
|
||||
void customFileIsResponded(String extension, PlanConfig config, DeliveryUtilities deliveryUtilities) throws Exception {
|
||||
String fileName = "test." + extension;
|
||||
Path publicHtmlDirectory = config.getResourceSettings().getPublicHtmlDirectory();
|
||||
Path file = publicHtmlDirectory.resolve(fileName);
|
||||
Files.createDirectories(publicHtmlDirectory);
|
||||
Files.write(file, new byte[]{1, 1, 1, 1});
|
||||
String address = deliveryUtilities.getAddresses().getAccessAddress()
|
||||
.orElse(deliveryUtilities.getAddresses().getFallbackLocalhostAddress());
|
||||
|
||||
assertEquals(200, access(address + "/" + fileName));
|
||||
assertEquals(404, access(address + "/does-not-exist-" + fileName));
|
||||
}
|
||||
|
||||
private int access(String address) throws Exception {
|
||||
HttpURLConnection connection = null;
|
||||
try {
|
||||
connection = CONNECTOR.getConnection("GET", address);
|
||||
|
||||
return connection.getResponseCode();
|
||||
} finally {
|
||||
if (connection != null) connection.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
@ -26,6 +26,7 @@ import com.djrapitops.plan.settings.config.paths.WebserverSettings;
|
||||
import com.djrapitops.plan.storage.database.Database;
|
||||
import com.djrapitops.plan.storage.file.PlanFiles;
|
||||
import com.djrapitops.plan.storage.file.PublicHtmlFiles;
|
||||
import javassist.tools.web.Webserver;
|
||||
import org.junit.jupiter.api.extension.*;
|
||||
import utilities.RandomData;
|
||||
import utilities.dagger.PlanPluginComponent;
|
||||
@ -90,6 +91,7 @@ public class FullSystemExtension implements ParameterResolver, BeforeAllCallback
|
||||
Database.class.equals(type) ||
|
||||
DeliveryUtilities.class.equals(type) ||
|
||||
PublicHtmlFiles.class.equals(type) ||
|
||||
Webserver.class.equals(type) ||
|
||||
Exporter.class.equals(type);
|
||||
}
|
||||
|
||||
@ -131,6 +133,9 @@ public class FullSystemExtension implements ParameterResolver, BeforeAllCallback
|
||||
if (PublicHtmlFiles.class.equals(type)) {
|
||||
return planSystem.getDeliveryUtilities().getPublicHtmlFiles();
|
||||
}
|
||||
if (Webserver.class.equals(type)) {
|
||||
return planSystem.getWebServerSystem().getWebServer();
|
||||
}
|
||||
if (Exporter.class.equals(type)) {
|
||||
return planSystem.getExportSystem().getExporter();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user