From: David ‘Bombe’ Roden Date: Sat, 21 Jan 2017 19:38:28 +0000 (+0100) Subject: Add unit test for untrust page X-Git-Tag: 0.9.7^2~323 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=1d15e8bc128c8368337674064d11dccbf6207195;p=Sone.git Add unit test for untrust page --- diff --git a/src/test/kotlin/net/pterodactylus/sone/web/UntrustPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/UntrustPageTest.kt new file mode 100644 index 0000000..166fd34 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/web/UntrustPageTest.kt @@ -0,0 +1,58 @@ +package net.pterodactylus.sone.web + +import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.test.mock +import net.pterodactylus.util.web.Method.POST +import org.junit.Test +import org.mockito.ArgumentMatchers.any +import org.mockito.ArgumentMatchers.eq +import org.mockito.Mockito.never +import org.mockito.Mockito.verify + +/** + * Unit test for [UntrustPage]. + */ +class UntrustPageTest : WebPageTest() { + + private val page = UntrustPage(template, webInterface) + + override fun getPage() = page + + @Test + fun `get request does not redirect`() { + page.handleRequest(freenetRequest, templateContext) + verify(core, never()).untrustSone(eq(currentSone), any()) + } + + @Test + fun `post request without sone parameter does not untrust but redirects`() { + request("", POST) + addHttpRequestParameter("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") + 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") + val sone = mock() + addSone("sone-id", sone) + verifyRedirect("return.html") { + verify(core).untrustSone(currentSone, sone) + } + } + +}