1
0

DirectTransferTests.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. // In case we're dealing with some older version of nunit
  45. if (Common.TheInstance == null)
  46. {
  47. Common.TheInstance = new Common();
  48. Common.TheInstance.SetUp();
  49. }
  50. Common.TheInstance.DeleteObjectsFolders();
  51. }
  52. /// <summary>
  53. /// Test giving simple objecta with various combinations of next owner perms.
  54. /// </summary>
  55. [Test]
  56. public void TestGiveBox()
  57. {
  58. TestHelpers.InMethod();
  59. // C, CT, MC, MCT, MT, T
  60. string[] names = new string[6] { "Box C", "Box CT", "Box MC", "Box MCT", "Box MT", "Box T" };
  61. PermissionMask[] perms = new PermissionMask[6] {
  62. PermissionMask.Copy,
  63. PermissionMask.Copy | PermissionMask.Transfer,
  64. PermissionMask.Modify | PermissionMask.Copy,
  65. PermissionMask.Modify | PermissionMask.Copy | PermissionMask.Transfer,
  66. PermissionMask.Modify | PermissionMask.Transfer,
  67. PermissionMask.Transfer
  68. };
  69. for (int i = 0; i < 6; i++)
  70. TestOneBox(names[i], perms[i]);
  71. }
  72. private void TestOneBox(string name, PermissionMask mask)
  73. {
  74. InventoryItemBase item = Common.TheInstance.GetItemFromInventory(Common.TheAvatars[0].UUID, "Objects", name);
  75. Common.TheInstance.GiveInventoryItem(item.ID, Common.TheAvatars[0], Common.TheAvatars[1]);
  76. item = Common.TheInstance.GetItemFromInventory(Common.TheAvatars[1].UUID, "Objects", name);
  77. // Check the receiver
  78. Common.TheInstance.PrintPerms(item);
  79. Common.TheInstance.AssertPermissions(mask, (PermissionMask)item.BasePermissions, item.Owner.ToString().Substring(34) + " : " + item.Name);
  80. int nObjects = Common.TheScene.GetSceneObjectGroups().Count;
  81. // Rez it and check perms in scene too
  82. Common.TheScene.RezObject(Common.TheAvatars[1].ControllingClient, item.ID, UUID.Zero, Vector3.One, Vector3.Zero, UUID.Zero, 0, false, false, false, UUID.Zero);
  83. Assert.That(Common.TheScene.GetSceneObjectGroups().Count, Is.EqualTo(nObjects + 1));
  84. SceneObjectGroup box = Common.TheScene.GetSceneObjectGroups().Find(sog => sog.OwnerID == Common.TheAvatars[1].UUID && sog.Name == name);
  85. Common.TheInstance.PrintPerms(box);
  86. Assert.That(box, Is.Not.Null);
  87. // Check Owner permissions
  88. Common.TheInstance.AssertPermissions(mask, (PermissionMask)box.EffectiveOwnerPerms, box.OwnerID.ToString().Substring(34) + " : " + box.Name);
  89. // Check Next Owner permissions
  90. Common.TheInstance.AssertPermissions(mask, (PermissionMask)box.RootPart.NextOwnerMask, box.OwnerID.ToString().Substring(34) + " : " + box.Name);
  91. }
  92. /// <summary>
  93. /// Test giving simple objecta with variour combinations of next owner perms.
  94. /// </summary>
  95. [Test]
  96. public void TestDoubleGiveWithChange()
  97. {
  98. TestHelpers.InMethod();
  99. string name = "Box MCT-C";
  100. InventoryItemBase item = Common.TheInstance.GetItemFromInventory(Common.TheAvatars[0].UUID, "Objects", name);
  101. // Now give the item to A2. We give the original item, not a clone.
  102. // The giving methods are supposed to duplicate it.
  103. Common.TheInstance.GiveInventoryItem(item.ID, Common.TheAvatars[0], Common.TheAvatars[1]);
  104. item = Common.TheInstance.GetItemFromInventory(Common.TheAvatars[1].UUID, "Objects", name);
  105. // Check the receiver
  106. Common.TheInstance.PrintPerms(item);
  107. Common.TheInstance.AssertPermissions(PermissionMask.Modify | PermissionMask.Transfer,
  108. (PermissionMask)item.BasePermissions, Common.TheInstance.IdStr(item));
  109. // ---------------------------
  110. // Second transfer
  111. //----------------------------
  112. // A2 revokes M
  113. Common.TheInstance.RevokePermission(1, name, PermissionMask.Modify);
  114. item = Common.TheInstance.GetItemFromInventory(Common.TheAvatars[1].UUID, "Objects", name);
  115. // Now give the item to A3. We give the original item, not a clone.
  116. // The giving methods are supposed to duplicate it.
  117. Common.TheInstance.GiveInventoryItem(item.ID, Common.TheAvatars[1], Common.TheAvatars[2]);
  118. item = Common.TheInstance.GetItemFromInventory(Common.TheAvatars[2].UUID, "Objects", name);
  119. // Check the receiver
  120. Common.TheInstance.PrintPerms(item);
  121. Common.TheInstance.AssertPermissions(PermissionMask.Transfer,
  122. (PermissionMask)item.BasePermissions, Common.TheInstance.IdStr(item));
  123. }
  124. }
  125. }