SceneObjectCopyTests.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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 Nini.Config;
  31. using NUnit.Framework;
  32. using OpenMetaverse;
  33. using OpenSim.Framework;
  34. using OpenSim.Region.CoreModules.Framework.EntityTransfer;
  35. using OpenSim.Region.CoreModules.Framework.InventoryAccess;
  36. using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
  37. using OpenSim.Region.CoreModules.World.Permissions;
  38. using OpenSim.Region.Framework.Scenes;
  39. using OpenSim.Services.Interfaces;
  40. using OpenSim.Tests.Common;
  41. namespace OpenSim.Region.Framework.Scenes.Tests
  42. {
  43. /*
  44. /// <summary>
  45. /// Test copying of scene objects.
  46. /// </summary>
  47. /// <remarks>
  48. /// This is at a level above the SceneObjectBasicTests, which act on the scene directly.
  49. /// </remarks>
  50. [TestFixture]
  51. public class SceneObjectCopyTests : OpenSimTestCase
  52. {
  53. [TestFixtureSetUp]
  54. public void FixtureInit()
  55. {
  56. // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
  57. // This facility was added after the original async delete tests were written, so it may be possible now
  58. // to not bother explicitly disabling their async (since everything will be running sync).
  59. Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest;
  60. }
  61. [TestFixtureTearDown]
  62. public void TearDown()
  63. {
  64. // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
  65. // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression
  66. // tests really shouldn't).
  67. Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
  68. }
  69. [Test]
  70. public void TestTakeCopyWhenCopierIsOwnerWithPerms()
  71. {
  72. TestHelpers.InMethod();
  73. // TestHelpers.EnableLogging();
  74. IConfigSource config = new IniConfigSource();
  75. config.AddConfig("Modules");
  76. config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule");
  77. TestScene scene = new SceneHelpers().SetupScene("s1", TestHelpers.ParseTail(0x99), 1000, 1000, config);
  78. SceneHelpers.SetupSceneModules(scene, config, new PermissionsModule(), new BasicInventoryAccessModule());
  79. UserAccount ua = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(0x1));
  80. TestClient client = (TestClient)SceneHelpers.AddScenePresence(scene, ua.PrincipalID).ControllingClient;
  81. // Turn off the timer on the async sog deleter - we'll crank it by hand for this test.
  82. AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter;
  83. sogd.Enabled = false;
  84. SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, "so1", ua.PrincipalID);
  85. uint soLocalId = so.LocalId;
  86. // so.UpdatePermissions(
  87. // ua.PrincipalID, (byte)PermissionWho.Owner, so.LocalId, (uint)OpenMetaverse.PermissionMask.Copy, 1);
  88. // so.UpdatePermissions(
  89. // ua.PrincipalID, (byte)PermissionWho.Owner, so.LocalId, (uint)OpenMetaverse.PermissionMask.Transfer, 0);
  90. // so.UpdatePermissions(
  91. // ua.PrincipalID, (byte)PermissionWho.Base, so.LocalId, (uint)OpenMetaverse.PermissionMask.Transfer, 0);
  92. // scene.HandleObjectPermissionsUpdate(client, client.AgentId, client.SessionId, (byte)PermissionWho.Owner, so.LocalId, (uint)OpenMetaverse.PermissionMask.Transfer, 0);
  93. // Ideally we might change these via client-focussed method calls as commented out above. However, this
  94. // becomes very convoluted so we will set only the copy perm directly.
  95. so.RootPart.BaseMask = (uint)OpenMetaverse.PermissionMask.Copy;
  96. // so.RootPart.OwnerMask = (uint)OpenMetaverse.PermissionMask.Copy;
  97. List<uint> localIds = new List<uint>();
  98. localIds.Add(so.LocalId);
  99. // Specifying a UUID.Zero in this case will currently plop it in Lost and Found
  100. scene.DeRezObjects(client, localIds, UUID.Zero, DeRezAction.TakeCopy, UUID.Zero);
  101. // Check that object isn't copied until we crank the sogd handle.
  102. SceneObjectPart retrievedPart = scene.GetSceneObjectPart(so.LocalId);
  103. Assert.That(retrievedPart, Is.Not.Null);
  104. Assert.That(retrievedPart.ParentGroup.IsDeleted, Is.False);
  105. sogd.InventoryDeQueueAndDelete();
  106. // Check that object is still there.
  107. SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(so.LocalId);
  108. Assert.That(retrievedPart2, Is.Not.Null);
  109. Assert.That(client.ReceivedKills.Count, Is.EqualTo(0));
  110. // Check that we have a copy in inventory
  111. InventoryItemBase item
  112. = UserInventoryHelpers.GetInventoryItem(scene.InventoryService, ua.PrincipalID, "Lost And Found/so1");
  113. Assert.That(item, Is.Not.Null);
  114. }
  115. [Test]
  116. public void TestTakeCopyWhenCopierIsOwnerWithoutPerms()
  117. {
  118. TestHelpers.InMethod();
  119. // TestHelpers.EnableLogging();
  120. IConfigSource config = new IniConfigSource();
  121. config.AddConfig("Modules");
  122. config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule");
  123. TestScene scene = new SceneHelpers().SetupScene("s1", TestHelpers.ParseTail(0x99), 1000, 1000, config);
  124. SceneHelpers.SetupSceneModules(scene, config, new PermissionsModule(), new BasicInventoryAccessModule());
  125. UserAccount ua = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(0x1));
  126. TestClient client = (TestClient)SceneHelpers.AddScenePresence(scene, ua.PrincipalID).ControllingClient;
  127. // Turn off the timer on the async sog deleter - we'll crank it by hand for this test.
  128. AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter;
  129. sogd.Enabled = false;
  130. SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, "so1", ua.PrincipalID);
  131. uint soLocalId = so.LocalId;
  132. so.RootPart.BaseMask = (uint)(OpenMetaverse.PermissionMask.All & ~OpenMetaverse.PermissionMask.Copy);
  133. //so.RootPart.OwnerMask = (uint)(OpenMetaverse.PermissionMask.Copy & ~OpenMetaverse.PermissionMask.Copy);
  134. List<uint> localIds = new List<uint>();
  135. localIds.Add(so.LocalId);
  136. // Specifying a UUID.Zero in this case will currently plop it in Lost and Found
  137. scene.DeRezObjects(client, localIds, UUID.Zero, DeRezAction.TakeCopy, UUID.Zero);
  138. // Check that object isn't copied until we crank the sogd handle.
  139. SceneObjectPart retrievedPart = scene.GetSceneObjectPart(so.LocalId);
  140. Assert.That(retrievedPart, Is.Not.Null);
  141. Assert.That(retrievedPart.ParentGroup.IsDeleted, Is.False);
  142. sogd.InventoryDeQueueAndDelete();
  143. // Check that object is still there.
  144. SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(so.LocalId);
  145. Assert.That(retrievedPart2, Is.Not.Null);
  146. Assert.That(client.ReceivedKills.Count, Is.EqualTo(0));
  147. // Check that we do not have a copy in inventory
  148. InventoryItemBase item
  149. = UserInventoryHelpers.GetInventoryItem(scene.InventoryService, ua.PrincipalID, "Lost And Found/so1");
  150. Assert.That(item, Is.Null);
  151. }
  152. [Test]
  153. public void TestTakeCopyWhenCopierIsNotOwnerWithPerms()
  154. {
  155. TestHelpers.InMethod();
  156. // TestHelpers.EnableLogging();
  157. IConfigSource config = new IniConfigSource();
  158. config.AddConfig("Modules");
  159. config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule");
  160. TestScene scene = new SceneHelpers().SetupScene("s1", TestHelpers.ParseTail(0x99), 1000, 1000, config);
  161. SceneHelpers.SetupSceneModules(scene, config, new PermissionsModule(), new BasicInventoryAccessModule());
  162. UserAccount ua = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(0x1));
  163. TestClient client = (TestClient)SceneHelpers.AddScenePresence(scene, ua.PrincipalID).ControllingClient;
  164. // Turn off the timer on the async sog deleter - we'll crank it by hand for this test.
  165. AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter;
  166. sogd.Enabled = false;
  167. SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, "so1", TestHelpers.ParseTail(0x2));
  168. uint soLocalId = so.LocalId;
  169. // Base must allow transfer and copy
  170. so.RootPart.BaseMask = (uint)(OpenMetaverse.PermissionMask.Copy | OpenMetaverse.PermissionMask.Transfer);
  171. // Must be set so anyone can copy
  172. so.RootPart.EveryoneMask = (uint)OpenMetaverse.PermissionMask.Copy;
  173. List<uint> localIds = new List<uint>();
  174. localIds.Add(so.LocalId);
  175. // Specifying a UUID.Zero in this case will plop it in the Objects folder
  176. scene.DeRezObjects(client, localIds, UUID.Zero, DeRezAction.TakeCopy, UUID.Zero);
  177. // Check that object isn't copied until we crank the sogd handle.
  178. SceneObjectPart retrievedPart = scene.GetSceneObjectPart(so.LocalId);
  179. Assert.That(retrievedPart, Is.Not.Null);
  180. Assert.That(retrievedPart.ParentGroup.IsDeleted, Is.False);
  181. sogd.InventoryDeQueueAndDelete();
  182. // Check that object is still there.
  183. SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(so.LocalId);
  184. Assert.That(retrievedPart2, Is.Not.Null);
  185. Assert.That(client.ReceivedKills.Count, Is.EqualTo(0));
  186. // Check that we have a copy in inventory
  187. InventoryItemBase item
  188. = UserInventoryHelpers.GetInventoryItem(scene.InventoryService, ua.PrincipalID, "Objects/so1");
  189. Assert.That(item, Is.Not.Null);
  190. }
  191. [Test]
  192. public void TestTakeCopyWhenCopierIsNotOwnerWithoutPerms()
  193. {
  194. TestHelpers.InMethod();
  195. // TestHelpers.EnableLogging();
  196. IConfigSource config = new IniConfigSource();
  197. config.AddConfig("Modules");
  198. config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule");
  199. TestScene scene = new SceneHelpers().SetupScene("s1", TestHelpers.ParseTail(0x99), 1000, 1000, config);
  200. SceneHelpers.SetupSceneModules(scene, config, new PermissionsModule(), new BasicInventoryAccessModule());
  201. UserAccount ua = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(0x1));
  202. TestClient client = (TestClient)SceneHelpers.AddScenePresence(scene, ua.PrincipalID).ControllingClient;
  203. // Turn off the timer on the async sog deleter - we'll crank it by hand for this test.
  204. AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter;
  205. sogd.Enabled = false;
  206. SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, "so1", TestHelpers.ParseTail(0x2));
  207. uint soLocalId = so.LocalId;
  208. {
  209. // Check that object is not copied if copy base perms is missing.
  210. // Should not allow copy if base does not have this.
  211. so.RootPart.BaseMask = (uint)OpenMetaverse.PermissionMask.Transfer;
  212. // Must be set so anyone can copy
  213. so.RootPart.EveryoneMask = (uint)OpenMetaverse.PermissionMask.Copy;
  214. // Check that object is not copied
  215. List<uint> localIds = new List<uint>();
  216. localIds.Add(so.LocalId);
  217. // Specifying a UUID.Zero in this case will plop it in the Objects folder if we have perms
  218. scene.DeRezObjects(client, localIds, UUID.Zero, DeRezAction.TakeCopy, UUID.Zero);
  219. // Check that object isn't copied until we crank the sogd handle.
  220. SceneObjectPart retrievedPart = scene.GetSceneObjectPart(so.LocalId);
  221. Assert.That(retrievedPart, Is.Not.Null);
  222. Assert.That(retrievedPart.ParentGroup.IsDeleted, Is.False);
  223. sogd.InventoryDeQueueAndDelete();
  224. // Check that object is still there.
  225. SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(so.LocalId);
  226. Assert.That(retrievedPart2, Is.Not.Null);
  227. Assert.That(client.ReceivedKills.Count, Is.EqualTo(0));
  228. // Check that we have a copy in inventory
  229. InventoryItemBase item
  230. = UserInventoryHelpers.GetInventoryItem(scene.InventoryService, ua.PrincipalID, "Objects/so1");
  231. Assert.That(item, Is.Null);
  232. }
  233. {
  234. // Check that object is not copied if copy trans perms is missing.
  235. // Should not allow copy if base does not have this.
  236. so.RootPart.BaseMask = (uint)OpenMetaverse.PermissionMask.Copy;
  237. // Must be set so anyone can copy
  238. so.RootPart.EveryoneMask = (uint)OpenMetaverse.PermissionMask.Copy;
  239. // Check that object is not copied
  240. List<uint> localIds = new List<uint>();
  241. localIds.Add(so.LocalId);
  242. // Specifying a UUID.Zero in this case will plop it in the Objects folder if we have perms
  243. scene.DeRezObjects(client, localIds, UUID.Zero, DeRezAction.TakeCopy, UUID.Zero);
  244. // Check that object isn't copied until we crank the sogd handle.
  245. SceneObjectPart retrievedPart = scene.GetSceneObjectPart(so.LocalId);
  246. Assert.That(retrievedPart, Is.Not.Null);
  247. Assert.That(retrievedPart.ParentGroup.IsDeleted, Is.False);
  248. sogd.InventoryDeQueueAndDelete();
  249. // Check that object is still there.
  250. SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(so.LocalId);
  251. Assert.That(retrievedPart2, Is.Not.Null);
  252. Assert.That(client.ReceivedKills.Count, Is.EqualTo(0));
  253. // Check that we have a copy in inventory
  254. InventoryItemBase item
  255. = UserInventoryHelpers.GetInventoryItem(scene.InventoryService, ua.PrincipalID, "Objects/so1");
  256. Assert.That(item, Is.Null);
  257. }
  258. {
  259. // Check that object is not copied if everyone copy perms is missing.
  260. // Should not allow copy if base does not have this.
  261. so.RootPart.BaseMask = (uint)(OpenMetaverse.PermissionMask.Copy | OpenMetaverse.PermissionMask.Transfer);
  262. // Make sure everyone perm does not allow copy
  263. so.RootPart.EveryoneMask = (uint)(OpenMetaverse.PermissionMask.All & ~OpenMetaverse.PermissionMask.Copy);
  264. // Check that object is not copied
  265. List<uint> localIds = new List<uint>();
  266. localIds.Add(so.LocalId);
  267. // Specifying a UUID.Zero in this case will plop it in the Objects folder if we have perms
  268. scene.DeRezObjects(client, localIds, UUID.Zero, DeRezAction.TakeCopy, UUID.Zero);
  269. // Check that object isn't copied until we crank the sogd handle.
  270. SceneObjectPart retrievedPart = scene.GetSceneObjectPart(so.LocalId);
  271. Assert.That(retrievedPart, Is.Not.Null);
  272. Assert.That(retrievedPart.ParentGroup.IsDeleted, Is.False);
  273. sogd.InventoryDeQueueAndDelete();
  274. // Check that object is still there.
  275. SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(so.LocalId);
  276. Assert.That(retrievedPart2, Is.Not.Null);
  277. Assert.That(client.ReceivedKills.Count, Is.EqualTo(0));
  278. // Check that we have a copy in inventory
  279. InventoryItemBase item
  280. = UserInventoryHelpers.GetInventoryItem(scene.InventoryService, ua.PrincipalID, "Objects/so1");
  281. Assert.That(item, Is.Null);
  282. }
  283. }
  284. }
  285. */
  286. }