From: David ‘Bombe’ Roden Date: Thu, 28 Nov 2019 15:12:31 +0000 (+0100) Subject: 🔥 Remove all trust/distrust/untrust pages X-Git-Tag: v81^2~17^2~5 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=28be0e47c683650202cc74795d002acd10616642;p=Sone.git 🔥 Remove all trust/distrust/untrust pages --- diff --git a/src/main/java/net/pterodactylus/sone/web/AllPages.kt b/src/main/java/net/pterodactylus/sone/web/AllPages.kt index 9eccccf..c538f0e 100644 --- a/src/main/java/net/pterodactylus/sone/web/AllPages.kt +++ b/src/main/java/net/pterodactylus/sone/web/AllPages.kt @@ -23,7 +23,6 @@ class AllPages { @Inject lateinit var deleteReplyPage: DeleteReplyPage @Inject lateinit var deleteSonePage: DeleteSonePage @Inject lateinit var dismissNotificationPage: DismissNotificationPage - @Inject lateinit var distrustPage: DistrustPage @Inject lateinit var editAlbumPage: EditAlbumPage @Inject lateinit var editImagePage: EditImagePage @Inject lateinit var editProfileFieldPage: EditProfileFieldPage @@ -42,12 +41,10 @@ class AllPages { @Inject lateinit var optionsPage: OptionsPage @Inject lateinit var rescuePage: RescuePage @Inject lateinit var searchPage: SearchPage - @Inject lateinit var trustPage: TrustPage @Inject lateinit var unbookmarkPage: UnbookmarkPage @Inject lateinit var unfollowSonePage: UnfollowSonePage @Inject lateinit var unlikePage: UnlikePage @Inject lateinit var unlockSonePage: UnlockSonePage - @Inject lateinit var untrustPage: UntrustPage @Inject lateinit var uploadImagePage: UploadImagePage @Inject lateinit var viewPostPage: ViewPostPage @Inject lateinit var viewSonePage: ViewSonePage diff --git a/src/main/java/net/pterodactylus/sone/web/WebInterface.java b/src/main/java/net/pterodactylus/sone/web/WebInterface.java index 588ffb7..e31d9a8 100644 --- a/src/main/java/net/pterodactylus/sone/web/WebInterface.java +++ b/src/main/java/net/pterodactylus/sone/web/WebInterface.java @@ -69,7 +69,6 @@ import net.pterodactylus.sone.web.ajax.DeletePostAjaxPage; import net.pterodactylus.sone.web.ajax.DeleteProfileFieldAjaxPage; import net.pterodactylus.sone.web.ajax.DeleteReplyAjaxPage; import net.pterodactylus.sone.web.ajax.DismissNotificationAjaxPage; -import net.pterodactylus.sone.web.ajax.DistrustAjaxPage; import net.pterodactylus.sone.web.ajax.EditAlbumAjaxPage; import net.pterodactylus.sone.web.ajax.EditImageAjaxPage; import net.pterodactylus.sone.web.ajax.EditProfileFieldAjaxPage; @@ -86,12 +85,10 @@ import net.pterodactylus.sone.web.ajax.LikeAjaxPage; import net.pterodactylus.sone.web.ajax.LockSoneAjaxPage; import net.pterodactylus.sone.web.ajax.MarkAsKnownAjaxPage; import net.pterodactylus.sone.web.ajax.MoveProfileFieldAjaxPage; -import net.pterodactylus.sone.web.ajax.TrustAjaxPage; import net.pterodactylus.sone.web.ajax.UnbookmarkAjaxPage; import net.pterodactylus.sone.web.ajax.UnfollowSoneAjaxPage; import net.pterodactylus.sone.web.ajax.UnlikeAjaxPage; import net.pterodactylus.sone.web.ajax.UnlockSoneAjaxPage; -import net.pterodactylus.sone.web.ajax.UntrustAjaxPage; import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.sone.web.page.TemplateRenderer; import net.pterodactylus.sone.web.pages.*; @@ -574,9 +571,6 @@ public class WebInterface implements SessionProvider { pageToadletRegistry.addPage(new UploadImagePage(this, loaders, templateRenderer)); pageToadletRegistry.addPage(new EditImagePage(this, loaders, templateRenderer)); pageToadletRegistry.addPage(new DeleteImagePage(this, loaders, templateRenderer)); - pageToadletRegistry.addPage(new TrustPage(this, loaders, templateRenderer)); - pageToadletRegistry.addPage(new DistrustPage(this, loaders, templateRenderer)); - pageToadletRegistry.addPage(new UntrustPage(this, loaders, templateRenderer)); pageToadletRegistry.addPage(new MarkAsKnownPage(this, loaders, templateRenderer)); pageToadletRegistry.addPage(new BookmarkPage(this, loaders, templateRenderer)); pageToadletRegistry.addPage(new UnbookmarkPage(this, loaders, templateRenderer)); @@ -619,9 +613,6 @@ public class WebInterface implements SessionProvider { pageToadletRegistry.addPage(new UnfollowSoneAjaxPage(this)); pageToadletRegistry.addPage(new EditAlbumAjaxPage(this)); pageToadletRegistry.addPage(new EditImageAjaxPage(this, parserFilter, shortenFilter, renderFilter)); - pageToadletRegistry.addPage(new TrustAjaxPage(this)); - pageToadletRegistry.addPage(new DistrustAjaxPage(this)); - pageToadletRegistry.addPage(new UntrustAjaxPage(this)); pageToadletRegistry.addPage(new LikeAjaxPage(this)); pageToadletRegistry.addPage(new UnlikeAjaxPage(this)); pageToadletRegistry.addPage(new GetLikesAjaxPage(this)); diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/DistrustAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/DistrustAjaxPage.kt deleted file mode 100644 index cbeed6e..0000000 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/DistrustAjaxPage.kt +++ /dev/null @@ -1,29 +0,0 @@ -package net.pterodactylus.sone.web.ajax - -import net.pterodactylus.sone.core.* -import net.pterodactylus.sone.data.* -import net.pterodactylus.sone.utils.* -import net.pterodactylus.sone.web.* -import net.pterodactylus.sone.web.page.* -import javax.inject.* - -/** - * AJAX page that lets the user distrust a Sone. - * - * @see Core.distrustSone(Sone, Sone) - */ -@ToadletPath("distrustSone.ajax") -class DistrustAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) { - - override fun createJsonObject(currentSone: Sone, request: FreenetRequest) = - request.parameters["sone"] - ?.let(core::getSone) - ?.let { sone -> - createSuccessJsonObject() - .put("trustValue", core.preferences.negativeTrust) - .also { - core.distrustSone(currentSone, sone) - } - } ?: createErrorJsonObject("invalid-sone-id") - -} diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/TrustAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/TrustAjaxPage.kt deleted file mode 100644 index 9f0de87..0000000 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/TrustAjaxPage.kt +++ /dev/null @@ -1,24 +0,0 @@ -package net.pterodactylus.sone.web.ajax - -import net.pterodactylus.sone.data.* -import net.pterodactylus.sone.utils.* -import net.pterodactylus.sone.web.* -import net.pterodactylus.sone.web.page.* -import javax.inject.* - -/** - * AJAX page that lets the user trust a Sone. - * - * @see net.pterodactylus.sone.core.Core.trustSone - */ -@ToadletPath("trustSone.ajax") -class TrustAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) { - - override fun createJsonObject(currentSone: Sone, request: FreenetRequest) = - request.parameters["sone"] - ?.let(core::getSone) - ?.let { core.trustSone(currentSone, it) } - ?.let { createSuccessJsonObject().put("trustValue", core.preferences.positiveTrust) } - ?: createErrorJsonObject("invalid-sone-id") - -} diff --git a/src/main/kotlin/net/pterodactylus/sone/web/ajax/UntrustAjaxPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/ajax/UntrustAjaxPage.kt deleted file mode 100644 index e4b5edb..0000000 --- a/src/main/kotlin/net/pterodactylus/sone/web/ajax/UntrustAjaxPage.kt +++ /dev/null @@ -1,22 +0,0 @@ -package net.pterodactylus.sone.web.ajax - -import net.pterodactylus.sone.data.Sone -import net.pterodactylus.sone.utils.parameters -import net.pterodactylus.sone.web.WebInterface -import net.pterodactylus.sone.web.page.* -import javax.inject.Inject - -/** - * AJAX page that lets the user [untrust][net.pterodactylus.sone.core.Core.untrustSone] a [Sone]. - */ -@ToadletPath("untrustSone.ajax") -class UntrustAjaxPage @Inject constructor(webInterface: WebInterface) : LoggedInJsonPage(webInterface) { - - override fun createJsonObject(currentSone: Sone, request: FreenetRequest) = - request.parameters["sone"] - ?.let(core::getSone) - ?.also { core.untrustSone(currentSone, it) } - ?.let { createSuccessJsonObject() } - ?: createErrorJsonObject("invalid-sone-id") - -} diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/DistrustPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/DistrustPage.kt deleted file mode 100644 index dd3ad8c..0000000 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/DistrustPage.kt +++ /dev/null @@ -1,29 +0,0 @@ -package net.pterodactylus.sone.web.pages - -import net.pterodactylus.sone.data.* -import net.pterodactylus.sone.main.* -import net.pterodactylus.sone.utils.* -import net.pterodactylus.sone.web.* -import net.pterodactylus.sone.web.page.* -import net.pterodactylus.util.template.* -import javax.inject.* - -/** - * Page that lets the user distrust another Sone. This will assign a - * configurable (negative) amount of trust to an identity. - * - * @see net.pterodactylus.sone.core.Core#distrustSone(Sone, Sone) - */ -@ToadletPath("distrust.html") -class DistrustPage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) : - LoggedInPage("Page.Distrust.Title", webInterface, loaders, templateRenderer) { - - override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { - if (soneRequest.isPOST) { - soneRequest.core.getSone(soneRequest.httpRequest.getPartAsStringFailsafe("sone", 44)) - ?.run { soneRequest.core.distrustSone(currentSone, this) } - redirectTo(soneRequest.httpRequest.getPartAsStringFailsafe("returnPage", 256)) - } - } - -} diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/TrustPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/TrustPage.kt deleted file mode 100644 index 54edc5d..0000000 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/TrustPage.kt +++ /dev/null @@ -1,28 +0,0 @@ -package net.pterodactylus.sone.web.pages - -import net.pterodactylus.sone.data.* -import net.pterodactylus.sone.main.* -import net.pterodactylus.sone.utils.* -import net.pterodactylus.sone.web.* -import net.pterodactylus.sone.web.page.* -import net.pterodactylus.util.template.* -import javax.inject.* - -/** - * Page that lets the user trust another Sone. This will assign a configurable - * amount of trust to an identity. - */ -@ToadletPath("trust.html") -class TrustPage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) : - LoggedInPage("Page.Trust.Title", webInterface, loaders, templateRenderer) { - - override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { - if (soneRequest.isPOST) { - soneRequest.core.getSone(soneRequest.parameters["sone"]!!)?.let { sone -> - soneRequest.core.trustSone(currentSone, sone) - } - redirectTo(soneRequest.parameters["returnPage", 256]) - } - } - -} diff --git a/src/main/kotlin/net/pterodactylus/sone/web/pages/UntrustPage.kt b/src/main/kotlin/net/pterodactylus/sone/web/pages/UntrustPage.kt deleted file mode 100644 index dd445c8..0000000 --- a/src/main/kotlin/net/pterodactylus/sone/web/pages/UntrustPage.kt +++ /dev/null @@ -1,28 +0,0 @@ -package net.pterodactylus.sone.web.pages - -import net.pterodactylus.sone.data.* -import net.pterodactylus.sone.main.* -import net.pterodactylus.sone.utils.* -import net.pterodactylus.sone.web.* -import net.pterodactylus.sone.web.page.* -import net.pterodactylus.util.template.* -import javax.inject.* - -/** - * Page that lets the user untrust another Sone. This will remove all trust - * assignments for an identity. - */ -@ToadletPath("untrust.html") -class UntrustPage @Inject constructor(webInterface: WebInterface, loaders: Loaders, templateRenderer: TemplateRenderer) : - LoggedInPage("Page.Untrust.Title", webInterface, loaders, templateRenderer) { - - override fun handleRequest(soneRequest: SoneRequest, currentSone: Sone, templateContext: TemplateContext) { - if (soneRequest.isPOST) { - soneRequest.parameters["sone", 44]!! - .let(soneRequest.core::getSone) - ?.also { soneRequest.core.untrustSone(currentSone, it) } - redirectTo(soneRequest.parameters["returnPage", 256]) - } - } - -} diff --git a/src/test/kotlin/net/pterodactylus/sone/web/AllPagesTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/AllPagesTest.kt index cf6ab15..842feb4 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/AllPagesTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/AllPagesTest.kt @@ -102,11 +102,6 @@ class AllPagesTest { } @Test - fun `distrust page can be injected`() { - assertThat(allPages.distrustPage, instanceOf()) - } - - @Test fun `edit album page can be injected`() { assertThat(allPages.editAlbumPage, instanceOf()) } @@ -197,11 +192,6 @@ class AllPagesTest { } @Test - fun `trust page can be injected`() { - assertThat(allPages.trustPage, instanceOf()) - } - - @Test fun `unbookmark page can be injected`() { assertThat(allPages.unbookmarkPage, instanceOf()) } @@ -222,11 +212,6 @@ class AllPagesTest { } @Test - fun `untrust page can be injected`() { - assertThat(allPages.untrustPage, instanceOf()) - } - - @Test fun `upload image page can be injected`() { assertThat(allPages.uploadImagePage, instanceOf()) } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/DistrustAjaxPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/DistrustAjaxPageTest.kt deleted file mode 100644 index 868819e..0000000 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/DistrustAjaxPageTest.kt +++ /dev/null @@ -1,53 +0,0 @@ -package net.pterodactylus.sone.web.ajax - -import net.pterodactylus.sone.data.Sone -import net.pterodactylus.sone.test.getInstance -import net.pterodactylus.sone.test.mock -import net.pterodactylus.sone.web.baseInjector -import org.hamcrest.MatcherAssert.assertThat -import org.hamcrest.Matchers.equalTo -import org.hamcrest.Matchers.notNullValue -import org.junit.Test -import org.mockito.Mockito.verify - -/** - * Unit test for [DistrustAjaxPage]. - */ -class DistrustAjaxPageTest : JsonPageTest("distrustSone.ajax", pageSupplier = ::DistrustAjaxPage) { - - @Test - fun `request with missing sone results in invalid-sone-id`() { - assertThatJsonFailed("invalid-sone-id") - } - - @Test - fun `request with invalid sone results in invalid-sone-id`() { - addRequestParameter("sone", "invalid-sone") - assertThatJsonFailed("invalid-sone-id") - } - - @Test - fun `request with valid sone results in distrusted sone`() { - val sone = mock() - addSone(sone, "sone-id") - addRequestParameter("sone", "sone-id") - assertThatJsonIsSuccessful() - verify(core).distrustSone(currentSone, sone) - } - - @Test - fun `request with valid sone results in correct trust value being sent back`() { - core.preferences.newNegativeTrust = -33 - val sone = mock() - addSone(sone, "sone-id") - addRequestParameter("sone", "sone-id") - assertThatJsonIsSuccessful() - assertThat(json["trustValue"]?.asInt(), equalTo(-33)) - } - - @Test - fun `page can be created by dependency injection`() { - assertThat(baseInjector.getInstance(), notNullValue()) - } - -} diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/TrustAjaxPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/TrustAjaxPageTest.kt deleted file mode 100644 index d557790..0000000 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/TrustAjaxPageTest.kt +++ /dev/null @@ -1,47 +0,0 @@ -package net.pterodactylus.sone.web.ajax - -import net.pterodactylus.sone.data.Sone -import net.pterodactylus.sone.test.getInstance -import net.pterodactylus.sone.test.mock -import net.pterodactylus.sone.web.baseInjector -import org.hamcrest.MatcherAssert.assertThat -import org.hamcrest.Matchers.equalTo -import org.hamcrest.Matchers.notNullValue -import org.junit.Test -import org.mockito.Mockito.verify - -/** - * Unit test for [TrustAjaxPage]. - */ -class TrustAjaxPageTest : JsonPageTest("trustSone.ajax", requiresLogin = true, needsFormPassword = true, pageSupplier = ::TrustAjaxPage) { - - private val sone = mock() - - @Test - fun `request with invalid sone results in invalid-sone-id`() { - assertThatJsonFailed("invalid-sone-id") - } - - @Test - fun `request with valid sone trust sone`() { - addSone(sone, "sone-id") - addRequestParameter("sone", "sone-id") - assertThatJsonIsSuccessful() - verify(core).trustSone(currentSone, sone) - } - - @Test - fun `request with valid sone returns positive trust value`() { - addSone(sone, "sone-id") - addRequestParameter("sone", "sone-id") - core.preferences.newPositiveTrust = 31 - assertThatJsonIsSuccessful() - assertThat(json["trustValue"]?.asInt(), equalTo(31)) - } - - @Test - fun `page can be created by dependency injection`() { - assertThat(baseInjector.getInstance(), notNullValue()) - } - -} diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/UntrustAjaxPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/UntrustAjaxPageTest.kt deleted file mode 100644 index b693194..0000000 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/UntrustAjaxPageTest.kt +++ /dev/null @@ -1,50 +0,0 @@ -package net.pterodactylus.sone.web.ajax - -import net.pterodactylus.sone.data.* -import net.pterodactylus.sone.test.* -import net.pterodactylus.sone.web.* -import org.hamcrest.MatcherAssert.* -import org.hamcrest.Matchers.* -import org.junit.* -import org.mockito.Mockito.* - -/** - * Unit test for [UntrustAjaxPage]. - */ -class UntrustAjaxPageTest : JsonPageTest("untrustSone.ajax", pageSupplier = ::UntrustAjaxPage) { - - @Test - fun `request without sone results in invalid-sone-id`() { - assertThatJsonFailed("invalid-sone-id") - } - - @Test - fun `request with invalid sone results in invalid-sone-id`() { - addRequestParameter("sone", "invalid") - assertThatJsonFailed("invalid-sone-id") - } - - @Test - fun `request with valid sone results in sone being untrusted`() { - val sone = mock() - addSone(sone, "sone-id") - addRequestParameter("sone", "sone-id") - assertThatJsonIsSuccessful() - verify(core).untrustSone(currentSone, sone) - } - - @Test - fun `request with valid sone results in null trust value being returned`() { - val sone = mock() - addSone(sone, "sone-id") - addRequestParameter("sone", "sone-id") - assertThatJsonIsSuccessful() - assertThat(json["trustValue"], nullValue()) - } - - @Test - fun `page can be created by dependency injection`() { - assertThat(baseInjector.getInstance(), notNullValue()) - } - -} diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/DistrustPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/DistrustPageTest.kt deleted file mode 100644 index df16a53..0000000 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/DistrustPageTest.kt +++ /dev/null @@ -1,62 +0,0 @@ -package net.pterodactylus.sone.web.pages - -import net.pterodactylus.sone.data.* -import net.pterodactylus.sone.test.* -import net.pterodactylus.sone.web.* -import net.pterodactylus.util.web.Method.* -import org.hamcrest.MatcherAssert.* -import org.hamcrest.Matchers.* -import org.junit.* -import org.mockito.Mockito.* - -/** - * Unit test for [DistrustPage]. - */ -class DistrustPageTest : WebPageTest(::DistrustPage) { - - @Test - fun `page returns correct path`() { - assertThat(page.path, equalTo("distrust.html")) - } - - @Test - fun `page requires login`() { - assertThat(page.requiresLogin(), equalTo(true)) - } - - @Test - fun `page returns correct title`() { - addTranslation("Page.Distrust.Title", "distrust page title") - assertThat(page.getPageTitle(soneRequest), equalTo("distrust page title")) - } - - @Test - fun `get request does not redirect`() { - page.processTemplate(freenetRequest, templateContext) - } - - @Test - fun `post request with invalid sone redirects to return page`() { - setMethod(POST) - addHttpRequestPart("returnPage", "return.html") - verifyRedirect("return.html") - } - - @Test - fun `post request with valid sone distrusts sone and redirects to return page`() { - setMethod(POST) - val remoteSone = mock() - addSone("remote-sone-id", remoteSone) - addHttpRequestPart("returnPage", "return.html") - addHttpRequestPart("sone", "remote-sone-id") - verifyRedirect("return.html") { - verify(core).distrustSone(currentSone, remoteSone) - } - } - - @Test - fun `page can be created by dependency injection`() { - assertThat(baseInjector.getInstance(), notNullValue()) - } - -} diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/TrustPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/TrustPageTest.kt deleted file mode 100644 index 990c1b7..0000000 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/TrustPageTest.kt +++ /dev/null @@ -1,78 +0,0 @@ -package net.pterodactylus.sone.web.pages - -import net.pterodactylus.sone.data.* -import net.pterodactylus.sone.test.getInstance -import net.pterodactylus.sone.test.mock -import net.pterodactylus.sone.web.* -import net.pterodactylus.util.web.Method.* -import org.hamcrest.MatcherAssert.* -import org.hamcrest.Matchers.* -import org.junit.* -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(::TrustPage) { - - @Test - fun `page returns correct path`() { - assertThat(page.path, equalTo("trust.html")) - } - - @Test - fun `page requires login`() { - assertThat(page.requiresLogin(), equalTo(true)) - } - - @Test - fun `page returns correct title`() { - addTranslation("Page.Trust.Title", "title trust page") - assertThat(page.getPageTitle(soneRequest), equalTo("title trust page")) - } - - @Test - fun `get method does not redirect`() { - verifyNoRedirect { } - } - - @Test - fun `post request without sone redirects to return page`() { - setMethod(POST) - addHttpRequestPart("returnPage", "return.html") - verifyRedirect("return.html") { - verify(core, never()).trustSone(eq(currentSone), any()) - } - } - - @Test - fun `post request with missing sone redirects to return page`() { - setMethod(POST) - addHttpRequestPart("returnPage", "return.html") - addHttpRequestPart("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`() { - setMethod(POST) - addHttpRequestPart("returnPage", "return.html") - addHttpRequestPart("sone", "sone-id") - val sone = mock() - addSone("sone-id", sone) - verifyRedirect("return.html") { - verify(core).trustSone(eq(currentSone), eq(sone)) - } - } - - @Test - fun `page can be created by dependency injection`() { - assertThat(baseInjector.getInstance(), notNullValue()) - } - -} diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/UntrustPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/UntrustPageTest.kt deleted file mode 100644 index eb0ebdd..0000000 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/UntrustPageTest.kt +++ /dev/null @@ -1,80 +0,0 @@ -package net.pterodactylus.sone.web.pages - -import net.pterodactylus.sone.data.* -import net.pterodactylus.sone.test.getInstance -import net.pterodactylus.sone.test.mock -import net.pterodactylus.sone.web.* -import net.pterodactylus.util.web.Method.* -import org.hamcrest.MatcherAssert.* -import org.hamcrest.Matchers.* -import org.junit.* -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(::UntrustPage) { - - @Test - fun `page returns correct path`() { - assertThat(page.path, equalTo("untrust.html")) - } - - @Test - fun `page requires login`() { - assertThat(page.requiresLogin(), equalTo(true)) - } - - @Test - fun `page returns correct title`() { - addTranslation("Page.Untrust.Title", "untrust page title") - assertThat(page.getPageTitle(soneRequest), equalTo("untrust page title")) - } - - @Test - fun `get request does not redirect`() { - verifyNoRedirect { - verify(core, never()).untrustSone(eq(currentSone), any()) - } - } - - @Test - fun `post request without sone parameter does not untrust but redirects`() { - setMethod(POST) - addHttpRequestPart("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`() { - setMethod(POST) - addHttpRequestPart("returnPage", "return.html") - addHttpRequestPart("sone", "no-sone") - verifyRedirect("return.html") { - verify(core, never()).untrustSone(eq(currentSone), any()) - } - } - - @Test - fun `post request with valid sone parameter untrusts and redirects`() { - setMethod(POST) - addHttpRequestPart("returnPage", "return.html") - addHttpRequestPart("sone", "sone-id") - val sone = mock() - addSone("sone-id", sone) - verifyRedirect("return.html") { - verify(core).untrustSone(currentSone, sone) - } - } - - @Test - fun `page can be created by dependency injection`() { - assertThat(baseInjector.getInstance(), notNullValue()) - } - -}