aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Communications/Tests
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Communications/Tests')
-rw-r--r--OpenSim/Framework/Communications/Tests/Cache/UserProfileCacheServiceTests.cs345
-rw-r--r--OpenSim/Framework/Communications/Tests/LoginServiceTests.cs453
2 files changed, 0 insertions, 798 deletions
diff --git a/OpenSim/Framework/Communications/Tests/Cache/UserProfileCacheServiceTests.cs b/OpenSim/Framework/Communications/Tests/Cache/UserProfileCacheServiceTests.cs
deleted file mode 100644
index 830c877..0000000
--- a/OpenSim/Framework/Communications/Tests/Cache/UserProfileCacheServiceTests.cs
+++ /dev/null
@@ -1,345 +0,0 @@
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
28using NUnit.Framework;
29using NUnit.Framework.SyntaxHelpers;
30using System.Threading;
31using OpenMetaverse;
32using OpenSim.Data;
33using OpenSim.Framework;
34using OpenSim.Framework.Communications.Cache;
35using OpenSim.Region.Framework.Scenes;
36using OpenSim.Region.Communications.Local;
37using OpenSim.Tests.Common.Mock;
38using OpenSim.Tests.Common.Setup;
39using OpenSim.Tests.Common;
40
41namespace OpenSim.Framework.Communications.Tests
42{
43 [TestFixture]
44 public class UserProfileCacheServiceTests
45 {
46 /// <value>Used by tests to indicate whether an async operation timed out</value>
47 private bool timedOut;
48
49 private void InventoryReceived(UUID userId)
50 {
51 lock (this)
52 {
53 timedOut = false;
54 Monitor.PulseAll(this);
55 }
56 }
57
58 [Test]
59 public void TestGetUserDetails()
60 {
61 TestHelper.InMethod();
62
63 UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000002");
64 string firstName = "Bill";
65 string lastName = "Bailey";
66 CachedUserInfo nonExistingUserInfo;
67
68 TestCommunicationsManager commsManager = new TestCommunicationsManager();
69 // Scene myScene = SceneSetupHelpers.SetupScene(commsManager, "");
70
71 // Check we can't retrieve info before it exists by uuid
72 nonExistingUserInfo = commsManager.UserProfileCacheService.GetUserDetails(userId);
73 Assert.That(nonExistingUserInfo, Is.Null, "User info found by uuid before user creation");
74
75 // Check we can't retrieve info before it exists by name
76 nonExistingUserInfo = commsManager.UserProfileCacheService.GetUserDetails(firstName, lastName);
77 Assert.That(nonExistingUserInfo, Is.Null, "User info found by name before user creation");
78
79 LocalUserServices lus = (LocalUserServices)commsManager.UserService;
80 lus.AddUser(firstName, lastName, "troll", "bill@bailey.com", 1000, 1000, userId);
81
82 CachedUserInfo existingUserInfo;
83
84 // Check we can retrieve info by uuid
85 existingUserInfo = commsManager.UserProfileCacheService.GetUserDetails(userId);
86 Assert.That(existingUserInfo, Is.Not.Null, "User info not found by uuid");
87
88 // Check we can retrieve info by name
89 existingUserInfo = commsManager.UserProfileCacheService.GetUserDetails(firstName, lastName);
90 Assert.That(existingUserInfo, Is.Not.Null, "User info not found by name");
91 }
92
93 /**
94 * Disabled as not fully implemented
95 [Test]
96 public void TestUpdateProfile()
97 {
98 UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000292");
99 string firstName = "Inspector";
100 string originalLastName = "Morse";
101 string newLastName = "Gadget";
102
103 UserProfileData newProfile = new UserProfileData();
104 newProfile.ID = userId;
105 newProfile.FirstName = firstName;
106 newProfile.SurName = newLastName;
107
108 TestCommunicationsManager commsManager = new TestCommunicationsManager();
109 UserProfileCacheService userCacheService = commsManager.UserProfileCacheService;
110 IUserDataPlugin userDataPlugin = commsManager.UserDataPlugin;
111
112 // Check that we can't update info before it exists
113 Assert.That(userCacheService.StoreProfile(newProfile), Is.False);
114 Assert.That(userDataPlugin.GetUserByUUID(userId), Is.Null);
115
116 // Check that we can update a profile once it exists
117 LocalUserServices lus = (LocalUserServices)commsManager.UserService;
118 lus.AddUser(firstName, originalLastName, "pingu", "ted@excellentadventure.com", 1000, 1000, userId);
119
120 Assert.That(userCacheService.StoreProfile(newProfile), Is.True);
121 UserProfileData retrievedProfile = userCacheService.GetUserDetails(userId).UserProfile;
122 Assert.That(retrievedProfile.SurName, Is.EqualTo(newLastName));
123 Assert.That(userDataPlugin.GetUserByUUID(userId).SurName, Is.EqualTo(newLastName));
124 }
125 */
126
127 [Test]
128 public void TestFetchInventory()
129 {
130 TestHelper.InMethod();
131
132 Scene myScene = SceneSetupHelpers.SetupScene("inventory");
133
134 timedOut = true;
135 lock (this)
136 {
137 UserProfileTestUtils.CreateUserWithInventory(myScene.CommsManager, InventoryReceived);
138 Monitor.Wait(this, 60000);
139 }
140
141 Assert.That(timedOut, Is.False, "Timed out");
142 }
143
144 [Test]
145 public void TestGetChildFolder()
146 {
147 TestHelper.InMethod();
148
149 Scene myScene = SceneSetupHelpers.SetupScene("inventory");
150 CachedUserInfo userInfo;
151
152 lock (this)
153 {
154 userInfo = UserProfileTestUtils.CreateUserWithInventory(myScene.CommsManager, InventoryReceived);
155 Monitor.Wait(this, 60000);
156 }
157
158 UUID folderId = UUID.Parse("00000000-0000-0000-0000-000000000011");
159 Assert.That(userInfo.RootFolder.GetChildFolder(folderId), Is.Null);
160 userInfo.CreateFolder("testFolder", folderId, (ushort)AssetType.Animation, userInfo.RootFolder.ID);
161
162 Assert.That(userInfo.RootFolder.GetChildFolder(folderId), Is.Not.Null);
163 }
164
165 [Test]
166 public void TestCreateFolder()
167 {
168 TestHelper.InMethod();
169
170 Scene myScene = SceneSetupHelpers.SetupScene("inventory");
171 CachedUserInfo userInfo;
172
173 lock (this)
174 {
175 userInfo = UserProfileTestUtils.CreateUserWithInventory(myScene.CommsManager, InventoryReceived);
176 Monitor.Wait(this, 60000);
177 }
178
179 UUID folderId = UUID.Parse("00000000-0000-0000-0000-000000000010");
180 Assert.That(userInfo.RootFolder.ContainsChildFolder(folderId), Is.False);
181
182 // 1: Try a folder create that should fail because the parent id given does not exist
183 UUID missingFolderId = UUID.Random();
184 InventoryFolderBase myFolder = new InventoryFolderBase();
185 myFolder.ID = folderId;
186
187 Assert.That(
188 userInfo.CreateFolder("testFolder1", folderId, (ushort)AssetType.Animation, missingFolderId), Is.False);
189 Assert.That(myScene.InventoryService.GetFolder(myFolder), Is.Null);
190 Assert.That(userInfo.RootFolder.ContainsChildFolder(missingFolderId), Is.False);
191 Assert.That(userInfo.RootFolder.FindFolder(folderId), Is.Null);
192
193 // 2: Try a folder create that should work
194 Assert.That(
195 userInfo.CreateFolder("testFolder2", folderId, (ushort)AssetType.Animation, userInfo.RootFolder.ID), Is.True);
196 Assert.That(myScene.InventoryService.GetFolder(myFolder), Is.Not.Null);
197 Assert.That(userInfo.RootFolder.ContainsChildFolder(folderId), Is.True);
198 }
199
200 //[Test]
201 public void TestUpdateFolder()
202 {
203 TestHelper.InMethod();
204
205 Scene myScene = SceneSetupHelpers.SetupScene("inventory");
206 CachedUserInfo userInfo;
207
208 lock (this)
209 {
210 userInfo = UserProfileTestUtils.CreateUserWithInventory(myScene.CommsManager, InventoryReceived);
211 Monitor.Wait(this, 60000);
212 }
213
214 UUID folder1Id = UUID.Parse("00000000-0000-0000-0000-000000000060");
215 InventoryFolderImpl rootFolder = userInfo.RootFolder;
216 InventoryFolderBase myFolder = new InventoryFolderBase();
217 myFolder.ID = folder1Id;
218
219 userInfo.CreateFolder("folder1", folder1Id, (ushort)AssetType.Animation, rootFolder.ID);
220
221 // 1: Test updates that don't involve moving the folder
222 {
223 string newFolderName1 = "newFolderName1";
224 ushort folderType1 = (ushort)AssetType.Texture;
225 userInfo.UpdateFolder(newFolderName1, folder1Id, folderType1, rootFolder.ID);
226
227 InventoryFolderImpl folder1 = rootFolder.GetChildFolder(folder1Id);
228 Assert.That(newFolderName1, Is.EqualTo(folder1.Name));
229 Assert.That(folderType1, Is.EqualTo((ushort)folder1.Type));
230
231 InventoryFolderBase dataFolder1 = myScene.InventoryService.GetFolder(myFolder);
232 Assert.That(newFolderName1, Is.EqualTo(dataFolder1.Name));
233 Assert.That(folderType1, Is.EqualTo((ushort)dataFolder1.Type));
234 }
235
236 // 2: Test an update that also involves moving the folder
237 {
238 UUID folder2Id = UUID.Parse("00000000-0000-0000-0000-000000000061");
239 userInfo.CreateFolder("folder2", folder2Id, (ushort)AssetType.Animation, rootFolder.ID);
240 InventoryFolderImpl folder2 = rootFolder.GetChildFolder(folder2Id);
241
242 InventoryFolderBase myFolder2 = new InventoryFolderBase();
243 myFolder2.ID = folder2Id;
244
245 string newFolderName2 = "newFolderName2";
246 ushort folderType2 = (ushort)AssetType.Bodypart;
247 userInfo.UpdateFolder(newFolderName2, folder1Id, folderType2, folder2Id);
248
249 InventoryFolderImpl folder1 = folder2.GetChildFolder(folder1Id);
250 Assert.That(newFolderName2, Is.EqualTo(folder1.Name));
251 Assert.That(folderType2, Is.EqualTo((ushort)folder1.Type));
252 Assert.That(folder2Id, Is.EqualTo(folder1.ParentID));
253
254 Assert.That(folder2.ContainsChildFolder(folder1Id), Is.True);
255 Assert.That(rootFolder.ContainsChildFolder(folder1Id), Is.False);
256
257 InventoryFolderBase dataFolder1 = myScene.InventoryService.GetFolder(myFolder2);
258 Assert.That(newFolderName2, Is.EqualTo(dataFolder1.Name));
259 Assert.That(folderType2, Is.EqualTo((ushort)dataFolder1.Type));
260 Assert.That(folder2Id, Is.EqualTo(dataFolder1.ParentID));
261 }
262
263 }
264
265 [Test]
266 public void TestMoveFolder()
267 {
268 TestHelper.InMethod();
269
270 Scene myScene = SceneSetupHelpers.SetupScene("inventory");
271 CachedUserInfo userInfo;
272
273 lock (this)
274 {
275 userInfo = UserProfileTestUtils.CreateUserWithInventory(myScene.CommsManager, InventoryReceived);
276 Monitor.Wait(this, 60000);
277 }
278
279 UUID folder1Id = UUID.Parse("00000000-0000-0000-0000-000000000020");
280 UUID folder2Id = UUID.Parse("00000000-0000-0000-0000-000000000021");
281 UUID folderToMoveId = UUID.Parse("00000000-0000-0000-0000-000000000030");
282 InventoryFolderImpl rootFolder = userInfo.RootFolder;
283
284 userInfo.CreateFolder("folder1", folder1Id, (ushort)AssetType.Animation, rootFolder.ID);
285 InventoryFolderImpl folder1 = rootFolder.GetChildFolder(folder1Id);
286 userInfo.CreateFolder("folder2", folder2Id, (ushort)AssetType.Animation, rootFolder.ID);
287 InventoryFolderImpl folder2 = rootFolder.GetChildFolder(folder2Id);
288
289 // Check folder is currently in folder1
290 userInfo.CreateFolder("folderToMove", folderToMoveId, (ushort)AssetType.Animation, folder1Id);
291 Assert.That(folder1.ContainsChildFolder(folderToMoveId), Is.True);
292
293 userInfo.MoveFolder(folderToMoveId, folder2Id);
294
295 // Check folder is now in folder2 and no trace remains in folder1
296 InventoryFolderBase myFolder = new InventoryFolderBase();
297 myFolder.ID = folderToMoveId;
298 Assert.That(folder2.ContainsChildFolder(folderToMoveId), Is.True);
299 Assert.That(myScene.InventoryService.GetFolder(myFolder).ParentID, Is.EqualTo(folder2Id));
300
301 Assert.That(folder1.ContainsChildFolder(folderToMoveId), Is.False);
302 }
303
304 [Test]
305 public void TestPurgeFolder()
306 {
307 TestHelper.InMethod();
308 //log4net.Config.XmlConfigurator.Configure();
309
310 Scene myScene = SceneSetupHelpers.SetupScene("inventory");
311 CachedUserInfo userInfo;
312
313 lock (this)
314 {
315 userInfo = UserProfileTestUtils.CreateUserWithInventory(myScene.CommsManager, InventoryReceived);
316 Monitor.Wait(this, 60000);
317 }
318
319 UUID folder1Id = UUID.Parse("00000000-0000-0000-0000-000000000070");
320 InventoryFolderImpl rootFolder = userInfo.RootFolder;
321 InventoryFolderBase myFolder = new InventoryFolderBase();
322 myFolder.ID = folder1Id;
323
324 userInfo.CreateFolder("folder1", folder1Id, (ushort)AssetType.Animation, rootFolder.ID);
325 Assert.That(myScene.InventoryService.GetFolder(myFolder), Is.Not.Null);
326
327 // Test purge
328 userInfo.PurgeFolder(rootFolder.ID);
329
330 Assert.That(rootFolder.RequestListOfFolders(), Is.Empty);
331 Assert.That(myScene.InventoryService.GetFolder(myFolder), Is.Null);
332 }
333
334 [TearDown]
335 public void TearDown()
336 {
337 try
338 {
339 if (MainServer.Instance != null) MainServer.Instance.Stop();
340 }
341 catch (System.NullReferenceException)
342 { }
343 }
344 }
345} \ No newline at end of file
diff --git a/OpenSim/Framework/Communications/Tests/LoginServiceTests.cs b/OpenSim/Framework/Communications/Tests/LoginServiceTests.cs
deleted file mode 100644
index a274ae7..0000000
--- a/OpenSim/Framework/Communications/Tests/LoginServiceTests.cs
+++ /dev/null
@@ -1,453 +0,0 @@
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
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.Net;
32using System.Text.RegularExpressions;
33using NUnit.Framework;
34using NUnit.Framework.SyntaxHelpers;
35using Nwc.XmlRpc;
36using OpenSim.Framework.Communications.Cache;
37using OpenSim.Framework.Communications.Services;
38using OpenSim.Region.Communications.Local;
39using OpenSim.Tests.Common.Setup;
40using OpenSim.Tests.Common.Mock;
41using OpenSim.Client.Linden;
42using OpenSim.Tests.Common;
43using OpenSim.Services.Interfaces;
44using OpenMetaverse;
45
46namespace OpenSim.Framework.Communications.Tests
47{
48 /// <summary>
49 /// Test the login service. For now, most of this will be done through the LocalLoginService as LoginService
50 /// is abstract
51 /// </summary>
52
53 [TestFixture]
54 public class LoginServiceTests
55 {
56 private string m_firstName = "Adam";
57 private string m_lastName = "West";
58 private string m_regionExternalName = "localhost";
59
60 private IPEndPoint m_capsEndPoint;
61 private TestCommunicationsManager m_commsManager;
62 private TestLoginToRegionConnector m_regionConnector;
63 private LocalUserServices m_localUserServices;
64 private LoginService m_loginService;
65 private UserProfileData m_userProfileData;
66 private TestScene m_testScene;
67
68 [SetUp]
69 public void SetUpLoginEnviroment()
70 {
71 m_capsEndPoint = new IPEndPoint(IPAddress.Loopback, 9123);
72 m_commsManager = new TestCommunicationsManager(new NetworkServersInfo(42, 43));
73 m_regionConnector = new TestLoginToRegionConnector();
74 m_testScene = SceneSetupHelpers.SetupScene(m_commsManager, "");
75
76 m_regionConnector.AddRegion(new RegionInfo(42, 43, m_capsEndPoint, m_regionExternalName));
77
78 //IInventoryService m_inventoryService = new MockInventoryService();
79
80 m_localUserServices = (LocalUserServices) m_commsManager.UserService;
81 m_localUserServices.AddUser(m_firstName,m_lastName,"boingboing","abc@ftw.com",42,43);
82
83 m_loginService = new LLStandaloneLoginService((UserManagerBase) m_localUserServices, "Hello folks", m_testScene.InventoryService,
84 m_commsManager.NetworkServersInfo, true, new LibraryRootFolder(String.Empty), m_regionConnector);
85
86 m_userProfileData = m_localUserServices.GetUserProfile(m_firstName, m_lastName);
87 }
88
89 /// <summary>
90 /// Test the normal response to a login. Does not test authentication.
91 /// </summary>
92 [Test]
93 public void T010_TestUnauthenticatedLogin()
94 {
95 TestHelper.InMethod();
96 // We want to use our own LoginService for this test, one that
97 // doesn't require authentication.
98 new LLStandaloneLoginService(
99 (UserManagerBase)m_commsManager.UserService, "Hello folks", new MockInventoryService(),
100 m_commsManager.NetworkServersInfo, false, new LibraryRootFolder(String.Empty), m_regionConnector);
101
102 Hashtable loginParams = new Hashtable();
103 loginParams["first"] = m_firstName;
104 loginParams["last"] = m_lastName;
105 loginParams["passwd"] = "boingboing";
106
107 ArrayList sendParams = new ArrayList();
108 sendParams.Add(loginParams);
109 sendParams.Add(m_capsEndPoint); // is this parameter correct?
110 sendParams.Add(new Uri("http://localhost:8002/")); // is this parameter correct?
111
112 XmlRpcRequest request = new XmlRpcRequest("login_to_simulator", sendParams);
113
114 IPAddress tmpLocal = Util.GetLocalHost();
115 IPEndPoint tmpEnd = new IPEndPoint(tmpLocal, 80);
116 XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, tmpEnd);
117
118 Hashtable responseData = (Hashtable)response.Value;
119
120 Assert.That(responseData["first_name"], Is.EqualTo(m_firstName));
121 Assert.That(responseData["last_name"], Is.EqualTo(m_lastName));
122 Assert.That(
123 responseData["circuit_code"], Is.GreaterThanOrEqualTo(0) & Is.LessThanOrEqualTo(Int32.MaxValue));
124
125 Regex capsSeedPattern
126 = new Regex("^http://"
127 + NetworkUtil.GetHostFor(tmpLocal, m_regionExternalName)
128 + ":9000/CAPS/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}0000/$");
129
130 Assert.That(capsSeedPattern.IsMatch((string)responseData["seed_capability"]), Is.True);
131 }
132
133 [Test]
134 public void T011_TestAuthenticatedLoginSuccess()
135 {
136 TestHelper.InMethod();
137 // TODO: Not check inventory part of response yet.
138 // TODO: Not checking all of login response thoroughly yet.
139
140 // 1) Test for positive authentication
141
142 Hashtable loginParams = new Hashtable();
143 loginParams["first"] = m_firstName;
144 loginParams["last"] = m_lastName;
145 loginParams["passwd"] = "boingboing";
146
147 ArrayList sendParams = new ArrayList();
148 sendParams.Add(loginParams);
149 sendParams.Add(m_capsEndPoint); // is this parameter correct?
150 sendParams.Add(new Uri("http://localhost:8002/")); // is this parameter correct?
151
152 XmlRpcRequest request = new XmlRpcRequest("login_to_simulator", sendParams);
153
154 IPAddress tmpLocal = Util.GetLocalHost();
155 IPEndPoint tmpEnd = new IPEndPoint(tmpLocal, 80);
156 XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, tmpEnd);
157
158 Hashtable responseData = (Hashtable)response.Value;
159
160 UserAgentData uagent = m_userProfileData.CurrentAgent;
161 Assert.That(uagent,Is.Not.Null);
162
163 Assert.That(responseData["first_name"], Is.Not.Null);
164 Assert.That(responseData["first_name"], Is.EqualTo(m_firstName));
165 Assert.That(responseData["last_name"], Is.EqualTo(m_lastName));
166 Assert.That(responseData["agent_id"], Is.EqualTo(uagent.ProfileID.ToString()));
167 Assert.That(responseData["session_id"], Is.EqualTo(uagent.SessionID.ToString()));
168 Assert.That(responseData["secure_session_id"], Is.EqualTo(uagent.SecureSessionID.ToString()));
169 ArrayList invlibroot = (ArrayList) responseData["inventory-lib-root"];
170 Hashtable invlibroothash = (Hashtable) invlibroot[0];
171 Assert.That(invlibroothash["folder_id"],Is.EqualTo("00000112-000f-0000-0000-000100bba000"));
172 Assert.That(
173 responseData["circuit_code"], Is.GreaterThanOrEqualTo(0) & Is.LessThanOrEqualTo(Int32.MaxValue));
174 Assert.That(responseData["message"], Is.EqualTo("Hello folks"));
175 Assert.That(responseData["buddy-list"], Is.Empty);
176 Assert.That(responseData["start_location"], Is.EqualTo("last"));
177
178 Regex capsSeedPattern
179 = new Regex("^http://"
180 + NetworkUtil.GetHostFor(tmpLocal, m_regionExternalName)
181 + ":9000/CAPS/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}0000/$");
182
183 Assert.That(capsSeedPattern.IsMatch((string)responseData["seed_capability"]), Is.True);
184 }
185
186 [Test]
187 public void T012_TestAuthenticatedLoginForBuddies()
188 {
189 TestHelper.InMethod();
190 // 1.1) Test for budddies!
191 m_localUserServices.AddUser("Friend","Number1","boingboing","abc@ftw.com",42,43);
192 m_localUserServices.AddUser("Friend","Number2","boingboing","abc@ftw.com",42,43);
193
194 UserProfileData friend1 = m_localUserServices.GetUserProfile("Friend","Number1");
195 UserProfileData friend2 = m_localUserServices.GetUserProfile("Friend","Number2");
196 m_localUserServices.AddNewUserFriend(friend1.ID,m_userProfileData.ID,1);
197 m_localUserServices.AddNewUserFriend(friend1.ID,friend2.ID,2);
198
199 Hashtable loginParams = new Hashtable();
200 loginParams["first"] = "Friend";
201 loginParams["last"] = "Number1";
202 loginParams["passwd"] = "boingboing";
203
204 ArrayList sendParams = new ArrayList();
205 sendParams.Add(loginParams);
206 sendParams.Add(m_capsEndPoint); // is this parameter correct?
207 sendParams.Add(new Uri("http://localhost:8002/")); // is this parameter correct?
208
209 XmlRpcRequest request = new XmlRpcRequest("login_to_simulator", sendParams);
210
211 IPAddress tmpLocal = Util.GetLocalHost();
212 IPEndPoint tmpEnd = new IPEndPoint(tmpLocal, 80);
213 XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, tmpEnd);
214
215 Hashtable responseData = (Hashtable)response.Value;
216
217 ArrayList friendslist = (ArrayList) responseData["buddy-list"];
218
219 Assert.That(friendslist,Is.Not.Null);
220
221 Hashtable buddy1 = (Hashtable) friendslist[0];
222 Hashtable buddy2 = (Hashtable) friendslist[1];
223 Assert.That(friendslist.Count, Is.EqualTo(2));
224 Assert.That(m_userProfileData.ID.ToString(), Is.EqualTo(buddy1["buddy_id"]) | Is.EqualTo(buddy2["buddy_id"]));
225 Assert.That(friend2.ID.ToString(), Is.EqualTo(buddy1["buddy_id"]) | Is.EqualTo(buddy2["buddy_id"]));
226 }
227
228 [Test]
229 public void T020_TestAuthenticatedLoginBadUsername()
230 {
231 TestHelper.InMethod();
232
233 // 2) Test for negative authentication
234 //
235 string error_auth_message = "Could not authenticate your avatar. Please check your username and password, and check the grid if problems persist.";
236 //string error_region_unavailable = "The region you are attempting to log into is not responding. Please select another region and try again.";
237 // 2.1) Test for wrong user name
238 Hashtable loginParams = new Hashtable();
239 loginParams["first"] = m_lastName;
240 loginParams["last"] = m_firstName;
241 loginParams["passwd"] = "boingboing";
242
243 ArrayList sendParams = new ArrayList();
244 sendParams.Add(loginParams);
245 sendParams.Add(m_capsEndPoint); // is this parameter correct?
246 sendParams.Add(new Uri("http://localhost:8002/")); // is this parameter correct?
247
248 XmlRpcRequest request = new XmlRpcRequest("login_to_simulator", sendParams);
249
250 IPAddress tmpLocal = Util.GetLocalHost();
251 IPEndPoint tmpEnd = new IPEndPoint(tmpLocal, 80);
252 XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, tmpEnd);
253
254 Hashtable responseData = (Hashtable)response.Value;
255 Assert.That(responseData["message"], Is.EqualTo(error_auth_message));
256
257 }
258
259 [Test]
260 public void T021_TestAuthenticatedLoginBadPassword()
261 {
262 TestHelper.InMethod();
263
264 string error_auth_message = "Could not authenticate your avatar. Please check your username and password, and check the grid if problems persist.";
265 // 2.2) Test for wrong password
266 Hashtable loginParams = new Hashtable();
267 loginParams["first"] = "Friend";
268 loginParams["last"] = "Number2";
269 loginParams["passwd"] = "boing";
270
271 ArrayList sendParams = new ArrayList();
272 sendParams.Add(loginParams);
273 sendParams.Add(m_capsEndPoint); // is this parameter correct?
274 sendParams.Add(new Uri("http://localhost:8002/")); // is this parameter correct?
275
276 XmlRpcRequest request = new XmlRpcRequest("login_to_simulator", sendParams);
277
278 IPAddress tmpLocal = Util.GetLocalHost();
279 IPEndPoint tmpEnd = new IPEndPoint(tmpLocal, 80);
280 XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, tmpEnd);
281
282 Hashtable responseData = (Hashtable)response.Value;
283 Assert.That(responseData["message"], Is.EqualTo(error_auth_message));
284
285 }
286
287 [Test]
288 public void T022_TestAuthenticatedLoginBadXml()
289 {
290 TestHelper.InMethod();
291
292 string error_xml_message = "Error connecting to grid. Could not percieve credentials from login XML.";
293 // 2.3) Bad XML
294 Hashtable loginParams = new Hashtable();
295 loginParams["first"] = "Friend";
296 loginParams["banana"] = "Banana";
297 loginParams["passwd"] = "boingboing";
298
299 ArrayList sendParams = new ArrayList();
300 sendParams.Add(loginParams);
301 sendParams.Add(m_capsEndPoint); // is this parameter correct?
302 sendParams.Add(new Uri("http://localhost:8002/")); // is this parameter correct?
303
304 XmlRpcRequest request = new XmlRpcRequest("login_to_simulator", sendParams);
305
306 IPAddress tmpLocal = Util.GetLocalHost();
307 IPEndPoint tmpEnd = new IPEndPoint(tmpLocal, 80);
308 XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, tmpEnd);
309
310 Hashtable responseData = (Hashtable)response.Value;
311 Assert.That(responseData["message"], Is.EqualTo(error_xml_message));
312
313 }
314
315 // [Test]
316 // Commenting out test now that LLStandAloneLoginService no longer replies with message in this case.
317 // Kept the code for future test with grid mode, which will keep this behavior.
318 public void T023_TestAuthenticatedLoginAlreadyLoggedIn()
319 {
320 TestHelper.InMethod();
321
322 //Console.WriteLine("Starting T023_TestAuthenticatedLoginAlreadyLoggedIn()");
323 //log4net.Config.XmlConfigurator.Configure();
324
325 string error_already_logged = "You appear to be already logged in. " +
326 "If this is not the case please wait for your session to timeout. " +
327 "If this takes longer than a few minutes please contact the grid owner. " +
328 "Please wait 5 minutes if you are going to connect to a region nearby to the region you were at previously.";
329 // 2.4) Already logged in and sucessfull post login
330 Hashtable loginParams = new Hashtable();
331 loginParams["first"] = "Adam";
332 loginParams["last"] = "West";
333 loginParams["passwd"] = "boingboing";
334
335 ArrayList sendParams = new ArrayList();
336 sendParams.Add(loginParams);
337 sendParams.Add(m_capsEndPoint); // is this parameter correct?
338 sendParams.Add(new Uri("http://localhost:8002/")); // is this parameter correct?
339
340 // First we log in.
341 XmlRpcRequest request = new XmlRpcRequest("login_to_simulator", sendParams);
342
343 IPAddress tmpLocal = Util.GetLocalHost();
344 IPEndPoint tmpEnd = new IPEndPoint(tmpLocal, 80);
345 XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, tmpEnd);
346
347 Hashtable responseData = (Hashtable)response.Value;
348 Assert.That(responseData["message"], Is.EqualTo("Hello folks"));
349
350 // Then we try again, this time expecting failure.
351 request = new XmlRpcRequest("login_to_simulator", sendParams);
352 response = m_loginService.XmlRpcLoginMethod(request, tmpEnd);
353 responseData = (Hashtable)response.Value;
354 Assert.That(responseData["message"], Is.EqualTo(error_already_logged));
355
356 // Finally the third time we should be able to get right back in.
357 request = new XmlRpcRequest("login_to_simulator", sendParams);
358
359 response = m_loginService.XmlRpcLoginMethod(request, tmpEnd);
360 responseData = (Hashtable)response.Value;
361 Assert.That(responseData["message"], Is.EqualTo("Hello folks"));
362
363 //Console.WriteLine("Finished T023_TestAuthenticatedLoginAlreadyLoggedIn()");
364 }
365
366 [TearDown]
367 public void TearDown()
368 {
369 try
370 {
371 if (MainServer.Instance != null) MainServer.Instance.Stop();
372 } catch (NullReferenceException)
373 {}
374 }
375
376 public class TestLoginToRegionConnector : ILoginServiceToRegionsConnector
377 {
378 private List<RegionInfo> m_regionsList = new List<RegionInfo>();
379
380 public void AddRegion(RegionInfo regionInfo)
381 {
382 lock (m_regionsList)
383 {
384 if (!m_regionsList.Contains(regionInfo))
385 {
386 m_regionsList.Add(regionInfo);
387 }
388 }
389 }
390
391 public void LogOffUserFromGrid(ulong regionHandle, OpenMetaverse.UUID AvatarID, OpenMetaverse.UUID RegionSecret, string message)
392 {
393 }
394
395 public bool NewUserConnection(ulong regionHandle, AgentCircuitData agent, out string reason)
396 {
397 reason = String.Empty;
398 lock (m_regionsList)
399 {
400 foreach (RegionInfo regInfo in m_regionsList)
401 {
402 if (regInfo.RegionHandle == regionHandle)
403 return true;
404 }
405 }
406 reason = "Region not found";
407 return false;
408 }
409
410 public RegionInfo RequestClosestRegion(string region)
411 {
412 lock (m_regionsList)
413 {
414 foreach (RegionInfo regInfo in m_regionsList)
415 {
416 if (regInfo.RegionName == region)
417 return regInfo;
418 }
419 }
420
421 return null;
422 }
423
424 public RegionInfo RequestNeighbourInfo(OpenMetaverse.UUID regionID)
425 {
426 lock (m_regionsList)
427 {
428 foreach (RegionInfo regInfo in m_regionsList)
429 {
430 if (regInfo.RegionID == regionID)
431 return regInfo;
432 }
433 }
434
435 return null;
436 }
437
438 public RegionInfo RequestNeighbourInfo(ulong regionHandle)
439 {
440 lock (m_regionsList)
441 {
442 foreach (RegionInfo regInfo in m_regionsList)
443 {
444 if (regInfo.RegionHandle == regionHandle)
445 return regInfo;
446 }
447 }
448
449 return null;
450 }
451 }
452 }
453}