UserInventoryTests.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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;
  28. using System.Collections.Generic;
  29. using System.Reflection;
  30. using System.Text;
  31. using System.Threading;
  32. using System.Timers;
  33. using Timer=System.Timers.Timer;
  34. using Nini.Config;
  35. using NUnit.Framework;
  36. using OpenMetaverse;
  37. using OpenMetaverse.Assets;
  38. using OpenSim.Framework;
  39. using OpenSim.Region.Framework.Scenes;
  40. using OpenSim.Region.CoreModules.Framework.InventoryAccess;
  41. using OpenSim.Services.Interfaces;
  42. using OpenSim.Tests.Common;
  43. namespace OpenSim.Region.Framework.Tests
  44. {
  45. [TestFixture]
  46. public class UserInventoryTests : OpenSimTestCase
  47. {
  48. [Test]
  49. public void TestCreateInventoryFolders()
  50. {
  51. TestHelpers.InMethod();
  52. // TestHelpers.EnableLogging();
  53. // For this test both folders will have the same name which is legal in SL user inventories.
  54. string foldersName = "f1";
  55. Scene scene = new SceneHelpers().SetupScene();
  56. UserAccount user1 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1001));
  57. UserInventoryHelpers.CreateInventoryFolder(scene.InventoryService, user1.PrincipalID, foldersName, false);
  58. List<InventoryFolderBase> oneFolder
  59. = UserInventoryHelpers.GetInventoryFolders(scene.InventoryService, user1.PrincipalID, foldersName);
  60. Assert.That(oneFolder.Count, Is.EqualTo(1));
  61. InventoryFolderBase firstRetrievedFolder = oneFolder[0];
  62. Assert.That(firstRetrievedFolder.Name, Is.EqualTo(foldersName));
  63. UserInventoryHelpers.CreateInventoryFolder(scene.InventoryService, user1.PrincipalID, foldersName, false);
  64. List<InventoryFolderBase> twoFolders
  65. = UserInventoryHelpers.GetInventoryFolders(scene.InventoryService, user1.PrincipalID, foldersName);
  66. Assert.That(twoFolders.Count, Is.EqualTo(2));
  67. Assert.That(twoFolders[0].Name, Is.EqualTo(foldersName));
  68. Assert.That(twoFolders[1].Name, Is.EqualTo(foldersName));
  69. Assert.That(twoFolders[0].ID, Is.Not.EqualTo(twoFolders[1].ID));
  70. }
  71. [Test]
  72. public void TestGiveInventoryItem()
  73. {
  74. TestHelpers.InMethod();
  75. // log4net.Config.XmlConfigurator.Configure();
  76. Scene scene = new SceneHelpers().SetupScene();
  77. UserAccount user1 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1001));
  78. UserAccount user2 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1002));
  79. InventoryItemBase item1 = UserInventoryHelpers.CreateInventoryItem(scene, "item1", user1.PrincipalID);
  80. string message;
  81. scene.GiveInventoryItem(user2.PrincipalID, user1.PrincipalID, item1.ID, out message);
  82. InventoryItemBase retrievedItem1
  83. = UserInventoryHelpers.GetInventoryItem(scene.InventoryService, user2.PrincipalID, "Notecards/item1");
  84. Assert.That(retrievedItem1, Is.Not.Null);
  85. // Try giving back the freshly received item
  86. scene.GiveInventoryItem(user1.PrincipalID, user2.PrincipalID, retrievedItem1.ID, out message);
  87. List<InventoryItemBase> reretrievedItems
  88. = UserInventoryHelpers.GetInventoryItems(scene.InventoryService, user1.PrincipalID, "Notecards/item1");
  89. Assert.That(reretrievedItems.Count, Is.EqualTo(2));
  90. }
  91. [Test]
  92. public void TestGiveInventoryFolder()
  93. {
  94. TestHelpers.InMethod();
  95. // TestHelpers.EnableLogging();
  96. Scene scene = new SceneHelpers().SetupScene();
  97. UserAccount user1 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1001));
  98. UserAccount user2 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1002));
  99. InventoryFolderBase folder1
  100. = UserInventoryHelpers.CreateInventoryFolder(scene.InventoryService, user1.PrincipalID, "folder1", false);
  101. scene.GiveInventoryFolder(null, user2.PrincipalID, user1.PrincipalID, folder1.ID, UUID.Zero);
  102. InventoryFolderBase retrievedFolder1
  103. = UserInventoryHelpers.GetInventoryFolder(scene.InventoryService, user2.PrincipalID, "folder1");
  104. Assert.That(retrievedFolder1, Is.Not.Null);
  105. // Try giving back the freshly received folder
  106. scene.GiveInventoryFolder(null, user1.PrincipalID, user2.PrincipalID, retrievedFolder1.ID, UUID.Zero);
  107. List<InventoryFolderBase> reretrievedFolders
  108. = UserInventoryHelpers.GetInventoryFolders(scene.InventoryService, user1.PrincipalID, "folder1");
  109. Assert.That(reretrievedFolders.Count, Is.EqualTo(2));
  110. }
  111. // Work in Progress test. All Assertions pertaining permissions are commented for now.
  112. [Test]
  113. public void TestGiveInventoryItemFullPerms()
  114. {
  115. TestHelpers.InMethod();
  116. List<Object> modules = new List<object>();
  117. IConfigSource config = DefaultConfig(modules);
  118. Scene scene = new SceneHelpers().SetupScene("Inventory Permissions", UUID.Random(), 1000, 1000, config);
  119. SceneHelpers.SetupSceneModules(scene, config, modules.ToArray());
  120. UserAccount user1 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1001));
  121. UserAccount user2 = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(1002));
  122. ScenePresence sp1 = SceneHelpers.AddScenePresence(scene, user1.PrincipalID);
  123. ScenePresence sp2 = SceneHelpers.AddScenePresence(scene, user2.PrincipalID);
  124. InventoryItemBase item1 = UserInventoryHelpers.CreateInventoryItem(scene, "SomeObject", user1.PrincipalID, InventoryType.Object);
  125. // Set All perms in inventory
  126. item1.NextPermissions = (uint)OpenMetaverse.PermissionMask.All;
  127. scene.UpdateInventoryItemAsset(sp1.ControllingClient, UUID.Zero, item1.ID, item1);
  128. //Assert.That((item1.NextPermissions & (uint)OpenMetaverse.PermissionMask.All) == (uint)OpenMetaverse.PermissionMask.All);
  129. string message;
  130. InventoryItemBase retrievedItem1 = scene.GiveInventoryItem(user2.PrincipalID, user1.PrincipalID, item1.ID, out message);
  131. Assert.That(retrievedItem1, Is.Not.Null);
  132. //Assert.That((retrievedItem1.CurrentPermissions & (uint)OpenMetaverse.PermissionMask.All) == (uint)OpenMetaverse.PermissionMask.All);
  133. retrievedItem1
  134. = UserInventoryHelpers.GetInventoryItem(scene.InventoryService, user2.PrincipalID, "Objects/SomeObject");
  135. Assert.That(retrievedItem1, Is.Not.Null);
  136. //Assert.That((retrievedItem1.BasePermissions & (uint)OpenMetaverse.PermissionMask.All) == (uint)OpenMetaverse.PermissionMask.All);
  137. //Assert.That((retrievedItem1.CurrentPermissions & (uint)OpenMetaverse.PermissionMask.All) == (uint)OpenMetaverse.PermissionMask.All);
  138. // Rez the object
  139. scene.RezObject(sp2.ControllingClient, retrievedItem1.ID, UUID.Zero, Vector3.Zero, Vector3.Zero, UUID.Zero, 0, false, false, false, UUID.Zero);
  140. SceneObjectGroup sog = scene.GetSceneObjectGroup("SomeObject");
  141. Assert.That(sog, Is.Not.Null);
  142. // This is failing for all sorts of reasons. We'll fix it after perms are fixed.
  143. //Console.WriteLine("Item Perms " + retrievedItem1.CurrentPermissions + " Obj Owner Perms " + sog.RootPart.OwnerMask + " Base Perms " + sog.RootPart.BaseMask + "\n");
  144. //Assert.True((sog.RootPart.OwnerMask & (uint)OpenMetaverse.PermissionMask.All) == (uint)OpenMetaverse.PermissionMask.All);
  145. }
  146. public static IConfigSource DefaultConfig(List<object> modules)
  147. {
  148. IConfigSource config = new IniConfigSource();
  149. config.AddConfig("Modules");
  150. config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule");
  151. config.AddConfig("Permissions");
  152. config.Configs["Permissions"].Set("permissionmodules", "DefaultPermissionsModule");
  153. config.Configs["Permissions"].Set("serverside_object_permissions", true);
  154. config.Configs["Permissions"].Set("propagate_permissions", true);
  155. modules.Add(new BasicInventoryAccessModule());
  156. return config;
  157. }
  158. }
  159. }