1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.Sone
4 import net.pterodactylus.sone.test.getInstance
5 import net.pterodactylus.sone.test.mock
6 import net.pterodactylus.sone.web.baseInjector
7 import net.pterodactylus.util.web.Method.POST
8 import org.hamcrest.MatcherAssert.assertThat
9 import org.hamcrest.Matchers.equalTo
10 import org.hamcrest.Matchers.notNullValue
12 import org.mockito.ArgumentMatchers.any
13 import org.mockito.ArgumentMatchers.eq
14 import org.mockito.Mockito.never
15 import org.mockito.Mockito.verify
18 * Unit test for [TrustPage].
20 class TrustPageTest: WebPageTest(::TrustPage) {
23 fun `page returns correct path`() {
24 assertThat(page.path, equalTo("trust.html"))
28 fun `page requires login`() {
29 assertThat(page.requiresLogin(), equalTo(true))
33 fun `page returns correct title`() {
34 addTranslation("Page.Trust.Title", "title trust page")
35 assertThat(page.getPageTitle(freenetRequest), equalTo("title trust page"))
39 fun `get method does not redirect`() {
44 fun `post request without sone redirects to return page`() {
46 addHttpRequestPart("returnPage", "return.html")
47 verifyRedirect("return.html") {
48 verify(core, never()).trustSone(eq(currentSone), any())
53 fun `post request with missing sone redirects to return page`() {
55 addHttpRequestPart("returnPage", "return.html")
56 addHttpRequestPart("sone", "sone-id")
57 verifyRedirect("return.html") {
58 verify(core, never()).trustSone(eq(currentSone), any())
63 fun `post request with existing sone trusts the identity and redirects to return page`() {
65 addHttpRequestPart("returnPage", "return.html")
66 addHttpRequestPart("sone", "sone-id")
67 val sone = mock<Sone>()
68 addSone("sone-id", sone)
69 verifyRedirect("return.html") {
70 verify(core).trustSone(eq(currentSone), eq(sone))
75 fun `page can be created by dependency injection`() {
76 assertThat(baseInjector.getInstance<TrustPage>(), notNullValue())