summaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2023-02-12 13:35:27 +0100
committerRoland Reichwein <mail@reichwein.it>2023-02-12 13:35:27 +0100
commit139f0cee972ecd2928b78fdbbc0635b183b1728f (patch)
tree16d767d2742cc37dc2c46a27ee200a3d1698d058 /tests
parentb0f8b28977e59b7fbfc1ce57ee5c102b8e4e0690 (diff)
Validate ids, server-side
Diffstat (limited to 'tests')
-rw-r--r--tests/test-whiteboard.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/test-whiteboard.cpp b/tests/test-whiteboard.cpp
index b6fe9c5..3f70bcf 100644
--- a/tests/test-whiteboard.cpp
+++ b/tests/test-whiteboard.cpp
@@ -222,3 +222,34 @@ TEST_F(WhiteboardTest, max_connections)
ASSERT_THROW(WebsocketClient wc4, std::exception);
}
+
+TEST_F(WhiteboardTest, id)
+{
+ WebsocketClient wc;
+
+ wc.write("<request><command>getfile</command><id>1</id></request>");
+ std::string result {wc.read()};
+
+ EXPECT_EQ(result, "<serverinfo><type>getfile</type><data/><revision>0</revision><pos>0</pos></serverinfo>");
+
+ wc.write("<request><command>getfile</command><id></id></request>");
+ result = wc.read();
+ EXPECT_EQ(result, "<serverinfo><type>error</type><message>Message handling error: Invalid id (empty)</message></serverinfo>");
+
+ wc.write("<request><command>getfile</command><id>01234567890123456789</id></request>");
+ result = wc.read();
+ EXPECT_EQ(result, "<serverinfo><type>error</type><message>Message handling error: Invalid id (size &gt; 16)</message></serverinfo>");
+
+ wc.write("<request><command>getfile</command><id>X</id></request>");
+ result = wc.read();
+ EXPECT_EQ(result, "<serverinfo><type>error</type><message>Message handling error: Invalid id char: X</message></serverinfo>");
+
+ wc.write("<request><command>getfile</command><id>a.</id></request>");
+ result = wc.read();
+ EXPECT_EQ(result, "<serverinfo><type>error</type><message>Message handling error: Invalid id char: .</message></serverinfo>");
+
+ wc.write("<request><command>getfile</command><id>a$b</id></request>");
+ result = wc.read();
+ EXPECT_EQ(result, "<serverinfo><type>error</type><message>Message handling error: Invalid id char: $</message></serverinfo>");
+}
+