1+ using System . Net ;
2+ using RCONServerLib . Utils ;
3+ using Xunit ;
4+
5+ namespace RCONServerLib . Tests
6+ {
7+ public class RemoteConTests
8+ {
9+ [ Fact ]
10+ public void RemoteConInvalidAuthPacketTypeTest ( )
11+ {
12+ var server = new RemoteConServer ( IPAddress . Any , 27015 ) ;
13+ server . CommandManager . Add ( "test" , "Test" , ( command , args ) => "test" ) ;
14+
15+ var client = new RemoteConClient ( server ) ;
16+
17+ // Wrong Auth packet type test
18+ Assert . Throws < NotAuthenticatedException > ( ( ) =>
19+ {
20+ client . ParsePacket ( new byte [ ]
21+ {
22+ 0x15 , 0x00 , 0x00 , 0x00 , // Size
23+ 0x02 , 0x00 , 0x00 , 0x00 , // Id
24+ 0x02 , 0x00 , 0x00 , 0x00 , // Type
25+ 0x48 , 0x65 , 0x6C , 0x6C , 0x6F , 0x20 , 0x57 , 0x6F , 0x72 , 0x6C , 0x64 , 0x00 ,
26+ 0x00 ,
27+ } ) ;
28+ } ) ;
29+ }
30+
31+ [ Fact ]
32+ public void RemoteConAuthFailureTest ( )
33+ {
34+ var server = new RemoteConServer ( IPAddress . Any , 27015 ) ;
35+ server . CommandManager . Add ( "test" , "Test" , ( command , args ) => "test" ) ;
36+
37+ var client = new RemoteConClient ( server ) ;
38+
39+ // Auth wrong test
40+ client . ParsePacket ( new byte [ ]
41+ {
42+ 0x15 , 0x00 , 0x00 , 0x00 , // Size
43+ 0x02 , 0x00 , 0x00 , 0x00 , // Id
44+ 0x03 , 0x00 , 0x00 , 0x00 , // Type
45+ 0x48 , 0x65 , 0x6C , 0x6C , 0x6F , 0x20 , 0x57 , 0x6F , 0x72 , 0x6C , 0x64 , 0x00 ,
46+ 0x00 ,
47+ } ) ;
48+ }
49+
50+ [ Fact ]
51+ public void RemoteConAuthSuccessTest ( )
52+ {
53+ var server = new RemoteConServer ( IPAddress . Any , 27015 ) ;
54+ server . CommandManager . Add ( "test" , "Test" , ( command , args ) => "test" ) ;
55+
56+ var client = new RemoteConClient ( server ) ;
57+
58+ // Auth correct test
59+ client . ParsePacket ( new byte [ ]
60+ {
61+ 0x1D , 0x00 , 0x00 , 0x00 , // Size
62+ 0x02 , 0x00 , 0x00 , 0x00 , // Id
63+ 0x03 , 0x00 , 0x00 , 0x00 , // Type
64+ 0x73 , 0x75 , 0x70 , 0x65 , 0x72 , 0x73 , 0x65 , 0x63 , 0x75 , 0x72 , 0x65 , 0x70 , 0x61 , 0x73 , 0x73 , 0x77 , 0x6F , 0x72 , 0x64 , 0x00 ,
65+ 0x00 ,
66+ } ) ;
67+ }
68+
69+ [ Fact ]
70+ public void RemoteConInvalidCommandTest ( )
71+ {
72+ var server = new RemoteConServer ( IPAddress . Any , 27015 ) ;
73+ server . CommandManager . Add ( "test" , "Test" , ( command , args ) => "test" ) ;
74+
75+ var client = new RemoteConClient ( server ) ;
76+ client . Authenticated = true ;
77+
78+ // No command found test
79+ client . ParsePacket ( new byte [ ]
80+ {
81+ 0x15 , 0x00 , 0x00 , 0x00 , // Size
82+ 0x02 , 0x00 , 0x00 , 0x00 , // Id
83+ 0x02 , 0x00 , 0x00 , 0x00 , // Type
84+ 0x48 , 0x65 , 0x6C , 0x6C , 0x6F , 0x20 , 0x57 , 0x6F , 0x72 , 0x6C , 0x64 , 0x00 ,
85+ 0x00 ,
86+ } ) ;
87+ }
88+
89+ [ Fact ]
90+ public void RemoteConCommandTest ( )
91+ {
92+ var server = new RemoteConServer ( IPAddress . Any , 27015 ) ;
93+ server . CommandManager . Add ( "test" , "Test" , ( command , args ) => "test" ) ;
94+
95+ var client = new RemoteConClient ( server ) ;
96+ client . Authenticated = true ;
97+
98+ // Command test
99+ client . ParsePacket ( new byte [ ]
100+ {
101+ 0x0E , 0x00 , 0x00 , 0x00 , // Size
102+ 0x02 , 0x00 , 0x00 , 0x00 , // Id
103+ 0x02 , 0x00 , 0x00 , 0x00 , // Type
104+ 0x74 , 0x65 , 0x73 , 0x74 , 0x00 ,
105+ 0x00 ,
106+ } ) ;
107+ }
108+
109+ [ Fact ]
110+ public void RemoteConEmptyPayloadTest ( )
111+ {
112+ var server = new RemoteConServer ( IPAddress . Any , 27015 ) ;
113+ server . CommandManager . Add ( "test" , "Test" , ( command , args ) => "test" ) ;
114+
115+ var client = new RemoteConClient ( server ) ;
116+ client . Authenticated = true ;
117+
118+ // Empty payload test
119+ Assert . Throws < EmptyPacketPayloadException > ( ( ) =>
120+ {
121+ client . ParsePacket ( new byte [ ]
122+ {
123+ 0x0A , 0x00 , 0x00 , 0x00 , // Size
124+ 0x02 , 0x00 , 0x00 , 0x00 , // Id
125+ 0x02 , 0x00 , 0x00 , 0x00 , // Type
126+ 0x00 ,
127+ 0x00 ,
128+ } ) ;
129+ } ) ;
130+ }
131+
132+ [ Fact ]
133+ public void RemoteConInvalidPacketTypeTest ( )
134+ {
135+ var server = new RemoteConServer ( IPAddress . Any , 27015 ) ;
136+ server . CommandManager . Add ( "test" , "Test" , ( command , args ) => "test" ) ;
137+
138+ var client = new RemoteConClient ( server ) ;
139+ client . Authenticated = true ;
140+
141+ // Type other than execcommand
142+ Assert . Throws < InvalidPacketTypeException > ( ( ) =>
143+ {
144+ client . ParsePacket ( new byte [ ]
145+ {
146+ 0x0E , 0x00 , 0x00 , 0x00 , // Size
147+ 0x02 , 0x00 , 0x00 , 0x00 , // Id
148+ 0x00 , 0x00 , 0x00 , 0x00 , // Type
149+ 0x74 , 0x65 , 0x73 , 0x74 , 0x00 ,
150+ 0x00 ,
151+ } ) ;
152+ } ) ;
153+ }
154+ }
155+ }
0 commit comments