From: David ‘Bombe’ Roden Date: Thu, 27 Apr 2017 18:44:09 +0000 (+0200) Subject: Actually differentiate between GET and POST parameters X-Git-Tag: 0.9.7^2~234 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=05fb821e72072bde52f383bdc5a988da67f66d0c;p=Sone.git Actually differentiate between GET and POST parameters --- diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteAlbumPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteAlbumPage.kt index 9e6bf38..8009c72 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteAlbumPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteAlbumPage.kt @@ -14,9 +14,8 @@ class DeleteAlbumPage(template: Template, webInterface: WebInterface): SoneTemplatePage("deleteAlbum.html", template, "Page.DeleteAlbum.Title", webInterface, true) { override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) { - val album = webInterface.core.getAlbum(request.httpRequest.getPartAsStringFailsafe("album", 36)) - templateContext["album"] = album ?: throw RedirectException("invalid.html") if (request.isPOST) { + val album = webInterface.core.getAlbum(request.httpRequest.getPartAsStringFailsafe("album", 36)) ?: throw RedirectException("invalid.html") if (!album.sone.isLocal) { throw RedirectException("noPermission.html") } @@ -26,6 +25,8 @@ class DeleteAlbumPage(template: Template, webInterface: WebInterface): webInterface.core.deleteAlbum(album) throw RedirectException(if (album.parent.isRoot) "imageBrowser.html?sone=${album.sone.id}" else "imageBrowser.html?album=${album.parent.id}") } + val album = webInterface.core.getAlbum(request.httpRequest.getParam("album")) + templateContext["album"] = album ?: throw RedirectException("invalid.html") } } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteImagePage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteImagePage.kt index 183705a..dc272be 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteImagePage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteImagePage.kt @@ -14,17 +14,21 @@ class DeleteImagePage(template: Template, webInterface: WebInterface): SoneTemplatePage("deleteImage.html", template, "Page.DeleteImage.Title", webInterface, true) { override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) { - val image = webInterface.core.getImage(request.httpRequest.getPartAsStringFailsafe("image", 36)) ?: throw RedirectException("invalid.html") - if (!image.sone.isLocal) { - throw RedirectException("noPermission.html") - } if (request.isPOST) { + val image = webInterface.core.getImage(request.httpRequest.getPartAsStringFailsafe("image", 36)) ?: throw RedirectException("invalid.html") + if (!image.sone.isLocal) { + throw RedirectException("noPermission.html") + } if (request.httpRequest.isPartSet("abortDelete")) { throw RedirectException("imageBrowser.html?image=${image.id}") } webInterface.core.deleteImage(image) throw RedirectException("imageBrowser.html?album=${image.album.id}") } + val image = webInterface.core.getImage(request.httpRequest.getParam("image")) ?: throw RedirectException("invalid.html") + if (!image.sone.isLocal) { + throw RedirectException("noPermission.html") + } templateContext["image"] = image } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeletePostPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeletePostPage.kt index 99ccb3a..c7931cf 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeletePostPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeletePostPage.kt @@ -14,9 +14,9 @@ class DeletePostPage(template: Template, webInterface: WebInterface): SoneTemplatePage("deletePost.html", template, "Page.DeletePost.Title", webInterface, true) { override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) { - val post = webInterface.core.getPost(request.httpRequest.getPartAsStringFailsafe("post", 36)).orNull() ?: throw RedirectException("noPermission.html") - val returnPage = request.httpRequest.getPartAsStringFailsafe("returnPage", 256) if (request.isPOST) { + val post = webInterface.core.getPost(request.httpRequest.getPartAsStringFailsafe("post", 36)).orNull() ?: throw RedirectException("noPermission.html") + val returnPage = request.httpRequest.getPartAsStringFailsafe("returnPage", 256) if (!post.sone.isLocal) { throw RedirectException("noPermission.html") } @@ -26,9 +26,12 @@ class DeletePostPage(template: Template, webInterface: WebInterface): } else if (request.httpRequest.isPartSet("abortDelete")) { throw RedirectException(returnPage) } + templateContext["post"] = post + templateContext["returnPage"] = returnPage + return } - templateContext["post"] = post - templateContext["returnPage"] = returnPage + templateContext["post"] = webInterface.core.getPost(request.httpRequest.getParam("post")).orNull() ?: throw RedirectException("noPermission.html") + templateContext["returnPage"] = request.httpRequest.getParam("returnPage") } } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteProfileFieldPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteProfileFieldPage.kt index 890ac74..5c1abdf 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteProfileFieldPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteProfileFieldPage.kt @@ -15,14 +15,15 @@ class DeleteProfileFieldPage(template: Template, webInterface: WebInterface): override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) { val currentSone = getCurrentSone(request.toadletContext)!! - val field = currentSone.profile.getFieldById(request.httpRequest.getPartAsStringFailsafe("field", 36)) ?: throw RedirectException("invalid.html") - templateContext["field"] = field if (request.isPOST) { + val field = currentSone.profile.getFieldById(request.httpRequest.getPartAsStringFailsafe("field", 36)) ?: throw RedirectException("invalid.html") if (request.httpRequest.getPartAsStringFailsafe("confirm", 4) == "true") { currentSone.profile = currentSone.profile.apply { removeField(field) } } throw RedirectException("editProfile.html#profile-fields") } + val field = currentSone.profile.getFieldById(request.httpRequest.getParam("field")) ?: throw RedirectException("invalid.html") + templateContext["field"] = field } } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteReplyPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteReplyPage.kt index f9c51a3..0b922b0 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteReplyPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/DeleteReplyPage.kt @@ -14,15 +14,13 @@ class DeleteReplyPage(template: Template, webInterface: WebInterface): SoneTemplatePage("deleteReply.html", template, "Page.DeleteReply.Title", webInterface, true) { override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) { - val replyId = request.httpRequest.getPartAsStringFailsafe("reply", 36) - templateContext["reply"] = replyId - val returnPage = request.httpRequest.getPartAsStringFailsafe("returnPage", 256) - templateContext["returnPage"] = returnPage if (request.isPOST) { + val replyId = request.httpRequest.getPartAsStringFailsafe("reply", 36) val reply = webInterface.core.getPostReply(replyId).orNull() ?: throw RedirectException("noPermission.html") if (!reply.sone.isLocal) { throw RedirectException("noPermission.html") } + val returnPage = request.httpRequest.getPartAsStringFailsafe("returnPage", 256) if (request.httpRequest.isPartSet("confirmDelete")) { webInterface.core.deleteReply(reply) throw RedirectException(returnPage) @@ -30,7 +28,12 @@ class DeleteReplyPage(template: Template, webInterface: WebInterface): if (request.httpRequest.isPartSet("abortDelete")) { throw RedirectException(returnPage) } + templateContext["reply"] = replyId + templateContext["returnPage"] = returnPage + return } + templateContext["reply"] = request.httpRequest.getParam("reply") + templateContext["returnPage"] = request.httpRequest.getParam("returnPage") } } diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/EditProfileFieldPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/EditProfileFieldPage.kt index 8109e3a..be681e3 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/EditProfileFieldPage.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/pages/EditProfileFieldPage.kt @@ -15,11 +15,11 @@ class EditProfileFieldPage(template: Template, webInterface: WebInterface): override fun handleRequest(request: FreenetRequest, templateContext: TemplateContext) { sessionProvider.getCurrentSone(request.toadletContext)!!.let { currentSone -> currentSone.profile.let { profile -> - val field = profile.getFieldById(request.httpRequest.getPartAsStringFailsafe("field", 36)) ?: throw RedirectException("invalid.html") if (request.isPOST) { if (request.httpRequest.getPartAsStringFailsafe("cancel", 4) == "true") { throw RedirectException("editProfile.html#profile-fields") } + val field = profile.getFieldById(request.httpRequest.getPartAsStringFailsafe("field", 36)) ?: throw RedirectException("invalid.html") request.httpRequest.getPartAsStringFailsafe("name", 256).let { name -> try { if (name != field.name) { @@ -29,10 +29,11 @@ class EditProfileFieldPage(template: Template, webInterface: WebInterface): throw RedirectException("editProfile.html#profile-fields") } catch (e: IllegalArgumentException) { templateContext["duplicateFieldName"] = true + return } } } - templateContext["field"] = field + templateContext["field"] = profile.getFieldById(request.httpRequest.getParam("field")) ?: throw RedirectException("invalid.html") } } } diff --git a/src/test/java/net/pterodactylus/sone/web/pages/WebPageTest.java b/src/test/java/net/pterodactylus/sone/web/pages/WebPageTest.java index 532c09a..f4936b7 100644 --- a/src/test/java/net/pterodactylus/sone/web/pages/WebPageTest.java +++ b/src/test/java/net/pterodactylus/sone/web/pages/WebPageTest.java @@ -24,9 +24,11 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.NoSuchElementException; import java.util.Set; import javax.annotation.Nonnull; +import javax.naming.SizeLimitExceededException; import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.core.Preferences; @@ -92,6 +94,7 @@ public abstract class WebPageTest { protected final TemplateContext templateContext = new TemplateContext(); protected final HTTPRequest httpRequest = mock(HTTPRequest.class); protected final Multimap requestParameters = ArrayListMultimap.create(); + protected final Map requestParts = new HashMap<>(); protected final Map requestHeaders = new HashMap<>(); private final Map uploadedFilesNames = new HashMap<>(); private final Map uploadedFilesContentTypes = new HashMap<>(); @@ -121,7 +124,7 @@ public abstract class WebPageTest { } @Before - public final void setupFreenetRequest() { + public final void setupFreenetRequest() throws SizeLimitExceededException { when(freenetRequest.getToadletContext()).thenReturn(toadletContext); when(freenetRequest.getHttpRequest()).thenReturn(httpRequest); when(httpRequest.getMultipleParam(anyString())).thenAnswer(new Answer() { @@ -130,13 +133,35 @@ public abstract class WebPageTest { return requestParameters.get(invocation.getArgument(0)).toArray(new String[0]); } }); + when(httpRequest.isPartSet(anyString())).thenAnswer(new Answer() { + @Override + public Boolean answer(InvocationOnMock invocation) throws Throwable { + return requestParts.get(invocation.getArgument(0)) != null; + } + }); + when(httpRequest.getParts()).thenAnswer(new Answer() { + @Override + public String[] answer(InvocationOnMock invocation) throws Throwable { + return requestParts.keySet().toArray(new String[requestParts.size()]); + } + }); when(httpRequest.getPartAsStringFailsafe(anyString(), anyInt())).thenAnswer(new Answer() { @Override public String answer(InvocationOnMock invocation) throws Throwable { String parameter = invocation.getArgument(0); int maxLength = invocation.getArgument(1); - Collection values = requestParameters.get(parameter); - return requestParameters.containsKey(parameter) ? values.iterator().next().substring(0, Math.min(maxLength, values.iterator().next().length())) : ""; + String value = requestParts.get(parameter); + return requestParts.containsKey(parameter) ? value.substring(0, Math.min(maxLength, value.length())) : ""; + } + }); + when(httpRequest.getPartAsStringThrowing(anyString(), anyInt())).thenAnswer(new Answer() { + @Override + public String answer(InvocationOnMock invocation) throws Throwable { + String partName = invocation.getArgument(0); + if (!requestParts.containsKey(partName)) throw new NoSuchElementException(); + String partValue = requestParts.get(partName); + if (partValue.length() > invocation.getArgument(1)) throw new SizeLimitExceededException(); + return partValue; } }); when(httpRequest.hasParameters()).thenAnswer(new Answer() { @@ -172,19 +197,6 @@ public abstract class WebPageTest { requestParameters.get(invocation.getArgument(0)).iterator().next() != null; } }); - when(httpRequest.isPartSet(anyString())).thenAnswer(new Answer() { - @Override - public Boolean answer(InvocationOnMock invocation) throws Throwable { - return requestParameters.containsKey(invocation.getArgument(0)) && - requestParameters.get(invocation.getArgument(0)).iterator().next() != null; - } - }); - when(httpRequest.getParts()).thenAnswer(new Answer() { - @Override - public String[] answer(InvocationOnMock invocation) throws Throwable { - return requestParameters.keySet().toArray(new String[requestParameters.size()]); - } - }); when(httpRequest.getHeader(anyString())).thenAnswer(new Answer() { @Override public String answer(InvocationOnMock invocation) throws Throwable { @@ -314,6 +326,10 @@ public abstract class WebPageTest { requestParameters.put(name, value); } + protected void addHttpRequestPart(String name, String value) { + requestParts.put(name, value); + } + protected void addPost(String postId, Post post) { when(core.getPost(postId)).thenReturn(Optional.fromNullable(post)); } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt index 490d770..e719c06 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageTest.kt @@ -1,6 +1,7 @@ package net.pterodactylus.sone.web.ajax import freenet.clients.http.ToadletContext +import freenet.support.SimpleReadOnlyArrayBucket import freenet.support.api.HTTPRequest import net.pterodactylus.sone.core.Core import net.pterodactylus.sone.core.ElementLoader @@ -18,7 +19,11 @@ import net.pterodactylus.sone.web.WebInterface import net.pterodactylus.sone.web.page.FreenetRequest import net.pterodactylus.util.notify.Notification import org.junit.Before +import org.mockito.ArgumentMatchers.anyInt import org.mockito.ArgumentMatchers.anyString +import java.util.NoSuchElementException +import javax.naming.SizeLimitExceededException +import kotlin.coroutines.experimental.EmptyCoroutineContext.plus /** * Base class for tests for any [JsonPage] implementations. @@ -37,6 +42,7 @@ open class JsonPageTest { protected val currentSone = deepMock() private val requestParameters = mutableMapOf() + private val requestParts = mutableMapOf() private val localSones = mutableMapOf() private val remoteSones = mutableMapOf() private val newPosts = mutableMapOf() @@ -81,6 +87,13 @@ open class JsonPageTest { fun setupHttpRequest() { whenever(httpRequest.getParam(anyString())).thenAnswer { requestParameters[it.getArgument(0)] ?: "" } whenever(httpRequest.getParam(anyString(), anyString())).thenAnswer { requestParameters[it.getArgument(0)] ?: it.getArgument(1) } + whenever(httpRequest.getPart(anyString())).thenAnswer { requestParts[it.getArgument(0)]?.let { SimpleReadOnlyArrayBucket(it.toByteArray()) } } + whenever(httpRequest.getPartAsBytesFailsafe(anyString(), anyInt())).thenAnswer { requestParts[it.getArgument(0)]?.toByteArray()?.copyOf(it.getArgument(1)) ?: ByteArray(0) } + whenever(httpRequest.getPartAsBytesThrowing(anyString(), anyInt())).thenAnswer { invocation -> requestParts[invocation.getArgument(0)]?.let { it.toByteArray().let { if (it.size > invocation.getArgument(1)) throw SizeLimitExceededException() else it } } ?: throw NoSuchElementException() } + whenever(httpRequest.getPartAsStringFailsafe(anyString(), anyInt())).thenAnswer { requestParts[it.getArgument(0)]?.substring(0, it.getArgument(1)) ?: "" } + whenever(httpRequest.getPartAsStringThrowing(anyString(), anyInt())).thenAnswer { invocation -> requestParts[invocation.getArgument(0)]?.let { if (it.length > invocation.getArgument(1)) throw SizeLimitExceededException() else it } ?: throw NoSuchElementException() } + whenever(httpRequest.getIntPart(anyString(), anyInt())).thenAnswer { invocation -> requestParts[invocation.getArgument(0)]?.toIntOrNull() ?: invocation.getArgument(1) } + whenever(httpRequest.isPartSet(anyString())).thenAnswer { it.getArgument(0) in requestParts } } protected fun Sone.mock(id: String, name: String, local: Boolean = false, time: Long, status: SoneStatus = idle) = apply { @@ -100,6 +113,10 @@ open class JsonPageTest { requestParameters += key to value } + protected fun addRequestPart(key: String, value: String) { + requestParts += key to value + } + protected fun addNotification(vararg notifications: Notification) { this.notifications += notifications } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/BookmarkPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/BookmarkPageTest.kt index b5d10cc..411d051 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/BookmarkPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/BookmarkPageTest.kt @@ -33,8 +33,8 @@ class BookmarkPageTest : WebPageTest() { private fun setupBookmarkRequest() { request("", POST) - addHttpRequestParameter("returnPage", "return-page.html") - addHttpRequestParameter("post", "post-id") + addHttpRequestPart("returnPage", "return-page.html") + addHttpRequestPart("post", "post-id") } @Test diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPageTest.kt index c4f2ee4..9851530 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPageTest.kt @@ -62,9 +62,9 @@ class CreateAlbumPageTest: WebPageTest() { fun `title and description are set correctly on the album`() { request("", POST) addAlbum("parent-id", parentAlbum) - addHttpRequestParameter("name", "new name") - addHttpRequestParameter("description", "new description") - addHttpRequestParameter("parent", "parent-id") + addHttpRequestPart("name", "new name") + addHttpRequestPart("description", "new description") + addHttpRequestPart("parent", "parent-id") verifyRedirect("imageBrowser.html?album=album-id") { verify(newAlbum).modify() verify(newAlbum.modify()).setTitle("new name") @@ -77,8 +77,8 @@ class CreateAlbumPageTest: WebPageTest() { @Test fun `root album is used if no parent is specified`() { request("", POST) - addHttpRequestParameter("name", "new name") - addHttpRequestParameter("description", "new description") + addHttpRequestPart("name", "new name") + addHttpRequestPart("description", "new description") verifyRedirect("imageBrowser.html?album=album-id") } @@ -86,16 +86,16 @@ class CreateAlbumPageTest: WebPageTest() { fun `empty album title redirects to error page`() { request("", POST) whenever(newAlbum.modify().update()).thenThrow(AlbumTitleMustNotBeEmpty::class.java) - addHttpRequestParameter("name", "new name") - addHttpRequestParameter("description", "new description") + addHttpRequestPart("name", "new name") + addHttpRequestPart("description", "new description") verifyRedirect("emptyAlbumTitle.html") } @Test fun `album description is filtered`() { request("", POST) - addHttpRequestParameter("name", "new name") - addHttpRequestParameter("description", "new http://localhost:12345/KSK@foo description") + addHttpRequestPart("name", "new name") + addHttpRequestPart("description", "new http://localhost:12345/KSK@foo description") addHttpRequestHeader("Host", "localhost:12345") verifyRedirect("imageBrowser.html?album=album-id") { verify(newAlbum.modify()).setDescription("new KSK@foo description") diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/CreatePostPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/CreatePostPageTest.kt index 45a2451..14f4fa3 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/CreatePostPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/CreatePostPageTest.kt @@ -33,7 +33,7 @@ class CreatePostPageTest: WebPageTest() { @Test fun `return page is set in template context`() { - addHttpRequestParameter("returnPage", "return.html") + addHttpRequestPart("returnPage", "return.html") page.processTemplate(freenetRequest, templateContext) assertThat(templateContext["returnPage"], equalTo("return.html")) } @@ -41,8 +41,8 @@ class CreatePostPageTest: WebPageTest() { @Test fun `post is created correctly`() { request("", POST) - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("text", "post text") + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("text", "post text") verifyRedirect("return.html") { verify(core).createPost(currentSone, absent(), "post text") } @@ -51,8 +51,8 @@ class CreatePostPageTest: WebPageTest() { @Test fun `creating an empty post is denied`() { request("", POST) - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("text", " ") + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("text", " ") page.processTemplate(freenetRequest, templateContext) assertThat(templateContext["errorTextEmpty"], equalTo(true)) } @@ -60,9 +60,9 @@ class CreatePostPageTest: WebPageTest() { @Test fun `a sender can be selected`() { request("", POST) - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("text", "post text") - addHttpRequestParameter("sender", "sender-id") + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("text", "post text") + addHttpRequestPart("sender", "sender-id") val sender = mock() addLocalSone("sender-id", sender) verifyRedirect("return.html") { @@ -73,9 +73,9 @@ class CreatePostPageTest: WebPageTest() { @Test fun `a recipient can be selected`() { request("", POST) - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("text", "post text") - addHttpRequestParameter("recipient", "recipient-id") + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("text", "post text") + addHttpRequestPart("recipient", "recipient-id") val recipient = mock() addSone("recipient-id", recipient) verifyRedirect("return.html") { @@ -86,8 +86,8 @@ class CreatePostPageTest: WebPageTest() { @Test fun `text is filtered correctly`() { request("", POST) - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("text", "post http://localhost:12345/KSK@foo text") + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("text", "post http://localhost:12345/KSK@foo text") addHttpRequestHeader("Host", "localhost:12345") verifyRedirect("return.html") { verify(core).createPost(currentSone, absent(), "post KSK@foo text") diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateReplyPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateReplyPageTest.kt index 052620a..01f3361 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateReplyPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateReplyPageTest.kt @@ -32,9 +32,9 @@ class CreateReplyPageTest: WebPageTest() { @Test fun `reply is created correctly`() { request("", POST) - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("post", "post-id") - addHttpRequestParameter("text", "new text") + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("post", "post-id") + addHttpRequestPart("text", "new text") val post = mock().apply { addPost("post-id", this) } verifyRedirect("return.html") { verify(core).createReply(currentSone, post, "new text") @@ -44,9 +44,9 @@ class CreateReplyPageTest: WebPageTest() { @Test fun `reply is filtered`() { request("", POST) - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("post", "post-id") - addHttpRequestParameter("text", "new http://localhost:12345/KSK@foo text") + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("post", "post-id") + addHttpRequestPart("text", "new http://localhost:12345/KSK@foo text") addHttpRequestHeader("Host", "localhost:12345") val post = mock().apply { addPost("post-id", this) } verifyRedirect("return.html") { @@ -57,10 +57,10 @@ class CreateReplyPageTest: WebPageTest() { @Test fun `reply is created with correct sender`() { request("", POST) - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("post", "post-id") - addHttpRequestParameter("text", "new text") - addHttpRequestParameter("sender", "sender-id") + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("post", "post-id") + addHttpRequestPart("text", "new text") + addHttpRequestPart("sender", "sender-id") val sender = mock().apply { addLocalSone("sender-id", this) } val post = mock().apply { addPost("post-id", this) } verifyRedirect("return.html") { @@ -71,9 +71,9 @@ class CreateReplyPageTest: WebPageTest() { @Test fun `empty text sets parameters in template contexty`() { request("", POST) - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("post", "post-id") - addHttpRequestParameter("text", " ") + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("post", "post-id") + addHttpRequestPart("text", " ") page.processTemplate(freenetRequest, templateContext) assertThat(templateContext["errorTextEmpty"], equalTo(true)) assertThat(templateContext["returnPage"], equalTo("return.html")) @@ -84,21 +84,10 @@ class CreateReplyPageTest: WebPageTest() { @Test fun `user is redirected to no permissions page if post does not exist`() { request("", POST) - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("post", "post-id") - addHttpRequestParameter("text", "new text") + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("post", "post-id") + addHttpRequestPart("text", "new text") verifyRedirect("noPermission.html") } - @Test - fun `get request stores parameters in template context`() { - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("post", "post-id") - addHttpRequestParameter("text", "new text") - page.processTemplate(freenetRequest, templateContext) - assertThat(templateContext["returnPage"], equalTo("return.html")) - assertThat(templateContext["postId"], equalTo("post-id")) - assertThat(templateContext["text"], equalTo("new text")) - } - } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateSonePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateSonePageTest.kt index f14d536..04ed0aa 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateSonePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateSonePageTest.kt @@ -86,7 +86,7 @@ class CreateSonePageTest: WebPageTest() { fun `sone is created and logged in`() { addExistingOwnIdentities() request("", POST) - addHttpRequestParameter("identity", "own-id-3") + addHttpRequestPart("identity", "own-id-3") val newSone = mock() whenever(core.createSone(ownIdentities_[2])).thenReturn(newSone) verifyRedirect("index.html") { @@ -106,7 +106,7 @@ class CreateSonePageTest: WebPageTest() { fun `if sone is not created user is still redirected to index`() { addExistingOwnIdentities() request("", POST) - addHttpRequestParameter("identity", "own-id-3") + addHttpRequestPart("identity", "own-id-3") whenever(core.createSone(ownIdentities_[2])).thenReturn(null) verifyRedirect("index.html") { verify(core).createSone(ownIdentities_[2]) diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteAlbumPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteAlbumPageTest.kt index 3efd109..3a1c504 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteAlbumPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteAlbumPageTest.kt @@ -78,7 +78,7 @@ class DeleteAlbumPageTest: WebPageTest() { request("", POST) whenever(sone.isLocal).thenReturn(false) addAlbum("album-id", album) - addHttpRequestParameter("album", "album-id") + addHttpRequestPart("album", "album-id") verifyRedirect("noPermission.html") } @@ -86,8 +86,8 @@ class DeleteAlbumPageTest: WebPageTest() { fun `post request with abort delete parameter set redirects to album browser`() { request("", POST) addAlbum("album-id", album) - addHttpRequestParameter("album", "album-id") - addHttpRequestParameter("abortDelete", "true") + addHttpRequestPart("album", "album-id") + addHttpRequestPart("abortDelete", "true") verifyRedirect("imageBrowser.html?album=album-id") } @@ -95,7 +95,7 @@ class DeleteAlbumPageTest: WebPageTest() { fun `album is deleted and page redirects to sone if parent album is root album`() { request("", POST) addAlbum("album-id", album) - addHttpRequestParameter("album", "album-id") + addHttpRequestPart("album", "album-id") verifyRedirect("imageBrowser.html?sone=sone-id") { verify(core).deleteAlbum(album) } @@ -107,7 +107,7 @@ class DeleteAlbumPageTest: WebPageTest() { whenever(parentAlbum.isRoot).thenReturn(false) whenever(sone.rootAlbum).thenReturn(mock()) addAlbum("album-id", album) - addHttpRequestParameter("album", "album-id") + addHttpRequestPart("album", "album-id") verifyRedirect("imageBrowser.html?album=parent-id") { verify(core).deleteAlbum(album) } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteImagePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteImagePageTest.kt index 78000a1..89e2879 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteImagePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteImagePageTest.kt @@ -74,8 +74,8 @@ class DeleteImagePageTest: WebPageTest() { fun `post request with abort delete flag set redirects to image browser`() { request("", POST) addImage("image-id", image) - addHttpRequestParameter("image", "image-id") - addHttpRequestParameter("abortDelete", "true") + addHttpRequestPart("image", "image-id") + addHttpRequestPart("abortDelete", "true") verifyRedirect("imageBrowser.html?image=image-id") } @@ -83,7 +83,7 @@ class DeleteImagePageTest: WebPageTest() { fun `post request deletes image and redirects to image browser`() { request("", POST) addImage("image-id", image) - addHttpRequestParameter("image", "image-id") + addHttpRequestPart("image", "image-id") verifyRedirect("imageBrowser.html?album=album-id") { verify(webInterface.core).deleteImage(image) } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/DeletePostPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/DeletePostPageTest.kt index 152e70d..c55f1a5 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/DeletePostPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/DeletePostPageTest.kt @@ -71,8 +71,8 @@ class DeletePostPageTest : WebPageTest() { request("", POST) whenever(sone.isLocal).thenReturn(false) addPost("post-id", post) - addHttpRequestParameter("post", "post-id") - addHttpRequestParameter("returnPage", "return.html") + addHttpRequestPart("post", "post-id") + addHttpRequestPart("returnPage", "return.html") verifyRedirect("noPermission.html") } @@ -80,9 +80,9 @@ class DeletePostPageTest : WebPageTest() { fun `post request with confirmation deletes post and redirects to return page`() { request("", POST) addPost("post-id", post) - addHttpRequestParameter("post", "post-id") - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("confirmDelete", "true") + addHttpRequestPart("post", "post-id") + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("confirmDelete", "true") verifyRedirect("return.html") { verify(core).deletePost(post) } @@ -92,9 +92,9 @@ class DeletePostPageTest : WebPageTest() { fun `post request with abort delete does not delete post and redirects to return page`() { request("", POST) addPost("post-id", post) - addHttpRequestParameter("post", "post-id") - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("abortDelete", "true") + addHttpRequestPart("post", "post-id") + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("abortDelete", "true") verifyRedirect("return.html") { verify(core, never()).deletePost(post) } @@ -104,8 +104,8 @@ class DeletePostPageTest : WebPageTest() { fun `post request without delete or abort sets post in template context`() { request("", POST) addPost("post-id", post) - addHttpRequestParameter("post", "post-id") - addHttpRequestParameter("returnPage", "return.html") + addHttpRequestPart("post", "post-id") + addHttpRequestPart("returnPage", "return.html") page.processTemplate(freenetRequest, templateContext) assertThat(templateContext["post"], equalTo(post)) assertThat(templateContext["returnPage"], equalTo("return.html")) diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteProfileFieldPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteProfileFieldPageTest.kt index ebfadcc..39bd8af 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteProfileFieldPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteProfileFieldPageTest.kt @@ -52,7 +52,7 @@ class DeleteProfileFieldPageTest: WebPageTest() { @Test fun `post request with invalid field name redirects to invalid page`() { request("", POST) - addHttpRequestParameter("field", "wrong-id") + addHttpRequestPart("field", "wrong-id") verifyRedirect("invalid.html") } @@ -67,7 +67,7 @@ class DeleteProfileFieldPageTest: WebPageTest() { @Test fun `post request without confirm redirects to edit profile page`() { request("", POST) - addHttpRequestParameter("field", field.id) + addHttpRequestPart("field", field.id) verifyRedirect("editProfile.html#profile-fields") { verify(currentSone, never()).profile = any() } @@ -76,8 +76,8 @@ class DeleteProfileFieldPageTest: WebPageTest() { @Test fun `post request with confirm removes field and redirects to edit profile page`() { request("", POST) - addHttpRequestParameter("field", field.id) - addHttpRequestParameter("confirm", "true") + addHttpRequestPart("field", field.id) + addHttpRequestPart("confirm", "true") verifyRedirect("editProfile.html#profile-fields") { assertThat(profile.getFieldById(field.id), nullValue()) verify(currentSone).profile = profile diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteReplyPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteReplyPageTest.kt index ff65e9d..7944321 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteReplyPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteReplyPageTest.kt @@ -57,8 +57,8 @@ class DeleteReplyPageTest : WebPageTest() { fun `post request without any action sets reply ID and return page in template context`() { request("", POST) addPostReply("reply-id", reply) - addHttpRequestParameter("reply", "reply-id") - addHttpRequestParameter("returnPage", "return.html") + addHttpRequestPart("reply", "reply-id") + addHttpRequestPart("returnPage", "return.html") page.processTemplate(freenetRequest, templateContext) assertThat(templateContext["reply"], equalTo("reply-id")) assertThat(templateContext["returnPage"], equalTo("return.html")) @@ -73,7 +73,7 @@ class DeleteReplyPageTest : WebPageTest() { @Test fun `trying to delete a reply from a non-local sone results in no permission page`() { request("", POST) - addHttpRequestParameter("reply", "reply-id") + addHttpRequestPart("reply", "reply-id") whenever(sone.isLocal).thenReturn(false) addPostReply("reply-id", reply) verifyRedirect("noPermission.html") @@ -83,9 +83,9 @@ class DeleteReplyPageTest : WebPageTest() { fun `confirming deletion of reply deletes the reply and redirects to return page`() { request("", POST) addPostReply("reply-id", reply) - addHttpRequestParameter("reply", "reply-id") - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("confirmDelete", "true") + addHttpRequestPart("reply", "reply-id") + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("confirmDelete", "true") verifyRedirect("return.html") { verify(core).deleteReply(reply) } @@ -95,9 +95,9 @@ class DeleteReplyPageTest : WebPageTest() { fun `aborting deletion of reply redirects to return page`() { request("", POST) addPostReply("reply-id", reply) - addHttpRequestParameter("reply", "reply-id") - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("abortDelete", "true") + addHttpRequestPart("reply", "reply-id") + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("abortDelete", "true") verifyRedirect("return.html") { verify(core, never()).deleteReply(reply) } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteSonePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteSonePageTest.kt index b94c3fa..8b04261 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteSonePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteSonePageTest.kt @@ -56,7 +56,7 @@ class DeleteSonePageTest : WebPageTest() { @Test fun `post request with delete confirmation deletes sone and redirects to index`() { request("", POST) - addHttpRequestParameter("deleteSone", "true") + addHttpRequestPart("deleteSone", "true") verifyRedirect("index.html") { verify(core).deleteSone(currentSone) } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/DismissNotificationPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/DismissNotificationPageTest.kt index b6524a8..1b482ce 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/DismissNotificationPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/DismissNotificationPageTest.kt @@ -6,6 +6,7 @@ import net.pterodactylus.sone.web.pages.WebPageTest import net.pterodactylus.sone.web.pages.DismissNotificationPage import net.pterodactylus.util.notify.Notification import net.pterodactylus.util.web.Method.GET +import net.pterodactylus.util.web.Method.POST import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo import org.junit.Test @@ -40,29 +41,29 @@ class DismissNotificationPageTest: WebPageTest() { @Test fun `get request with invalid notification ID redirects to return page`() { - request("", GET) - addHttpRequestParameter("returnPage", "return.html") + request("", POST) + addHttpRequestPart("returnPage", "return.html") verifyRedirect("return.html") } @Test fun `get request with non-dismissible notification never dismisses the notification but redirects to return page`() { - request("", GET) + request("", POST) addNotification("notification-id", notification) - addHttpRequestParameter("notification", "notification-id") - addHttpRequestParameter("returnPage", "return.html") + addHttpRequestPart("notification", "notification-id") + addHttpRequestPart("returnPage", "return.html") verifyRedirect("return.html") { verify(notification, never()).dismiss() } } @Test - fun `get request with dismissible notification dismisses the notification and redirects to return page`() { - request("", GET) + fun `post request with dismissible notification dismisses the notification and redirects to return page`() { + request("", POST) whenever(notification.isDismissable).thenReturn(true) addNotification("notification-id", notification) - addHttpRequestParameter("notification", "notification-id") - addHttpRequestParameter("returnPage", "return.html") + addHttpRequestPart("notification", "notification-id") + addHttpRequestPart("returnPage", "return.html") verifyRedirect("return.html") { verify(notification).dismiss() } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/DistrustPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/DistrustPageTest.kt index 45498c2..e5e672f 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/DistrustPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/DistrustPageTest.kt @@ -46,7 +46,7 @@ class DistrustPageTest: WebPageTest() { @Test fun `post request with invalid sone redirects to return page`() { request("", POST) - addHttpRequestParameter("returnPage", "return.html") + addHttpRequestPart("returnPage", "return.html") verifyRedirect("return.html") } @@ -55,8 +55,8 @@ class DistrustPageTest: WebPageTest() { request("", POST) val remoteSone = mock() addSone("remote-sone-id", remoteSone) - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("sone", "remote-sone-id") + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("sone", "remote-sone-id") verifyRedirect("return.html") { verify(core).distrustSone(currentSone, remoteSone) } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/EditAlbumPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/EditAlbumPageTest.kt index c9bd4fb..3583762 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/EditAlbumPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/EditAlbumPageTest.kt @@ -76,7 +76,7 @@ class EditAlbumPageTest: WebPageTest() { request("", POST) whenever(sone.isLocal).thenReturn(false) addAlbum("album-id", album) - addHttpRequestParameter("album", "album-id") + addHttpRequestPart("album", "album-id") verifyRedirect("noPermission.html") } @@ -84,8 +84,8 @@ class EditAlbumPageTest: WebPageTest() { fun `post request with move left requested moves album to the left and redirects to album browser`() { request("", POST) addAlbum("album-id", album) - addHttpRequestParameter("album", "album-id") - addHttpRequestParameter("moveLeft", "true") + addHttpRequestPart("album", "album-id") + addHttpRequestPart("moveLeft", "true") verifyRedirect("imageBrowser.html?album=parent-id") { verify(parentAlbum).moveAlbumUp(album) verify(core).touchConfiguration() @@ -96,8 +96,8 @@ class EditAlbumPageTest: WebPageTest() { fun `post request with move right requested moves album to the left and redirects to album browser`() { request("", POST) addAlbum("album-id", album) - addHttpRequestParameter("album", "album-id") - addHttpRequestParameter("moveRight", "true") + addHttpRequestPart("album", "album-id") + addHttpRequestPart("moveRight", "true") verifyRedirect("imageBrowser.html?album=parent-id") { verify(parentAlbum).moveAlbumDown(album) verify(core).touchConfiguration() @@ -108,7 +108,7 @@ class EditAlbumPageTest: WebPageTest() { fun `post request with empty album title redirects to empty album title page`() { request("", POST) addAlbum("album-id", album) - addHttpRequestParameter("album", "album-id") + addHttpRequestPart("album", "album-id") whenever(modifier.setTitle("")).thenThrow(AlbumTitleMustNotBeEmpty()) verifyRedirect("emptyAlbumTitle.html") } @@ -117,9 +117,9 @@ class EditAlbumPageTest: WebPageTest() { fun `post request with non-empty album title and description redirects to album browser`() { request("", POST) addAlbum("album-id", album) - addHttpRequestParameter("album", "album-id") - addHttpRequestParameter("title", "title") - addHttpRequestParameter("description", "description") + addHttpRequestPart("album", "album-id") + addHttpRequestPart("title", "title") + addHttpRequestPart("description", "description") verifyRedirect("imageBrowser.html?album=album-id") { verify(modifier).setTitle("title") verify(modifier).setDescription("description") diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/EditImagePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/EditImagePageTest.kt index 4a39cdf..ac710d5 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/EditImagePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/EditImagePageTest.kt @@ -75,7 +75,7 @@ class EditImagePageTest : WebPageTest() { request("", POST) whenever(sone.isLocal).thenReturn(false) addImage("image-id", image) - addHttpRequestParameter("image", "image-id") + addHttpRequestPart("image", "image-id") verifyRedirect("noPermission.html") } @@ -83,9 +83,9 @@ class EditImagePageTest : WebPageTest() { fun `post request with valid image and move left requested moves image left and redirects to return page`() { request("", POST) addImage("image-id", image) - addHttpRequestParameter("image", "image-id") - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("moveLeft", "true") + addHttpRequestPart("image", "image-id") + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("moveLeft", "true") verifyRedirect("return.html") { verify(album).moveImageUp(image) verify(core).touchConfiguration() @@ -96,9 +96,9 @@ class EditImagePageTest : WebPageTest() { fun `post request with valid image and move right requested moves image right and redirects to return page`() { request("", POST) addImage("image-id", image) - addHttpRequestParameter("image", "image-id") - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("moveRight", "true") + addHttpRequestPart("image", "image-id") + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("moveRight", "true") verifyRedirect("return.html") { verify(album).moveImageDown(image) verify(core).touchConfiguration() @@ -109,9 +109,9 @@ class EditImagePageTest : WebPageTest() { fun `post request with valid image but only whitespace in the title redirects to empty image title page`() { request("", POST) addImage("image-id", image) - addHttpRequestParameter("image", "image-id") - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("title", " ") + addHttpRequestPart("image", "image-id") + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("title", " ") whenever(modifier.update()).doThrow() verifyRedirect("emptyImageTitle.html") { verify(core, never()).touchConfiguration() @@ -122,10 +122,10 @@ class EditImagePageTest : WebPageTest() { fun `post request with valid image title and description modifies image and redirects to reutrn page`() { request("", POST) addImage("image-id", image) - addHttpRequestParameter("image", "image-id") - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("title", "Title") - addHttpRequestParameter("description", "Description") + addHttpRequestPart("image", "image-id") + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("title", "Title") + addHttpRequestPart("description", "Description") verifyRedirect("return.html") { verify(modifier).setTitle("Title") verify(modifier).setDescription("Description") @@ -138,11 +138,11 @@ class EditImagePageTest : WebPageTest() { fun `post request with image title and description modifies image with filtered description and redirects to return page`() { request("", POST) addImage("image-id", image) - addHttpRequestParameter("image", "image-id") - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("title", "Title") + addHttpRequestPart("image", "image-id") + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("title", "Title") addHttpRequestHeader("Host", "www.te.st") - addHttpRequestParameter("description", "Get http://www.te.st/KSK@GPL.txt") + addHttpRequestPart("description", "Get http://www.te.st/KSK@GPL.txt") verifyRedirect("return.html") { verify(modifier).setTitle("Title") verify(modifier).setDescription("Get KSK@GPL.txt") diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/EditProfileFieldPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/EditProfileFieldPageTest.kt index 83385d2..78b27b7 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/EditProfileFieldPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/EditProfileFieldPageTest.kt @@ -63,16 +63,16 @@ class EditProfileFieldPageTest : WebPageTest() { @Test fun `post request with cancel set redirects to profile edit page`() { request("", POST) - addHttpRequestParameter("field", field.id) - addHttpRequestParameter("cancel", "true") + addHttpRequestPart("field", field.id) + addHttpRequestPart("cancel", "true") verifyRedirect("editProfile.html#profile-fields") } @Test fun `post request with new name renames field and redirects to profile edit page`() { request("", POST) - addHttpRequestParameter("field", field.id) - addHttpRequestParameter("name", "New Name") + addHttpRequestPart("field", field.id) + addHttpRequestPart("name", "New Name") verifyRedirect("editProfile.html#profile-fields") { assertThat(field.name, equalTo("New Name")) verify(currentSone).profile = profile @@ -82,8 +82,8 @@ class EditProfileFieldPageTest : WebPageTest() { @Test fun `post request with same name does not modify field and redirects to profile edit page`() { request("", POST) - addHttpRequestParameter("field", field.id) - addHttpRequestParameter("name", "Name") + addHttpRequestPart("field", field.id) + addHttpRequestPart("name", "Name") verifyRedirect("editProfile.html#profile-fields") { assertThat(field.name, equalTo("Name")) verify(currentSone, never()).profile = profile @@ -94,8 +94,8 @@ class EditProfileFieldPageTest : WebPageTest() { fun `post request with same name as different field sets error condition in template`() { request("", POST) profile.addField("New Name") - addHttpRequestParameter("field", field.id) - addHttpRequestParameter("name", "New Name") + addHttpRequestPart("field", field.id) + addHttpRequestPart("name", "New Name") page.processTemplate(freenetRequest, templateContext) assertThat(field.name, equalTo("Name")) verify(currentSone, never()).profile = profile diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/EditProfilePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/EditProfilePageTest.kt index 282dbc2..274f0fe 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/EditProfilePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/EditProfilePageTest.kt @@ -91,8 +91,8 @@ class EditProfilePageTest : WebPageTest() { private fun verifySingleFieldCanBeChanged(fieldName: String, newValue: T, expectedValue: T = newValue, fieldAccessor: () -> T) { request("", POST) - addHttpRequestParameter("save-profile", "true") - addHttpRequestParameter(fieldName, newValue.toString()) + addHttpRequestPart("save-profile", "true") + addHttpRequestPart(fieldName, newValue.toString()) verifyRedirect("editProfile.html") { verify(core).touchConfiguration() assertThat(fieldAccessor(), equalTo(expectedValue)) @@ -157,8 +157,8 @@ class EditProfilePageTest : WebPageTest() { fun `adding a field with a duplicate name sets error in template context`() { request("", POST) profile.addField("new-field") - addHttpRequestParameter("add-field", "true") - addHttpRequestParameter("field-name", "new-field") + addHttpRequestPart("add-field", "true") + addHttpRequestPart("field-name", "new-field") page.processTemplate(freenetRequest, templateContext) assertThat(templateContext["fieldName"], equalTo("new-field")) assertThat(templateContext["duplicateFieldName"], equalTo(true)) @@ -168,8 +168,8 @@ class EditProfilePageTest : WebPageTest() { @Test fun `adding a field with a new name sets adds field to profile and redirects to profile edit page`() { request("", POST) - addHttpRequestParameter("add-field", "true") - addHttpRequestParameter("field-name", "new-field") + addHttpRequestPart("add-field", "true") + addHttpRequestPart("field-name", "new-field") verifyRedirect("editProfile.html#profile-fields") { assertThat(profile.getFieldByName("new-field"), notNullValue()) verify(currentSone).profile = profile @@ -180,14 +180,14 @@ class EditProfilePageTest : WebPageTest() { @Test fun `deleting a field redirects to delete field page`() { request("", POST) - addHttpRequestParameter("delete-field-${firstField.id}", "true") + addHttpRequestPart("delete-field-${firstField.id}", "true") verifyRedirect("deleteProfileField.html?field=${firstField.id}") } @Test fun `moving a field up moves the field up and redirects to the edit profile page`() { request("", POST) - addHttpRequestParameter("move-up-field-${secondField.id}", "true") + addHttpRequestPart("move-up-field-${secondField.id}", "true") verifyRedirect("editProfile.html#profile-fields") { assertThat(profile.fields, contains(secondField, firstField)) verify(currentSone).profile = profile @@ -197,14 +197,14 @@ class EditProfilePageTest : WebPageTest() { @Test fun `moving an invalid field up does not redirect`() { request("", POST) - addHttpRequestParameter("move-up-field-foo", "true") + addHttpRequestPart("move-up-field-foo", "true") page.processTemplate(freenetRequest, templateContext) } @Test fun `moving a field down moves the field down and redirects to the edit profile page`() { request("", POST) - addHttpRequestParameter("move-down-field-${firstField.id}", "true") + addHttpRequestPart("move-down-field-${firstField.id}", "true") verifyRedirect("editProfile.html#profile-fields") { assertThat(profile.fields, contains(secondField, firstField)) verify(currentSone).profile = profile @@ -214,14 +214,14 @@ class EditProfilePageTest : WebPageTest() { @Test fun `moving an invalid field down does not redirect`() { request("", POST) - addHttpRequestParameter("move-down-field-foo", "true") + addHttpRequestPart("move-down-field-foo", "true") page.processTemplate(freenetRequest, templateContext) } @Test fun `editing a field redirects to the edit profile page`() { request("", POST) - addHttpRequestParameter("edit-field-${firstField.id}", "true") + addHttpRequestPart("edit-field-${firstField.id}", "true") verifyRedirect("editProfileField.html?field=${firstField.id}") } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/FollowSonePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/FollowSonePageTest.kt index 0cd8444..a95e34c 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/FollowSonePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/FollowSonePageTest.kt @@ -50,8 +50,8 @@ class FollowSonePageTest : WebPageTest() { request("", POST) val sone = mock() addSone("sone-id", sone) - addHttpRequestParameter("sone", "sone-id") - addHttpRequestParameter("returnPage", "return.html") + addHttpRequestPart("sone", "sone-id") + addHttpRequestPart("returnPage", "return.html") verifyRedirect("return.html") { verify(core).followSone(currentSone, "sone-id") verify(core).markSoneKnown(sone) @@ -65,8 +65,8 @@ class FollowSonePageTest : WebPageTest() { addSone("sone-id1", firstSone) val secondSone = mock() addSone("sone-id2", secondSone) - addHttpRequestParameter("sone", "sone-id1,sone-id2") - addHttpRequestParameter("returnPage", "return.html") + addHttpRequestPart("sone", "sone-id1,sone-id2") + addHttpRequestPart("returnPage", "return.html") verifyRedirect("return.html") { verify(core).followSone(currentSone, "sone-id1") verify(core).followSone(currentSone, "sone-id2") @@ -78,8 +78,8 @@ class FollowSonePageTest : WebPageTest() { @Test fun `a non-existing sone is not followed`() { request("", POST) - addHttpRequestParameter("sone", "sone-id") - addHttpRequestParameter("returnPage", "return.html") + addHttpRequestPart("sone", "sone-id") + addHttpRequestPart("returnPage", "return.html") verifyRedirect("return.html") { verify(core, never()).followSone(ArgumentMatchers.eq(currentSone), anyString()) verify(core, never()).markSoneKnown(any()) diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/LikePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/LikePageTest.kt index 10baf5e..26bd37e 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/LikePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/LikePageTest.kt @@ -26,9 +26,9 @@ class LikePageTest : WebPageTest() { @Test fun `post request with post id likes post and redirects to return page`() { request("", POST) - addHttpRequestParameter("type", "post") - addHttpRequestParameter("post", "post-id") - addHttpRequestParameter("returnPage", "return.html") + addHttpRequestPart("type", "post") + addHttpRequestPart("post", "post-id") + addHttpRequestPart("returnPage", "return.html") verifyRedirect("return.html") { verify(currentSone).addLikedPostId("post-id") } @@ -37,9 +37,9 @@ class LikePageTest : WebPageTest() { @Test fun `post request with reply id likes post and redirects to return page`() { request("", POST) - addHttpRequestParameter("type", "reply") - addHttpRequestParameter("reply", "reply-id") - addHttpRequestParameter("returnPage", "return.html") + addHttpRequestPart("type", "reply") + addHttpRequestPart("reply", "reply-id") + addHttpRequestPart("returnPage", "return.html") verifyRedirect("return.html") { verify(currentSone).addLikedReplyId("reply-id") } @@ -48,8 +48,8 @@ class LikePageTest : WebPageTest() { @Test fun `post request with invalid likes redirects to return page`() { request("", POST) - addHttpRequestParameter("type", "foo") - addHttpRequestParameter("returnPage", "return.html") + addHttpRequestPart("type", "foo") + addHttpRequestPart("returnPage", "return.html") verifyRedirect("return.html") { verifyNoMoreInteractions(currentSone) } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/LockSonePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/LockSonePageTest.kt index 9a6876c..f58ea97 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/LockSonePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/LockSonePageTest.kt @@ -20,7 +20,7 @@ class LockSonePageTest : WebPageTest() { @Test fun `locking an invalid local sone redirects to return page`() { - addHttpRequestParameter("returnPage", "return.html") + addHttpRequestPart("returnPage", "return.html") verifyRedirect("return.html") { verify(core, never()).lockSone(any()) } @@ -28,10 +28,10 @@ class LockSonePageTest : WebPageTest() { @Test fun `locking an valid local sone locks the sone and redirects to return page`() { - addHttpRequestParameter("sone", "sone-id") + addHttpRequestPart("sone", "sone-id") val sone = mock() addLocalSone("sone-id", sone) - addHttpRequestParameter("returnPage", "return.html") + addHttpRequestPart("returnPage", "return.html") verifyRedirect("return.html") { verify(core).lockSone(sone) } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/LoginPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/LoginPageTest.kt index 0da820c..7832f68 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/LoginPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/LoginPageTest.kt @@ -88,7 +88,7 @@ class LoginPageTest : WebPageTest() { @Test fun `post request with valid sone logs in the sone and redirects to index page`() { request("", POST) - addHttpRequestParameter("sone-id", "sone2") + addHttpRequestPart("sone-id", "sone2") verifyRedirect("index.html") { verify(webInterface).setCurrentSone(toadletContext, sones[1]) } @@ -97,7 +97,7 @@ class LoginPageTest : WebPageTest() { @Test fun `post request with valid sone and target redirects to target page`() { request("", POST) - addHttpRequestParameter("sone-id", "sone2") + addHttpRequestPart("sone-id", "sone2") addHttpRequestParameter("target", "foo.html") verifyRedirect("foo.html") { verify(webInterface).setCurrentSone(toadletContext, sones[1]) diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/MarkAsKnownPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/MarkAsKnownPageTest.kt index cc19b60..dac31ff 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/MarkAsKnownPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/MarkAsKnownPageTest.kt @@ -20,9 +20,9 @@ class MarkAsKnownPageTest : WebPageTest() { @Test fun `posts can be marked as known`() { - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("type", "post") - addHttpRequestParameter("id", "post1 post2 post3") + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("type", "post") + addHttpRequestPart("id", "post1 post2 post3") val posts = listOf(mock(), mock()) addPost("post1", posts[0]) addPost("post3", posts[1]) @@ -34,9 +34,9 @@ class MarkAsKnownPageTest : WebPageTest() { @Test fun `replies can be marked as known`() { - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("type", "reply") - addHttpRequestParameter("id", "reply1 reply2 reply3") + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("type", "reply") + addHttpRequestPart("id", "reply1 reply2 reply3") val replies = listOf(mock(), mock()) addPostReply("reply1", replies[0]) addPostReply("reply3", replies[1]) @@ -48,9 +48,9 @@ class MarkAsKnownPageTest : WebPageTest() { @Test fun `sones can be marked as known`() { - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("type", "sone") - addHttpRequestParameter("id", "sone1 sone2 sone3") + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("type", "sone") + addHttpRequestPart("id", "sone1 sone2 sone3") val sones = listOf(mock(), mock()) addSone("sone1", sones[0]) addSone("sone3", sones[1]) @@ -62,7 +62,7 @@ class MarkAsKnownPageTest : WebPageTest() { @Test fun `different type redirects to invalid page`() { - addHttpRequestParameter("type", "foo") + addHttpRequestPart("type", "foo") verifyRedirect("invalid.html") } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt index 950a3fe..f239e3e 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt @@ -95,9 +95,9 @@ class OptionsPageTest : WebPageTest() { private fun verifyThatOptionCanBeSet(option: String, setValue: Any?, expectedValue: T, getter: () -> T) { request("", POST) - addHttpRequestParameter(option, setValue.toString()) - addHttpRequestParameter("show-custom-avatars", "ALWAYS") - addHttpRequestParameter("load-linked-images", "ALWAYS") + addHttpRequestPart("show-custom-avatars", "ALWAYS") + addHttpRequestPart("load-linked-images", "ALWAYS") + addHttpRequestPart(option, setValue.toString()) verifyRedirect("options.html") { assertThat(getter(), equalTo(expectedValue)) } @@ -141,7 +141,7 @@ class OptionsPageTest : WebPageTest() { private fun verifyThatWrongValueForPreferenceIsDetected(name: String, value: String) { unsetCurrentSone() request("", POST) - addHttpRequestParameter(name, value) + addHttpRequestPart(name, value) page.handleRequest(freenetRequest, templateContext) assertThat(templateContext["fieldErrors"] as Iterable<*>, hasItem(name)) } @@ -149,7 +149,7 @@ class OptionsPageTest : WebPageTest() { private fun verifyThatPreferencesCanBeSet(name: String, setValue: String?, expectedValue: T, getter: () -> T) { unsetCurrentSone() request("", POST) - addHttpRequestParameter(name, setValue) + addHttpRequestPart(name, setValue) verifyRedirect("options.html") { assertThat(getter(), equalTo(expectedValue)) } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/RescuePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/RescuePageTest.kt index db6903e..cbc8968 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/RescuePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/RescuePageTest.kt @@ -46,7 +46,7 @@ class RescuePageTest : WebPageTest() { @Test fun `post request with fetch and invalid edition starts next fetch`() { request("", POST) - addHttpRequestParameter("fetch", "true") + addHttpRequestPart("fetch", "true") verifyRedirect("rescue.html") { verify(soneRescuer, never()).setEdition(anyLong()) verify(soneRescuer).startNextFetch() @@ -56,8 +56,8 @@ class RescuePageTest : WebPageTest() { @Test fun `post request with fetch and valid edition sets edition and starts next fetch`() { request("", POST) - addHttpRequestParameter("fetch", "true") - addHttpRequestParameter("edition", "123") + addHttpRequestPart("fetch", "true") + addHttpRequestPart("edition", "123") verifyRedirect("rescue.html") { verify(soneRescuer).setEdition(123L) verify(soneRescuer).startNextFetch() diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/TrustPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/TrustPageTest.kt index 6947f63..3aa6ba2 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/TrustPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/TrustPageTest.kt @@ -27,8 +27,8 @@ class TrustPageTest : WebPageTest() { @Test fun `post request with missing sone redirects to return page`() { request("", POST) - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("sone", "sone-id") + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("sone", "sone-id") verifyRedirect("return.html") { verify(core, never()).trustSone(eq(currentSone), any()) } @@ -37,8 +37,8 @@ class TrustPageTest : WebPageTest() { @Test fun `post request with existing sone trusts the identity and redirects to return page`() { request("", POST) - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("sone", "sone-id") + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("sone", "sone-id") val sone = mock() addSone("sone-id", sone) verifyRedirect("return.html") { diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/UnbookmarkPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/UnbookmarkPageTest.kt index b18211f..be451b5 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/UnbookmarkPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/UnbookmarkPageTest.kt @@ -43,8 +43,8 @@ class UnbookmarkPageTest : WebPageTest() { @Test fun `post request does not unbookmark not-present post but redirects to return page`() { request("", POST) - addHttpRequestParameter("post", "post-id") - addHttpRequestParameter("returnPage", "return.html") + addHttpRequestPart("post", "post-id") + addHttpRequestPart("returnPage", "return.html") verifyRedirect("return.html") { verify(core, never()).unbookmarkPost(any()) } @@ -53,8 +53,8 @@ class UnbookmarkPageTest : WebPageTest() { @Test fun `post request unbookmarks present post and redirects to return page`() { request("", POST) - addHttpRequestParameter("post", "post-id") - addHttpRequestParameter("returnPage", "return.html") + addHttpRequestPart("post", "post-id") + addHttpRequestPart("returnPage", "return.html") val post = mock().apply { whenever(isLoaded).thenReturn(true) } addPost("post-id", post) verifyRedirect("return.html") { diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/UnfollowSonePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/UnfollowSonePageTest.kt index 5bcd65f..e7e6786 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/UnfollowSonePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/UnfollowSonePageTest.kt @@ -22,8 +22,8 @@ class UnfollowSonePageTest : WebPageTest() { @Test fun `post request unfollows a single sone and redirects to return page`() { request("", POST) - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("sone", "sone-id") + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("sone", "sone-id") verifyRedirect("return.html") { verify(core).unfollowSone(currentSone, "sone-id") } @@ -32,8 +32,8 @@ class UnfollowSonePageTest : WebPageTest() { @Test fun `post request unfollows two sones and redirects to return page`() { request("", POST) - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("sone", "sone-id1, sone-id2") + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("sone", "sone-id1, sone-id2") verifyRedirect("return.html") { verify(core).unfollowSone(currentSone, "sone-id1") verify(core).unfollowSone(currentSone, "sone-id2") diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/UnlikePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/UnlikePageTest.kt index 0de0308..7059057 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/UnlikePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/UnlikePageTest.kt @@ -27,7 +27,7 @@ class UnlikePageTest : WebPageTest() { @Test fun `post request does not remove any likes but redirects`() { request("", POST) - addHttpRequestParameter("returnPage", "return.html") + addHttpRequestPart("returnPage", "return.html") verifyRedirect("return.html") { verify(currentSone, never()).removeLikedPostId(any()) verify(currentSone, never()).removeLikedReplyId(any()) @@ -37,9 +37,9 @@ class UnlikePageTest : WebPageTest() { @Test fun `post request removes post like and redirects`() { request("", POST) - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("type", "post") - addHttpRequestParameter("id", "post-id") + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("type", "post") + addHttpRequestPart("id", "post-id") verifyRedirect("return.html") { verify(currentSone, never()).removeLikedPostId("post-id") verify(currentSone, never()).removeLikedReplyId(any()) @@ -49,9 +49,9 @@ class UnlikePageTest : WebPageTest() { @Test fun `post request removes reply like and redirects`() { request("", POST) - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("type", "reply") - addHttpRequestParameter("id", "reply-id") + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("type", "reply") + addHttpRequestPart("id", "reply-id") verifyRedirect("return.html") { verify(currentSone, never()).removeLikedPostId(any()) verify(currentSone, never()).removeLikedReplyId("reply-id") diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/UnlockSonePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/UnlockSonePageTest.kt index 390c1fc..a29b372 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/UnlockSonePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/UnlockSonePageTest.kt @@ -4,6 +4,7 @@ import net.pterodactylus.sone.data.Sone import net.pterodactylus.sone.test.mock import net.pterodactylus.sone.test.whenever import net.pterodactylus.sone.web.pages.UnlockSonePage +import net.pterodactylus.util.web.Method.POST import org.junit.Test import org.mockito.ArgumentMatchers.any import org.mockito.Mockito.never @@ -19,26 +20,29 @@ class UnlockSonePageTest : WebPageTest() { override fun getPage() = page @Test - fun `get request without sone redirects to return page`() { - addHttpRequestParameter("returnPage", "return.html") + fun `post request without sone redirects to return page`() { + request("", POST) + addHttpRequestPart("returnPage", "return.html") verifyRedirect("return.html") { verify(core, never()).unlockSone(any()) } } @Test - fun `get request without invalid local sone does not unlock any sone and redirects to return page`() { - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("sone", "invalid-sone") + fun `post request without invalid local sone does not unlock any sone and redirects to return page`() { + request("", POST) + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("sone", "invalid-sone") verifyRedirect("return.html") { verify(core, never()).unlockSone(any()) } } @Test - fun `get request without remote sone does not unlock any sone and redirects to return page`() { - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("sone", "remote-sone") + fun `post request without remote sone does not unlock any sone and redirects to return page`() { + request("", POST) + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("sone", "remote-sone") addSone("remote-sone", mock()) verifyRedirect("return.html") { verify(core, never()).unlockSone(any()) @@ -46,9 +50,10 @@ class UnlockSonePageTest : WebPageTest() { } @Test - fun `get request with local sone unlocks sone and redirects to return page`() { - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("sone", "local-sone") + fun `post request with local sone unlocks sone and redirects to return page`() { + request("", POST) + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("sone", "local-sone") val sone = mock().apply { whenever(isLocal).thenReturn(true) } addLocalSone("local-sone", sone) verifyRedirect("return.html") { diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/UntrustPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/UntrustPageTest.kt index 0a59453..c6d0c55 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/UntrustPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/UntrustPageTest.kt @@ -28,7 +28,7 @@ class UntrustPageTest : WebPageTest() { @Test fun `post request without sone parameter does not untrust but redirects`() { request("", POST) - addHttpRequestParameter("returnPage", "return.html") + addHttpRequestPart("returnPage", "return.html") verifyRedirect("return.html") { verify(core, never()).untrustSone(eq(currentSone), any()) } @@ -37,8 +37,8 @@ class UntrustPageTest : WebPageTest() { @Test fun `post request with invalid sone parameter does not untrust but redirects`() { request("", POST) - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("sone", "no-sone") + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("sone", "no-sone") verifyRedirect("return.html") { verify(core, never()).untrustSone(eq(currentSone), any()) } @@ -47,8 +47,8 @@ class UntrustPageTest : WebPageTest() { @Test fun `post request with valid sone parameter untrusts and redirects`() { request("", POST) - addHttpRequestParameter("returnPage", "return.html") - addHttpRequestParameter("sone", "sone-id") + addHttpRequestPart("returnPage", "return.html") + addHttpRequestPart("sone", "sone-id") val sone = mock() addSone("sone-id", sone) verifyRedirect("return.html") { diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/UploadImagePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/UploadImagePageTest.kt index 232601b..38c5fe1 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/UploadImagePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/UploadImagePageTest.kt @@ -46,7 +46,7 @@ class UploadImagePageTest : WebPageTest() { @Test fun `post request with parent that is not the current sone results in no permission error page`() { request("", POST) - addHttpRequestParameter("parent", "parent-id") + addHttpRequestPart("parent", "parent-id") whenever(parentAlbum.sone).thenReturn(mock()) addAlbum("parent-id", parentAlbum) verifyRedirect("noPermission.html") @@ -56,8 +56,8 @@ class UploadImagePageTest : WebPageTest() { fun `post request with empty name redirects to error page`() { request("", POST) addAlbum("parent-id", parentAlbum) - addHttpRequestParameter("parent", "parent-id") - addHttpRequestParameter("title", " ") + addHttpRequestPart("parent", "parent-id") + addHttpRequestPart("title", " ") verifyRedirect("emptyImageTitle.html") } @@ -65,8 +65,8 @@ class UploadImagePageTest : WebPageTest() { fun `uploading an invalid image results in no redirect and message set in template context`() { request("", POST) addAlbum("parent-id", parentAlbum) - addHttpRequestParameter("parent", "parent-id") - addHttpRequestParameter("title", "title") + addHttpRequestPart("parent", "parent-id") + addHttpRequestPart("title", "title") addUploadedFile("image", "image.png", "image/png", "no-image.png") page.handleRequest(freenetRequest, templateContext) verify(core, never()).createTemporaryImage(any(), any()) @@ -77,9 +77,9 @@ class UploadImagePageTest : WebPageTest() { fun `uploading a valid image uploads image and redirects to album browser`() { request("", POST) addAlbum("parent-id", parentAlbum) - addHttpRequestParameter("parent", "parent-id") - addHttpRequestParameter("title", "Title") - addHttpRequestParameter("description", "Description") + addHttpRequestPart("parent", "parent-id") + addHttpRequestPart("title", "Title") + addHttpRequestPart("description", "Description") addUploadedFile("image", "image.png", "image/png", "image.png") val temporaryImage = TemporaryImage("temp-image") val imageModifier = mockBuilder()