aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tests/Permissions
diff options
context:
space:
mode:
authoronefang2019-09-11 16:36:50 +1000
committeronefang2019-09-11 16:36:50 +1000
commit50cd1ffd32f69228e566f2b0b89f86ea0d9fe489 (patch)
tree52f2ab0c04f1a5d7d6ac5dc872981b4b156447e7 /OpenSim/Tests/Permissions
parentRenamed branch to SledjChisl. (diff)
parentBump to release flavour, build 0. (diff)
downloadopensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.zip
opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.tar.gz
opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.tar.bz2
opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.tar.xz
Merge branch 'SledjChisl'
Diffstat (limited to 'OpenSim/Tests/Permissions')
-rw-r--r--OpenSim/Tests/Permissions/Common.cs374
-rw-r--r--OpenSim/Tests/Permissions/DirectTransferTests.cs153
-rw-r--r--OpenSim/Tests/Permissions/IndirectTransferTests.cs132
3 files changed, 659 insertions, 0 deletions
diff --git a/OpenSim/Tests/Permissions/Common.cs b/OpenSim/Tests/Permissions/Common.cs
new file mode 100644
index 0000000..4ecce38
--- /dev/null
+++ b/OpenSim/Tests/Permissions/Common.cs
@@ -0,0 +1,374 @@
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 */
27using System;
28using System.Collections.Generic;
29using System.Threading;
30using Nini.Config;
31using NUnit.Framework;
32using OpenMetaverse;
33using OpenSim.Framework;
34using OpenSim.Region.Framework.Scenes;
35using OpenSim.Region.CoreModules.World.Permissions;
36using OpenSim.Region.CoreModules.Avatar.Inventory.Transfer;
37using OpenSim.Region.CoreModules.Framework.InventoryAccess;
38using OpenSim.Services.Interfaces;
39using OpenSim.Tests.Common;
40using PermissionMask = OpenSim.Framework.PermissionMask;
41
42namespace OpenSim.Tests.Permissions
43{
44 [SetUpFixture]
45 public class Common : OpenSimTestCase
46 {
47 public static Common TheInstance;
48
49 public static TestScene TheScene
50 {
51 get { return TheInstance.m_Scene; }
52 }
53
54 public static ScenePresence[] TheAvatars
55 {
56 get { return TheInstance.m_Avatars; }
57 }
58
59 private static string Perms = "Owner: {0}; Group: {1}; Everyone: {2}; Next: {3}";
60 private TestScene m_Scene;
61 private ScenePresence[] m_Avatars = new ScenePresence[3];
62
63 [SetUp]
64 public override void SetUp()
65 {
66 if (TheInstance == null)
67 TheInstance = this;
68
69 base.SetUp();
70 TestHelpers.EnableLogging();
71
72 IConfigSource config = new IniConfigSource();
73 config.AddConfig("Messaging");
74 config.Configs["Messaging"].Set("InventoryTransferModule", "InventoryTransferModule");
75
76 config.AddConfig("Modules");
77 config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule");
78
79 config.AddConfig("InventoryService");
80 config.Configs["InventoryService"].Set("LocalServiceModule", "OpenSim.Services.InventoryService.dll:XInventoryService");
81 config.Configs["InventoryService"].Set("StorageProvider", "OpenSim.Tests.Common.dll:TestXInventoryDataPlugin");
82
83 config.AddConfig("Groups");
84 config.Configs["Groups"].Set("Enabled", "true");
85 config.Configs["Groups"].Set("Module", "Groups Module V2");
86 config.Configs["Groups"].Set("StorageProvider", "OpenSim.Tests.Common.dll:TestGroupsDataPlugin");
87 config.Configs["Groups"].Set("ServicesConnectorModule", "Groups Local Service Connector");
88 config.Configs["Groups"].Set("LocalService", "local");
89
90 m_Scene = new SceneHelpers().SetupScene("Test", UUID.Random(), 1000, 1000, config);
91 // Add modules
92 SceneHelpers.SetupSceneModules(m_Scene, config, new DefaultPermissionsModule(), new InventoryTransferModule(), new BasicInventoryAccessModule());
93
94 SetUpBasicEnvironment();
95 }
96
97 /// <summary>
98 /// The basic environment consists of:
99 /// - 3 avatars: A1, A2, A3
100 /// - 6 simple boxes inworld belonging to A0 and with Next Owner perms:
101 /// C, CT, MC, MCT, MT, T
102 /// - Copies of all of these boxes in A0's inventory in the Objects folder
103 /// - One additional box inworld and in A0's inventory which is a copy of MCT, but
104 /// with C removed in inventory. This one is called MCT-C
105 /// </summary>
106 private void SetUpBasicEnvironment()
107 {
108 Console.WriteLine("===> SetUpBasicEnvironment <===");
109
110 // Add 3 avatars
111 for (int i = 0; i < 3; i++)
112 {
113 UUID id = TestHelpers.ParseTail(i + 1);
114
115 m_Avatars[i] = AddScenePresence("Bot", "Bot_" + (i+1), id);
116 Assert.That(m_Avatars[i], Is.Not.Null);
117 Assert.That(m_Avatars[i].IsChildAgent, Is.False);
118 Assert.That(m_Avatars[i].UUID, Is.EqualTo(id));
119 Assert.That(m_Scene.GetScenePresences().Count, Is.EqualTo(i + 1));
120 }
121
122 AddA1Object("Box C", 10, PermissionMask.Copy);
123 AddA1Object("Box CT", 11, PermissionMask.Copy | PermissionMask.Transfer);
124 AddA1Object("Box MC", 12, PermissionMask.Modify | PermissionMask.Copy);
125 AddA1Object("Box MCT", 13, PermissionMask.Modify | PermissionMask.Copy | PermissionMask.Transfer);
126 AddA1Object("Box MT", 14, PermissionMask.Modify | PermissionMask.Transfer);
127 AddA1Object("Box T", 15, PermissionMask.Transfer);
128
129 // MCT-C
130 AddA1Object("Box MCT-C", 16, PermissionMask.Modify | PermissionMask.Copy | PermissionMask.Transfer);
131
132 Thread.Sleep(5000);
133
134 InventoryFolderBase objsFolder = UserInventoryHelpers.GetInventoryFolder(m_Scene.InventoryService, m_Avatars[0].UUID, "Objects");
135 List<InventoryItemBase> items = m_Scene.InventoryService.GetFolderItems(m_Avatars[0].UUID, objsFolder.ID);
136 Assert.That(items.Count, Is.EqualTo(7));
137
138 RevokePermission(0, "Box MCT-C", PermissionMask.Copy);
139 }
140
141 private ScenePresence AddScenePresence(string first, string last, UUID id)
142 {
143 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(m_Scene, first, last, id, "pw");
144 ScenePresence sp = SceneHelpers.AddScenePresence(m_Scene, id);
145 Assert.That(m_Scene.AuthenticateHandler.GetAgentCircuitData(id), Is.Not.Null);
146
147 return sp;
148 }
149
150 private void AddA1Object(string name, int suffix, PermissionMask nextOwnerPerms)
151 {
152 // Create a Box. Default permissions are just T
153 SceneObjectGroup box = AddSceneObject(name, suffix, 1, m_Avatars[0].UUID);
154 Assert.True((box.RootPart.NextOwnerMask & (int)PermissionMask.Copy) == 0);
155 Assert.True((box.RootPart.NextOwnerMask & (int)PermissionMask.Modify) == 0);
156 Assert.True((box.RootPart.NextOwnerMask & (int)PermissionMask.Transfer) != 0);
157
158 // field = 16 is NextOwner
159 // set = 1 means add the permission; set = 0 means remove permission
160
161 if ((nextOwnerPerms & PermissionMask.Copy) != 0)
162 m_Scene.HandleObjectPermissionsUpdate((IClientAPI)m_Avatars[0].ClientView, m_Avatars[0].UUID,
163 ((IClientAPI)(m_Avatars[0].ClientView)).SessionId, 16, box.LocalId, (uint)PermissionMask.Copy, 1);
164
165 if ((nextOwnerPerms & PermissionMask.Modify) != 0)
166 m_Scene.HandleObjectPermissionsUpdate((IClientAPI)m_Avatars[0].ClientView, m_Avatars[0].UUID,
167 ((IClientAPI)(m_Avatars[0].ClientView)).SessionId, 16, box.LocalId, (uint)PermissionMask.Modify, 1);
168
169 if ((nextOwnerPerms & PermissionMask.Transfer) == 0)
170 m_Scene.HandleObjectPermissionsUpdate((IClientAPI)m_Avatars[0].ClientView, m_Avatars[0].UUID,
171 ((IClientAPI)(m_Avatars[0].ClientView)).SessionId, 16, box.LocalId, (uint)PermissionMask.Transfer, 0);
172
173 PrintPerms(box);
174 AssertPermissions(nextOwnerPerms, (PermissionMask)box.RootPart.NextOwnerMask, box.OwnerID.ToString().Substring(34) + " : " + box.Name);
175
176 TakeCopyToInventory(0, box);
177
178 }
179
180 public void RevokePermission(int ownerIndex, string name, PermissionMask perm)
181 {
182 InventoryItemBase item = Common.TheInstance.GetItemFromInventory(m_Avatars[ownerIndex].UUID, "Objects", name);
183 Assert.That(item, Is.Not.Null);
184
185 // Clone it, so to avoid aliasing -- just like the viewer does.
186 InventoryItemBase clone = Common.TheInstance.CloneInventoryItem(item);
187 // Revoke the permission in this copy
188 clone.NextPermissions &= ~(uint)perm;
189 Common.TheInstance.AssertPermissions((PermissionMask)clone.NextPermissions & ~perm,
190 (PermissionMask)clone.NextPermissions, Common.TheInstance.IdStr(clone));
191 Assert.That(clone.ID == item.ID);
192
193 // Update properties of the item in inventory. This should affect the original item above.
194 Common.TheScene.UpdateInventoryItemAsset(m_Avatars[ownerIndex].ControllingClient, UUID.Zero, clone.ID, clone);
195
196 item = Common.TheInstance.GetItemFromInventory(m_Avatars[ownerIndex].UUID, "Objects", name);
197 Assert.That(item, Is.Not.Null);
198 Common.TheInstance.PrintPerms(item);
199 Common.TheInstance.AssertPermissions((PermissionMask)item.NextPermissions & ~perm,
200 (PermissionMask)item.NextPermissions, Common.TheInstance.IdStr(item));
201
202 }
203
204 public void PrintPerms(SceneObjectGroup sog)
205 {
206 Console.WriteLine("SOG " + sog.Name + " (" + sog.OwnerID.ToString().Substring(34) + "): " +
207 String.Format(Perms, (PermissionMask)sog.EffectiveOwnerPerms,
208 (PermissionMask)sog.EffectiveGroupPerms, (PermissionMask)sog.EffectiveEveryOnePerms, (PermissionMask)sog.RootPart.NextOwnerMask));
209
210 }
211
212 public void PrintPerms(InventoryItemBase item)
213 {
214 Console.WriteLine("Inv " + item.Name + " (" + item.Owner.ToString().Substring(34) + "): " +
215 String.Format(Perms, (PermissionMask)item.BasePermissions,
216 (PermissionMask)item.GroupPermissions, (PermissionMask)item.EveryOnePermissions, (PermissionMask)item.NextPermissions));
217
218 }
219
220 public void AssertPermissions(PermissionMask desired, PermissionMask actual, string message)
221 {
222 if ((desired & PermissionMask.Copy) != 0)
223 Assert.True((actual & PermissionMask.Copy) != 0, message);
224 else
225 Assert.True((actual & PermissionMask.Copy) == 0, message);
226
227 if ((desired & PermissionMask.Modify) != 0)
228 Assert.True((actual & PermissionMask.Modify) != 0, message);
229 else
230 Assert.True((actual & PermissionMask.Modify) == 0, message);
231
232 if ((desired & PermissionMask.Transfer) != 0)
233 Assert.True((actual & PermissionMask.Transfer) != 0, message);
234 else
235 Assert.True((actual & PermissionMask.Transfer) == 0, message);
236
237 }
238
239 public SceneObjectGroup AddSceneObject(string name, int suffix, int partsToTestCount, UUID ownerID)
240 {
241 SceneObjectGroup so = SceneHelpers.CreateSceneObject(partsToTestCount, ownerID, name, suffix);
242 so.Name = name;
243 so.Description = name;
244
245 Assert.That(m_Scene.AddNewSceneObject(so, false), Is.True);
246 SceneObjectGroup retrievedSo = m_Scene.GetSceneObjectGroup(so.UUID);
247
248 // If the parts have the same UUID then we will consider them as one and the same
249 Assert.That(retrievedSo.PrimCount, Is.EqualTo(partsToTestCount));
250
251 return so;
252 }
253
254 public void TakeCopyToInventory(int userIndex, SceneObjectGroup sog)
255 {
256 InventoryFolderBase objsFolder = UserInventoryHelpers.GetInventoryFolder(m_Scene.InventoryService, m_Avatars[userIndex].UUID, "Objects");
257 Assert.That(objsFolder, Is.Not.Null);
258
259 List<uint> localIds = new List<uint>(); localIds.Add(sog.LocalId);
260 // This is an async operation
261 m_Scene.DeRezObjects((IClientAPI)m_Avatars[userIndex].ClientView, localIds, m_Avatars[userIndex].UUID, DeRezAction.TakeCopy, objsFolder.ID);
262 }
263
264 public InventoryItemBase GetItemFromInventory(UUID userID, string folderName, string itemName)
265 {
266 InventoryFolderBase objsFolder = UserInventoryHelpers.GetInventoryFolder(m_Scene.InventoryService, userID, folderName);
267 Assert.That(objsFolder, Is.Not.Null);
268 List<InventoryItemBase> items = m_Scene.InventoryService.GetFolderItems(userID, objsFolder.ID);
269 InventoryItemBase item = items.Find(i => i.Name == itemName);
270 Assert.That(item, Is.Not.Null);
271
272 return item;
273 }
274
275 public InventoryItemBase CloneInventoryItem(InventoryItemBase item)
276 {
277 InventoryItemBase clone = new InventoryItemBase(item.ID);
278 clone.Name = item.Name;
279 clone.Description = item.Description;
280 clone.AssetID = item.AssetID;
281 clone.AssetType = item.AssetType;
282 clone.BasePermissions = item.BasePermissions;
283 clone.CreatorId = item.CreatorId;
284 clone.CurrentPermissions = item.CurrentPermissions;
285 clone.EveryOnePermissions = item.EveryOnePermissions;
286 clone.Flags = item.Flags;
287 clone.Folder = item.Folder;
288 clone.GroupID = item.GroupID;
289 clone.GroupOwned = item.GroupOwned;
290 clone.GroupPermissions = item.GroupPermissions;
291 clone.InvType = item.InvType;
292 clone.NextPermissions = item.NextPermissions;
293 clone.Owner = item.Owner;
294
295 return clone;
296 }
297
298 public void DeleteObjectsFolders()
299 {
300 // Delete everything in A2 and A3's Objects folders, so we can restart
301 for (int i = 1; i < 3; i++)
302 {
303 InventoryFolderBase objsFolder = UserInventoryHelpers.GetInventoryFolder(Common.TheScene.InventoryService, Common.TheAvatars[i].UUID, "Objects");
304 Assert.That(objsFolder, Is.Not.Null);
305
306 List<InventoryItemBase> items = Common.TheScene.InventoryService.GetFolderItems(Common.TheAvatars[i].UUID, objsFolder.ID);
307 List<UUID> ids = new List<UUID>();
308 foreach (InventoryItemBase it in items)
309 ids.Add(it.ID);
310
311 Common.TheScene.InventoryService.DeleteItems(Common.TheAvatars[i].UUID, ids);
312 items = Common.TheScene.InventoryService.GetFolderItems(Common.TheAvatars[i].UUID, objsFolder.ID);
313 Assert.That(items.Count, Is.EqualTo(0), "A" + (i + 1));
314 }
315
316 }
317
318 public string IdStr(InventoryItemBase item)
319 {
320 return item.Owner.ToString().Substring(34) + " : " + item.Name;
321 }
322
323 public string IdStr(SceneObjectGroup sog)
324 {
325 return sog.OwnerID.ToString().Substring(34) + " : " + sog.Name;
326 }
327
328 public void GiveInventoryItem(UUID itemId, ScenePresence giverSp, ScenePresence receiverSp)
329 {
330 TestClient giverClient = (TestClient)giverSp.ControllingClient;
331 TestClient receiverClient = (TestClient)receiverSp.ControllingClient;
332
333 UUID initialSessionId = TestHelpers.ParseTail(0x10);
334 byte[] giveImBinaryBucket = new byte[17];
335 byte[] itemIdBytes = itemId.GetBytes();
336 Array.Copy(itemIdBytes, 0, giveImBinaryBucket, 1, itemIdBytes.Length);
337
338 GridInstantMessage giveIm
339 = new GridInstantMessage(
340 m_Scene,
341 giverSp.UUID,
342 giverSp.Name,
343 receiverSp.UUID,
344 (byte)InstantMessageDialog.InventoryOffered,
345 false,
346 "inventory offered msg",
347 initialSessionId,
348 false,
349 Vector3.Zero,
350 giveImBinaryBucket,
351 true);
352
353 giverClient.HandleImprovedInstantMessage(giveIm);
354
355 // These details might not all be correct.
356 GridInstantMessage acceptIm
357 = new GridInstantMessage(
358 m_Scene,
359 receiverSp.UUID,
360 receiverSp.Name,
361 giverSp.UUID,
362 (byte)InstantMessageDialog.InventoryAccepted,
363 false,
364 "inventory accepted msg",
365 initialSessionId,
366 false,
367 Vector3.Zero,
368 null,
369 true);
370
371 receiverClient.HandleImprovedInstantMessage(acceptIm);
372 }
373 }
374}
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
28using NUnit.Framework;
29using OpenMetaverse;
30using OpenSim.Framework;
31using OpenSim.Region.Framework.Scenes;
32using OpenSim.Tests.Common;
33using PermissionMask = OpenSim.Framework.PermissionMask;
34
35namespace 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
diff --git a/OpenSim/Tests/Permissions/IndirectTransferTests.cs b/OpenSim/Tests/Permissions/IndirectTransferTests.cs
new file mode 100644
index 0000000..fb96b8b
--- /dev/null
+++ b/OpenSim/Tests/Permissions/IndirectTransferTests.cs
@@ -0,0 +1,132 @@
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
28using System.Collections.Generic;
29using System.Threading;
30using NUnit.Framework;
31using OpenMetaverse;
32using OpenSim.Framework;
33using OpenSim.Region.Framework.Scenes;
34using OpenSim.Tests.Common;
35using PermissionMask = OpenSim.Framework.PermissionMask;
36
37namespace OpenSim.Tests.Permissions
38{
39 /// <summary>
40 /// Basic scene object tests (create, read and delete but not update).
41 /// </summary>
42 [TestFixture]
43 public class IndirectTransferTests
44 {
45
46 [SetUp]
47 public void SetUp()
48 {
49 // In case we're dealing with some older version of nunit
50 if (Common.TheInstance == null)
51 {
52 Common.TheInstance = new Common();
53 Common.TheInstance.SetUp();
54 }
55 Common.TheInstance.DeleteObjectsFolders();
56 }
57
58 /// <summary>
59 /// Test giving simple objecta with various combinations of next owner perms.
60 /// </summary>
61 [Test]
62 public void SimpleTakeCopy()
63 {
64 TestHelpers.InMethod();
65
66 // The Objects folder of A2
67 InventoryFolderBase objsFolder = UserInventoryHelpers.GetInventoryFolder(Common.TheScene.InventoryService, Common.TheAvatars[1].UUID, "Objects");
68
69 // C, CT, MC, MCT, MT, T
70 string[] names = new string[6] { "Box C", "Box CT", "Box MC", "Box MCT", "Box MT", "Box T" };
71 PermissionMask[] perms = new PermissionMask[6] {
72 PermissionMask.Copy,
73 PermissionMask.Copy | PermissionMask.Transfer,
74 PermissionMask.Modify | PermissionMask.Copy,
75 PermissionMask.Modify | PermissionMask.Copy | PermissionMask.Transfer,
76 PermissionMask.Modify | PermissionMask.Transfer,
77 PermissionMask.Transfer
78 };
79
80 // Try A2 takes copies of objects that cannot be copied.
81 for (int i = 0; i < 6; i++)
82 TakeOneBox(Common.TheScene.GetSceneObjectGroups(), names[i], perms[i]);
83 // Ad-hoc. Enough time to let the take work.
84 Thread.Sleep(5000);
85
86 List<InventoryItemBase> items = Common.TheScene.InventoryService.GetFolderItems(Common.TheAvatars[1].UUID, objsFolder.ID);
87 Assert.That(items.Count, Is.EqualTo(0));
88
89 // A1 makes the objects copyable
90 for (int i = 0; i < 6; i++)
91 MakeCopyable(Common.TheScene.GetSceneObjectGroups(), names[i]);
92
93 // Try A2 takes copies of objects that can be copied.
94 for (int i = 0; i < 6; i++)
95 TakeOneBox(Common.TheScene.GetSceneObjectGroups(), names[i], perms[i]);
96 // Ad-hoc. Enough time to let the take work.
97 Thread.Sleep(5000);
98
99 items = Common.TheScene.InventoryService.GetFolderItems(Common.TheAvatars[1].UUID, objsFolder.ID);
100 Assert.That(items.Count, Is.EqualTo(6));
101
102 for (int i = 0; i < 6; i++)
103 {
104 InventoryItemBase item = Common.TheInstance.GetItemFromInventory(Common.TheAvatars[1].UUID, "Objects", names[i]);
105 Assert.That(item, Is.Not.Null);
106 Common.TheInstance.AssertPermissions(perms[i], (PermissionMask)item.BasePermissions, Common.TheInstance.IdStr(item));
107 }
108 }
109
110 private void TakeOneBox(List<SceneObjectGroup> objs, string name, PermissionMask mask)
111 {
112 // Find the object inworld
113 SceneObjectGroup box = objs.Find(sog => sog.Name == name && sog.OwnerID == Common.TheAvatars[0].UUID);
114 Assert.That(box, Is.Not.Null, name);
115
116 // A2's inventory (index 1)
117 Common.TheInstance.TakeCopyToInventory(1, box);
118 }
119
120 private void MakeCopyable(List<SceneObjectGroup> objs, string name)
121 {
122 SceneObjectGroup box = objs.Find(sog => sog.Name == name && sog.OwnerID == Common.TheAvatars[0].UUID);
123 Assert.That(box, Is.Not.Null, name);
124
125 // field = 8 is Everyone
126 // set = 1 means add the permission; set = 0 means remove permission
127 Common.TheScene.HandleObjectPermissionsUpdate((IClientAPI)Common.TheAvatars[0].ClientView, Common.TheAvatars[0].UUID,
128 Common.TheAvatars[0].ControllingClient.SessionId, 8, box.LocalId, (uint)PermissionMask.Copy, 1);
129 Common.TheInstance.PrintPerms(box);
130 }
131 }
132} \ No newline at end of file