From 1ca2a7937ebf246bb2ebe4b1355f8068912ea4b0 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Mon, 1 May 2017 14:58:03 -0700 Subject: [PATCH] Permissions tests: added test with 2 direct transfers with permission changes in between (in inventory) --- OpenSim/Tests/Permissions/Common.cs | 64 ++++++++++++++++++- .../Tests/Permissions/DirectTransferTests.cs | 51 +++++++++++++-- 2 files changed, 110 insertions(+), 5 deletions(-) diff --git a/OpenSim/Tests/Permissions/Common.cs b/OpenSim/Tests/Permissions/Common.cs index 63b91b62ba..84dadf28a3 100644 --- a/OpenSim/Tests/Permissions/Common.cs +++ b/OpenSim/Tests/Permissions/Common.cs @@ -93,11 +93,16 @@ namespace OpenSim.Tests.Permissions AddA1Object("Box MT", 14, PermissionMask.Modify | PermissionMask.Transfer); AddA1Object("Box T", 15, PermissionMask.Transfer); + // MCT-C + AddA1Object("Box MCT-C", 16, PermissionMask.Modify | PermissionMask.Copy | PermissionMask.Transfer); + Thread.Sleep(5000); InventoryFolderBase objsFolder = UserInventoryHelpers.GetInventoryFolder(m_Scene.InventoryService, m_Avatars[0].UUID, "Objects"); List items = m_Scene.InventoryService.GetFolderItems(m_Avatars[0].UUID, objsFolder.ID); - Assert.That(items.Count, Is.EqualTo(6)); + Assert.That(items.Count, Is.EqualTo(7)); + + RevokePermission(0, "Box MCT-C", PermissionMask.Copy); } private ScenePresence AddScenePresence(string first, string last, UUID id) @@ -139,6 +144,30 @@ namespace OpenSim.Tests.Permissions } + public void RevokePermission(int ownerIndex, string name, PermissionMask perm) + { + InventoryItemBase item = Common.TheInstance.GetItemFromInventory(m_Avatars[ownerIndex].UUID, "Objects", name); + Assert.That(item, Is.Not.Null); + + // Clone it, so to avoid aliasing -- just like the viewer does. + InventoryItemBase clone = Common.TheInstance.CloneInventoryItem(item); + // Revoke the permission in this copy + clone.NextPermissions &= ~(uint)perm; + Common.TheInstance.AssertPermissions((PermissionMask)clone.NextPermissions & ~perm, + (PermissionMask)clone.NextPermissions, Common.TheInstance.IdStr(clone)); + Assert.That(clone.ID == item.ID); + + // Update properties of the item in inventory. This should affect the original item above. + Common.TheScene.UpdateInventoryItemAsset(m_Avatars[ownerIndex].ControllingClient, UUID.Zero, clone.ID, clone); + + item = Common.TheInstance.GetItemFromInventory(m_Avatars[ownerIndex].UUID, "Objects", name); + Assert.That(item, Is.Not.Null); + Common.TheInstance.PrintPerms(item); + Common.TheInstance.AssertPermissions((PermissionMask)item.NextPermissions & ~perm, + (PermissionMask)item.NextPermissions, Common.TheInstance.IdStr(item)); + + } + public void PrintPerms(SceneObjectGroup sog) { Console.WriteLine("SOG " + sog.Name + " (" + sog.OwnerID.ToString().Substring(34) + "): " + @@ -210,6 +239,39 @@ namespace OpenSim.Tests.Permissions return item; } + public InventoryItemBase CloneInventoryItem(InventoryItemBase item) + { + InventoryItemBase clone = new InventoryItemBase(item.ID); + clone.Name = item.Name; + clone.Description = item.Description; + clone.AssetID = item.AssetID; + clone.AssetType = item.AssetType; + clone.BasePermissions = item.BasePermissions; + clone.CreatorId = item.CreatorId; + clone.CurrentPermissions = item.CurrentPermissions; + clone.EveryOnePermissions = item.EveryOnePermissions; + clone.Flags = item.Flags; + clone.Folder = item.Folder; + clone.GroupID = item.GroupID; + clone.GroupOwned = item.GroupOwned; + clone.GroupPermissions = item.GroupPermissions; + clone.InvType = item.InvType; + clone.NextPermissions = item.NextPermissions; + clone.Owner = item.Owner; + + return clone; + } + + public string IdStr(InventoryItemBase item) + { + return item.Owner.ToString().Substring(34) + " : " + item.Name; + } + + public string IdStr(SceneObjectGroup sog) + { + return sog.OwnerID.ToString().Substring(34) + " : " + sog.Name; + } + public void GiveInventoryItem(UUID itemId, ScenePresence giverSp, ScenePresence receiverSp) { TestClient giverClient = (TestClient)giverSp.ControllingClient; diff --git a/OpenSim/Tests/Permissions/DirectTransferTests.cs b/OpenSim/Tests/Permissions/DirectTransferTests.cs index e103d01d1a..3ca711aadf 100644 --- a/OpenSim/Tests/Permissions/DirectTransferTests.cs +++ b/OpenSim/Tests/Permissions/DirectTransferTests.cs @@ -48,7 +48,7 @@ namespace OpenSim.Tests.Permissions /// Basic scene object tests (create, read and delete but not update). /// [TestFixture] - public class DirectTransferTests + public class DirectTransferTests { [SetUp] @@ -57,15 +57,15 @@ namespace OpenSim.Tests.Permissions } /// - /// Test giving a C object. + /// Test giving simple objecta with various combinations of next owner perms. /// [Test] - public void TestGiveCBox() + public void TestGiveBox() { TestHelpers.InMethod(); // C, CT, MC, MCT, MT, T - string[] names = new string[6] { "Box C", "Box CT", "Box MC", "Box MCT", "Box MT", "Box T"}; + string[] names = new string[6] { "Box C", "Box CT", "Box MC", "Box MCT", "Box MT", "Box T" }; PermissionMask[] perms = new PermissionMask[6] { PermissionMask.Copy, PermissionMask.Copy | PermissionMask.Transfer, @@ -108,5 +108,48 @@ namespace OpenSim.Tests.Permissions } + /// + /// Test giving simple objecta with variour combinations of next owner perms. + /// + [Test] + public void TestDoubleGiveWithChange() + { + TestHelpers.InMethod(); + + string name = "Box MCT-C"; + InventoryItemBase item = Common.TheInstance.GetItemFromInventory(Common.TheAvatars[0].UUID, "Objects", name); + + // Now give the item to A2. We give the original item, not a clone. + // The giving methods are supposed to duplicate it. + Common.TheInstance.GiveInventoryItem(item.ID, Common.TheAvatars[0], Common.TheAvatars[1]); + + item = Common.TheInstance.GetItemFromInventory(Common.TheAvatars[1].UUID, "Objects", name); + + // Check the receiver + Common.TheInstance.PrintPerms(item); + Common.TheInstance.AssertPermissions(PermissionMask.Modify | PermissionMask.Transfer, + (PermissionMask)item.BasePermissions, Common.TheInstance.IdStr(item)); + + // --------------------------- + // Second transfer + //---------------------------- + + // A2 revokes M + Common.TheInstance.RevokePermission(1, name, PermissionMask.Modify); + + item = Common.TheInstance.GetItemFromInventory(Common.TheAvatars[1].UUID, "Objects", name); + + // Now give the item to A3. We give the original item, not a clone. + // The giving methods are supposed to duplicate it. + Common.TheInstance.GiveInventoryItem(item.ID, Common.TheAvatars[1], Common.TheAvatars[2]); + + item = Common.TheInstance.GetItemFromInventory(Common.TheAvatars[2].UUID, "Objects", name); + + // Check the receiver + Common.TheInstance.PrintPerms(item); + Common.TheInstance.AssertPermissions(PermissionMask.Transfer, + (PermissionMask)item.BasePermissions, Common.TheInstance.IdStr(item)); + + } } } \ No newline at end of file