Add test for client put not reacting to wrong TestDDAReply
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Thu, 9 Jul 2015 05:12:56 +0000 (07:12 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Thu, 9 Jul 2015 05:12:56 +0000 (07:12 +0200)
src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java

index 47aff70..da454df 100644 (file)
@@ -473,5 +473,47 @@ public class DefaultFcpClientTest {
                assertThat(key.get().isPresent(), is(false));
        }
 
+       @Test
+       public void clientPutDoesNotReplyToWrongTestDdaReply() throws IOException, ExecutionException,
+       InterruptedException {
+               File tempFile = createTempFile();
+               fcpClient.clientPut().from(new File(tempFile.getParent(), "test.dat")).key(new Key("KSK@foo.txt"));
+               connectNode();
+               List<String> lines = fcpServer.collectUntil(is("EndMessage"));
+               String identifier = extractIdentifier(lines);
+               fcpServer.writeLine(
+                       "ProtocolError",
+                       "Identifier=" + identifier,
+                       "Code=25",
+                       "EndMessage"
+               );
+               lines = fcpServer.collectUntil(is("EndMessage"));
+               assertThat(lines, matchesFcpMessage(
+                       "TestDDARequest",
+                       "Directory=" + tempFile.getParent(),
+                       "WantReadDirectory=true",
+                       "WantWriteDirectory=false",
+                       "EndMessage"
+               ));
+               fcpServer.writeLine(
+                       "TestDDAReply",
+                       "Directory=/some-other-directory",
+                       "ReadFilename=" + tempFile,
+                       "EndMessage"
+               );
+               fcpServer.writeLine(
+                       "TestDDAReply",
+                       "Directory=" + tempFile.getParent(),
+                       "ReadFilename=" + tempFile,
+                       "EndMessage"
+               );
+               lines = fcpServer.collectUntil(is("EndMessage"));
+               assertThat(lines, matchesFcpMessage(
+                       "TestDDAResponse",
+                       "Directory=" + tempFile.getParent(),
+                       "ReadContent=test-content",
+                       "EndMessage"
+               ));
+       }
 
 }