diff options
author | Teravus Ovares (Dan Olivares) | 2009-08-13 21:01:39 -0400 |
---|---|---|
committer | Teravus Ovares (Dan Olivares) | 2009-08-13 21:01:39 -0400 |
commit | 7a761560c6482b092b16464b2cde893a74f8ffb6 (patch) | |
tree | fdcc678b353f619a42335006e044c3ca92a40952 | |
parent | * Adds two tests to OpenSim.Framework.Tests. *AgentCircuitData test to ensure... (diff) | |
download | opensim-SC_OLD-7a761560c6482b092b16464b2cde893a74f8ffb6.zip opensim-SC_OLD-7a761560c6482b092b16464b2cde893a74f8ffb6.tar.gz opensim-SC_OLD-7a761560c6482b092b16464b2cde893a74f8ffb6.tar.bz2 opensim-SC_OLD-7a761560c6482b092b16464b2cde893a74f8ffb6.tar.xz |
* Add AgentCircuitManager tests for adding, removing, changing circuit code, and authentication.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/Tests/AgentCircuitManagerTests.cs | 201 |
1 files changed, 201 insertions, 0 deletions
diff --git a/OpenSim/Framework/Tests/AgentCircuitManagerTests.cs b/OpenSim/Framework/Tests/AgentCircuitManagerTests.cs new file mode 100644 index 0000000..ab5f04a --- /dev/null +++ b/OpenSim/Framework/Tests/AgentCircuitManagerTests.cs | |||
@@ -0,0 +1,201 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | using System.Collections.Generic; | ||
28 | using OpenMetaverse; | ||
29 | using NUnit.Framework; | ||
30 | using System; | ||
31 | |||
32 | namespace OpenSim.Framework.Tests | ||
33 | { | ||
34 | [TestFixture] | ||
35 | public class AgentCircuitManagerTests | ||
36 | { | ||
37 | private AgentCircuitData m_agentCircuitData1; | ||
38 | private AgentCircuitData m_agentCircuitData2; | ||
39 | private UUID AgentId1; | ||
40 | private UUID AgentId2; | ||
41 | private uint circuitcode1; | ||
42 | private uint circuitcode2; | ||
43 | |||
44 | private UUID SessionId1; | ||
45 | private UUID SessionId2; | ||
46 | private Random rnd = new Random(Environment.TickCount); | ||
47 | |||
48 | [SetUp] | ||
49 | public void setup() | ||
50 | { | ||
51 | |||
52 | AgentId1 = UUID.Random(); | ||
53 | AgentId2 = UUID.Random(); | ||
54 | circuitcode1 = (uint) rnd.Next((int)uint.MinValue, int.MaxValue); | ||
55 | circuitcode2 = (uint) rnd.Next((int)uint.MinValue, int.MaxValue); | ||
56 | SessionId1 = UUID.Random(); | ||
57 | SessionId2 = UUID.Random(); | ||
58 | UUID BaseFolder = UUID.Random(); | ||
59 | string CapsPath = "http://www.opensimulator.org/Caps/Foo"; | ||
60 | Dictionary<ulong,string> ChildrenCapsPaths = new Dictionary<ulong, string>(); | ||
61 | ChildrenCapsPaths.Add(ulong.MaxValue, "http://www.opensimulator.org/Caps/Foo2"); | ||
62 | string firstname = "CoolAvatarTest"; | ||
63 | string lastname = "test"; | ||
64 | Vector3 StartPos = new Vector3(5, 23, 125); | ||
65 | |||
66 | UUID SecureSessionId = UUID.Random(); | ||
67 | UUID SessionId = UUID.Random(); | ||
68 | |||
69 | m_agentCircuitData1 = new AgentCircuitData(); | ||
70 | m_agentCircuitData1.AgentID = AgentId1; | ||
71 | m_agentCircuitData1.Appearance = new AvatarAppearance(AgentId1); | ||
72 | m_agentCircuitData1.BaseFolder = BaseFolder; | ||
73 | m_agentCircuitData1.CapsPath = CapsPath; | ||
74 | m_agentCircuitData1.child = false; | ||
75 | m_agentCircuitData1.ChildrenCapSeeds = ChildrenCapsPaths; | ||
76 | m_agentCircuitData1.circuitcode = circuitcode1; | ||
77 | m_agentCircuitData1.firstname = firstname; | ||
78 | m_agentCircuitData1.InventoryFolder = BaseFolder; | ||
79 | m_agentCircuitData1.lastname = lastname; | ||
80 | m_agentCircuitData1.SecureSessionID = SecureSessionId; | ||
81 | m_agentCircuitData1.SessionID = SessionId1; | ||
82 | m_agentCircuitData1.startpos = StartPos; | ||
83 | |||
84 | m_agentCircuitData2 = new AgentCircuitData(); | ||
85 | m_agentCircuitData2.AgentID = AgentId2; | ||
86 | m_agentCircuitData2.Appearance = new AvatarAppearance(AgentId2); | ||
87 | m_agentCircuitData2.BaseFolder = BaseFolder; | ||
88 | m_agentCircuitData2.CapsPath = CapsPath; | ||
89 | m_agentCircuitData2.child = false; | ||
90 | m_agentCircuitData2.ChildrenCapSeeds = ChildrenCapsPaths; | ||
91 | m_agentCircuitData2.circuitcode = circuitcode2; | ||
92 | m_agentCircuitData2.firstname = firstname; | ||
93 | m_agentCircuitData2.InventoryFolder = BaseFolder; | ||
94 | m_agentCircuitData2.lastname = lastname; | ||
95 | m_agentCircuitData2.SecureSessionID = SecureSessionId; | ||
96 | m_agentCircuitData2.SessionID = SessionId2; | ||
97 | m_agentCircuitData2.startpos = StartPos; | ||
98 | } | ||
99 | |||
100 | /// <summary> | ||
101 | /// Validate that adding the circuit works appropriately | ||
102 | /// </summary> | ||
103 | [Test] | ||
104 | public void AddAgentCircuitTest() | ||
105 | { | ||
106 | AgentCircuitManager agentCircuitManager = new AgentCircuitManager(); | ||
107 | agentCircuitManager.AddNewCircuit(circuitcode1,m_agentCircuitData1); | ||
108 | agentCircuitManager.AddNewCircuit(circuitcode2, m_agentCircuitData2); | ||
109 | AgentCircuitData agent = agentCircuitManager.GetAgentCircuitData(circuitcode1); | ||
110 | |||
111 | Assert.That((m_agentCircuitData1.AgentID == agent.AgentID)); | ||
112 | Assert.That((m_agentCircuitData1.BaseFolder == agent.BaseFolder)); | ||
113 | |||
114 | Assert.That((m_agentCircuitData1.CapsPath == agent.CapsPath)); | ||
115 | Assert.That((m_agentCircuitData1.child == agent.child)); | ||
116 | Assert.That((m_agentCircuitData1.ChildrenCapSeeds.Count == agent.ChildrenCapSeeds.Count)); | ||
117 | Assert.That((m_agentCircuitData1.circuitcode == agent.circuitcode)); | ||
118 | Assert.That((m_agentCircuitData1.firstname == agent.firstname)); | ||
119 | Assert.That((m_agentCircuitData1.InventoryFolder == agent.InventoryFolder)); | ||
120 | Assert.That((m_agentCircuitData1.lastname == agent.lastname)); | ||
121 | Assert.That((m_agentCircuitData1.SecureSessionID == agent.SecureSessionID)); | ||
122 | Assert.That((m_agentCircuitData1.SessionID == agent.SessionID)); | ||
123 | Assert.That((m_agentCircuitData1.startpos == agent.startpos)); | ||
124 | } | ||
125 | |||
126 | /// <summary> | ||
127 | /// Validate that removing the circuit code removes it appropriately | ||
128 | /// </summary> | ||
129 | [Test] | ||
130 | public void RemoveAgentCircuitTest() | ||
131 | { | ||
132 | AgentCircuitManager agentCircuitManager = new AgentCircuitManager(); | ||
133 | agentCircuitManager.AddNewCircuit(circuitcode1, m_agentCircuitData1); | ||
134 | agentCircuitManager.AddNewCircuit(circuitcode2, m_agentCircuitData2); | ||
135 | agentCircuitManager.RemoveCircuit(circuitcode2); | ||
136 | |||
137 | AgentCircuitData agent = agentCircuitManager.GetAgentCircuitData(circuitcode2); | ||
138 | Assert.That(agent == null); | ||
139 | |||
140 | } | ||
141 | |||
142 | /// <summary> | ||
143 | /// Validate that changing the circuit code works | ||
144 | /// </summary> | ||
145 | [Test] | ||
146 | public void ChangeAgentCircuitCodeTest() | ||
147 | { | ||
148 | AgentCircuitManager agentCircuitManager = new AgentCircuitManager(); | ||
149 | agentCircuitManager.AddNewCircuit(circuitcode1, m_agentCircuitData1); | ||
150 | agentCircuitManager.AddNewCircuit(circuitcode2, m_agentCircuitData2); | ||
151 | bool result = false; | ||
152 | |||
153 | result = agentCircuitManager.TryChangeCiruitCode(circuitcode1, 393930); | ||
154 | |||
155 | AgentCircuitData agent = agentCircuitManager.GetAgentCircuitData(393930); | ||
156 | AgentCircuitData agent2 = agentCircuitManager.GetAgentCircuitData(circuitcode1); | ||
157 | Assert.That(agent != null); | ||
158 | Assert.That(agent2 == null); | ||
159 | Assert.That(result); | ||
160 | |||
161 | } | ||
162 | |||
163 | /// <summary> | ||
164 | /// Validates that the login authentication scheme is working | ||
165 | /// First one should be authorized | ||
166 | /// Rest should not be authorized | ||
167 | /// </summary> | ||
168 | [Test] | ||
169 | public void ValidateLoginTest() | ||
170 | { | ||
171 | AgentCircuitManager agentCircuitManager = new AgentCircuitManager(); | ||
172 | agentCircuitManager.AddNewCircuit(circuitcode1, m_agentCircuitData1); | ||
173 | agentCircuitManager.AddNewCircuit(circuitcode2, m_agentCircuitData2); | ||
174 | |||
175 | // should be authorized | ||
176 | AuthenticateResponse resp = agentCircuitManager.AuthenticateSession(SessionId1, AgentId1, circuitcode1); | ||
177 | Assert.That(resp.Authorised); | ||
178 | |||
179 | |||
180 | //should not be authorized | ||
181 | resp = agentCircuitManager.AuthenticateSession(SessionId1, UUID.Random(), circuitcode1); | ||
182 | Assert.That(!resp.Authorised); | ||
183 | |||
184 | resp = agentCircuitManager.AuthenticateSession(UUID.Random(), AgentId1, circuitcode1); | ||
185 | Assert.That(!resp.Authorised); | ||
186 | |||
187 | resp = agentCircuitManager.AuthenticateSession(SessionId1, AgentId1, circuitcode2); | ||
188 | Assert.That(!resp.Authorised); | ||
189 | |||
190 | resp = agentCircuitManager.AuthenticateSession(SessionId2, AgentId1, circuitcode2); | ||
191 | Assert.That(!resp.Authorised); | ||
192 | |||
193 | agentCircuitManager.RemoveCircuit(circuitcode2); | ||
194 | |||
195 | resp = agentCircuitManager.AuthenticateSession(SessionId2, AgentId2, circuitcode2); | ||
196 | Assert.That(!resp.Authorised); | ||
197 | |||
198 | } | ||
199 | |||
200 | } | ||
201 | } | ||