aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/PathTests.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/PathTests.cs')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/PathTests.cs478
1 files changed, 478 insertions, 0 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/PathTests.cs b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/PathTests.cs
new file mode 100644
index 0000000..0e8f647
--- /dev/null
+++ b/OpenSim/Region/CoreModules/Avatar/Inventory/Archiver/Tests/PathTests.cs
@@ -0,0 +1,478 @@
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.Generic;
30using System.IO;
31using System.Reflection;
32using System.Threading;
33using NUnit.Framework;
34using OpenMetaverse;
35using OpenSim.Data;
36using OpenSim.Framework;
37using OpenSim.Framework.Serialization;
38using OpenSim.Framework.Serialization.External;
39using OpenSim.Framework.Communications;
40using OpenSim.Region.CoreModules.Avatar.Inventory.Archiver;
41using OpenSim.Region.CoreModules.World.Serialiser;
42using OpenSim.Region.Framework.Scenes;
43using OpenSim.Region.Framework.Scenes.Serialization;
44using OpenSim.Services.Interfaces;
45using OpenSim.Tests.Common;
46using OpenSim.Tests.Common.Mock;
47using OpenSim.Tests.Common.Setup;
48
49namespace OpenSim.Region.CoreModules.Avatar.Inventory.Archiver.Tests
50{
51 [TestFixture]
52 public class PathTests : InventoryArchiveTestCase
53 {
54 /// <summary>
55 /// Test saving an inventory path to a V0.1 OpenSim Inventory Archive
56 /// (subject to change since there is no fixed format yet).
57 /// </summary>
58 [Test]
59 public void TestSavePathToIarV0_1()
60 {
61 TestHelper.InMethod();
62// log4net.Config.XmlConfigurator.Configure();
63
64 InventoryArchiverModule archiverModule = new InventoryArchiverModule();
65
66 Scene scene = SceneSetupHelpers.SetupScene("Inventory");
67 SceneSetupHelpers.SetupSceneModules(scene, archiverModule);
68
69 // Create user
70 string userFirstName = "Jock";
71 string userLastName = "Stirrup";
72 string userPassword = "troll";
73 UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000020");
74 UserProfileTestUtils.CreateUserWithInventory(scene, userFirstName, userLastName, userId, userPassword);
75
76 // Create asset
77 SceneObjectGroup object1;
78 SceneObjectPart part1;
79 {
80 string partName = "My Little Dog Object";
81 UUID ownerId = UUID.Parse("00000000-0000-0000-0000-000000000040");
82 PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere();
83 Vector3 groupPosition = new Vector3(10, 20, 30);
84 Quaternion rotationOffset = new Quaternion(20, 30, 40, 50);
85 Vector3 offsetPosition = new Vector3(5, 10, 15);
86
87 part1 = new SceneObjectPart(ownerId, shape, groupPosition, rotationOffset, offsetPosition);
88 part1.Name = partName;
89
90 object1 = new SceneObjectGroup(part1);
91 scene.AddNewSceneObject(object1, false);
92 }
93
94 UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060");
95 AssetBase asset1 = AssetHelpers.CreateAsset(asset1Id, object1);
96 scene.AssetService.Store(asset1);
97
98 // Create item
99 UUID item1Id = UUID.Parse("00000000-0000-0000-0000-000000000080");
100 InventoryItemBase item1 = new InventoryItemBase();
101 item1.Name = "My Little Dog";
102 item1.AssetID = asset1.FullID;
103 item1.ID = item1Id;
104 InventoryFolderBase objsFolder
105 = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects")[0];
106 item1.Folder = objsFolder.ID;
107 scene.AddInventoryItem(item1);
108
109 MemoryStream archiveWriteStream = new MemoryStream();
110 archiverModule.OnInventoryArchiveSaved += SaveCompleted;
111
112 // Test saving a particular path
113 mre.Reset();
114 archiverModule.ArchiveInventory(
115 Guid.NewGuid(), userFirstName, userLastName, "Objects", userPassword, archiveWriteStream);
116 mre.WaitOne(60000, false);
117
118 byte[] archive = archiveWriteStream.ToArray();
119 MemoryStream archiveReadStream = new MemoryStream(archive);
120 TarArchiveReader tar = new TarArchiveReader(archiveReadStream);
121
122 //bool gotControlFile = false;
123 bool gotObject1File = false;
124 //bool gotObject2File = false;
125 string expectedObject1FileName = InventoryArchiveWriteRequest.CreateArchiveItemName(item1);
126 string expectedObject1FilePath = string.Format(
127 "{0}{1}{2}",
128 ArchiveConstants.INVENTORY_PATH,
129 InventoryArchiveWriteRequest.CreateArchiveFolderName(objsFolder),
130 expectedObject1FileName);
131
132 string filePath;
133 TarArchiveReader.TarEntryType tarEntryType;
134
135// Console.WriteLine("Reading archive");
136
137 while (tar.ReadEntry(out filePath, out tarEntryType) != null)
138 {
139// Console.WriteLine("Got {0}", filePath);
140
141// if (ArchiveConstants.CONTROL_FILE_PATH == filePath)
142// {
143// gotControlFile = true;
144// }
145
146 if (filePath.StartsWith(ArchiveConstants.INVENTORY_PATH) && filePath.EndsWith(".xml"))
147 {
148// string fileName = filePath.Remove(0, "Objects/".Length);
149//
150// if (fileName.StartsWith(part1.Name))
151// {
152 Assert.That(expectedObject1FilePath, Is.EqualTo(filePath));
153 gotObject1File = true;
154// }
155// else if (fileName.StartsWith(part2.Name))
156// {
157// Assert.That(fileName, Is.EqualTo(expectedObject2FileName));
158// gotObject2File = true;
159// }
160 }
161 }
162
163// Assert.That(gotControlFile, Is.True, "No control file in archive");
164 Assert.That(gotObject1File, Is.True, "No item1 file in archive");
165// Assert.That(gotObject2File, Is.True, "No object2 file in archive");
166
167 // TODO: Test presence of more files and contents of files.
168 }
169
170 /// <summary>
171 /// Test loading an IAR to various different inventory paths.
172 /// </summary>
173 [Test]
174 public void TestLoadIarToInventoryPaths()
175 {
176 TestHelper.InMethod();
177// log4net.Config.XmlConfigurator.Configure();
178
179 SerialiserModule serialiserModule = new SerialiserModule();
180 InventoryArchiverModule archiverModule = new InventoryArchiverModule();
181
182 // Annoyingly, we have to set up a scene even though inventory loading has nothing to do with a scene
183 Scene scene = SceneSetupHelpers.SetupScene("inventory");
184
185 SceneSetupHelpers.SetupSceneModules(scene, serialiserModule, archiverModule);
186
187 UserProfileTestUtils.CreateUserWithInventory(scene, m_uaMT, "meowfood");
188 UserProfileTestUtils.CreateUserWithInventory(scene, m_uaLL1, "hampshire");
189
190 archiverModule.DearchiveInventory(m_uaMT.FirstName, m_uaMT.LastName, "/", "meowfood", m_iarStream);
191 InventoryItemBase foundItem1
192 = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, m_uaMT.PrincipalID, m_item1Name);
193
194 Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1");
195
196 // Now try loading to a root child folder
197 UserInventoryTestUtils.CreateInventoryFolder(scene.InventoryService, m_uaMT.PrincipalID, "xA");
198 MemoryStream archiveReadStream = new MemoryStream(m_iarStream.ToArray());
199 archiverModule.DearchiveInventory(m_uaMT.FirstName, m_uaMT.LastName, "xA", "meowfood", archiveReadStream);
200
201 InventoryItemBase foundItem2
202 = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, m_uaMT.PrincipalID, "xA/" + m_item1Name);
203 Assert.That(foundItem2, Is.Not.Null, "Didn't find loaded item 2");
204
205 // Now try loading to a more deeply nested folder
206 UserInventoryTestUtils.CreateInventoryFolder(scene.InventoryService, m_uaMT.PrincipalID, "xB/xC");
207 archiveReadStream = new MemoryStream(archiveReadStream.ToArray());
208 archiverModule.DearchiveInventory(m_uaMT.FirstName, m_uaMT.LastName, "xB/xC", "meowfood", archiveReadStream);
209
210 InventoryItemBase foundItem3
211 = InventoryArchiveUtils.FindItemByPath(scene.InventoryService, m_uaMT.PrincipalID, "xB/xC/" + m_item1Name);
212 Assert.That(foundItem3, Is.Not.Null, "Didn't find loaded item 3");
213 }
214
215 /// <summary>
216 /// Test that things work when the load path specified starts with a slash
217 /// </summary>
218 [Test]
219 public void TestLoadIarPathStartsWithSlash()
220 {
221 TestHelper.InMethod();
222// log4net.Config.XmlConfigurator.Configure();
223
224 SerialiserModule serialiserModule = new SerialiserModule();
225 InventoryArchiverModule archiverModule = new InventoryArchiverModule();
226 Scene scene = SceneSetupHelpers.SetupScene("inventory");
227 SceneSetupHelpers.SetupSceneModules(scene, serialiserModule, archiverModule);
228
229 UserProfileTestUtils.CreateUserWithInventory(scene, m_uaMT, "password");
230 archiverModule.DearchiveInventory(m_uaMT.FirstName, m_uaMT.LastName, "/Objects", "password", m_iarStream);
231
232 InventoryItemBase foundItem1
233 = InventoryArchiveUtils.FindItemByPath(
234 scene.InventoryService, m_uaMT.PrincipalID, "/Objects/" + m_item1Name);
235
236 Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1 in TestLoadIarFolderStartsWithSlash()");
237 }
238
239 [Test]
240 public void TestLoadIarPathWithEscapedChars()
241 {
242 TestHelper.InMethod();
243// log4net.Config.XmlConfigurator.Configure();
244
245 string itemName = "You & you are a mean/man/";
246 string humanEscapedItemName = @"You & you are a mean\/man\/";
247 string userPassword = "meowfood";
248
249 InventoryArchiverModule archiverModule = new InventoryArchiverModule();
250
251 Scene scene = SceneSetupHelpers.SetupScene("Inventory");
252 SceneSetupHelpers.SetupSceneModules(scene, archiverModule);
253
254 // Create user
255 string userFirstName = "Jock";
256 string userLastName = "Stirrup";
257 UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000020");
258 UserProfileTestUtils.CreateUserWithInventory(scene, userFirstName, userLastName, userId, "meowfood");
259
260 // Create asset
261 SceneObjectGroup object1;
262 SceneObjectPart part1;
263 {
264 string partName = "part name";
265 UUID ownerId = UUID.Parse("00000000-0000-0000-0000-000000000040");
266 PrimitiveBaseShape shape = PrimitiveBaseShape.CreateSphere();
267 Vector3 groupPosition = new Vector3(10, 20, 30);
268 Quaternion rotationOffset = new Quaternion(20, 30, 40, 50);
269 Vector3 offsetPosition = new Vector3(5, 10, 15);
270
271 part1
272 = new SceneObjectPart(
273 ownerId, shape, groupPosition, rotationOffset, offsetPosition);
274 part1.Name = partName;
275
276 object1 = new SceneObjectGroup(part1);
277 scene.AddNewSceneObject(object1, false);
278 }
279
280 UUID asset1Id = UUID.Parse("00000000-0000-0000-0000-000000000060");
281 AssetBase asset1 = AssetHelpers.CreateAsset(asset1Id, object1);
282 scene.AssetService.Store(asset1);
283
284 // Create item
285 UUID item1Id = UUID.Parse("00000000-0000-0000-0000-000000000080");
286 InventoryItemBase item1 = new InventoryItemBase();
287 item1.Name = itemName;
288 item1.AssetID = asset1.FullID;
289 item1.ID = item1Id;
290 InventoryFolderBase objsFolder
291 = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, userId, "Objects")[0];
292 item1.Folder = objsFolder.ID;
293 scene.AddInventoryItem(item1);
294
295 MemoryStream archiveWriteStream = new MemoryStream();
296 archiverModule.OnInventoryArchiveSaved += SaveCompleted;
297
298 mre.Reset();
299 archiverModule.ArchiveInventory(
300 Guid.NewGuid(), userFirstName, userLastName, "Objects", userPassword, archiveWriteStream);
301 mre.WaitOne(60000, false);
302
303 // LOAD ITEM
304 MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray());
305
306 archiverModule.DearchiveInventory(userFirstName, userLastName, "Scripts", userPassword, archiveReadStream);
307
308 InventoryItemBase foundItem1
309 = InventoryArchiveUtils.FindItemByPath(
310 scene.InventoryService, userId, "Scripts/Objects/" + humanEscapedItemName);
311
312 Assert.That(foundItem1, Is.Not.Null, "Didn't find loaded item 1");
313// Assert.That(
314// foundItem1.CreatorId, Is.EqualTo(userUuid),
315// "Loaded item non-uuid creator doesn't match that of the loading user");
316 Assert.That(
317 foundItem1.Name, Is.EqualTo(itemName),
318 "Loaded item name doesn't match saved name");
319 }
320
321 /// <summary>
322 /// Test replication of an archive path to the user's inventory.
323 /// </summary>
324 [Test]
325 public void TestNewIarPath()
326 {
327 TestHelper.InMethod();
328// log4net.Config.XmlConfigurator.Configure();
329
330 Scene scene = SceneSetupHelpers.SetupScene("inventory");
331 UserAccount ua1 = UserProfileTestUtils.CreateUserWithInventory(scene);
332
333 Dictionary <string, InventoryFolderBase> foldersCreated = new Dictionary<string, InventoryFolderBase>();
334 HashSet<InventoryNodeBase> nodesLoaded = new HashSet<InventoryNodeBase>();
335
336 string folder1Name = "1";
337 string folder2aName = "2a";
338 string folder2bName = "2b";
339
340 string folder1ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder1Name, UUID.Random());
341 string folder2aArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2aName, UUID.Random());
342 string folder2bArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2bName, UUID.Random());
343
344 string iarPath1 = string.Join("", new string[] { folder1ArchiveName, folder2aArchiveName });
345 string iarPath2 = string.Join("", new string[] { folder1ArchiveName, folder2bArchiveName });
346
347 {
348 // Test replication of path1
349 new InventoryArchiveReadRequest(scene, ua1, null, (Stream)null, false)
350 .ReplicateArchivePathToUserInventory(
351 iarPath1, scene.InventoryService.GetRootFolder(ua1.PrincipalID),
352 foldersCreated, nodesLoaded);
353
354 List<InventoryFolderBase> folder1Candidates
355 = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, ua1.PrincipalID, folder1Name);
356 Assert.That(folder1Candidates.Count, Is.EqualTo(1));
357
358 InventoryFolderBase folder1 = folder1Candidates[0];
359 List<InventoryFolderBase> folder2aCandidates
360 = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1, folder2aName);
361 Assert.That(folder2aCandidates.Count, Is.EqualTo(1));
362 }
363
364 {
365 // Test replication of path2
366 new InventoryArchiveReadRequest(scene, ua1, null, (Stream)null, false)
367 .ReplicateArchivePathToUserInventory(
368 iarPath2, scene.InventoryService.GetRootFolder(ua1.PrincipalID),
369 foldersCreated, nodesLoaded);
370
371 List<InventoryFolderBase> folder1Candidates
372 = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, ua1.PrincipalID, folder1Name);
373 Assert.That(folder1Candidates.Count, Is.EqualTo(1));
374
375 InventoryFolderBase folder1 = folder1Candidates[0];
376
377 List<InventoryFolderBase> folder2aCandidates
378 = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1, folder2aName);
379 Assert.That(folder2aCandidates.Count, Is.EqualTo(1));
380
381 List<InventoryFolderBase> folder2bCandidates
382 = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1, folder2bName);
383 Assert.That(folder2bCandidates.Count, Is.EqualTo(1));
384 }
385 }
386
387 /// <summary>
388 /// Test replication of a partly existing archive path to the user's inventory. This should create
389 /// a duplicate path without the merge option.
390 /// </summary>
391 [Test]
392 public void TestPartExistingIarPath()
393 {
394 TestHelper.InMethod();
395 //log4net.Config.XmlConfigurator.Configure();
396
397 Scene scene = SceneSetupHelpers.SetupScene("inventory");
398 UserAccount ua1 = UserProfileTestUtils.CreateUserWithInventory(scene);
399
400 string folder1ExistingName = "a";
401 string folder2Name = "b";
402
403 InventoryFolderBase folder1
404 = UserInventoryTestUtils.CreateInventoryFolder(
405 scene.InventoryService, ua1.PrincipalID, folder1ExistingName);
406
407 string folder1ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder1ExistingName, UUID.Random());
408 string folder2ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2Name, UUID.Random());
409
410 string itemArchivePath = string.Join("", new string[] { folder1ArchiveName, folder2ArchiveName });
411
412 new InventoryArchiveReadRequest(scene, ua1, null, (Stream)null, false)
413 .ReplicateArchivePathToUserInventory(
414 itemArchivePath, scene.InventoryService.GetRootFolder(ua1.PrincipalID),
415 new Dictionary<string, InventoryFolderBase>(), new HashSet<InventoryNodeBase>());
416
417 List<InventoryFolderBase> folder1PostCandidates
418 = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, ua1.PrincipalID, folder1ExistingName);
419 Assert.That(folder1PostCandidates.Count, Is.EqualTo(2));
420
421 // FIXME: Temporarily, we're going to do something messy to make sure we pick up the created folder.
422 InventoryFolderBase folder1Post = null;
423 foreach (InventoryFolderBase folder in folder1PostCandidates)
424 {
425 if (folder.ID != folder1.ID)
426 {
427 folder1Post = folder;
428 break;
429 }
430 }
431// Assert.That(folder1Post.ID, Is.EqualTo(folder1.ID));
432
433 List<InventoryFolderBase> folder2PostCandidates
434 = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1Post, "b");
435 Assert.That(folder2PostCandidates.Count, Is.EqualTo(1));
436 }
437
438 /// <summary>
439 /// Test replication of a partly existing archive path to the user's inventory. This should create
440 /// a merged path.
441 /// </summary>
442 [Test]
443 public void TestMergeIarPath()
444 {
445 TestHelper.InMethod();
446// log4net.Config.XmlConfigurator.Configure();
447
448 Scene scene = SceneSetupHelpers.SetupScene("inventory");
449 UserAccount ua1 = UserProfileTestUtils.CreateUserWithInventory(scene);
450
451 string folder1ExistingName = "a";
452 string folder2Name = "b";
453
454 InventoryFolderBase folder1
455 = UserInventoryTestUtils.CreateInventoryFolder(
456 scene.InventoryService, ua1.PrincipalID, folder1ExistingName);
457
458 string folder1ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder1ExistingName, UUID.Random());
459 string folder2ArchiveName = InventoryArchiveWriteRequest.CreateArchiveFolderName(folder2Name, UUID.Random());
460
461 string itemArchivePath = string.Join("", new string[] { folder1ArchiveName, folder2ArchiveName });
462
463 new InventoryArchiveReadRequest(scene, ua1, folder1ExistingName, (Stream)null, true)
464 .ReplicateArchivePathToUserInventory(
465 itemArchivePath, scene.InventoryService.GetRootFolder(ua1.PrincipalID),
466 new Dictionary<string, InventoryFolderBase>(), new HashSet<InventoryNodeBase>());
467
468 List<InventoryFolderBase> folder1PostCandidates
469 = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, ua1.PrincipalID, folder1ExistingName);
470 Assert.That(folder1PostCandidates.Count, Is.EqualTo(1));
471 Assert.That(folder1PostCandidates[0].ID, Is.EqualTo(folder1.ID));
472
473 List<InventoryFolderBase> folder2PostCandidates
474 = InventoryArchiveUtils.FindFolderByPath(scene.InventoryService, folder1PostCandidates[0], "b");
475 Assert.That(folder2PostCandidates.Count, Is.EqualTo(1));
476 }
477 }
478} \ No newline at end of file