DirectTransferTests.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 NUnit.Framework;
  28. using OpenMetaverse;
  29. using OpenSim.Framework;
  30. using OpenSim.Region.Framework.Scenes;
  31. using OpenSim.Tests.Common;
  32. using PermissionMask = OpenSim.Framework.PermissionMask;
  33. namespace OpenSim.Tests.Permissions
  34. {
  35. /// <summary>
  36. /// Basic scene object tests (create, read and delete but not update).
  37. /// </summary>
  38. [TestFixture]
  39. public class DirectTransferTests
  40. {
  41. [SetUp]
  42. public void SetUp()
  43. {
  44. Common.TheInstance.DeleteObjectsFolders();
  45. }
  46. /// <summary>
  47. /// Test giving simple objecta with various combinations of next owner perms.
  48. /// </summary>
  49. [Test]
  50. public void TestGiveBox()
  51. {
  52. TestHelpers.InMethod();
  53. // C, CT, MC, MCT, MT, T
  54. string[] names = new string[6] { "Box C", "Box CT", "Box MC", "Box MCT", "Box MT", "Box T" };
  55. PermissionMask[] perms = new PermissionMask[6] {
  56. PermissionMask.Copy,
  57. PermissionMask.Copy | PermissionMask.Transfer,
  58. PermissionMask.Modify | PermissionMask.Copy,
  59. PermissionMask.Modify | PermissionMask.Copy | PermissionMask.Transfer,
  60. PermissionMask.Modify | PermissionMask.Transfer,
  61. PermissionMask.Transfer
  62. };
  63. for (int i = 0; i < 6; i++)
  64. TestOneBox(names[i], perms[i]);
  65. }
  66. private void TestOneBox(string name, PermissionMask mask)
  67. {
  68. InventoryItemBase item = Common.TheInstance.GetItemFromInventory(Common.TheAvatars[0].UUID, "Objects", name);
  69. Common.TheInstance.GiveInventoryItem(item.ID, Common.TheAvatars[0], Common.TheAvatars[1]);
  70. item = Common.TheInstance.GetItemFromInventory(Common.TheAvatars[1].UUID, "Objects", name);
  71. // Check the receiver
  72. Common.TheInstance.PrintPerms(item);
  73. Common.TheInstance.AssertPermissions(mask, (PermissionMask)item.BasePermissions, item.Owner.ToString().Substring(34) + " : " + item.Name);
  74. int nObjects = Common.TheScene.GetSceneObjectGroups().Count;
  75. // Rez it and check perms in scene too
  76. Common.TheScene.RezObject(Common.TheAvatars[1].ControllingClient, item.ID, UUID.Zero, Vector3.One, Vector3.Zero, UUID.Zero, 0, false, false, false, UUID.Zero);
  77. Assert.That(Common.TheScene.GetSceneObjectGroups().Count, Is.EqualTo(nObjects + 1));
  78. SceneObjectGroup box = Common.TheScene.GetSceneObjectGroups().Find(sog => sog.OwnerID == Common.TheAvatars[1].UUID && sog.Name == name);
  79. Common.TheInstance.PrintPerms(box);
  80. Assert.That(box, Is.Not.Null);
  81. // Check Owner permissions
  82. Common.TheInstance.AssertPermissions(mask, (PermissionMask)box.EffectiveOwnerPerms, box.OwnerID.ToString().Substring(34) + " : " + box.Name);
  83. // Check Next Owner permissions
  84. Common.TheInstance.AssertPermissions(mask, (PermissionMask)box.RootPart.NextOwnerMask, box.OwnerID.ToString().Substring(34) + " : " + box.Name);
  85. }
  86. /// <summary>
  87. /// Test giving simple objecta with variour combinations of next owner perms.
  88. /// </summary>
  89. [Test]
  90. public void TestDoubleGiveWithChange()
  91. {
  92. TestHelpers.InMethod();
  93. string name = "Box MCT-C";
  94. InventoryItemBase item = Common.TheInstance.GetItemFromInventory(Common.TheAvatars[0].UUID, "Objects", name);
  95. // Now give the item to A2. We give the original item, not a clone.
  96. // The giving methods are supposed to duplicate it.
  97. Common.TheInstance.GiveInventoryItem(item.ID, Common.TheAvatars[0], Common.TheAvatars[1]);
  98. item = Common.TheInstance.GetItemFromInventory(Common.TheAvatars[1].UUID, "Objects", name);
  99. // Check the receiver
  100. Common.TheInstance.PrintPerms(item);
  101. Common.TheInstance.AssertPermissions(PermissionMask.Modify | PermissionMask.Transfer,
  102. (PermissionMask)item.BasePermissions, Common.TheInstance.IdStr(item));
  103. // ---------------------------
  104. // Second transfer
  105. //----------------------------
  106. // A2 revokes M
  107. Common.TheInstance.RevokePermission(1, name, PermissionMask.Modify);
  108. item = Common.TheInstance.GetItemFromInventory(Common.TheAvatars[1].UUID, "Objects", name);
  109. // Now give the item to A3. We give the original item, not a clone.
  110. // The giving methods are supposed to duplicate it.
  111. Common.TheInstance.GiveInventoryItem(item.ID, Common.TheAvatars[1], Common.TheAvatars[2]);
  112. item = Common.TheInstance.GetItemFromInventory(Common.TheAvatars[2].UUID, "Objects", name);
  113. // Check the receiver
  114. Common.TheInstance.PrintPerms(item);
  115. Common.TheInstance.AssertPermissions(PermissionMask.Transfer,
  116. (PermissionMask)item.BasePermissions, Common.TheInstance.IdStr(item));
  117. }
  118. }
  119. }