From: David ‘Bombe’ Roden Date: Mon, 5 Aug 2019 09:53:49 +0000 (+0200) Subject: 🐛 Unregister USKs even if edition differs X-Git-Tag: v81^2~133^2~1 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=55912e67b37ad339a34b2a12aff685d8d81ed135;p=Sone.git 🐛 Unregister USKs even if edition differs --- 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()) + } + }