From b31d36fc6fa19e9d47677b7450cd96881945b2ef Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 7 Apr 2020 18:59:26 +0200 Subject: [PATCH] =?utf8?q?=F0=9F=94=A5=20Remove=20session=20manager=20from?= =?utf8?q?=20freenet=20request?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/net/pterodactylus/sone/web/page/FreenetRequest.kt | 6 +----- src/main/kotlin/net/pterodactylus/sone/web/page/PageToadlet.kt | 4 ++-- src/main/kotlin/net/pterodactylus/sone/web/page/SoneRequest.kt | 6 +++--- .../kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePage.kt | 2 +- src/test/java/net/pterodactylus/sone/main/DebugLoadersTest.java | 2 +- src/test/java/net/pterodactylus/sone/main/DefaultLoadersTest.java | 2 +- .../kotlin/net/pterodactylus/sone/web/page/FreenetRequestTest.kt | 2 +- src/test/kotlin/net/pterodactylus/sone/web/page/SoneRequestTest.kt | 7 ++----- src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest.kt | 3 --- 9 files changed, 12 insertions(+), 22 deletions(-) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/page/FreenetRequest.kt b/src/main/kotlin/net/pterodactylus/sone/web/page/FreenetRequest.kt index ce2eacb..5729b25 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/page/FreenetRequest.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/page/FreenetRequest.kt @@ -18,15 +18,11 @@ package net.pterodactylus.sone.web.page import freenet.clients.http.* -import freenet.clients.http.SessionManager.* import freenet.support.api.* -import net.pterodactylus.sone.freenet.* import net.pterodactylus.util.web.* import java.net.* -import java.util.UUID.* open class FreenetRequest(uri: URI, method: Method, val httpRequest: HTTPRequest, - val toadletContext: ToadletContext, - val sessionManager: SessionManager + val toadletContext: ToadletContext ) : Request(uri, method) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/page/PageToadlet.kt b/src/main/kotlin/net/pterodactylus/sone/web/page/PageToadlet.kt index a1cddfe..32da313 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/page/PageToadlet.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/page/PageToadlet.kt @@ -45,10 +45,10 @@ class PageToadlet( override fun path() = pathPrefix + page.path override fun handleMethodGET(uri: URI, httpRequest: HTTPRequest, toadletContext: ToadletContext) = - handleRequest(FreenetRequest(uri, Method.GET, httpRequest, toadletContext, sessionManager)) + handleRequest(FreenetRequest(uri, Method.GET, httpRequest, toadletContext)) fun handleMethodPOST(uri: URI?, httpRequest: HTTPRequest?, toadletContext: ToadletContext?) = - handleRequest(FreenetRequest(uri!!, Method.POST, httpRequest!!, toadletContext!!, sessionManager)) + handleRequest(FreenetRequest(uri!!, Method.POST, httpRequest!!, toadletContext!!)) private fun handleRequest(pageRequest: FreenetRequest) { pageRequest.toadletContext.bucketFactory.makeBucket(-1).use { pageBucket -> diff --git a/src/main/kotlin/net/pterodactylus/sone/web/page/SoneRequest.kt b/src/main/kotlin/net/pterodactylus/sone/web/page/SoneRequest.kt index 703f953..fcfc63d 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/page/SoneRequest.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/page/SoneRequest.kt @@ -7,10 +7,10 @@ import net.pterodactylus.sone.web.* import net.pterodactylus.util.web.* import java.net.* -class SoneRequest(uri: URI, method: Method, httpRequest: HTTPRequest, toadletContext: ToadletContext, sessionManager: SessionManager, +class SoneRequest(uri: URI, method: Method, httpRequest: HTTPRequest, toadletContext: ToadletContext, val core: Core, val webInterface: WebInterface -) : FreenetRequest(uri, method, httpRequest, toadletContext, sessionManager) +) : FreenetRequest(uri, method, httpRequest, toadletContext) fun FreenetRequest.toSoneRequest(core: Core, webInterface: WebInterface) = - SoneRequest(uri, method, httpRequest, toadletContext, sessionManager, core, webInterface) + SoneRequest(uri, method, httpRequest, toadletContext, core, webInterface) diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePage.kt index 9734a03..bc00f99 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePage.kt @@ -91,7 +91,7 @@ open class SoneTemplatePage( private val String.urlEncode: String get() = URLEncoder.encode(this, "UTF-8") override fun isEnabled(toadletContext: ToadletContext) = - isEnabled(SoneRequest(toadletContext.uri, Method.GET, HTTPRequestImpl(toadletContext.uri, "GET"), toadletContext, webInterface.sessionManager, core, webInterface)) + isEnabled(SoneRequest(toadletContext.uri, Method.GET, HTTPRequestImpl(toadletContext.uri, "GET"), toadletContext, core, webInterface)) open fun isEnabled(soneRequest: SoneRequest) = when { requiresLogin && getCurrentSone(soneRequest.toadletContext) == null -> false diff --git a/src/test/java/net/pterodactylus/sone/main/DebugLoadersTest.java b/src/test/java/net/pterodactylus/sone/main/DebugLoadersTest.java index 72f0bf7..53391f6 100644 --- a/src/test/java/net/pterodactylus/sone/main/DebugLoadersTest.java +++ b/src/test/java/net/pterodactylus/sone/main/DebugLoadersTest.java @@ -70,7 +70,7 @@ public class DebugLoadersTest { HTTPRequest httpRequest = mock(HTTPRequest.class); ToadletContext toadletContext = mock(ToadletContext.class); SessionManager sessionManager = mock(SessionManager.class); - FreenetRequest request = new FreenetRequest(uri, method, httpRequest, toadletContext, sessionManager); + FreenetRequest request = new FreenetRequest(uri, method, httpRequest, toadletContext); OutputStream outputStream = new ByteArrayOutputStream(); Response response = new Response(outputStream); page.handleRequest(request, response); diff --git a/src/test/java/net/pterodactylus/sone/main/DefaultLoadersTest.java b/src/test/java/net/pterodactylus/sone/main/DefaultLoadersTest.java index d91e9e3..0afefe8 100644 --- a/src/test/java/net/pterodactylus/sone/main/DefaultLoadersTest.java +++ b/src/test/java/net/pterodactylus/sone/main/DefaultLoadersTest.java @@ -51,7 +51,7 @@ public class DefaultLoadersTest { HTTPRequest httpRequest = mock(HTTPRequest.class); ToadletContext toadletContext = mock(ToadletContext.class); SessionManager sessionManager = mock(SessionManager.class); - FreenetRequest request = new FreenetRequest(uri, method, httpRequest, toadletContext, sessionManager); + FreenetRequest request = new FreenetRequest(uri, method, httpRequest, toadletContext); OutputStream outputStream = new ByteArrayOutputStream(); Response response = new Response(outputStream); staticPage.handleRequest(request, response); diff --git a/src/test/kotlin/net/pterodactylus/sone/web/page/FreenetRequestTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/page/FreenetRequestTest.kt index 0c3fad9..feb9b0f 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/page/FreenetRequestTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/page/FreenetRequestTest.kt @@ -17,7 +17,7 @@ class FreenetRequestTest { private val httpRequest = mock(HTTPRequest::class.java) private val toadletContext = mock(ToadletContext::class.java) private val sessionManager = mock() - private val request = FreenetRequest(uri, method, httpRequest, toadletContext, sessionManager) + private val request = FreenetRequest(uri, method, httpRequest, toadletContext) @Test fun `uri is retained correctly`() { diff --git a/src/test/kotlin/net/pterodactylus/sone/web/page/SoneRequestTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/page/SoneRequestTest.kt index 5be6ff1..89b1d70 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/page/SoneRequestTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/page/SoneRequestTest.kt @@ -19,10 +19,9 @@ class SoneRequestTest { private val method = Method.GET private val httpRequest = Mockito.mock(HTTPRequest::class.java) private val toadletContext = Mockito.mock(ToadletContext::class.java) - private val sessionManager = mock() private val core = mock() private val webInterface = mock() - private val soneRequest = SoneRequest(uri, method, httpRequest, toadletContext, sessionManager, core, webInterface) + private val soneRequest = SoneRequest(uri, method, httpRequest, toadletContext, core, webInterface) @Test fun `freenet request properties are retained correctly`() { @@ -30,7 +29,6 @@ class SoneRequestTest { assertThat(soneRequest.method, equalTo(method)) assertThat(soneRequest.httpRequest, equalTo(httpRequest)) assertThat(soneRequest.toadletContext, equalTo(toadletContext)) - assertThat(soneRequest.sessionManager, equalTo(sessionManager)) } @Test @@ -45,13 +43,12 @@ class SoneRequestTest { @Test fun `freenet request is wrapped correctly`() { - val freenetRequest = FreenetRequest(uri, method, httpRequest, toadletContext, sessionManager) + val freenetRequest = FreenetRequest(uri, method, httpRequest, toadletContext) val wrappedSoneRequest = freenetRequest.toSoneRequest(core, webInterface) assertThat(wrappedSoneRequest.uri, equalTo(uri)) assertThat(wrappedSoneRequest.method, equalTo(method)) assertThat(wrappedSoneRequest.httpRequest, equalTo(httpRequest)) assertThat(wrappedSoneRequest.toadletContext, equalTo(toadletContext)) - assertThat(wrappedSoneRequest.sessionManager, equalTo(sessionManager)) assertThat(wrappedSoneRequest.core, sameInstance(core)) assertThat(wrappedSoneRequest.webInterface, sameInstance(webInterface)) } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest.kt index 07ae727..605ab33 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest.kt @@ -42,7 +42,6 @@ open class WebPageTest(pageSupplier: (WebInterface, Loaders, TemplateRenderer) - val core = webInterface.core val eventBus = mock() val preferences = Preferences(eventBus) - val sessionManager = mock() open val page by lazy { pageSupplier(webInterface, loaders, templateRenderer) } @@ -50,7 +49,6 @@ open class WebPageTest(pageSupplier: (WebInterface, Loaders, TemplateRenderer) - val freenetRequest = mock() init { - whenever(freenetRequest.sessionManager).thenReturn(sessionManager) whenever(freenetRequest.uri).thenReturn(mock()) } @@ -106,7 +104,6 @@ open class WebPageTest(pageSupplier: (WebInterface, Loaders, TemplateRenderer) - } private fun setupWebInterface() { - whenever(webInterface.sessionManager).thenReturn(sessionManager) whenever(webInterface.getCurrentSoneCreatingSession(eq(toadletContext))).thenReturn(currentSone) whenever(webInterface.getCurrentSone(eq(toadletContext), anyBoolean())).thenReturn(currentSone) whenever(webInterface.getCurrentSoneWithoutCreatingSession(eq(toadletContext))).thenReturn(currentSone) -- 2.7.4