FreeRDP
Loading...
Searching...
No Matches
TestRdstls.c
1
21#include <winpr/wtypes.h>
22#include <winpr/wlog.h>
23
24#include "../rdstls.h"
25
26/* PDU structure:
27 *
28 * - 2 bytes version
29 * - 2 bytes type
30 */
31struct test_case_t
32{
33 SSIZE_T expected;
34 size_t len;
35 char* data;
36};
37
38static const struct test_case_t tests[] = {
39 { 0, 1, "a" },
40 { 0, 2, "\x01\x00" },
41 { 0, 2, "\x02\x00" },
42 { -1, 2, "\x00\x00" },
43 { -1, 2, "\x03\x00" },
44 { 0, 3, "\x01\x00\x00" },
45 { -1, 4, "\x01\x00\x00\x00" },
46 { 8, 4, "\x01\x00\x01\x00" },
47 { 0, 4, "\x01\x00\x02\x00" },
48 { -1, 4, "\x01\x00\x03\x00" },
49 { 10, 4, "\x01\x00\x04\x00" },
50 { -1, 4, "\x01\x00\x05\x00" },
51 { -1, 4, "\x01\x00\x06\x00" },
52 { 0, 5, "\x01\x00\x02\x00\x00" },
53 { -1, 6, "\x01\x00\x02\x00\x00\x00" },
54 { -1, 6, "\x01\x00\x02\x00\x04\x00" },
55 { -1, 6, "\x01\x00\x02\x00\x05\x00" },
56 { -1, 6, "\x01\x00\x02\x00\x06\x00" },
57 { 0, 6, "\x01\x00\x02\x00\x01\x00" },
58 { 0, 6, "\x01\x00\x02\x00\x02\x00" },
59 { 0, 6, "\x01\x00\x02\x00\x03\x00" },
60 { -1, 12, "\x01\x00\x02\x00\x03\x00\x00\x00\x00\x00\x00\x00" },
61 { 12 + 1, 12, "\x01\x00\x02\x00\x03\x00\x00\x00\x00\x00\x01\x00" },
62 { 12 + 0x100, 12, "\x01\x00\x02\x00\x03\x00\x00\x00\x00\x00\x00\x01" },
63 { 12 + 0x3412, 12, "\x01\x00\x02\x00\x03\x00\x00\x00\x00\x00\x12\x34" },
64 { -1, 12, "\x01\x00\x02\x00\x02\x00\x00\x00\x00\x00\x00\x00" },
65 { 12 + 1, 12, "\x01\x00\x02\x00\x02\x00\x00\x00\x00\x00\x01\x00" },
66 { 12 + 0x100, 12, "\x01\x00\x02\x00\x02\x00\x00\x00\x00\x00\x00\x01" },
67 { 12 + 0x3412, 12, "\x01\x00\x02\x00\x02\x00\x00\x00\x00\x00\x12\x34" },
68 { -1, 14, "\x01\x00\x02\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00" },
69 { 14 + 1, 15, "\x01\x00\x02\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00" },
70 { -1, 15, "\x01\x00\x02\x00\x01\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00" },
71 { 14 + 2, 16, "\x01\x00\x02\x00\x01\x00\x00\x00\x00\x00\x01\x00\x00\x01\x00\x00" },
72 { 14 + 2, 16, "\x01\x00\x02\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x01\x00\x00" },
73 { 14 + 2, 16, "\x01\x00\x02\x00\x01\x00\x01\x00\x00\x00\x00\x00\x00\x01\x00\x00" },
74};
75
76#define RDSTLS_DATA_PASSWORD_CREDS 0x01
77#define RDSTLS_DATA_AUTORECONNECT_COOKIE 0x02
78#define RDSTLS_DATA_FEDAUTH_TOKEN 0x03
79
80static bool test_parse(void)
81{
82 wLog* log = WLog_Get(__func__);
83
84 for (size_t x = 0; x < ARRAYSIZE(tests); x++)
85 {
86 wStream buffer = WINPR_C_ARRAY_INIT;
87 const struct test_case_t* cur = &tests[x];
88 wStream* s = Stream_StaticConstInit(&buffer, cur->data, cur->len);
89 const SSIZE_T rc = rdstls_parse_pdu(log, s);
90 if (rc != cur->expected)
91 {
92 WLog_Print(log, WLOG_ERROR, "Test case %" PRIuz " failed", x);
93 return false;
94 }
95 }
96 return true;
97}
98
99int TestRdstls(WINPR_ATTR_UNUSED int argc, WINPR_ATTR_UNUSED char* argv[])
100{
101 if (!test_parse())
102 return -1;
103
104 return 0;
105}