diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Tests/Permissions/IndirectTransferTests.cs | 132 |
1 files changed, 132 insertions, 0 deletions
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 | |||
28 | using System.Collections.Generic; | ||
29 | using System.Threading; | ||
30 | using NUnit.Framework; | ||
31 | using OpenMetaverse; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Region.Framework.Scenes; | ||
34 | using OpenSim.Tests.Common; | ||
35 | using PermissionMask = OpenSim.Framework.PermissionMask; | ||
36 | |||
37 | namespace 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 | ||