LSL_ApiInventoryTests.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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 log4net;
  32. using Nini.Config;
  33. using NUnit.Framework;
  34. using OpenMetaverse;
  35. using OpenMetaverse.Assets;
  36. using OpenMetaverse.StructuredData;
  37. using OpenSim.Framework;
  38. using OpenSim.Region.CoreModules.Avatar.AvatarFactory;
  39. using OpenSim.Region.OptionalModules.World.NPC;
  40. using OpenSim.Region.Framework.Scenes;
  41. using OpenSim.Region.CoreModules.World.Permissions;
  42. using OpenSim.Region.ScriptEngine.Shared;
  43. using OpenSim.Region.ScriptEngine.Shared.Api;
  44. using OpenSim.Services.Interfaces;
  45. using OpenSim.Tests.Common;
  46. using PermissionMask = OpenSim.Framework.PermissionMask;
  47. namespace OpenSim.Region.ScriptEngine.Shared.Tests
  48. {
  49. /// <summary>
  50. /// Tests for inventory functions in LSL
  51. /// </summary>
  52. [TestFixture]
  53. /*
  54. public class LSL_ApiInventoryTests : OpenSimTestCase
  55. {
  56. protected Scene m_scene;
  57. protected XEngine.XEngine m_engine;
  58. [SetUp]
  59. public override void SetUp()
  60. {
  61. base.SetUp();
  62. IConfigSource initConfigSource = new IniConfigSource();
  63. IConfig config = initConfigSource.AddConfig("Startup");
  64. config.Set("serverside_object_permissions", true);
  65. config =initConfigSource.AddConfig("Permissions");
  66. config.Set("permissionmodules", "DefaultPermissionsModule");
  67. config.Set("serverside_object_permissions", true);
  68. config.Set("propagate_permissions", true);
  69. config = initConfigSource.AddConfig("XEngine");
  70. config.Set("Enabled", "true");
  71. config = initConfigSource.AddConfig("OSSL");
  72. config.Set("DebuggerSafe", false);
  73. config.Set("AllowOSFunctions", "true");
  74. config.Set("OSFunctionThreatLevel", "Severe");
  75. m_scene = new SceneHelpers().SetupScene();
  76. SceneHelpers.SetupSceneModules(m_scene, initConfigSource, new object[] { new DefaultPermissionsModule() });
  77. m_engine = new XEngine.XEngine();
  78. m_engine.Initialise(initConfigSource);
  79. m_engine.AddRegion(m_scene);
  80. }
  81. /// <summary>
  82. /// Test giving inventory from an object to an object where both are owned by the same user.
  83. /// </summary>
  84. [Test]
  85. public void TestLlGiveInventoryO2OSameOwner()
  86. {
  87. TestHelpers.InMethod();
  88. // log4net.Config.XmlConfigurator.Configure();
  89. UUID userId = TestHelpers.ParseTail(0x1);
  90. string inventoryItemName = "item1";
  91. SceneObjectGroup so1 = SceneHelpers.CreateSceneObject(1, userId, "so1", 0x10);
  92. m_scene.AddSceneObject(so1);
  93. // Create an object embedded inside the first
  94. UUID itemId = TestHelpers.ParseTail(0x20);
  95. TaskInventoryHelpers.AddSceneObject(m_scene.AssetService, so1.RootPart, inventoryItemName, itemId, userId);
  96. LSL_Api api = new LSL_Api();
  97. api.Initialize(m_engine, so1.RootPart, null);
  98. // Create a second object
  99. SceneObjectGroup so2 = SceneHelpers.CreateSceneObject(1, userId, "so2", 0x100);
  100. m_scene.AddSceneObject(so2);
  101. api.llGiveInventory(so2.UUID.ToString(), inventoryItemName);
  102. // Item has copy permissions so original should stay intact.
  103. List<TaskInventoryItem> originalItems = so1.RootPart.Inventory.GetInventoryItems();
  104. Assert.That(originalItems.Count, Is.EqualTo(1));
  105. List<TaskInventoryItem> copiedItems = so2.RootPart.Inventory.GetInventoryItems(inventoryItemName);
  106. Assert.That(copiedItems.Count, Is.EqualTo(1));
  107. Assert.That(copiedItems[0].Name, Is.EqualTo(inventoryItemName));
  108. }
  109. /// <summary>
  110. /// Test giving inventory from an object to an object where they have different owners
  111. /// </summary>
  112. [Test]
  113. public void TestLlGiveInventoryO2ODifferentOwners()
  114. {
  115. TestHelpers.InMethod();
  116. // log4net.Config.XmlConfigurator.Configure();
  117. UUID user1Id = TestHelpers.ParseTail(0x1);
  118. UUID user2Id = TestHelpers.ParseTail(0x2);
  119. string inventoryItemName = "item1";
  120. SceneObjectGroup so1 = SceneHelpers.CreateSceneObject(1, user1Id, "so1", 0x10);
  121. m_scene.AddSceneObject(so1);
  122. LSL_Api api = new LSL_Api();
  123. api.Initialize(m_engine, so1.RootPart, null);
  124. // Create an object embedded inside the first
  125. UUID itemId = TestHelpers.ParseTail(0x20);
  126. TaskInventoryHelpers.AddSceneObject(m_scene.AssetService, so1.RootPart, inventoryItemName, itemId, user1Id);
  127. // Create a second object
  128. SceneObjectGroup so2 = SceneHelpers.CreateSceneObject(1, user2Id, "so2", 0x100);
  129. m_scene.AddSceneObject(so2);
  130. LSL_Api api2 = new LSL_Api();
  131. api2.Initialize(m_engine, so2.RootPart, null);
  132. // *** Firstly, we test where llAllowInventoryDrop() has not been called. ***
  133. api.llGiveInventory(so2.UUID.ToString(), inventoryItemName);
  134. {
  135. // Item has copy permissions so original should stay intact.
  136. List<TaskInventoryItem> originalItems = so1.RootPart.Inventory.GetInventoryItems();
  137. Assert.That(originalItems.Count, Is.EqualTo(1));
  138. // Should have not copied
  139. List<TaskInventoryItem> copiedItems = so2.RootPart.Inventory.GetInventoryItems(inventoryItemName);
  140. Assert.That(copiedItems.Count, Is.EqualTo(0));
  141. }
  142. // *** Secondly, we turn on allow inventory drop in the target and retest. ***
  143. api2.llAllowInventoryDrop(1);
  144. api.llGiveInventory(so2.UUID.ToString(), inventoryItemName);
  145. {
  146. // Item has copy permissions so original should stay intact.
  147. List<TaskInventoryItem> originalItems = so1.RootPart.Inventory.GetInventoryItems();
  148. Assert.That(originalItems.Count, Is.EqualTo(1));
  149. // Should now have copied.
  150. List<TaskInventoryItem> copiedItems = so2.RootPart.Inventory.GetInventoryItems(inventoryItemName);
  151. Assert.That(copiedItems.Count, Is.EqualTo(1));
  152. Assert.That(copiedItems[0].Name, Is.EqualTo(inventoryItemName));
  153. }
  154. }
  155. /// <summary>
  156. /// Test giving inventory from an object to an avatar that is not the object's owner.
  157. /// </summary>
  158. [Test]
  159. public void TestLlGiveInventoryO2DifferentAvatar()
  160. {
  161. TestHelpers.InMethod();
  162. // TestHelpers.EnableLogging();
  163. UUID user1Id = TestHelpers.ParseTail(0x1);
  164. UUID user2Id = TestHelpers.ParseTail(0x2);
  165. string inventoryItemName = "item1";
  166. SceneObjectGroup so1 = SceneHelpers.CreateSceneObject(1, user1Id, "so1", 0x10);
  167. m_scene.AddSceneObject(so1);
  168. LSL_Api api = new LSL_Api();
  169. api.Initialize(m_engine, so1.RootPart, null);
  170. // Create an object embedded inside the first
  171. UUID itemId = TestHelpers.ParseTail(0x20);
  172. TaskInventoryHelpers.AddSceneObject(m_scene.AssetService, so1.RootPart, inventoryItemName, itemId, user1Id);
  173. UserAccountHelpers.CreateUserWithInventory(m_scene, user2Id);
  174. api.llGiveInventory(user2Id.ToString(), inventoryItemName);
  175. InventoryItemBase receivedItem
  176. = UserInventoryHelpers.GetInventoryItem(
  177. m_scene.InventoryService, user2Id, string.Format("Objects/{0}", inventoryItemName));
  178. Assert.IsNotNull(receivedItem);
  179. }
  180. /// <summary>
  181. /// Test giving inventory from an object to an avatar that is not the object's owner and where the next
  182. /// permissions do not include mod.
  183. /// </summary>
  184. [Test]
  185. public void TestLlGiveInventoryO2DifferentAvatarNoMod()
  186. {
  187. TestHelpers.InMethod();
  188. // TestHelpers.EnableLogging();
  189. UUID user1Id = TestHelpers.ParseTail(0x1);
  190. UUID user2Id = TestHelpers.ParseTail(0x2);
  191. string inventoryItemName = "item1";
  192. SceneObjectGroup so1 = SceneHelpers.CreateSceneObject(1, user1Id, "so1", 0x10);
  193. m_scene.AddSceneObject(so1);
  194. LSL_Api api = new LSL_Api();
  195. api.Initialize(m_engine, so1.RootPart, null);
  196. // Create an object embedded inside the first
  197. UUID itemId = TestHelpers.ParseTail(0x20);
  198. TaskInventoryItem tii
  199. = TaskInventoryHelpers.AddSceneObject(m_scene.AssetService, so1.RootPart, inventoryItemName, itemId, user1Id);
  200. tii.NextPermissions &= ~((uint)PermissionMask.Modify);
  201. UserAccountHelpers.CreateUserWithInventory(m_scene, user2Id);
  202. api.llGiveInventory(user2Id.ToString(), inventoryItemName);
  203. InventoryItemBase receivedItem
  204. = UserInventoryHelpers.GetInventoryItem(
  205. m_scene.InventoryService, user2Id, string.Format("Objects/{0}", inventoryItemName));
  206. Assert.IsNotNull(receivedItem);
  207. Assert.AreEqual(0, receivedItem.CurrentPermissions & (uint)PermissionMask.Modify);
  208. }
  209. [Test]
  210. public void TestLlRemoteLoadScriptPin()
  211. {
  212. TestHelpers.InMethod();
  213. // TestHelpers.EnableLogging();
  214. UUID user1Id = TestHelpers.ParseTail(0x1);
  215. UUID user2Id = TestHelpers.ParseTail(0x2);
  216. SceneObjectGroup sourceSo = SceneHelpers.AddSceneObject(m_scene, "sourceSo", user1Id);
  217. m_scene.AddSceneObject(sourceSo);
  218. LSL_Api api = new LSL_Api();
  219. api.Initialize(m_engine, sourceSo.RootPart, null);
  220. TaskInventoryHelpers.AddScript(m_scene.AssetService, sourceSo.RootPart, "script", "Hello World");
  221. SceneObjectGroup targetSo = SceneHelpers.AddSceneObject(m_scene, "targetSo", user1Id);
  222. SceneObjectGroup otherOwnedTargetSo = SceneHelpers.AddSceneObject(m_scene, "otherOwnedTargetSo", user2Id);
  223. // Test that we cannot load a script when the target pin has never been set (i.e. it is zero)
  224. api.llRemoteLoadScriptPin(targetSo.UUID.ToString(), "script", 0, 0, 0);
  225. Assert.IsNull(targetSo.RootPart.Inventory.GetInventoryItem("script"));
  226. // Test that we cannot load a script when the given pin does not match the target
  227. targetSo.RootPart.ScriptAccessPin = 5;
  228. api.llRemoteLoadScriptPin(targetSo.UUID.ToString(), "script", 3, 0, 0);
  229. Assert.IsNull(targetSo.RootPart.Inventory.GetInventoryItem("script"));
  230. // Test that we cannot load into a prim with a different owner
  231. otherOwnedTargetSo.RootPart.ScriptAccessPin = 3;
  232. api.llRemoteLoadScriptPin(otherOwnedTargetSo.UUID.ToString(), "script", 3, 0, 0);
  233. Assert.IsNull(otherOwnedTargetSo.RootPart.Inventory.GetInventoryItem("script"));
  234. // Test that we can load a script when given pin and dest pin match.
  235. targetSo.RootPart.ScriptAccessPin = 3;
  236. api.llRemoteLoadScriptPin(targetSo.UUID.ToString(), "script", 3, 0, 0);
  237. TaskInventoryItem insertedItem = targetSo.RootPart.Inventory.GetInventoryItem("script");
  238. Assert.IsNotNull(insertedItem);
  239. // Test that we can no longer load if access pin is unset
  240. targetSo.RootPart.Inventory.RemoveInventoryItem(insertedItem.ItemID);
  241. Assert.IsNull(targetSo.RootPart.Inventory.GetInventoryItem("script"));
  242. targetSo.RootPart.ScriptAccessPin = 0;
  243. api.llRemoteLoadScriptPin(otherOwnedTargetSo.UUID.ToString(), "script", 3, 0, 0);
  244. Assert.IsNull(otherOwnedTargetSo.RootPart.Inventory.GetInventoryItem("script"));
  245. }
  246. }
  247. */
  248. }