1
0

AgentCircuitManagerTests.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. namespace OpenSim.Framework.Tests
  32. {
  33. [TestFixture]
  34. public class AgentCircuitManagerTests
  35. {
  36. private AgentCircuitData m_agentCircuitData1;
  37. private AgentCircuitData m_agentCircuitData2;
  38. private UUID AgentId1;
  39. private UUID AgentId2;
  40. private uint circuitcode1;
  41. private uint circuitcode2;
  42. private UUID SessionId1;
  43. private UUID SessionId2;
  44. private Random rnd = new Random(Environment.TickCount);
  45. [SetUp]
  46. public void setup()
  47. {
  48. AgentId1 = UUID.Random();
  49. AgentId2 = UUID.Random();
  50. circuitcode1 = (uint) rnd.Next((int)uint.MinValue, int.MaxValue);
  51. circuitcode2 = (uint) rnd.Next((int)uint.MinValue, int.MaxValue);
  52. SessionId1 = UUID.Random();
  53. SessionId2 = UUID.Random();
  54. UUID BaseFolder = UUID.Random();
  55. string CapsPath = "http://www.opensimulator.org/Caps/Foo";
  56. Dictionary<ulong,string> ChildrenCapsPaths = new Dictionary<ulong, string>();
  57. ChildrenCapsPaths.Add(ulong.MaxValue, "http://www.opensimulator.org/Caps/Foo2");
  58. string firstname = "CoolAvatarTest";
  59. string lastname = "test";
  60. Vector3 StartPos = new Vector3(5, 23, 125);
  61. UUID SecureSessionId = UUID.Random();
  62. // TODO: unused: UUID SessionId = UUID.Random();
  63. m_agentCircuitData1 = new AgentCircuitData();
  64. m_agentCircuitData1.AgentID = AgentId1;
  65. m_agentCircuitData1.Appearance = new AvatarAppearance();
  66. m_agentCircuitData1.BaseFolder = BaseFolder;
  67. m_agentCircuitData1.CapsPath = CapsPath;
  68. m_agentCircuitData1.child = false;
  69. m_agentCircuitData1.ChildrenCapSeeds = ChildrenCapsPaths;
  70. m_agentCircuitData1.circuitcode = circuitcode1;
  71. m_agentCircuitData1.firstname = firstname;
  72. m_agentCircuitData1.InventoryFolder = BaseFolder;
  73. m_agentCircuitData1.lastname = lastname;
  74. m_agentCircuitData1.SecureSessionID = SecureSessionId;
  75. m_agentCircuitData1.SessionID = SessionId1;
  76. m_agentCircuitData1.startpos = StartPos;
  77. m_agentCircuitData2 = new AgentCircuitData();
  78. m_agentCircuitData2.AgentID = AgentId2;
  79. m_agentCircuitData2.Appearance = new AvatarAppearance();
  80. m_agentCircuitData2.BaseFolder = BaseFolder;
  81. m_agentCircuitData2.CapsPath = CapsPath;
  82. m_agentCircuitData2.child = false;
  83. m_agentCircuitData2.ChildrenCapSeeds = ChildrenCapsPaths;
  84. m_agentCircuitData2.circuitcode = circuitcode2;
  85. m_agentCircuitData2.firstname = firstname;
  86. m_agentCircuitData2.InventoryFolder = BaseFolder;
  87. m_agentCircuitData2.lastname = lastname;
  88. m_agentCircuitData2.SecureSessionID = SecureSessionId;
  89. m_agentCircuitData2.SessionID = SessionId2;
  90. m_agentCircuitData2.startpos = StartPos;
  91. }
  92. /// <summary>
  93. /// Validate that adding the circuit works appropriately
  94. /// </summary>
  95. [Test]
  96. public void AddAgentCircuitTest()
  97. {
  98. AgentCircuitManager agentCircuitManager = new AgentCircuitManager();
  99. agentCircuitManager.AddNewCircuit(circuitcode1,m_agentCircuitData1);
  100. agentCircuitManager.AddNewCircuit(circuitcode2, m_agentCircuitData2);
  101. AgentCircuitData agent = agentCircuitManager.GetAgentCircuitData(circuitcode1);
  102. Assert.That((m_agentCircuitData1.AgentID == agent.AgentID));
  103. Assert.That((m_agentCircuitData1.BaseFolder == agent.BaseFolder));
  104. Assert.That((m_agentCircuitData1.CapsPath == agent.CapsPath));
  105. Assert.That((m_agentCircuitData1.child == agent.child));
  106. Assert.That((m_agentCircuitData1.ChildrenCapSeeds.Count == agent.ChildrenCapSeeds.Count));
  107. Assert.That((m_agentCircuitData1.circuitcode == agent.circuitcode));
  108. Assert.That((m_agentCircuitData1.firstname == agent.firstname));
  109. Assert.That((m_agentCircuitData1.InventoryFolder == agent.InventoryFolder));
  110. Assert.That((m_agentCircuitData1.lastname == agent.lastname));
  111. Assert.That((m_agentCircuitData1.SecureSessionID == agent.SecureSessionID));
  112. Assert.That((m_agentCircuitData1.SessionID == agent.SessionID));
  113. Assert.That((m_agentCircuitData1.startpos == agent.startpos));
  114. }
  115. /// <summary>
  116. /// Validate that removing the circuit code removes it appropriately
  117. /// </summary>
  118. [Test]
  119. public void RemoveAgentCircuitTest()
  120. {
  121. AgentCircuitManager agentCircuitManager = new AgentCircuitManager();
  122. agentCircuitManager.AddNewCircuit(circuitcode1, m_agentCircuitData1);
  123. agentCircuitManager.AddNewCircuit(circuitcode2, m_agentCircuitData2);
  124. agentCircuitManager.RemoveCircuit(circuitcode2);
  125. AgentCircuitData agent = agentCircuitManager.GetAgentCircuitData(circuitcode2);
  126. Assert.That(agent == null);
  127. }
  128. /// <summary>
  129. /// Validate that changing the circuit code works
  130. /// </summary>
  131. [Test]
  132. public void ChangeAgentCircuitCodeTest()
  133. {
  134. AgentCircuitManager agentCircuitManager = new AgentCircuitManager();
  135. agentCircuitManager.AddNewCircuit(circuitcode1, m_agentCircuitData1);
  136. agentCircuitManager.AddNewCircuit(circuitcode2, m_agentCircuitData2);
  137. bool result = false;
  138. result = agentCircuitManager.TryChangeCiruitCode(circuitcode1, 393930);
  139. AgentCircuitData agent = agentCircuitManager.GetAgentCircuitData(393930);
  140. AgentCircuitData agent2 = agentCircuitManager.GetAgentCircuitData(circuitcode1);
  141. Assert.That(agent != null);
  142. Assert.That(agent2 == null);
  143. Assert.That(result);
  144. }
  145. /// <summary>
  146. /// Validates that the login authentication scheme is working
  147. /// First one should be authorized
  148. /// Rest should not be authorized
  149. /// </summary>
  150. [Test]
  151. public void ValidateLoginTest()
  152. {
  153. AgentCircuitManager agentCircuitManager = new AgentCircuitManager();
  154. agentCircuitManager.AddNewCircuit(circuitcode1, m_agentCircuitData1);
  155. agentCircuitManager.AddNewCircuit(circuitcode2, m_agentCircuitData2);
  156. // should be authorized
  157. AuthenticateResponse resp = agentCircuitManager.AuthenticateSession(SessionId1, AgentId1, circuitcode1);
  158. Assert.That(resp.Authorised);
  159. //should not be authorized
  160. resp = agentCircuitManager.AuthenticateSession(SessionId1, UUID.Random(), circuitcode1);
  161. Assert.That(!resp.Authorised);
  162. resp = agentCircuitManager.AuthenticateSession(UUID.Random(), AgentId1, circuitcode1);
  163. Assert.That(!resp.Authorised);
  164. resp = agentCircuitManager.AuthenticateSession(SessionId1, AgentId1, circuitcode2);
  165. Assert.That(!resp.Authorised);
  166. resp = agentCircuitManager.AuthenticateSession(SessionId2, AgentId1, circuitcode2);
  167. Assert.That(!resp.Authorised);
  168. agentCircuitManager.RemoveCircuit(circuitcode2);
  169. resp = agentCircuitManager.AuthenticateSession(SessionId2, AgentId2, circuitcode2);
  170. Assert.That(!resp.Authorised);
  171. }
  172. }
  173. }