From 66cbbc495bb21fb1dd96c0e4dea6014bc16fb6a7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 19 Jan 2017 21:09:32 +0100 Subject: [PATCH] Add unit test for trust page --- .../net/pterodactylus/sone/web/TrustPageTest.kt | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/test/kotlin/net/pterodactylus/sone/web/TrustPageTest.kt diff --git a/src/test/kotlin/net/pterodactylus/sone/web/TrustPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/TrustPageTest.kt new file mode 100644 index 0000000..a29c0c2 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/web/TrustPageTest.kt @@ -0,0 +1,48 @@ +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 [TrustPage]. + */ +class TrustPageTest : WebPageTest() { + + private val page = TrustPage(template, webInterface) + + override fun getPage() = page + + @Test + fun `get method does not redirect`() { + page.handleRequest(freenetRequest, templateContext) + } + + @Test + fun `post request with missing sone redirects to return page`() { + request("", POST) + addHttpRequestParameter("returnPage", "return.html") + addHttpRequestParameter("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") + val sone = mock() + addSone("sone-id", sone) + verifyRedirect("return.html") { + verify(core).trustSone(eq(currentSone), eq(sone)) + } + } + +} -- 2.7.4