pageToadletRegistry.addPage(new EmptyImageTitlePage(this, loaders, templateRenderer));
pageToadletRegistry.addPage(new EmptyAlbumTitlePage(this, loaders, templateRenderer));
pageToadletRegistry.addPage(new DismissNotificationPage(this, loaders, templateRenderer));
+ pageToadletRegistry.addPage(new DebugPage(this, loaders, templateRenderer));
pageToadletRegistry.addDebugPage(new MetricsPage(this, loaders, templateRenderer, metricRegistry));
pageToadletRegistry.addPage(loaders.<FreenetRequest>loadStaticPage("css/", "/static/css/", "text/css"));
pageToadletRegistry.addPage(loaders.<FreenetRequest>loadStaticPage("javascript/", "/static/javascript/", "text/javascript"));
--- /dev/null
+package net.pterodactylus.sone.web.pages
+
+import net.pterodactylus.sone.main.*
+import net.pterodactylus.sone.web.*
+import net.pterodactylus.sone.web.page.*
+import net.pterodactylus.util.template.*
+import javax.inject.*
+
+@ToadletPath("debug")
+class DebugPage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) :
+ SoneTemplatePage(webInterface, loaders, templateRenderer) {
+
+ override fun handleRequest(soneRequest: SoneRequest, templateContext: TemplateContext) {
+ soneRequest.core.setDebug()
+ throw RedirectException("./")
+ }
+
+}
--- /dev/null
+/**
+ * Sone - DebugPageTest.kt - Copyright © 2019 David ‘Bombe’ Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.web.pages
+
+import net.pterodactylus.sone.test.*
+import net.pterodactylus.sone.web.*
+import net.pterodactylus.sone.web.WebTestUtils.*
+import net.pterodactylus.sone.web.page.FreenetTemplatePage.*
+import org.hamcrest.MatcherAssert.*
+import org.hamcrest.Matchers.*
+import org.junit.Rule
+import org.junit.rules.*
+import org.junit.rules.ExpectedException.*
+import org.mockito.Mockito.*
+import kotlin.test.*
+
+class DebugPageTest : WebPageTest(::DebugPage) {
+
+ @Rule
+ @JvmField
+ val expectedException: ExpectedException = none()
+
+ @Test
+ fun `page returns correct path`() {
+ assertThat(page.path, equalTo("debug"))
+ }
+
+ @Test
+ fun `page does not require login`() {
+ assertThat(page.requiresLogin(), equalTo(false))
+ }
+
+ @Test
+ fun `page can be created by dependency injection`() {
+ assertThat(baseInjector.getInstance<DebugPage>(), notNullValue())
+ }
+
+ @Test
+ fun `get request activates debug mode`() {
+ try {
+ page.handleRequest(soneRequest, templateContext)
+ } catch (_: RedirectException) {
+ }
+ verify(core).setDebug()
+ }
+
+ @Test
+ fun `get request redirects to index`() {
+ expectedException.expect(redirectsTo("./"))
+ page.handleRequest(soneRequest, templateContext)
+ }
+
+}
+