From: David ‘Bombe’ Roden Date: Sun, 1 Oct 2017 14:39:15 +0000 (+0200) Subject: Always try to send an identifier back from the FCP interface X-Git-Tag: 0.9.7^2~51 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=1cf5a26a9d1b35a03b2d95edbad365101696919e;p=Sone.git Always try to send an identifier back from the FCP interface --- diff --git a/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java b/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java index c6957f4..6f28518 100644 --- a/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java +++ b/src/main/java/net/pterodactylus/sone/fcp/FcpInterface.java @@ -144,22 +144,22 @@ public class FcpInterface { * {@link FredPluginFCP#ACCESS_FCP_RESTRICTED} */ public void handle(PluginReplySender pluginReplySender, SimpleFieldSet parameters, Bucket data, int accessType) { + String identifier = parameters.get("Identifier"); + if ((identifier == null) || (identifier.length() == 0)) { + sendErrorReply(pluginReplySender, null, 400, "Missing Identifier."); + return; + } if (!active.get()) { - sendErrorReply(pluginReplySender, null, 503, "FCP Interface deactivated"); + sendErrorReply(pluginReplySender, identifier, 503, "FCP Interface deactivated"); return; } AbstractSoneCommand command = commands.get(parameters.get("Message")); if (command == null) { - sendErrorReply(pluginReplySender, null, 404, "Unrecognized Message: " + parameters.get("Message")); + sendErrorReply(pluginReplySender, identifier, 404, "Unrecognized Message: " + parameters.get("Message")); return; } if (!accessAuthorizer.authorized(AccessType.values()[accessType], fullAccessRequired.get(), command.requiresWriteAccess())) { - sendErrorReply(pluginReplySender, null, 401, "Not authorized"); - return; - } - String identifier = parameters.get("Identifier"); - if ((identifier == null) || (identifier.length() == 0)) { - sendErrorReply(pluginReplySender, null, 400, "Missing Identifier."); + sendErrorReply(pluginReplySender, identifier, 401, "Not authorized"); return; } try { diff --git a/src/test/kotlin/net/pterodactylus/sone/fcp/FcpInterfaceTest.kt b/src/test/kotlin/net/pterodactylus/sone/fcp/FcpInterfaceTest.kt index 9b591a0..6e1a06c 100644 --- a/src/test/kotlin/net/pterodactylus/sone/fcp/FcpInterfaceTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/fcp/FcpInterfaceTest.kt @@ -101,8 +101,9 @@ class FcpInterfaceTest { } @Test - fun `sending command to inactive fcp interface results in 400 error reply`() { + fun `sending command to inactive fcp interface results in 503 error reply`() { fcpInterface.fcpInterfaceDeactivated(FcpInterfaceDeactivatedEvent()) + parameters.putSingle("Identifier", "Test") fcpInterface.handle(pluginReplySender, parameters, null, 0) verify(pluginReplySender).send(replyParameters.capture()) assertThat(replyParameters.value["Message"], equalTo("Error")) @@ -119,6 +120,7 @@ class FcpInterfaceTest { @Test fun `sending command over non-authorized connection results in 401 error reply`() { fcpInterface.fcpInterfaceActivated(FcpInterfaceActivatedEvent()) + parameters.putSingle("Identifier", "Test") parameters.putSingle("Message", "Working") fcpInterface.handle(pluginReplySender, parameters, null, RESTRICTED_FCP.ordinal) verify(pluginReplySender).send(replyParameters.capture()) @@ -129,6 +131,7 @@ class FcpInterfaceTest { @Test fun `sending unknown command results in 404 error reply`() { fcpInterface.fcpInterfaceActivated(FcpInterfaceActivatedEvent()) + parameters.putSingle("Identifier", "Test") fcpInterface.handle(pluginReplySender, parameters, null, RESTRICTED_FCP.ordinal) verify(pluginReplySender).send(replyParameters.capture()) assertThat(replyParameters.value["Message"], equalTo("Error"))