From f3bc759f7876334bdb2184d756f8f1fc279fff52 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 11 Feb 2020 20:22:49 +0100 Subject: [PATCH] =?utf8?q?=E2=99=BB=EF=B8=8F=20Use=20URI=20creator=20to=20?= =?utf8?q?create=20Sone=20URIs?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../net/pterodactylus/sone/core/FreenetInterface.java | 9 ++++++--- .../net/pterodactylus/sone/core/FreenetInterfaceTest.kt | 16 ++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java index 7702d84..35ac6a1 100644 --- a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java +++ b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java @@ -91,6 +91,8 @@ public class FreenetInterface { /** The node to interact with. */ private final Node node; + private final SoneUriCreator soneUriCreator; + /** The high-level client to use for requests. */ private final HighLevelSimpleClient client; private final RequestClient requestClient = new RequestClientBuilder().realTime().build(); @@ -105,9 +107,10 @@ public class FreenetInterface { private final RequestClient imageLoader = new RequestClientBuilder().realTime().build(); @Inject - public FreenetInterface(EventBus eventBus, Node node) { + public FreenetInterface(EventBus eventBus, Node node, SoneUriCreator soneUriCreator) { this.eventBus = eventBus; this.node = node; + this.soneUriCreator = soneUriCreator; this.client = node.clientCore.makeClient(RequestStarter.INTERACTIVE_PRIORITY_CLASS, false, true); } @@ -283,9 +286,9 @@ public class FreenetInterface { } try { logger.log(Level.FINEST, String.format("Unsubscribing from USK for %s…", sone)); - node.clientCore.uskManager.unsubscribe(USK.create(sone.getRequestUri()), uskCallback); + node.clientCore.uskManager.unsubscribe(USK.create(soneUriCreator.getRequestUri(sone)), uskCallback); } catch (MalformedURLException mue1) { - logger.log(Level.FINE, String.format("Could not unsubscribe USK “%s”!", sone.getRequestUri()), mue1); + logger.log(Level.FINE, String.format("Could not unsubscribe USK “%s”!", soneUriCreator.getRequestUri(sone)), mue1); } } diff --git a/src/test/kotlin/net/pterodactylus/sone/core/FreenetInterfaceTest.kt b/src/test/kotlin/net/pterodactylus/sone/core/FreenetInterfaceTest.kt index 81b4e04..a7b187d 100644 --- a/src/test/kotlin/net/pterodactylus/sone/core/FreenetInterfaceTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/core/FreenetInterfaceTest.kt @@ -16,6 +16,7 @@ import net.pterodactylus.sone.core.FreenetInterface.* import net.pterodactylus.sone.core.event.* import net.pterodactylus.sone.data.* import net.pterodactylus.sone.data.impl.* +import net.pterodactylus.sone.freenet.wot.DefaultIdentity import net.pterodactylus.sone.test.* import net.pterodactylus.sone.test.Matchers.* import net.pterodactylus.sone.test.TestUtil.* @@ -64,6 +65,7 @@ class FreenetInterfaceTest { private val fetchResult = mock() private val backgroundFetchCallback = mock() private val clientGetter = mock() + private val soneUriCreator = SoneUriCreator() private val freenetInterface: FreenetInterface init { @@ -72,7 +74,7 @@ class FreenetInterfaceTest { setField(node, "random", randomSource) setField(nodeClientCore, "uskManager", uskManager) setField(nodeClientCore, "clientContext", mock()) - freenetInterface = FreenetInterface(eventBus, node) + freenetInterface = FreenetInterface(eventBus, node, soneUriCreator) insertToken = freenetInterface.InsertToken(image) insertToken.setBucket(bucket) } @@ -87,7 +89,7 @@ class FreenetInterfaceTest { fun setupSone() { val insertSsk = createRandom(randomSource, "test-0") whenever(sone.id).thenReturn(insertSsk.uri.routingKey.asFreenetBase64) - whenever(sone.requestUri).thenReturn(insertSsk.uri.uskForSSK()) + whenever(sone.identity).thenReturn(DefaultIdentity("id", "name", insertSsk.uri.toString())) } @Before @@ -188,7 +190,6 @@ class FreenetInterfaceTest { @Test fun `sone with wrong request uri will not be subscribed`() { - whenever(sone.requestUri).thenReturn(FreenetURI("KSK@GPLv3.txt")) freenetInterface.registerUsk(FreenetURI("KSK@GPLv3.txt"), null) verify(uskManager, never()).subscribe(any(USK::class.java), any(USKCallback::class.java), anyBoolean(), any(RequestClient::class.java)) } @@ -262,16 +263,15 @@ class FreenetInterfaceTest { } @Test - fun `unregistering aregistered sone unregisters the sone`() { - freenetInterface.registerActiveUsk(sone.requestUri, mock()) + fun `unregistering a registered sone unregisters the sone`() { + freenetInterface.registerActiveUsk(soneUriCreator.getRequestUri(sone), mock()) freenetInterface.unregisterUsk(sone) verify(uskManager).unsubscribe(any(USK::class.java), any(USKCallback::class.java)) } @Test - fun `unregistering asone with awrong request key will not unsubscribe`() { - whenever(sone.requestUri).thenReturn(FreenetURI("KSK@GPLv3.txt")) - freenetInterface.registerUsk(sone.requestUri, null) + fun `unregistering a sone with a wrong request key will not unsubscribe`() { + freenetInterface.registerUsk(FreenetURI("KSK@GPLv3.txt"), null) freenetInterface.unregisterUsk(sone) verify(uskManager, never()).unsubscribe(any(USK::class.java), any(USKCallback::class.java)) } -- 2.7.4