Skip to content
This repository was archived by the owner on Dec 23, 2022. It is now read-only.

Commit e637fdb

Browse files
committed
Refactored internal names
Added more RemoteConPacket tests Moved exceptions to own file
1 parent 8b30f00 commit e637fdb

File tree

11 files changed

+301
-175
lines changed

11 files changed

+301
-175
lines changed

RCONServerLib.Tests/RCONServerLib.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
</ItemGroup>
5454
<ItemGroup>
5555
<Compile Include="Properties\AssemblyInfo.cs" />
56+
<Compile Include="RemoteConTests.cs" />
5657
<Compile Include="Tests.cs" />
5758
</ItemGroup>
5859
<ItemGroup>
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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+
}

RCONServerLib.Tests/Tests.cs

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -127,72 +127,5 @@ public void ExtendedBinaryReaderTest()
127127
}
128128
}
129129
}
130-
131-
[Fact]
132-
public void RemoteConProcessPacketTest()
133-
{
134-
var server = new RemoteConServer(IPAddress.Any, 27015);
135-
server.CommandManager.Add("test", "Test", (command, args) => { return "test"; });
136-
137-
var client = new RemoteConClient(server);
138-
139-
// Auth wrong test
140-
client.ProcessPacket(new byte[]
141-
{
142-
0x15, 0x00, 0x00, 0x00, // Size
143-
0x02, 0x00, 0x00, 0x00, // Id
144-
0x03, 0x00, 0x00, 0x00, // Type
145-
0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x00,
146-
0x00,
147-
});
148-
149-
// Auth correct test
150-
client.ProcessPacket(new byte[]
151-
{
152-
0x1D, 0x00, 0x00, 0x00, // Size
153-
0x02, 0x00, 0x00, 0x00, // Id
154-
0x03, 0x00, 0x00, 0x00, // Type
155-
0x73, 0x75, 0x70, 0x65, 0x72, 0x73, 0x65, 0x63, 0x75, 0x72, 0x65, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6F, 0x72, 0x64, 0x00,
156-
0x00,
157-
});
158-
client.Authenticated = true;
159-
160-
// No command found test
161-
client.ProcessPacket(new byte[]
162-
{
163-
0x15, 0x00, 0x00, 0x00, // Size
164-
0x02, 0x00, 0x00, 0x00, // Id
165-
0x02, 0x00, 0x00, 0x00, // Type
166-
0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x00,
167-
0x00,
168-
});
169-
// Command test
170-
client.ProcessPacket(new byte[]
171-
{
172-
0x0E, 0x00, 0x00, 0x00, // Size
173-
0x02, 0x00, 0x00, 0x00, // Id
174-
0x02, 0x00, 0x00, 0x00, // Type
175-
0x74, 0x65, 0x73, 0x74, 0x00,
176-
0x00,
177-
});
178-
// Empty payload test
179-
client.ProcessPacket(new byte[]
180-
{
181-
0x0A, 0x00, 0x00, 0x00, // Size
182-
0x02, 0x00, 0x00, 0x00, // Id
183-
0x02, 0x00, 0x00, 0x00, // Type
184-
0x00,
185-
0x00,
186-
});
187-
// Type other than execcommand
188-
client.ProcessPacket(new byte[]
189-
{
190-
0x0E, 0x00, 0x00, 0x00, // Size
191-
0x02, 0x00, 0x00, 0x00, // Id
192-
0x00, 0x00, 0x00, 0x00, // Type
193-
0x74, 0x65, 0x73, 0x74, 0x00,
194-
0x00,
195-
});
196-
}
197130
}
198131
}

RCONServerLib/RCONServerLib.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
<Compile Include="Utils\BinaryReaderExt.cs" />
4848
<Compile Include="Utils\BinaryWriterExt.cs" />
4949
<Compile Include="Utils\CommandManager.cs" />
50+
<Compile Include="Utils\Exceptions.cs" />
5051
<Compile Include="Utils\IpExtension.cs" />
5152
</ItemGroup>
5253
<ItemGroup>

0 commit comments

Comments
 (0)