From 22ebdab821fb97eca189ecb80f99ad23fbe83697 Mon Sep 17 00:00:00 2001 From: Aurora Lahtela <24460436+AuroraLS3@users.noreply.github.com> Date: Sun, 27 Feb 2022 15:40:35 +0200 Subject: [PATCH] Export noauth.css to hide logout button - Added test for exported pages that uses Selenium to check for js errors --- Plan/build.gradle | 2 + Plan/common/build.gradle | 4 + .../plan/delivery/export/ExportSystem.java | 7 + .../delivery/export/NetworkPageExporter.java | 1 + .../delivery/export/PlayerPageExporter.java | 1 + .../delivery/export/PlayersPageExporter.java | 1 + .../export/ExportJSErrorRegressionTest.java | 185 ++++++++++++++++++ .../webserver/JSErrorRegressionTest.java | 88 ++++----- .../database/DatabaseTestComponent.java | 1 + .../java/extension/SeleniumExtension.java | 41 ++-- .../utilities/dagger/PlanPluginComponent.java | 1 + .../utilities/dagger/PlanPluginModule.java | 10 - .../dagger/PlanProxyPluginComponent.java | 72 +++++++ .../dagger/PlanProxyPluginModule.java | 32 +++ .../dagger/PlanServerPluginModule.java | 33 ++++ .../utilities/dagger/ProxyServerInfo.java | 119 +++++++++++ 16 files changed, 530 insertions(+), 68 deletions(-) create mode 100644 Plan/common/src/test/java/com/djrapitops/plan/delivery/export/ExportJSErrorRegressionTest.java create mode 100644 Plan/common/src/test/java/utilities/dagger/PlanProxyPluginComponent.java create mode 100644 Plan/common/src/test/java/utilities/dagger/PlanProxyPluginModule.java create mode 100644 Plan/common/src/test/java/utilities/dagger/PlanServerPluginModule.java create mode 100644 Plan/common/src/test/java/utilities/dagger/ProxyServerInfo.java diff --git a/Plan/build.gradle b/Plan/build.gradle index 9ffb4a622..ff4c035c5 100644 --- a/Plan/build.gradle +++ b/Plan/build.gradle @@ -86,6 +86,8 @@ subprojects { bstatsVersion = "2.2.1" placeholderapiVersion = "2.11.1" nkPlaceholderapiVersion = "1.4-SNAPSHOT" + + testContainersVersion = "1.16.3" } repositories { diff --git a/Plan/common/build.gradle b/Plan/common/build.gradle index 55fa8177e..1314b7b26 100644 --- a/Plan/common/build.gradle +++ b/Plan/common/build.gradle @@ -50,6 +50,10 @@ dependencies { testImplementation project(":api") testImplementation "com.google.code.gson:gson:$gsonVersion" + + testImplementation "org.testcontainers:testcontainers:$testContainersVersion" + testImplementation "org.testcontainers:junit-jupiter:$testContainersVersion" + testImplementation "org.testcontainers:nginx:$testContainersVersion" } import org.apache.tools.ant.filters.ReplaceTokens diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/ExportSystem.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/ExportSystem.java index 23f953285..b014ed7e4 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/ExportSystem.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/ExportSystem.java @@ -30,14 +30,17 @@ import javax.inject.Singleton; @Singleton public class ExportSystem implements SubSystem { + private final Exporter exporter; private final ExportScheduler exportScheduler; private final RunnableFactory runnableFactory; @Inject public ExportSystem( + Exporter exporter, ExportScheduler exportScheduler, RunnableFactory runnableFactory ) { + this.exporter = exporter; this.exportScheduler = exportScheduler; this.runnableFactory = runnableFactory; } @@ -51,4 +54,8 @@ public class ExportSystem implements SubSystem { public void disable() { // Nothing to disable } + + public Exporter getExporter() { + return exporter; + } } \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/NetworkPageExporter.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/NetworkPageExporter.java index 55142501f..9b5deb346 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/NetworkPageExporter.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/NetworkPageExporter.java @@ -183,6 +183,7 @@ public class NetworkPageExporter extends FileExporter { "./img/Flaticon_circle.png", "./css/sb-admin-2.css", "./css/style.css", + "./css/noauth.css", "./vendor/datatables/datatables.min.js", "./vendor/datatables/datatables.min.css", "./vendor/highcharts/modules/map.js", diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/PlayerPageExporter.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/PlayerPageExporter.java index e05431ce2..5de89c2f8 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/PlayerPageExporter.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/PlayerPageExporter.java @@ -143,6 +143,7 @@ public class PlayerPageExporter extends FileExporter { "../img/Flaticon_circle.png", "../css/sb-admin-2.css", "../css/style.css", + "../css/noauth.css", "../vendor/datatables/datatables.min.js", "../vendor/datatables/datatables.min.css", "../vendor/highcharts/modules/map.js", diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/PlayersPageExporter.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/PlayersPageExporter.java index 3954afe77..fc2e85dfd 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/PlayersPageExporter.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/export/PlayersPageExporter.java @@ -142,6 +142,7 @@ public class PlayersPageExporter extends FileExporter { "img/Flaticon_circle.png", "css/sb-admin-2.css", "css/style.css", + "css/noauth.css", "vendor/datatables/datatables.min.js", "vendor/datatables/datatables.min.css", "vendor/fontawesome-free/css/all.min.css", diff --git a/Plan/common/src/test/java/com/djrapitops/plan/delivery/export/ExportJSErrorRegressionTest.java b/Plan/common/src/test/java/com/djrapitops/plan/delivery/export/ExportJSErrorRegressionTest.java new file mode 100644 index 000000000..fc74cf7aa --- /dev/null +++ b/Plan/common/src/test/java/com/djrapitops/plan/delivery/export/ExportJSErrorRegressionTest.java @@ -0,0 +1,185 @@ +/* + * 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 . + */ +package com.djrapitops.plan.delivery.export; + +import com.djrapitops.plan.PlanSystem; +import com.djrapitops.plan.gathering.domain.DataMap; +import com.djrapitops.plan.gathering.domain.FinishedSession; +import com.djrapitops.plan.identification.ServerUUID; +import com.djrapitops.plan.settings.config.PlanConfig; +import com.djrapitops.plan.settings.config.paths.ExportSettings; +import com.djrapitops.plan.settings.config.paths.ProxySettings; +import com.djrapitops.plan.settings.config.paths.WebserverSettings; +import com.djrapitops.plan.storage.database.DBSystem; +import com.djrapitops.plan.storage.database.Database; +import com.djrapitops.plan.storage.database.transactions.events.PlayerRegisterTransaction; +import com.djrapitops.plan.storage.database.transactions.events.SessionEndTransaction; +import com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction; +import extension.SeleniumExtension; +import org.junit.jupiter.api.*; +import org.junit.jupiter.api.extension.ExtendWith; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.logging.LogEntry; +import org.openqa.selenium.logging.LogType; +import org.testcontainers.containers.NginxContainer; +import org.testcontainers.containers.wait.strategy.HttpWaitStrategy; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; +import utilities.RandomData; +import utilities.TestConstants; +import utilities.mocks.PluginMockComponent; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * This test class is for catching any JavaScript errors. + *

+ * Errors may have been caused by: + * - Missing placeholders {@code ${placeholder}} inside {@code