1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.Sone
4 import net.pterodactylus.sone.test.mock
5 import net.pterodactylus.sone.web.pages.TrustPage
6 import net.pterodactylus.util.web.Method.POST
8 import org.mockito.ArgumentMatchers.any
9 import org.mockito.ArgumentMatchers.eq
10 import org.mockito.Mockito.never
11 import org.mockito.Mockito.verify
14 * Unit test for [TrustPage].
16 class TrustPageTest : WebPageTest() {
18 private val page = TrustPage(template, webInterface)
20 override fun getPage() = page
23 fun `get method does not redirect`() {
24 page.handleRequest(freenetRequest, templateContext)
28 fun `post request with missing sone redirects to return page`() {
30 addHttpRequestParameter("returnPage", "return.html")
31 addHttpRequestParameter("sone", "sone-id")
32 verifyRedirect("return.html") {
33 verify(core, never()).trustSone(eq(currentSone), any())
38 fun `post request with existing sone trusts the identity and redirects to return page`() {
40 addHttpRequestParameter("returnPage", "return.html")
41 addHttpRequestParameter("sone", "sone-id")
42 val sone = mock<Sone>()
43 addSone("sone-id", sone)
44 verifyRedirect("return.html") {
45 verify(core).trustSone(eq(currentSone), eq(sone))