summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJesper Jensen <jesper@slashwin.dk>2021-10-05 23:07:06 +0200
committerJesper Jensen <jesper@slashwin.dk>2021-10-05 23:07:06 +0200
commite0074d8b74f9e62df913a3817fc4cecf7cac2c69 (patch)
tree46696da2ad28b316e75543bc79d63cc3e8ad3d4c /test
parent6e6829ad209550fbac0e363f9421c1fba78915b5 (diff)
Respond correctly no unknown query method
Diffstat (limited to 'test')
-rw-r--r--test/proto.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/proto.c b/test/proto.c
index 600602e..ae42e36 100644
--- a/test/proto.c
+++ b/test/proto.c
@@ -111,6 +111,32 @@ void test_ping() {
TEST_ASSERT_EQUAL_CHAR_ARRAY("d1:t2:aa1:y1:r1:rd2:id20:BBBBBBBBBBBBBBBBBBBBee", outbuff[0].payload, 47);
}
+void test_unknown_method() {
+ struct message outbuff[2] = {0};
+
+ struct dht dht;
+ dht.self = (struct nodeid){.inner={0x42424242, 0x42424242, 0x42424242, 0x42424242, 0x42424242}};
+ {
+ struct message* message_cursor = outbuff;
+ proto_begin(&dht, time(NULL), &message_cursor, outbuff+2);
+ }
+
+ struct sockaddr_in remote;
+ remote.sin_family = AF_INET;
+ inet_pton(AF_INET, "255.255.255.255", &remote.sin_addr.s_addr);
+ remote.sin_port = htons(6881);
+
+ char buff[] = "d1:q4:fake1:t2:aa1:y1:qe";
+ struct message* message_cursor = outbuff;
+ proto_run(&dht, buff, sizeof(buff), &remote, sizeof(remote), 0, &message_cursor, outbuff+2);
+
+ // We should have sent a response
+ TEST_ASSERT_EQUAL_PTR(message_cursor, outbuff+1);
+
+ TEST_ASSERT_EQUAL(42, outbuff[0].payload_len);
+ TEST_ASSERT_EQUAL_CHAR_ARRAY("d1:t2:aa1:y1:e1:eli204e14:Unknown Methodee", outbuff[0].payload, 42);
+}
+
void test_note_times_out() {
routing_flush();
struct message outbuff[2] = {0};