From: David ‘Bombe’ Roden Date: Sun, 28 Jul 2019 15:16:14 +0000 (+0200) Subject: ✨ Add page to activate debug mode X-Git-Tag: v81^2~166 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=14d030de10eff6c2279700b73150d8e3f84bc652;p=Sone.git ✨ Add page to activate debug mode --- diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index d7dd16c..4a572a2 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -616,6 +616,7 @@ public class WebInterface implements SessionProvider { 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.loadStaticPage("css/", "/static/css/", "text/css")); pageToadletRegistry.addPage(loaders.loadStaticPage("javascript/", "/static/javascript/", "text/javascript")); diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DebugPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DebugPage.kt new file mode 100644 index 0000000..29a8f8c --- /dev/null +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DebugPage.kt @@ -0,0 +1,18 @@ +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("./") + } + +} diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/DebugPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/DebugPageTest.kt new file mode 100644 index 0000000..3b2293e --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/DebugPageTest.kt @@ -0,0 +1,69 @@ +/** + * 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 . + */ + +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(), 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) + } + +} +