diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Tests/Permissions/DirectTransferTests.cs | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/OpenSim/Tests/Permissions/DirectTransferTests.cs b/OpenSim/Tests/Permissions/DirectTransferTests.cs new file mode 100644 index 0000000..0f251db --- /dev/null +++ b/OpenSim/Tests/Permissions/DirectTransferTests.cs | |||
@@ -0,0 +1,153 @@ | |||
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 | |||
28 | using NUnit.Framework; | ||
29 | using OpenMetaverse; | ||
30 | using OpenSim.Framework; | ||
31 | using OpenSim.Region.Framework.Scenes; | ||
32 | using OpenSim.Tests.Common; | ||
33 | using PermissionMask = OpenSim.Framework.PermissionMask; | ||
34 | |||
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 DirectTransferTests | ||
42 | { | ||
43 | |||
44 | [SetUp] | ||
45 | public void SetUp() | ||
46 | { | ||
47 | // In case we're dealing with some older version of nunit | ||
48 | if (Common.TheInstance == null) | ||
49 | { | ||
50 | Common.TheInstance = new Common(); | ||
51 | Common.TheInstance.SetUp(); | ||
52 | } | ||
53 | |||
54 | Common.TheInstance.DeleteObjectsFolders(); | ||
55 | } | ||
56 | |||
57 | /// <summary> | ||
58 | /// Test giving simple objecta with various combinations of next owner perms. | ||
59 | /// </summary> | ||
60 | [Test] | ||
61 | public void TestGiveBox() | ||
62 | { | ||
63 | TestHelpers.InMethod(); | ||
64 | |||
65 | // C, CT, MC, MCT, MT, T | ||
66 | string[] names = new string[6] { "Box C", "Box CT", "Box MC", "Box MCT", "Box MT", "Box T" }; | ||
67 | PermissionMask[] perms = new PermissionMask[6] { | ||
68 | PermissionMask.Copy, | ||
69 | PermissionMask.Copy | PermissionMask.Transfer, | ||
70 | PermissionMask.Modify | PermissionMask.Copy, | ||
71 | PermissionMask.Modify | PermissionMask.Copy | PermissionMask.Transfer, | ||
72 | PermissionMask.Modify | PermissionMask.Transfer, | ||
73 | PermissionMask.Transfer | ||
74 | }; | ||
75 | |||
76 | for (int i = 0; i < 6; i++) | ||
77 | TestOneBox(names[i], perms[i]); | ||
78 | } | ||
79 | |||
80 | private void TestOneBox(string name, PermissionMask mask) | ||
81 | { | ||
82 | InventoryItemBase item = Common.TheInstance.GetItemFromInventory(Common.TheAvatars[0].UUID, "Objects", name); | ||
83 | |||
84 | Common.TheInstance.GiveInventoryItem(item.ID, Common.TheAvatars[0], Common.TheAvatars[1]); | ||
85 | |||
86 | item = Common.TheInstance.GetItemFromInventory(Common.TheAvatars[1].UUID, "Objects", name); | ||
87 | |||
88 | // Check the receiver | ||
89 | Common.TheInstance.PrintPerms(item); | ||
90 | Common.TheInstance.AssertPermissions(mask, (PermissionMask)item.BasePermissions, item.Owner.ToString().Substring(34) + " : " + item.Name); | ||
91 | |||
92 | int nObjects = Common.TheScene.GetSceneObjectGroups().Count; | ||
93 | // Rez it and check perms in scene too | ||
94 | Common.TheScene.RezObject(Common.TheAvatars[1].ControllingClient, item.ID, UUID.Zero, Vector3.One, Vector3.Zero, UUID.Zero, 0, false, false, false, UUID.Zero); | ||
95 | Assert.That(Common.TheScene.GetSceneObjectGroups().Count, Is.EqualTo(nObjects + 1)); | ||
96 | |||
97 | SceneObjectGroup box = Common.TheScene.GetSceneObjectGroups().Find(sog => sog.OwnerID == Common.TheAvatars[1].UUID && sog.Name == name); | ||
98 | Common.TheInstance.PrintPerms(box); | ||
99 | Assert.That(box, Is.Not.Null); | ||
100 | |||
101 | // Check Owner permissions | ||
102 | Common.TheInstance.AssertPermissions(mask, (PermissionMask)box.EffectiveOwnerPerms, box.OwnerID.ToString().Substring(34) + " : " + box.Name); | ||
103 | |||
104 | // Check Next Owner permissions | ||
105 | Common.TheInstance.AssertPermissions(mask, (PermissionMask)box.RootPart.NextOwnerMask, box.OwnerID.ToString().Substring(34) + " : " + box.Name); | ||
106 | |||
107 | } | ||
108 | |||
109 | /// <summary> | ||
110 | /// Test giving simple objecta with variour combinations of next owner perms. | ||
111 | /// </summary> | ||
112 | [Test] | ||
113 | public void TestDoubleGiveWithChange() | ||
114 | { | ||
115 | TestHelpers.InMethod(); | ||
116 | |||
117 | string name = "Box MCT-C"; | ||
118 | InventoryItemBase item = Common.TheInstance.GetItemFromInventory(Common.TheAvatars[0].UUID, "Objects", name); | ||
119 | |||
120 | // Now give the item to A2. We give the original item, not a clone. | ||
121 | // The giving methods are supposed to duplicate it. | ||
122 | Common.TheInstance.GiveInventoryItem(item.ID, Common.TheAvatars[0], Common.TheAvatars[1]); | ||
123 | |||
124 | item = Common.TheInstance.GetItemFromInventory(Common.TheAvatars[1].UUID, "Objects", name); | ||
125 | |||
126 | // Check the receiver | ||
127 | Common.TheInstance.PrintPerms(item); | ||
128 | Common.TheInstance.AssertPermissions(PermissionMask.Modify | PermissionMask.Transfer, | ||
129 | (PermissionMask)item.BasePermissions, Common.TheInstance.IdStr(item)); | ||
130 | |||
131 | // --------------------------- | ||
132 | // Second transfer | ||
133 | //---------------------------- | ||
134 | |||
135 | // A2 revokes M | ||
136 | Common.TheInstance.RevokePermission(1, name, PermissionMask.Modify); | ||
137 | |||
138 | item = Common.TheInstance.GetItemFromInventory(Common.TheAvatars[1].UUID, "Objects", name); | ||
139 | |||
140 | // Now give the item to A3. We give the original item, not a clone. | ||
141 | // The giving methods are supposed to duplicate it. | ||
142 | Common.TheInstance.GiveInventoryItem(item.ID, Common.TheAvatars[1], Common.TheAvatars[2]); | ||
143 | |||
144 | item = Common.TheInstance.GetItemFromInventory(Common.TheAvatars[2].UUID, "Objects", name); | ||
145 | |||
146 | // Check the receiver | ||
147 | Common.TheInstance.PrintPerms(item); | ||
148 | Common.TheInstance.AssertPermissions(PermissionMask.Transfer, | ||
149 | (PermissionMask)item.BasePermissions, Common.TheInstance.IdStr(item)); | ||
150 | |||
151 | } | ||
152 | } | ||
153 | } \ No newline at end of file | ||