From 55912e67b37ad339a34b2a12aff685d8d81ed135 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 5 Aug 2019 11:53:49 +0200 Subject: [PATCH] =?utf8?q?=F0=9F=90=9B=20Unregister=20USKs=20even=20if=20e?= =?utf8?q?dition=20differs?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../java/net/pterodactylus/sone/core/FreenetInterface.java | 12 ++++++------ .../net/pterodactylus/sone/core/FreenetInterfaceTest.kt | 10 ++++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java index 1ed2024..b3b32b3 100644 --- a/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java +++ b/src/main/java/net/pterodactylus/sone/core/FreenetInterface.java @@ -327,7 +327,7 @@ public class FreenetInterface { }; try { node.clientCore.uskManager.subscribe(USK.create(uri), uskCallback, true, requestClient); - uriUskCallbacks.put(uri, uskCallback); + uriUskCallbacks.put(USK.create(uri).clearCopy().getURI(), uskCallback); } catch (MalformedURLException mue1) { logger.log(Level.WARNING, String.format("Could not subscribe to USK: %s", uri), mue1); } @@ -340,12 +340,12 @@ public class FreenetInterface { * The URI to unregister the USK watcher for */ public void unregisterUsk(FreenetURI uri) { - USKCallback uskCallback = uriUskCallbacks.remove(uri); - if (uskCallback == null) { - logger.log(Level.INFO, String.format("Could not unregister unknown USK: %s", uri)); - return; - } try { + USKCallback uskCallback = uriUskCallbacks.remove(USK.create(uri).clearCopy().getURI()); + if (uskCallback == null) { + logger.log(Level.INFO, String.format("Could not unregister unknown USK: %s", uri)); + return; + } node.clientCore.uskManager.unsubscribe(USK.create(uri), uskCallback); } catch (MalformedURLException mue1) { logger.log(Level.INFO, String.format("Could not unregister invalid USK: %s", uri), mue1); diff --git a/src/test/kotlin/net/pterodactylus/sone/core/FreenetInterfaceTest.kt b/src/test/kotlin/net/pterodactylus/sone/core/FreenetInterfaceTest.kt index 1893acc..cdf0dfb 100644 --- a/src/test/kotlin/net/pterodactylus/sone/core/FreenetInterfaceTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/core/FreenetInterfaceTest.kt @@ -32,6 +32,7 @@ import org.mockito.ArgumentMatchers.eq import org.mockito.Mockito.* import java.io.* import java.util.* +import kotlin.test.Test /** * Unit test for [FreenetInterface]. @@ -458,4 +459,13 @@ class FreenetInterfaceTest { verifyNoMoreInteractions(backgroundFetchCallback) } + @Test + fun `unregistering a registered USK with different edition unregisters USK`() { + val callback = mock() + val uri = createRandom(randomSource, "test-123").uri.uskForSSK() + freenetInterface.registerUsk(uri, callback) + freenetInterface.unregisterUsk(uri.setSuggestedEdition(234)) + verify(uskManager).unsubscribe(any(), any()) + } + } -- 2.7.4