IndirectTransferTests.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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.Collections.Generic;
  28. using System.Threading;
  29. using NUnit.Framework;
  30. using OpenMetaverse;
  31. using OpenSim.Framework;
  32. using OpenSim.Region.Framework.Scenes;
  33. using OpenSim.Tests.Common;
  34. using PermissionMask = OpenSim.Framework.PermissionMask;
  35. namespace OpenSim.Tests.Permissions
  36. {
  37. /// <summary>
  38. /// Basic scene object tests (create, read and delete but not update).
  39. /// </summary>
  40. [TestFixture]
  41. public class IndirectTransferTests
  42. {
  43. [SetUp]
  44. public void SetUp()
  45. {
  46. Common.TheInstance.DeleteObjectsFolders();
  47. }
  48. /// <summary>
  49. /// Test giving simple objecta with various combinations of next owner perms.
  50. /// </summary>
  51. [Test]
  52. public void SimpleTakeCopy()
  53. {
  54. TestHelpers.InMethod();
  55. // The Objects folder of A2
  56. InventoryFolderBase objsFolder = UserInventoryHelpers.GetInventoryFolder(Common.TheScene.InventoryService, Common.TheAvatars[1].UUID, "Objects");
  57. // C, CT, MC, MCT, MT, T
  58. string[] names = new string[6] { "Box C", "Box CT", "Box MC", "Box MCT", "Box MT", "Box T" };
  59. PermissionMask[] perms = new PermissionMask[6] {
  60. PermissionMask.Copy,
  61. PermissionMask.Copy | PermissionMask.Transfer,
  62. PermissionMask.Modify | PermissionMask.Copy,
  63. PermissionMask.Modify | PermissionMask.Copy | PermissionMask.Transfer,
  64. PermissionMask.Modify | PermissionMask.Transfer,
  65. PermissionMask.Transfer
  66. };
  67. // Try A2 takes copies of objects that cannot be copied.
  68. for (int i = 0; i < 6; i++)
  69. TakeOneBox(Common.TheScene.GetSceneObjectGroups(), names[i], perms[i]);
  70. // Ad-hoc. Enough time to let the take work.
  71. Thread.Sleep(5000);
  72. List<InventoryItemBase> items = Common.TheScene.InventoryService.GetFolderItems(Common.TheAvatars[1].UUID, objsFolder.ID);
  73. Assert.That(items.Count, Is.EqualTo(0));
  74. // A1 makes the objects copyable
  75. for (int i = 0; i < 6; i++)
  76. MakeCopyable(Common.TheScene.GetSceneObjectGroups(), names[i]);
  77. // Try A2 takes copies of objects that can be copied.
  78. for (int i = 0; i < 6; i++)
  79. TakeOneBox(Common.TheScene.GetSceneObjectGroups(), names[i], perms[i]);
  80. // Ad-hoc. Enough time to let the take work.
  81. Thread.Sleep(5000);
  82. items = Common.TheScene.InventoryService.GetFolderItems(Common.TheAvatars[1].UUID, objsFolder.ID);
  83. Assert.That(items.Count, Is.EqualTo(6));
  84. for (int i = 0; i < 6; i++)
  85. {
  86. InventoryItemBase item = Common.TheInstance.GetItemFromInventory(Common.TheAvatars[1].UUID, "Objects", names[i]);
  87. Assert.That(item, Is.Not.Null);
  88. Common.TheInstance.AssertPermissions(perms[i], (PermissionMask)item.BasePermissions, Common.TheInstance.IdStr(item));
  89. }
  90. }
  91. private void TakeOneBox(List<SceneObjectGroup> objs, string name, PermissionMask mask)
  92. {
  93. // Find the object inworld
  94. SceneObjectGroup box = objs.Find(sog => sog.Name == name && sog.OwnerID == Common.TheAvatars[0].UUID);
  95. Assert.That(box, Is.Not.Null, name);
  96. // A2's inventory (index 1)
  97. Common.TheInstance.TakeCopyToInventory(1, box);
  98. }
  99. private void MakeCopyable(List<SceneObjectGroup> objs, string name)
  100. {
  101. SceneObjectGroup box = objs.Find(sog => sog.Name == name && sog.OwnerID == Common.TheAvatars[0].UUID);
  102. Assert.That(box, Is.Not.Null, name);
  103. // field = 8 is Everyone
  104. // set = 1 means add the permission; set = 0 means remove permission
  105. Common.TheScene.HandleObjectPermissionsUpdate((IClientAPI)Common.TheAvatars[0].ClientView, Common.TheAvatars[0].UUID,
  106. Common.TheAvatars[0].ControllingClient.SessionId, 8, box.LocalId, (uint)PermissionMask.Copy, 1);
  107. Common.TheInstance.PrintPerms(box);
  108. }
  109. }
  110. }