mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice
synced 2026-08-07 08:25:39 +00:00
Test agent message filter processing
Signed-off-by: Pavel Grunt <pgrunt@redhat.com> Acked-by: Frediano Ziglio <fziglio@redhat.com>
This commit is contained in:
parent
dee20d8b43
commit
ddf028569e
@ -18,6 +18,7 @@
|
||||
#include <config.h>
|
||||
#include <glib.h>
|
||||
#include <spice/vd_agent.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "agent-msg-filter.h"
|
||||
|
||||
@ -51,11 +52,88 @@ static void test_agent_msg_filter_setup(void)
|
||||
g_assert(filter.discard_all == FALSE);
|
||||
}
|
||||
|
||||
static void test_agent_msg_filter_run(void)
|
||||
{
|
||||
AgentMsgFilter filter;
|
||||
union {
|
||||
struct VDAgentMessage msg_header;
|
||||
uint8_t data[VD_AGENT_MAX_DATA_SIZE];
|
||||
} msg;
|
||||
uint32_t len, type;
|
||||
|
||||
agent_msg_filter_init(&filter, TRUE, TRUE, TRUE, TRUE); /* discard all */
|
||||
|
||||
/* message size too large */
|
||||
len = VD_AGENT_MAX_DATA_SIZE + 1;
|
||||
g_assert_cmpint(agent_msg_filter_process_data(&filter, msg.data, len), ==,
|
||||
AGENT_MSG_FILTER_PROTO_ERROR);
|
||||
|
||||
/* data len too small */
|
||||
len = 0;
|
||||
g_assert_cmpint(agent_msg_filter_process_data(&filter, msg.data, len), ==,
|
||||
AGENT_MSG_FILTER_PROTO_ERROR);
|
||||
|
||||
/* invalid protocol */
|
||||
memset(&msg.msg_header, 0, sizeof(msg.msg_header));
|
||||
len = sizeof(msg.msg_header);
|
||||
g_assert_cmpint(agent_msg_filter_process_data(&filter, msg.data, len), ==,
|
||||
AGENT_MSG_FILTER_PROTO_ERROR);
|
||||
|
||||
/* all messages should be discarded */
|
||||
msg.msg_header.protocol = VD_AGENT_PROTOCOL;
|
||||
for (type = VD_AGENT_MOUSE_STATE; type < VD_AGENT_END_MESSAGE; type++) {
|
||||
msg.msg_header.type = type;
|
||||
g_assert_cmpint(agent_msg_filter_process_data(&filter, msg.data, len), ==,
|
||||
AGENT_MSG_FILTER_DISCARD);
|
||||
}
|
||||
|
||||
/* data exceeds size from header */
|
||||
msg.msg_header.size = 1;
|
||||
len = sizeof(msg.msg_header) + msg.msg_header.size + 1;
|
||||
g_assert_cmpint(agent_msg_filter_process_data(&filter, msg.data, len), ==,
|
||||
AGENT_MSG_FILTER_PROTO_ERROR);
|
||||
|
||||
len = sizeof(msg.msg_header) + msg.msg_header.size; /* restore correct size */
|
||||
|
||||
/* forward everything to the agent */
|
||||
agent_msg_filter_init(&filter, TRUE, TRUE, FALSE, FALSE);
|
||||
for (type = VD_AGENT_MOUSE_STATE; type < VD_AGENT_END_MESSAGE; type++) {
|
||||
msg.msg_header.type = type;
|
||||
g_assert_cmpint(agent_msg_filter_process_data(&filter, msg.data, len), ==,
|
||||
AGENT_MSG_FILTER_OK);
|
||||
}
|
||||
|
||||
/* filter everything */
|
||||
agent_msg_filter_config(&filter, FALSE, FALSE, TRUE);
|
||||
for (type = VD_AGENT_MOUSE_STATE; type < VD_AGENT_END_MESSAGE; type++) {
|
||||
AgentMsgFilterResult result;
|
||||
msg.msg_header.type = type;
|
||||
switch (type) {
|
||||
case VD_AGENT_CLIPBOARD:
|
||||
case VD_AGENT_CLIPBOARD_GRAB:
|
||||
case VD_AGENT_CLIPBOARD_REQUEST:
|
||||
case VD_AGENT_CLIPBOARD_RELEASE:
|
||||
case VD_AGENT_FILE_XFER_START:
|
||||
case VD_AGENT_FILE_XFER_STATUS:
|
||||
case VD_AGENT_FILE_XFER_DATA:
|
||||
result = AGENT_MSG_FILTER_DISCARD;
|
||||
break;
|
||||
case VD_AGENT_MONITORS_CONFIG:
|
||||
result = AGENT_MSG_FILTER_MONITORS_CONFIG;
|
||||
break;
|
||||
default:
|
||||
result = AGENT_MSG_FILTER_OK;
|
||||
}
|
||||
g_assert_cmpint(agent_msg_filter_process_data(&filter, msg.data, len), ==, result);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
g_test_init(&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func("/agent message filter/setup", test_agent_msg_filter_setup);
|
||||
g_test_add_func("/agent message filter/run", test_agent_msg_filter_run);
|
||||
|
||||
return g_test_run();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user