OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
SceneObjectCopyTests.cs
Go to the documentation of this file.
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 System;
29 using System.Collections.Generic;
30 using System.Reflection;
31 using Nini.Config;
32 using NUnit.Framework;
33 using OpenMetaverse;
34 using OpenSim.Framework;
35 using OpenSim.Region.CoreModules.Framework.EntityTransfer;
36 using OpenSim.Region.CoreModules.Framework.InventoryAccess;
37 using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
38 using OpenSim.Region.CoreModules.World.Permissions;
39 using OpenSim.Region.Framework.Scenes;
40 using OpenSim.Services.Interfaces;
41 using OpenSim.Tests.Common;
42 
43 namespace OpenSim.Region.Framework.Scenes.Tests
44 {
45  /*
52  [TestFixture]
53  public class SceneObjectCopyTests : OpenSimTestCase
54  {
55  [TestFixtureSetUp]
56  public void FixtureInit()
57  {
58  // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
59  // This facility was added after the original async delete tests were written, so it may be possible now
60  // to not bother explicitly disabling their async (since everything will be running sync).
61  Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest;
62  }
63 
64  [TestFixtureTearDown]
65  public void TearDown()
66  {
67  // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
68  // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression
69  // tests really shouldn't).
70  Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
71  }
72 
73  [Test]
74  public void TestTakeCopyWhenCopierIsOwnerWithPerms()
75  {
76  TestHelpers.InMethod();
77 // TestHelpers.EnableLogging();
78 
79  IConfigSource config = new IniConfigSource();
80  config.AddConfig("Modules");
81  config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule");
82 
83  TestScene scene = new SceneHelpers().SetupScene("s1", TestHelpers.ParseTail(0x99), 1000, 1000, config);
84  SceneHelpers.SetupSceneModules(scene, config, new PermissionsModule(), new BasicInventoryAccessModule());
85  UserAccount ua = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(0x1));
86  TestClient client = (TestClient)SceneHelpers.AddScenePresence(scene, ua.PrincipalID).ControllingClient;
87 
88  // Turn off the timer on the async sog deleter - we'll crank it by hand for this test.
89  AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter;
90  sogd.Enabled = false;
91 
92  SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, "so1", ua.PrincipalID);
93  uint soLocalId = so.LocalId;
94 // so.UpdatePermissions(
95 // ua.PrincipalID, (byte)PermissionWho.Owner, so.LocalId, (uint)OpenMetaverse.PermissionMask.Copy, 1);
96 // so.UpdatePermissions(
97 // ua.PrincipalID, (byte)PermissionWho.Owner, so.LocalId, (uint)OpenMetaverse.PermissionMask.Transfer, 0);
98 // so.UpdatePermissions(
99 // ua.PrincipalID, (byte)PermissionWho.Base, so.LocalId, (uint)OpenMetaverse.PermissionMask.Transfer, 0);
100 // scene.HandleObjectPermissionsUpdate(client, client.AgentId, client.SessionId, (byte)PermissionWho.Owner, so.LocalId, (uint)OpenMetaverse.PermissionMask.Transfer, 0);
101 
102  // Ideally we might change these via client-focussed method calls as commented out above. However, this
103  // becomes very convoluted so we will set only the copy perm directly.
104  so.RootPart.BaseMask = (uint)OpenMetaverse.PermissionMask.Copy;
105 // so.RootPart.OwnerMask = (uint)OpenMetaverse.PermissionMask.Copy;
106 
107  List<uint> localIds = new List<uint>();
108  localIds.Add(so.LocalId);
109 
110  // Specifying a UUID.Zero in this case will currently plop it in Lost and Found
111  scene.DeRezObjects(client, localIds, UUID.Zero, DeRezAction.TakeCopy, UUID.Zero);
112 
113  // Check that object isn't copied until we crank the sogd handle.
114  SceneObjectPart retrievedPart = scene.GetSceneObjectPart(so.LocalId);
115  Assert.That(retrievedPart, Is.Not.Null);
116  Assert.That(retrievedPart.ParentGroup.IsDeleted, Is.False);
117 
118  sogd.InventoryDeQueueAndDelete();
119 
120  // Check that object is still there.
121  SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(so.LocalId);
122  Assert.That(retrievedPart2, Is.Not.Null);
123  Assert.That(client.ReceivedKills.Count, Is.EqualTo(0));
124 
125  // Check that we have a copy in inventory
126  InventoryItemBase item
127  = UserInventoryHelpers.GetInventoryItem(scene.InventoryService, ua.PrincipalID, "Lost And Found/so1");
128  Assert.That(item, Is.Not.Null);
129  }
130 
131  [Test]
132  public void TestTakeCopyWhenCopierIsOwnerWithoutPerms()
133  {
134  TestHelpers.InMethod();
135 // TestHelpers.EnableLogging();
136 
137  IConfigSource config = new IniConfigSource();
138  config.AddConfig("Modules");
139  config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule");
140 
141  TestScene scene = new SceneHelpers().SetupScene("s1", TestHelpers.ParseTail(0x99), 1000, 1000, config);
142  SceneHelpers.SetupSceneModules(scene, config, new PermissionsModule(), new BasicInventoryAccessModule());
143  UserAccount ua = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(0x1));
144  TestClient client = (TestClient)SceneHelpers.AddScenePresence(scene, ua.PrincipalID).ControllingClient;
145 
146  // Turn off the timer on the async sog deleter - we'll crank it by hand for this test.
147  AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter;
148  sogd.Enabled = false;
149 
150  SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, "so1", ua.PrincipalID);
151  uint soLocalId = so.LocalId;
152 
153  so.RootPart.BaseMask = (uint)(OpenMetaverse.PermissionMask.All & ~OpenMetaverse.PermissionMask.Copy);
154  //so.RootPart.OwnerMask = (uint)(OpenMetaverse.PermissionMask.Copy & ~OpenMetaverse.PermissionMask.Copy);
155 
156  List<uint> localIds = new List<uint>();
157  localIds.Add(so.LocalId);
158 
159  // Specifying a UUID.Zero in this case will currently plop it in Lost and Found
160  scene.DeRezObjects(client, localIds, UUID.Zero, DeRezAction.TakeCopy, UUID.Zero);
161 
162  // Check that object isn't copied until we crank the sogd handle.
163  SceneObjectPart retrievedPart = scene.GetSceneObjectPart(so.LocalId);
164  Assert.That(retrievedPart, Is.Not.Null);
165  Assert.That(retrievedPart.ParentGroup.IsDeleted, Is.False);
166 
167  sogd.InventoryDeQueueAndDelete();
168 
169  // Check that object is still there.
170  SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(so.LocalId);
171  Assert.That(retrievedPart2, Is.Not.Null);
172  Assert.That(client.ReceivedKills.Count, Is.EqualTo(0));
173 
174  // Check that we do not have a copy in inventory
175  InventoryItemBase item
176  = UserInventoryHelpers.GetInventoryItem(scene.InventoryService, ua.PrincipalID, "Lost And Found/so1");
177  Assert.That(item, Is.Null);
178  }
179 
180  [Test]
181  public void TestTakeCopyWhenCopierIsNotOwnerWithPerms()
182  {
183  TestHelpers.InMethod();
184 // TestHelpers.EnableLogging();
185 
186  IConfigSource config = new IniConfigSource();
187  config.AddConfig("Modules");
188  config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule");
189 
190  TestScene scene = new SceneHelpers().SetupScene("s1", TestHelpers.ParseTail(0x99), 1000, 1000, config);
191  SceneHelpers.SetupSceneModules(scene, config, new PermissionsModule(), new BasicInventoryAccessModule());
192  UserAccount ua = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(0x1));
193  TestClient client = (TestClient)SceneHelpers.AddScenePresence(scene, ua.PrincipalID).ControllingClient;
194 
195  // Turn off the timer on the async sog deleter - we'll crank it by hand for this test.
196  AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter;
197  sogd.Enabled = false;
198 
199  SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, "so1", TestHelpers.ParseTail(0x2));
200  uint soLocalId = so.LocalId;
201 
202  // Base must allow transfer and copy
203  so.RootPart.BaseMask = (uint)(OpenMetaverse.PermissionMask.Copy | OpenMetaverse.PermissionMask.Transfer);
204  // Must be set so anyone can copy
205  so.RootPart.EveryoneMask = (uint)OpenMetaverse.PermissionMask.Copy;
206 
207  List<uint> localIds = new List<uint>();
208  localIds.Add(so.LocalId);
209 
210  // Specifying a UUID.Zero in this case will plop it in the Objects folder
211  scene.DeRezObjects(client, localIds, UUID.Zero, DeRezAction.TakeCopy, UUID.Zero);
212 
213  // Check that object isn't copied until we crank the sogd handle.
214  SceneObjectPart retrievedPart = scene.GetSceneObjectPart(so.LocalId);
215  Assert.That(retrievedPart, Is.Not.Null);
216  Assert.That(retrievedPart.ParentGroup.IsDeleted, Is.False);
217 
218  sogd.InventoryDeQueueAndDelete();
219 
220  // Check that object is still there.
221  SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(so.LocalId);
222  Assert.That(retrievedPart2, Is.Not.Null);
223  Assert.That(client.ReceivedKills.Count, Is.EqualTo(0));
224 
225  // Check that we have a copy in inventory
226  InventoryItemBase item
227  = UserInventoryHelpers.GetInventoryItem(scene.InventoryService, ua.PrincipalID, "Objects/so1");
228  Assert.That(item, Is.Not.Null);
229  }
230 
231  [Test]
232  public void TestTakeCopyWhenCopierIsNotOwnerWithoutPerms()
233  {
234  TestHelpers.InMethod();
235 // TestHelpers.EnableLogging();
236 
237  IConfigSource config = new IniConfigSource();
238  config.AddConfig("Modules");
239  config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule");
240 
241  TestScene scene = new SceneHelpers().SetupScene("s1", TestHelpers.ParseTail(0x99), 1000, 1000, config);
242  SceneHelpers.SetupSceneModules(scene, config, new PermissionsModule(), new BasicInventoryAccessModule());
243  UserAccount ua = UserAccountHelpers.CreateUserWithInventory(scene, TestHelpers.ParseTail(0x1));
244  TestClient client = (TestClient)SceneHelpers.AddScenePresence(scene, ua.PrincipalID).ControllingClient;
245 
246  // Turn off the timer on the async sog deleter - we'll crank it by hand for this test.
247  AsyncSceneObjectGroupDeleter sogd = scene.SceneObjectGroupDeleter;
248  sogd.Enabled = false;
249 
250  SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, "so1", TestHelpers.ParseTail(0x2));
251  uint soLocalId = so.LocalId;
252 
253  {
254  // Check that object is not copied if copy base perms is missing.
255  // Should not allow copy if base does not have this.
256  so.RootPart.BaseMask = (uint)OpenMetaverse.PermissionMask.Transfer;
257  // Must be set so anyone can copy
258  so.RootPart.EveryoneMask = (uint)OpenMetaverse.PermissionMask.Copy;
259 
260  // Check that object is not copied
261  List<uint> localIds = new List<uint>();
262  localIds.Add(so.LocalId);
263 
264  // Specifying a UUID.Zero in this case will plop it in the Objects folder if we have perms
265  scene.DeRezObjects(client, localIds, UUID.Zero, DeRezAction.TakeCopy, UUID.Zero);
266 
267  // Check that object isn't copied until we crank the sogd handle.
268  SceneObjectPart retrievedPart = scene.GetSceneObjectPart(so.LocalId);
269  Assert.That(retrievedPart, Is.Not.Null);
270  Assert.That(retrievedPart.ParentGroup.IsDeleted, Is.False);
271 
272  sogd.InventoryDeQueueAndDelete();
273  // Check that object is still there.
274  SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(so.LocalId);
275  Assert.That(retrievedPart2, Is.Not.Null);
276  Assert.That(client.ReceivedKills.Count, Is.EqualTo(0));
277 
278  // Check that we have a copy in inventory
279  InventoryItemBase item
280  = UserInventoryHelpers.GetInventoryItem(scene.InventoryService, ua.PrincipalID, "Objects/so1");
281  Assert.That(item, Is.Null);
282  }
283 
284  {
285  // Check that object is not copied if copy trans perms is missing.
286  // Should not allow copy if base does not have this.
287  so.RootPart.BaseMask = (uint)OpenMetaverse.PermissionMask.Copy;
288  // Must be set so anyone can copy
289  so.RootPart.EveryoneMask = (uint)OpenMetaverse.PermissionMask.Copy;
290 
291  // Check that object is not copied
292  List<uint> localIds = new List<uint>();
293  localIds.Add(so.LocalId);
294 
295  // Specifying a UUID.Zero in this case will plop it in the Objects folder if we have perms
296  scene.DeRezObjects(client, localIds, UUID.Zero, DeRezAction.TakeCopy, UUID.Zero);
297 
298  // Check that object isn't copied until we crank the sogd handle.
299  SceneObjectPart retrievedPart = scene.GetSceneObjectPart(so.LocalId);
300  Assert.That(retrievedPart, Is.Not.Null);
301  Assert.That(retrievedPart.ParentGroup.IsDeleted, Is.False);
302 
303  sogd.InventoryDeQueueAndDelete();
304  // Check that object is still there.
305  SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(so.LocalId);
306  Assert.That(retrievedPart2, Is.Not.Null);
307  Assert.That(client.ReceivedKills.Count, Is.EqualTo(0));
308 
309  // Check that we have a copy in inventory
310  InventoryItemBase item
311  = UserInventoryHelpers.GetInventoryItem(scene.InventoryService, ua.PrincipalID, "Objects/so1");
312  Assert.That(item, Is.Null);
313  }
314 
315  {
316  // Check that object is not copied if everyone copy perms is missing.
317  // Should not allow copy if base does not have this.
318  so.RootPart.BaseMask = (uint)(OpenMetaverse.PermissionMask.Copy | OpenMetaverse.PermissionMask.Transfer);
319  // Make sure everyone perm does not allow copy
320  so.RootPart.EveryoneMask = (uint)(OpenMetaverse.PermissionMask.All & ~OpenMetaverse.PermissionMask.Copy);
321 
322  // Check that object is not copied
323  List<uint> localIds = new List<uint>();
324  localIds.Add(so.LocalId);
325 
326  // Specifying a UUID.Zero in this case will plop it in the Objects folder if we have perms
327  scene.DeRezObjects(client, localIds, UUID.Zero, DeRezAction.TakeCopy, UUID.Zero);
328 
329  // Check that object isn't copied until we crank the sogd handle.
330  SceneObjectPart retrievedPart = scene.GetSceneObjectPart(so.LocalId);
331  Assert.That(retrievedPart, Is.Not.Null);
332  Assert.That(retrievedPart.ParentGroup.IsDeleted, Is.False);
333 
334  sogd.InventoryDeQueueAndDelete();
335  // Check that object is still there.
336  SceneObjectPart retrievedPart2 = scene.GetSceneObjectPart(so.LocalId);
337  Assert.That(retrievedPart2, Is.Not.Null);
338  Assert.That(client.ReceivedKills.Count, Is.EqualTo(0));
339 
340  // Check that we have a copy in inventory
341  InventoryItemBase item
342  = UserInventoryHelpers.GetInventoryItem(scene.InventoryService, ua.PrincipalID, "Objects/so1");
343  Assert.That(item, Is.Null);
344  }
345  }
346  }
347  */
348 }