aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorJohn Hurliman2009-11-05 23:50:42 -0800
committerJohn Hurliman2009-11-05 23:50:42 -0800
commitdfe4dc735af35e644130cc804828c518c8368836 (patch)
tree95c8e02cf8be328bdb44b5177bca4bad725328a6 /OpenSim
parent* Clamp the CoarseLocationUpdate packet at a maximum of 60 positions per pack... (diff)
parentadd unit test for iar & escaping (diff)
downloadopensim-SC_OLD-dfe4dc735af35e644130cc804828c518c8368836.zip
opensim-SC_OLD-dfe4dc735af35e644130cc804828c518c8368836.tar.gz
opensim-SC_OLD-dfe4dc735af35e644130cc804828c518c8368836.tar.bz2
opensim-SC_OLD-dfe4dc735af35e644130cc804828c518c8368836.tar.xz
Merge branch 'master' of ssh://opensimulator.org/var/git/opensim
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs13
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs7
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs110
-rw-r--r--OpenSim/Tests/Common/Setup/UserProfileTestUtils.cs24
-rw-r--r--OpenSim/Tests/Common/TestHelper.cs1
5 files changed, 142 insertions, 13 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs
index a4445eb..4c02214 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveReadRequest.cs
@@ -161,14 +161,18 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
161 failedAssetRestores++; 161 failedAssetRestores++;
162 } 162 }
163 else if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH)) 163 else if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH))
164 { 164 {
165 InventoryFolderBase foundFolder 165 InventoryFolderBase foundFolder
166 = ReplicateArchivePathToUserInventory( 166 = ReplicateArchivePathToUserInventory(
167 filePath, TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType, 167 filePath, TarArchiveReader.TarEntryType.TYPE_DIRECTORY == entryType,
168 rootDestinationFolder, foldersCreated, nodesLoaded); 168 rootDestinationFolder, foldersCreated, nodesLoaded);
169 169
170 if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY != entryType) 170 if (TarArchiveReader.TarEntryType.TYPE_DIRECTORY != entryType)
171 { 171 {
172 // Escape back characters
173 filePath = filePath.Replace("/", "/");
174 filePath = filePath.Replace("&", "&");
175
172 InventoryItemBase item = UserInventoryItemSerializer.Deserialize(data); 176 InventoryItemBase item = UserInventoryItemSerializer.Deserialize(data);
173 177
174 // Don't use the item ID that's in the file 178 // Don't use the item ID that's in the file
@@ -289,6 +293,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
289 ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR); 293 ArchiveConstants.INVENTORY_NODE_NAME_COMPONENT_SEPARATOR);
290 294
291 string newFolderName = rawDirsToCreate[i].Remove(identicalNameIdentifierIndex); 295 string newFolderName = rawDirsToCreate[i].Remove(identicalNameIdentifierIndex);
296
297 // Escape back characters
298 newFolderName = newFolderName.Replace("/", "/");
299 newFolderName = newFolderName.Replace("&", "&");
300
292 UUID newFolderId = UUID.Random(); 301 UUID newFolderId = UUID.Random();
293 302
294 // Asset type has to be Unknown here rather than Folder, otherwise the created folder can't be 303 // Asset type has to be Unknown here rather than Folder, otherwise the created folder can't be
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs
index 499c552..af0b72f 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/InventoryArchiveWriteRequest.cs
@@ -394,6 +394,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
394 /// <returns></returns> 394 /// <returns></returns>
395 public static string CreateArchiveFolderName(string name, UUID id) 395 public static string CreateArchiveFolderName(string name, UUID id)
396 { 396 {
397 // Only encode ampersands (for escaping anything) and / (since this is used as general dir separator).
398 name = name.Replace("&", "&amp;");
399 name = name.Replace("/", "&#47;");
400
397 return string.Format( 401 return string.Format(
398 "{0}{1}{2}/", 402 "{0}{1}{2}/",
399 name, 403 name,
@@ -409,6 +413,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver
409 /// <returns></returns> 413 /// <returns></returns>
410 public static string CreateArchiveItemName(string name, UUID id) 414 public static string CreateArchiveItemName(string name, UUID id)
411 { 415 {
416 name = name.Replace("&", "&amp;");
417 name = name.Replace("/", "&#47;");
418
412 return string.Format( 419 return string.Format(
413 "{0}{1}{2}.xml", 420 "{0}{1}{2}.xml",
414 name, 421 name,
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs
index 8ee9194..41bb9dc 100644
--- a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/InventoryArchiverTests.cs
@@ -135,7 +135,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
135 InventoryFolderBase objsFolder 135 InventoryFolderBase objsFolder
136 = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects"); 136 = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects");
137 item1.Folder = objsFolder.ID; 137 item1.Folder = objsFolder.ID;
138 scene.AddInventoryItem(userId, item1); 138 scene.AddInventoryItem(userId, item1);
139 139
140 MemoryStream archiveWriteStream = new MemoryStream(); 140 MemoryStream archiveWriteStream = new MemoryStream();
141 archiverModule.OnInventoryArchiveSaved += SaveCompleted; 141 archiverModule.OnInventoryArchiveSaved += SaveCompleted;
@@ -217,14 +217,14 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
217 string userItemCreatorLastName = "Lucan"; 217 string userItemCreatorLastName = "Lucan";
218 UUID userItemCreatorUuid = UUID.Parse("00000000-0000-0000-0000-000000000666"); 218 UUID userItemCreatorUuid = UUID.Parse("00000000-0000-0000-0000-000000000666");
219 219
220 string itemName = "b.lsl"; 220 string item1Name = "b.lsl";
221 string archiveItemName = InventoryArchiveWriteRequest.CreateArchiveItemName(itemName, UUID.Random()); 221 string archiveItemName = InventoryArchiveWriteRequest.CreateArchiveItemName(item1Name, UUID.Random());
222 222
223 MemoryStream archiveWriteStream = new MemoryStream(); 223 MemoryStream archiveWriteStream = new MemoryStream();
224 TarArchiveWriter tar = new TarArchiveWriter(archiveWriteStream); 224 TarArchiveWriter tar = new TarArchiveWriter(archiveWriteStream);
225 225
226 InventoryItemBase item1 = new InventoryItemBase(); 226 InventoryItemBase item1 = new InventoryItemBase();
227 item1.Name = itemName; 227 item1.Name = item1Name;
228 item1.AssetID = UUID.Random(); 228 item1.AssetID = UUID.Random();
229 item1.GroupID = UUID.Random(); 229 item1.GroupID = UUID.Random();
230 item1.CreatorId = OspResolver.MakeOspa(userItemCreatorFirstName, userItemCreatorLastName); 230 item1.CreatorId = OspResolver.MakeOspa(userItemCreatorFirstName, userItemCreatorLastName);
@@ -258,7 +258,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
258 = scene.CommsManager.UserProfileCacheService.GetUserDetails(userFirstName, userLastName); 258 = scene.CommsManager.UserProfileCacheService.GetUserDetails(userFirstName, userLastName);
259 259
260 InventoryItemBase foundItem1 260 InventoryItemBase foundItem1
261 = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, userInfo.UserProfile.ID, itemName); 261 = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, userInfo.UserProfile.ID, item1Name);
262 262
263 Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1"); 263 Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1");
264 Assert.That( 264 Assert.That(
@@ -276,7 +276,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
276 archiverModule.DearchiveInventory(userFirstName, userLastName, "xA", "meowfood", archiveReadStream); 276 archiverModule.DearchiveInventory(userFirstName, userLastName, "xA", "meowfood", archiveReadStream);
277 277
278 InventoryItemBase foundItem2 278 InventoryItemBase foundItem2
279 = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, userInfo.UserProfile.ID, "xA/" + itemName); 279 = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, userInfo.UserProfile.ID, "xA/" + item1Name);
280 Assert.That(foundItem2, Is.Not.Null, "Didn't find loaded item 2"); 280 Assert.That(foundItem2, Is.Not.Null, "Didn't find loaded item 2");
281 281
282 // Now try loading to a more deeply nested folder 282 // Now try loading to a more deeply nested folder
@@ -285,10 +285,102 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
285 archiverModule.DearchiveInventory(userFirstName, userLastName, "xB/xC", "meowfood", archiveReadStream); 285 archiverModule.DearchiveInventory(userFirstName, userLastName, "xB/xC", "meowfood", archiveReadStream);
286 286
287 InventoryItemBase foundItem3 287 InventoryItemBase foundItem3
288 = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, userInfo.UserProfile.ID, "xB/xC/" + itemName); 288 = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, userInfo.UserProfile.ID, "xB/xC/" + item1Name);
289 Assert.That(foundItem3, Is.Not.Null, "Didn't find loaded item 3"); 289 Assert.That(foundItem3, Is.Not.Null, "Didn't find loaded item 3");
290 } 290 }
291 291
292 [Test]
293 public void TestIarV0_1WithEscapedChars()
294 {
295 TestHelper.InMethod();
296 log4net.Config.XmlConfigurator.Configure();
297
298 string itemName = "You & you are a mean man";
299 string userPassword = "meowfood";
300
301 InventoryArchiverModule archiverModule = new InventoryArchiverModule(true);
302
303 Scene scene = SceneSetupHelpers.SetupScene("Inventory");
304 SceneSetupHelpers.SetupSceneModules(scene, archiverModule);
305 CommunicationsManager cm = scene.CommsManager;
306
307 // Create user
308 string userFirstName = "Jock";
309 string userLastName = "Stirrup";
310 UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000020");
311
312 lock (this)
313 {
314 UserProfileTestUtils.CreateUserWithInventory(
315 cm, userFirstName, userLastName, userPassword, userId, InventoryReceived);
316 Monitor.Wait(this, 60000);
317 }
318
319 // Create asset
320 SceneObjectGroup object1;
321 SceneObjectPart part1;
322 {
323 string partName = "part name";
324 UUID ownerId = UUID.Parse("00000000-0000-0000-0000-000000000040");
325 PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere();
326 Vector3 groupPosition = new Vector3(10, 20, 30);
327 Quaternion rotationOffset = new Quaternion(20, 30, 40, 50);
328 Vector3 offsetPosition = new Vector3(5, 10, 15);
329
330 part1
331 = new SceneObjectPart(
332 ownerId, shape, groupPosition, rotationOffset, offsetPosition);
333 part1.Name = partName;
334
335 object1 = new SceneObjectGroup(part1);
336 scene.AddNewSceneObject(object1, false);
337 }
338
339 UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060");
340 AssetBase asset1 = new AssetBase();
341 asset1.FullID = asset1Id;
342 asset1.Data = Encoding.ASCII.GetBytes(SceneObjectSerializer.ToXml2Format(object1));
343 scene.AssetService.Store(asset1);
344
345 // Create item
346 UUID item1Id = UUID.Parse("00000000-0000-0000-0000-000000000080");
347 InventoryItemBase item1 = new InventoryItemBase();
348 item1.Name = itemName;
349 item1.AssetID = asset1.FullID;
350 item1.ID = item1Id;
351 InventoryFolderBase objsFolder
352 = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects");
353 item1.Folder = objsFolder.ID;
354 scene.AddInventoryItem(userId, item1);
355
356 MemoryStream archiveWriteStream = new MemoryStream();
357 archiverModule.OnInventoryArchiveSaved += SaveCompleted;
358
359 mre.Reset();
360 archiverModule.ArchiveInventory(
361 Guid.NewGuid(), userFirstName, userLastName, "Objects", userPassword, archiveWriteStream);
362 mre.WaitOne(60000, false);
363
364 /// LOAD ITEM
365 MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray());
366
367 archiverModule.DearchiveInventory(userFirstName, userLastName, "Scripts", userPassword, archiveReadStream);
368
369 CachedUserInfo userInfo
370 = scene.CommsManager.UserProfileCacheService.GetUserDetails(userFirstName, userLastName);
371
372 InventoryItemBase foundItem1
373 = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, userId, "Scripts/Objects/" + itemName);
374
375 Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1");
376// Assert.That(
377// foundItem1.CreatorId, Is.EqualTo(userUuid),
378// "Loaded item non-uuid creator doesn't match that of the loading user");
379 Assert.That(
380 foundItem1.Name, Is.EqualTo(itemName),
381 "Loaded item name doesn't match saved name");
382 }
383
292 /// <summary> 384 /// <summary>
293 /// Test loading a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet) where 385 /// Test loading a V0.1 OpenSim Inventory Archive (subject to change since there is no fixed format yet) where
294 /// embedded creators do not exist in the system 386 /// embedded creators do not exist in the system
@@ -301,7 +393,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
301 { 393 {
302 TestHelper.InMethod(); 394 TestHelper.InMethod();
303 395
304 log4net.Config.XmlConfigurator.Configure(); 396 //log4net.Config.XmlConfigurator.Configure();
305 397
306 string userFirstName = "Charlie"; 398 string userFirstName = "Charlie";
307 string userLastName = "Chan"; 399 string userLastName = "Chan";
@@ -369,7 +461,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
369 { 461 {
370 TestHelper.InMethod(); 462 TestHelper.InMethod();
371 463
372 log4net.Config.XmlConfigurator.Configure(); 464 //log4net.Config.XmlConfigurator.Configure();
373 465
374 string userFirstName = "Dennis"; 466 string userFirstName = "Dennis";
375 string userLastName = "Menace"; 467 string userLastName = "Menace";
diff --git a/OpenSim/Tests/Common/Setup/UserProfileTestUtils.cs b/OpenSim/Tests/Common/Setup/UserProfileTestUtils.cs
index 3ca44a1..1b06a46 100644
--- a/OpenSim/Tests/Common/Setup/UserProfileTestUtils.cs
+++ b/OpenSim/Tests/Common/Setup/UserProfileTestUtils.cs
@@ -85,14 +85,34 @@ namespace OpenSim.Tests.Common.Setup
85 CommunicationsManager commsManager, string firstName, string lastName, 85 CommunicationsManager commsManager, string firstName, string lastName,
86 UUID userId, OnInventoryReceivedDelegate callback) 86 UUID userId, OnInventoryReceivedDelegate callback)
87 { 87 {
88 return CreateUserWithInventory(commsManager, firstName, lastName, "troll", userId, callback);
89 }
90
91 /// <summary>
92 /// Create a test user with a standard inventory
93 /// </summary>
94 /// <param name="commsManager"></param>
95 /// <param name="firstName">First name of user</param>
96 /// <param name="lastName">Last name of user</param>
97 /// <param name="password">Password</param>
98 /// <param name="userId">User ID</param>
99 /// <param name="callback">
100 /// Callback to invoke when inventory has been loaded. This is required because
101 /// loading may be asynchronous, even on standalone
102 /// </param>
103 /// <returns></returns>
104 public static CachedUserInfo CreateUserWithInventory(
105 CommunicationsManager commsManager, string firstName, string lastName, string password,
106 UUID userId, OnInventoryReceivedDelegate callback)
107 {
88 LocalUserServices lus = (LocalUserServices)commsManager.UserService; 108 LocalUserServices lus = (LocalUserServices)commsManager.UserService;
89 lus.AddUser(firstName, lastName, "troll", "bill@bailey.com", 1000, 1000, userId); 109 lus.AddUser(firstName, lastName, password, "bill@bailey.com", 1000, 1000, userId);
90 110
91 CachedUserInfo userInfo = commsManager.UserProfileCacheService.GetUserDetails(userId); 111 CachedUserInfo userInfo = commsManager.UserProfileCacheService.GetUserDetails(userId);
92 userInfo.OnInventoryReceived += callback; 112 userInfo.OnInventoryReceived += callback;
93 userInfo.FetchInventory(); 113 userInfo.FetchInventory();
94 114
95 return userInfo; 115 return userInfo;
96 } 116 }
97 } 117 }
98} 118}
diff --git a/OpenSim/Tests/Common/TestHelper.cs b/OpenSim/Tests/Common/TestHelper.cs
index 4abf2e3..9d53063 100644
--- a/OpenSim/Tests/Common/TestHelper.cs
+++ b/OpenSim/Tests/Common/TestHelper.cs
@@ -54,6 +54,7 @@ namespace OpenSim.Tests.Common
54 public static void InMethod() 54 public static void InMethod()
55 { 55 {
56 StackTrace stackTrace = new StackTrace(); 56 StackTrace stackTrace = new StackTrace();
57 Console.WriteLine();
57 Console.WriteLine("===> In Test Method : {0} <===", stackTrace.GetFrame(1).GetMethod().Name); 58 Console.WriteLine("===> In Test Method : {0} <===", stackTrace.GetFrame(1).GetMethod().Name);
58 } 59 }
59 } 60 }