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")
}
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")
}
}
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
}
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")
}
} 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")
}
}
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
}
}
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)
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")
}
}
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) {
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")
}
}
}
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;
protected final TemplateContext templateContext = new TemplateContext();
protected final HTTPRequest httpRequest = mock(HTTPRequest.class);
protected final Multimap<String, String> requestParameters = ArrayListMultimap.create();
+ protected final Map<String, String> requestParts = new HashMap<>();
protected final Map<String, String> requestHeaders = new HashMap<>();
private final Map<String, String> uploadedFilesNames = new HashMap<>();
private final Map<String, String> uploadedFilesContentTypes = new HashMap<>();
}
@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<String[]>() {
return requestParameters.get(invocation.<String>getArgument(0)).toArray(new String[0]);
}
});
+ when(httpRequest.isPartSet(anyString())).thenAnswer(new Answer<Boolean>() {
+ @Override
+ public Boolean answer(InvocationOnMock invocation) throws Throwable {
+ return requestParts.get(invocation.<String>getArgument(0)) != null;
+ }
+ });
+ when(httpRequest.getParts()).thenAnswer(new Answer<String[]>() {
+ @Override
+ public String[] answer(InvocationOnMock invocation) throws Throwable {
+ return requestParts.keySet().toArray(new String[requestParts.size()]);
+ }
+ });
when(httpRequest.getPartAsStringFailsafe(anyString(), anyInt())).thenAnswer(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
String parameter = invocation.getArgument(0);
int maxLength = invocation.getArgument(1);
- Collection<String> 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<String>() {
+ @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.<Integer>getArgument(1)) throw new SizeLimitExceededException();
+ return partValue;
}
});
when(httpRequest.hasParameters()).thenAnswer(new Answer<Boolean>() {
requestParameters.get(invocation.<String>getArgument(0)).iterator().next() != null;
}
});
- when(httpRequest.isPartSet(anyString())).thenAnswer(new Answer<Boolean>() {
- @Override
- public Boolean answer(InvocationOnMock invocation) throws Throwable {
- return requestParameters.containsKey(invocation.<String>getArgument(0)) &&
- requestParameters.get(invocation.<String>getArgument(0)).iterator().next() != null;
- }
- });
- when(httpRequest.getParts()).thenAnswer(new Answer<String[]>() {
- @Override
- public String[] answer(InvocationOnMock invocation) throws Throwable {
- return requestParameters.keySet().toArray(new String[requestParameters.size()]);
- }
- });
when(httpRequest.getHeader(anyString())).thenAnswer(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
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));
}
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
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.
protected val currentSone = deepMock<Sone>()
private val requestParameters = mutableMapOf<String, String>()
+ private val requestParts = mutableMapOf<String, String>()
private val localSones = mutableMapOf<String, Sone>()
private val remoteSones = mutableMapOf<String, Sone>()
private val newPosts = mutableMapOf<String, Post>()
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<Int>(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<Int>(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 {
requestParameters += key to value
}
+ protected fun addRequestPart(key: String, value: String) {
+ requestParts += key to value
+ }
+
protected fun addNotification(vararg notifications: Notification) {
this.notifications += notifications
}
private fun setupBookmarkRequest() {
request("", POST)
- addHttpRequestParameter("returnPage", "return-page.html")
- addHttpRequestParameter("post", "post-id")
+ addHttpRequestPart("returnPage", "return-page.html")
+ addHttpRequestPart("post", "post-id")
}
@Test
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")
@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")
}
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")
@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<Any>("return.html"))
}
@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")
}
@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<Any>(true))
}
@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<Sone>()
addLocalSone("sender-id", sender)
verifyRedirect("return.html") {
@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<Sone>()
addSone("recipient-id", recipient)
verifyRedirect("return.html") {
@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")
@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<Post>().apply { addPost("post-id", this) }
verifyRedirect("return.html") {
verify(core).createReply(currentSone, post, "new text")
@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<Post>().apply { addPost("post-id", this) }
verifyRedirect("return.html") {
@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<Sone>().apply { addLocalSone("sender-id", this) }
val post = mock<Post>().apply { addPost("post-id", this) }
verifyRedirect("return.html") {
@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<Any>(true))
assertThat(templateContext["returnPage"], equalTo<Any>("return.html"))
@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<Any>("return.html"))
- assertThat(templateContext["postId"], equalTo<Any>("post-id"))
- assertThat(templateContext["text"], equalTo<Any>("new text"))
- }
-
}
fun `sone is created and logged in`() {
addExistingOwnIdentities()
request("", POST)
- addHttpRequestParameter("identity", "own-id-3")
+ addHttpRequestPart("identity", "own-id-3")
val newSone = mock<Sone>()
whenever(core.createSone(ownIdentities_[2])).thenReturn(newSone)
verifyRedirect("index.html") {
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])
request("", POST)
whenever(sone.isLocal).thenReturn(false)
addAlbum("album-id", album)
- addHttpRequestParameter("album", "album-id")
+ addHttpRequestPart("album", "album-id")
verifyRedirect("noPermission.html")
}
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")
}
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)
}
whenever(parentAlbum.isRoot).thenReturn(false)
whenever(sone.rootAlbum).thenReturn(mock<Album>())
addAlbum("album-id", album)
- addHttpRequestParameter("album", "album-id")
+ addHttpRequestPart("album", "album-id")
verifyRedirect("imageBrowser.html?album=parent-id") {
verify(core).deleteAlbum(album)
}
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")
}
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)
}
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")
}
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)
}
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)
}
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<Any>(post))
assertThat(templateContext["returnPage"], equalTo<Any>("return.html"))
@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")
}
@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()
}
@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
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<Any>("reply-id"))
assertThat(templateContext["returnPage"], equalTo<Any>("return.html"))
@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")
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)
}
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)
}
@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)
}
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
@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()
}
@Test
fun `post request with invalid sone redirects to return page`() {
request("", POST)
- addHttpRequestParameter("returnPage", "return.html")
+ addHttpRequestPart("returnPage", "return.html")
verifyRedirect("return.html")
}
request("", POST)
val remoteSone = mock<Sone>()
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)
}
request("", POST)
whenever(sone.isLocal).thenReturn(false)
addAlbum("album-id", album)
- addHttpRequestParameter("album", "album-id")
+ addHttpRequestPart("album", "album-id")
verifyRedirect("noPermission.html")
}
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()
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()
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")
}
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")
request("", POST)
whenever(sone.isLocal).thenReturn(false)
addImage("image-id", image)
- addHttpRequestParameter("image", "image-id")
+ addHttpRequestPart("image", "image-id")
verifyRedirect("noPermission.html")
}
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()
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()
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<ImageTitleMustNotBeEmpty>()
verifyRedirect("emptyImageTitle.html") {
verify(core, never()).touchConfiguration()
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")
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")
@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
@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
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
private fun <T> 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))
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<Any>("new-field"))
assertThat(templateContext["duplicateFieldName"], equalTo<Any>(true))
@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
@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
@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
@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}")
}
request("", POST)
val sone = mock<Sone>()
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)
addSone("sone-id1", firstSone)
val secondSone = mock<Sone>()
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")
@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<Sone>())
@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")
}
@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")
}
@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)
}
@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<Sone>())
}
@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<Sone>()
addLocalSone("sone-id", sone)
- addHttpRequestParameter("returnPage", "return.html")
+ addHttpRequestPart("returnPage", "return.html")
verifyRedirect("return.html") {
verify(core).lockSone(sone)
}
@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])
}
@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])
@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<Post>(), mock<Post>())
addPost("post1", posts[0])
addPost("post3", posts[1])
@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<PostReply>(), mock<PostReply>())
addPostReply("reply1", replies[0])
addPostReply("reply3", replies[1])
@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<Sone>(), mock<Sone>())
addSone("sone1", sones[0])
addSone("sone3", sones[1])
@Test
fun `different type redirects to invalid page`() {
- addHttpRequestParameter("type", "foo")
+ addHttpRequestPart("type", "foo")
verifyRedirect("invalid.html")
}
private fun <T> 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))
}
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))
}
private fun <T> 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))
}
@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()
@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()
@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())
}
@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<Sone>()
addSone("sone-id", sone)
verifyRedirect("return.html") {
@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())
}
@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<Post>().apply { whenever(isLoaded).thenReturn(true) }
addPost("post-id", post)
verifyRedirect("return.html") {
@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")
}
@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")
@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())
@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())
@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")
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
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<Sone>())
verifyRedirect("return.html") {
verify(core, never()).unlockSone(any())
}
@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<Sone>().apply { whenever(isLocal).thenReturn(true) }
addLocalSone("local-sone", sone)
verifyRedirect("return.html") {
@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())
}
@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())
}
@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<Sone>()
addSone("sone-id", sone)
verifyRedirect("return.html") {
@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<Sone>())
addAlbum("parent-id", parentAlbum)
verifyRedirect("noPermission.html")
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")
}
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())
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<Modifier>()