From: David ‘Bombe’ Roden Date: Thu, 19 Jan 2017 20:09:32 +0000 (+0100) Subject: Add unit test for trust page X-Git-Tag: 0.9.7^2~328 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=66cbbc495bb21fb1dd96c0e4dea6014bc16fb6a7;p=Sone.git Add unit test for trust page --- 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)) + } + } + +}