From 419775c72bcf0297e84ff3c74354a0aba523e1e2 Mon Sep 17 00:00:00 2001
From: Justin Clarke Casey
Date: Thu, 30 Oct 2008 20:17:30 +0000
Subject: * test: Test that the client stack doesn't completely blow up if a
client passes it malformed data
---
.../LindenUDP/Tests/BasicCircuitTests.cs | 41 +++++++++++++++++-----
.../ClientStack/LindenUDP/Tests/TestLLUDPServer.cs | 12 ++++++-
2 files changed, 43 insertions(+), 10 deletions(-)
(limited to 'OpenSim/Region/ClientStack/LindenUDP/Tests')
diff --git a/OpenSim/Region/ClientStack/LindenUDP/Tests/BasicCircuitTests.cs b/OpenSim/Region/ClientStack/LindenUDP/Tests/BasicCircuitTests.cs
index 07fbf55..c75a5b3 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/Tests/BasicCircuitTests.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/Tests/BasicCircuitTests.cs
@@ -62,7 +62,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
///
///
/// Agent circuit manager used in setting up the stack
- protected void SetupStack( out TestLLUDPServer testLLUDPServer, out AgentCircuitManager acm)
+ protected void SetupStack(out TestLLUDPServer testLLUDPServer, out AgentCircuitManager acm)
{
ClientStackUserSettings userSettings = new ClientStackUserSettings();
testLLUDPServer = new TestLLUDPServer();
@@ -78,9 +78,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
/// Set up a client for tests which aren't concerned with this process itself
///
///
+ ///
///
///
- protected void AddClient(uint circuitCode, TestLLUDPServer testLLUDPServer, AgentCircuitManager acm)
+ protected void AddClient(
+ uint circuitCode, EndPoint epSender, TestLLUDPServer testLLUDPServer, AgentCircuitManager acm)
{
UUID myAgentUuid = UUID.Parse("00000000-0000-0000-0000-000000000001");
UUID mySessionUuid = UUID.Parse("00000000-0000-0000-0000-000000000002");
@@ -97,19 +99,17 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
uccpCcBlock.ID = myAgentUuid;
uccpCcBlock.SessionID = mySessionUuid;
uccp.CircuitCode = uccpCcBlock;
-
- EndPoint testEp = new IPEndPoint(IPAddress.Loopback, 999);
-
+
acm.AddNewCircuit(circuitCode, acd);
- testLLUDPServer.LoadReceive(uccp, testEp);
+ testLLUDPServer.LoadReceive(uccp, epSender);
testLLUDPServer.ReceiveData(null);
}
- [Test]
///
/// Test adding a client to the stack
///
+ [Test]
public void TestAddClient()
{
uint myCircuitCode = 123456;
@@ -151,10 +151,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
Assert.IsFalse(testLLUDPServer.HasCircuit(101));
}
- [Test]
///
/// Test removing a client from the stack
///
+ [Test]
public void TestRemoveClient()
{
uint myCircuitCode = 123457;
@@ -162,7 +162,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
TestLLUDPServer testLLUDPServer;
AgentCircuitManager acm;
SetupStack(out testLLUDPServer, out acm);
- AddClient(myCircuitCode, testLLUDPServer, acm);
+ AddClient(myCircuitCode, new IPEndPoint(IPAddress.Loopback, 1000), testLLUDPServer, acm);
testLLUDPServer.RemoveClientCircuit(myCircuitCode);
Assert.IsFalse(testLLUDPServer.HasCircuit(myCircuitCode));
@@ -171,5 +171,28 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
testLLUDPServer.RemoveClientCircuit(101);
Assert.IsFalse(testLLUDPServer.HasCircuit(101));
}
+
+ ///
+ /// Make sure that the client stack reacts okay to malformed packets
+ ///
+ [Test]
+ public void TestMalformedPacketSend()
+ {
+ uint myCircuitCode = 123458;
+ EndPoint testEp = new IPEndPoint(IPAddress.Loopback, 1001);
+
+ TestLLUDPServer testLLUDPServer;
+ AgentCircuitManager acm;
+ SetupStack(out testLLUDPServer, out acm);
+ AddClient(myCircuitCode, testEp, testLLUDPServer, acm);
+
+ byte[] data = new byte[] { 0x01, 0x02, 0x03, 0x04 };
+
+ testLLUDPServer.LoadReceive(data, testEp);
+ testLLUDPServer.ReceiveData(null);
+
+ // Check that we are still here
+ Assert.IsTrue(testLLUDPServer.HasCircuit(myCircuitCode));
+ }
}
}
diff --git a/OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLUDPServer.cs
index 8170150..95ee516 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLUDPServer.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLUDPServer.cs
@@ -72,12 +72,22 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests
}
///
+ /// Load some data to be received by the LLUDPServer on the next receive call
+ ///
+ ///
+ ///
+ public void LoadReceive(byte[] data, EndPoint epSender)
+ {
+ m_chunksToLoad.Enqueue(new ChunkSenderTuple(data, epSender));
+ }
+
+ ///
/// Load a packet to be received by the LLUDPServer on the next receive call
///
///
public void LoadReceive(Packet packet, EndPoint epSender)
{
- m_chunksToLoad.Enqueue(new ChunkSenderTuple(packet.ToBytes(), epSender));
+ LoadReceive(packet.ToBytes(), epSender);
}
///
--
cgit v1.1