aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Tests/Permissions/Common.cs259
-rw-r--r--OpenSim/Tests/Permissions/DirectTransferTests.cs112
-rw-r--r--prebuild.xml41
3 files changed, 411 insertions, 1 deletions
diff --git a/OpenSim/Tests/Permissions/Common.cs b/OpenSim/Tests/Permissions/Common.cs
new file mode 100644
index 0000000..63b91b6
--- /dev/null
+++ b/OpenSim/Tests/Permissions/Common.cs
@@ -0,0 +1,259 @@
1using System;
2using System.Collections.Generic;
3using System.Reflection;
4using System.Threading;
5using Nini.Config;
6using NUnit.Framework;
7using OpenMetaverse;
8using OpenSim.Framework;
9using OpenSim.Region.Framework.Scenes;
10using OpenSim.Region.CoreModules.World.Permissions;
11using OpenSim.Region.CoreModules.Avatar.Inventory.Transfer;
12using OpenSim.Region.CoreModules.Framework.InventoryAccess;
13using OpenSim.Region.Framework.Scenes.Serialization;
14using OpenSim.Services.Interfaces;
15using OpenSim.Tests.Common;
16using PermissionMask = OpenSim.Framework.PermissionMask;
17
18namespace OpenSim.Tests.Permissions
19{
20 [SetUpFixture]
21 public class Common : OpenSimTestCase
22 {
23 public static Common TheInstance;
24
25 public static TestScene TheScene
26 {
27 get { return TheInstance.m_Scene; }
28 }
29
30 public static ScenePresence[] TheAvatars
31 {
32 get { return TheInstance.m_Avatars; }
33 }
34
35 private static string Perms = "Owner: {0}; Group: {1}; Everyone: {2}; Next: {3}";
36 private TestScene m_Scene;
37 private ScenePresence[] m_Avatars = new ScenePresence[3];
38
39 [SetUp]
40 public override void SetUp()
41 {
42 if (TheInstance == null)
43 TheInstance = this;
44
45 base.SetUp();
46 TestHelpers.EnableLogging();
47
48 IConfigSource config = new IniConfigSource();
49 config.AddConfig("Messaging");
50 config.Configs["Messaging"].Set("InventoryTransferModule", "InventoryTransferModule");
51 config.AddConfig("Modules");
52 config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule");
53 config.AddConfig("InventoryService");
54 config.Configs["InventoryService"].Set("LocalServiceModule", "OpenSim.Services.InventoryService.dll:XInventoryService");
55 config.Configs["InventoryService"].Set("StorageProvider", "OpenSim.Tests.Common.dll:TestXInventoryDataPlugin");
56
57 m_Scene = new SceneHelpers().SetupScene("Test", UUID.Random(), 1000, 1000, config);
58 // Add modules
59 SceneHelpers.SetupSceneModules(m_Scene, config, new DefaultPermissionsModule(), new InventoryTransferModule(), new BasicInventoryAccessModule());
60
61 SetUpBasicEnvironment();
62 }
63
64 /// <summary>
65 /// The basic environment consists of:
66 /// - 3 avatars: A1, A2, A3
67 /// - 6 simple boxes inworld belonging to A0 and with Next Owner perms:
68 /// C, CT, MC, MCT, MT, T
69 /// - Copies of all of these boxes in A0's inventory in the Objects folder
70 /// - One additional box in A0's inventory which is a copy of MCT, but
71 /// with C removed in inventory. This one is called MCT-C
72 /// </summary>
73 private void SetUpBasicEnvironment()
74 {
75 Console.WriteLine("===> SetUpBasicEnvironment <===");
76
77 // Add 3 avatars
78 for (int i = 0; i < 3; i++)
79 {
80 UUID id = TestHelpers.ParseTail(i + 1);
81
82 m_Avatars[i] = AddScenePresence("Bot", "Bot_" + (i+1), id);
83 Assert.That(m_Avatars[i], Is.Not.Null);
84 Assert.That(m_Avatars[i].IsChildAgent, Is.False);
85 Assert.That(m_Avatars[i].UUID, Is.EqualTo(id));
86 Assert.That(m_Scene.GetScenePresences().Count, Is.EqualTo(i + 1));
87 }
88
89 AddA1Object("Box C", 10, PermissionMask.Copy);
90 AddA1Object("Box CT", 11, PermissionMask.Copy | PermissionMask.Transfer);
91 AddA1Object("Box MC", 12, PermissionMask.Modify | PermissionMask.Copy);
92 AddA1Object("Box MCT", 13, PermissionMask.Modify | PermissionMask.Copy | PermissionMask.Transfer);
93 AddA1Object("Box MT", 14, PermissionMask.Modify | PermissionMask.Transfer);
94 AddA1Object("Box T", 15, PermissionMask.Transfer);
95
96 Thread.Sleep(5000);
97
98 InventoryFolderBase objsFolder = UserInventoryHelpers.GetInventoryFolder(m_Scene.InventoryService, m_Avatars[0].UUID, "Objects");
99 List<InventoryItemBase> items = m_Scene.InventoryService.GetFolderItems(m_Avatars[0].UUID, objsFolder.ID);
100 Assert.That(items.Count, Is.EqualTo(6));
101 }
102
103 private ScenePresence AddScenePresence(string first, string last, UUID id)
104 {
105 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(m_Scene, first, last, id, "pw");
106 ScenePresence sp = SceneHelpers.AddScenePresence(m_Scene, id);
107 Assert.That(m_Scene.AuthenticateHandler.GetAgentCircuitData(id), Is.Not.Null);
108
109 return sp;
110 }
111
112 private void AddA1Object(string name, int suffix, PermissionMask nextOwnerPerms)
113 {
114 // Create a Box. Default permissions are just T
115 SceneObjectGroup box = AddSceneObject(name, suffix, 1, m_Avatars[0].UUID);
116 Assert.True((box.RootPart.NextOwnerMask & (int)PermissionMask.Copy) == 0);
117 Assert.True((box.RootPart.NextOwnerMask & (int)PermissionMask.Modify) == 0);
118 Assert.True((box.RootPart.NextOwnerMask & (int)PermissionMask.Transfer) != 0);
119
120 // field = 16 is NextOwner
121 // set = 1 means add the permission; set = 0 means remove permission
122
123 if ((nextOwnerPerms & PermissionMask.Copy) != 0)
124 m_Scene.HandleObjectPermissionsUpdate((IClientAPI)m_Avatars[0].ClientView, m_Avatars[0].UUID,
125 ((IClientAPI)(m_Avatars[0].ClientView)).SessionId, 16, box.LocalId, (uint)PermissionMask.Copy, 1);
126
127 if ((nextOwnerPerms & PermissionMask.Modify) != 0)
128 m_Scene.HandleObjectPermissionsUpdate((IClientAPI)m_Avatars[0].ClientView, m_Avatars[0].UUID,
129 ((IClientAPI)(m_Avatars[0].ClientView)).SessionId, 16, box.LocalId, (uint)PermissionMask.Modify, 1);
130
131 if ((nextOwnerPerms & PermissionMask.Transfer) == 0)
132 m_Scene.HandleObjectPermissionsUpdate((IClientAPI)m_Avatars[0].ClientView, m_Avatars[0].UUID,
133 ((IClientAPI)(m_Avatars[0].ClientView)).SessionId, 16, box.LocalId, (uint)PermissionMask.Transfer, 0);
134
135 PrintPerms(box);
136 AssertPermissions(nextOwnerPerms, (PermissionMask)box.RootPart.NextOwnerMask, box.OwnerID.ToString().Substring(34) + " : " + box.Name);
137
138 TakeCopyToInventory(box);
139
140 }
141
142 public void PrintPerms(SceneObjectGroup sog)
143 {
144 Console.WriteLine("SOG " + sog.Name + " (" + sog.OwnerID.ToString().Substring(34) + "): " +
145 String.Format(Perms, (PermissionMask)sog.EffectiveOwnerPerms,
146 (PermissionMask)sog.EffectiveGroupPerms, (PermissionMask)sog.EffectiveEveryOnePerms, (PermissionMask)sog.RootPart.NextOwnerMask));
147
148 }
149
150 public void PrintPerms(InventoryItemBase item)
151 {
152 Console.WriteLine("Inv " + item.Name + " (" + item.Owner.ToString().Substring(34) + "): " +
153 String.Format(Perms, (PermissionMask)item.BasePermissions,
154 (PermissionMask)item.GroupPermissions, (PermissionMask)item.EveryOnePermissions, (PermissionMask)item.NextPermissions));
155
156 }
157
158 public void AssertPermissions(PermissionMask desired, PermissionMask actual, string message)
159 {
160 if ((desired & PermissionMask.Copy) != 0)
161 Assert.True((actual & PermissionMask.Copy) != 0, message);
162 else
163 Assert.True((actual & PermissionMask.Copy) == 0, message);
164
165 if ((desired & PermissionMask.Modify) != 0)
166 Assert.True((actual & PermissionMask.Modify) != 0, message);
167 else
168 Assert.True((actual & PermissionMask.Modify) == 0, message);
169
170 if ((desired & PermissionMask.Transfer) != 0)
171 Assert.True((actual & PermissionMask.Transfer) != 0, message);
172 else
173 Assert.True((actual & PermissionMask.Transfer) == 0, message);
174
175 }
176
177 public SceneObjectGroup AddSceneObject(string name, int suffix, int partsToTestCount, UUID ownerID)
178 {
179 SceneObjectGroup so = SceneHelpers.CreateSceneObject(partsToTestCount, ownerID, name, suffix);
180 so.Name = name;
181 so.Description = name;
182
183 Assert.That(m_Scene.AddNewSceneObject(so, false), Is.True);
184 SceneObjectGroup retrievedSo = m_Scene.GetSceneObjectGroup(so.UUID);
185
186 // If the parts have the same UUID then we will consider them as one and the same
187 Assert.That(retrievedSo.PrimCount, Is.EqualTo(partsToTestCount));
188
189 return so;
190 }
191
192 public void TakeCopyToInventory(SceneObjectGroup sog)
193 {
194 InventoryFolderBase objsFolder = UserInventoryHelpers.GetInventoryFolder(m_Scene.InventoryService, sog.OwnerID, "Objects");
195 Assert.That(objsFolder, Is.Not.Null);
196
197 List<uint> localIds = new List<uint>(); localIds.Add(sog.LocalId);
198 // This is an async operation
199 m_Scene.DeRezObjects((IClientAPI)m_Avatars[0].ClientView, localIds, sog.UUID, DeRezAction.TakeCopy, objsFolder.ID);
200 }
201
202 public InventoryItemBase GetItemFromInventory(UUID userID, string folderName, string itemName)
203 {
204 InventoryFolderBase objsFolder = UserInventoryHelpers.GetInventoryFolder(m_Scene.InventoryService, userID, folderName);
205 Assert.That(objsFolder, Is.Not.Null);
206 List<InventoryItemBase> items = m_Scene.InventoryService.GetFolderItems(userID, objsFolder.ID);
207 InventoryItemBase item = items.Find(i => i.Name == itemName);
208 Assert.That(item, Is.Not.Null);
209
210 return item;
211 }
212
213 public void GiveInventoryItem(UUID itemId, ScenePresence giverSp, ScenePresence receiverSp)
214 {
215 TestClient giverClient = (TestClient)giverSp.ControllingClient;
216 TestClient receiverClient = (TestClient)receiverSp.ControllingClient;
217
218 UUID initialSessionId = TestHelpers.ParseTail(0x10);
219 byte[] giveImBinaryBucket = new byte[17];
220 byte[] itemIdBytes = itemId.GetBytes();
221 Array.Copy(itemIdBytes, 0, giveImBinaryBucket, 1, itemIdBytes.Length);
222
223 GridInstantMessage giveIm
224 = new GridInstantMessage(
225 m_Scene,
226 giverSp.UUID,
227 giverSp.Name,
228 receiverSp.UUID,
229 (byte)InstantMessageDialog.InventoryOffered,
230 false,
231 "inventory offered msg",
232 initialSessionId,
233 false,
234 Vector3.Zero,
235 giveImBinaryBucket,
236 true);
237
238 giverClient.HandleImprovedInstantMessage(giveIm);
239
240 // These details might not all be correct.
241 GridInstantMessage acceptIm
242 = new GridInstantMessage(
243 m_Scene,
244 receiverSp.UUID,
245 receiverSp.Name,
246 giverSp.UUID,
247 (byte)InstantMessageDialog.InventoryAccepted,
248 false,
249 "inventory accepted msg",
250 initialSessionId,
251 false,
252 Vector3.Zero,
253 null,
254 true);
255
256 receiverClient.HandleImprovedInstantMessage(acceptIm);
257 }
258 }
259}
diff --git a/OpenSim/Tests/Permissions/DirectTransferTests.cs b/OpenSim/Tests/Permissions/DirectTransferTests.cs
new file mode 100644
index 0000000..e103d01
--- /dev/null
+++ b/OpenSim/Tests/Permissions/DirectTransferTests.cs
@@ -0,0 +1,112 @@
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;
29using System.Collections.Generic;
30using System.Reflection;
31using System.Threading;
32using Nini.Config;
33using NUnit.Framework;
34using OpenMetaverse;
35using OpenSim.Framework;
36using OpenSim.Region.Framework.Scenes;
37using OpenSim.Region.CoreModules.World.Permissions;
38using OpenSim.Region.CoreModules.Avatar.Inventory.Transfer;
39using OpenSim.Region.CoreModules.Framework.InventoryAccess;
40using OpenSim.Region.Framework.Scenes.Serialization;
41using OpenSim.Services.Interfaces;
42using OpenSim.Tests.Common;
43using PermissionMask = OpenSim.Framework.PermissionMask;
44
45namespace OpenSim.Tests.Permissions
46{
47 /// <summary>
48 /// Basic scene object tests (create, read and delete but not update).
49 /// </summary>
50 [TestFixture]
51 public class DirectTransferTests
52 {
53
54 [SetUp]
55 public void SetUp()
56 {
57 }
58
59 /// <summary>
60 /// Test giving a C object.
61 /// </summary>
62 [Test]
63 public void TestGiveCBox()
64 {
65 TestHelpers.InMethod();
66
67 // C, CT, MC, MCT, MT, T
68 string[] names = new string[6] { "Box C", "Box CT", "Box MC", "Box MCT", "Box MT", "Box T"};
69 PermissionMask[] perms = new PermissionMask[6] {
70 PermissionMask.Copy,
71 PermissionMask.Copy | PermissionMask.Transfer,
72 PermissionMask.Modify | PermissionMask.Copy,
73 PermissionMask.Modify | PermissionMask.Copy | PermissionMask.Transfer,
74 PermissionMask.Modify | PermissionMask.Transfer,
75 PermissionMask.Transfer
76 };
77
78 for (int i = 0; i < 6; i++)
79 TestOneBox(names[i], perms[i]);
80 }
81
82 private void TestOneBox(string name, PermissionMask mask)
83 {
84 InventoryItemBase item = Common.TheInstance.GetItemFromInventory(Common.TheAvatars[0].UUID, "Objects", name);
85
86 Common.TheInstance.GiveInventoryItem(item.ID, Common.TheAvatars[0], Common.TheAvatars[1]);
87
88 item = Common.TheInstance.GetItemFromInventory(Common.TheAvatars[1].UUID, "Objects", name);
89
90 // Check the receiver
91 Common.TheInstance.PrintPerms(item);
92 Common.TheInstance.AssertPermissions(mask, (PermissionMask)item.BasePermissions, item.Owner.ToString().Substring(34) + " : " + item.Name);
93
94 int nObjects = Common.TheScene.GetSceneObjectGroups().Count;
95 // Rez it and check perms in scene too
96 Common.TheScene.RezObject(Common.TheAvatars[1].ControllingClient, item.ID, UUID.Zero, Vector3.One, Vector3.Zero, UUID.Zero, 0, false, false, false, UUID.Zero);
97 Assert.That(Common.TheScene.GetSceneObjectGroups().Count, Is.EqualTo(nObjects + 1));
98
99 SceneObjectGroup box = Common.TheScene.GetSceneObjectGroups().Find(sog => sog.OwnerID == Common.TheAvatars[1].UUID && sog.Name == name);
100 Common.TheInstance.PrintPerms(box);
101 Assert.That(box, Is.Not.Null);
102
103 // Check Owner permissions
104 Common.TheInstance.AssertPermissions(mask, (PermissionMask)box.EffectiveOwnerPerms, box.OwnerID.ToString().Substring(34) + " : " + box.Name);
105
106 // Check Next Owner permissions
107 Common.TheInstance.AssertPermissions(mask, (PermissionMask)box.RootPart.NextOwnerMask, box.OwnerID.ToString().Substring(34) + " : " + box.Name);
108
109 }
110
111 }
112} \ No newline at end of file
diff --git a/prebuild.xml b/prebuild.xml
index c087def..52fb74a 100644
--- a/prebuild.xml
+++ b/prebuild.xml
@@ -3300,7 +3300,46 @@
3300 </Files> 3300 </Files>
3301 </Project> 3301 </Project>
3302 3302
3303 <?include file="addon-modules/*/prebuild*.xml" ?> 3303 <Project frameworkVersion="v4_0" name="OpenSim.Tests.Permissions" path="OpenSim/Tests/Permissions" type="Library">
3304 <Configuration name="Debug">
3305 <Options>
3306 <OutputPath>../../../bin/</OutputPath>
3307 </Options>
3308 </Configuration>
3309 <Configuration name="Release">
3310 <Options>
3311 <OutputPath>../../../bin/</OutputPath>
3312 </Options>
3313 </Configuration>
3314
3315 <ReferencePath>../../../bin/</ReferencePath>
3316 <Reference name="System"/>
3317 <Reference name="System.Core"/>
3318 <Reference name="System.Xml"/>
3319 <Reference name="Mono.Addins" path="../../../bin/"/>
3320 <Reference name="OpenMetaverseTypes" path="../../../bin/"/>
3321 <Reference name="OpenMetaverse" path="../../../bin/"/>
3322 <Reference name="OpenSim"/>
3323 <Reference name="OpenSim.ApplicationPlugins.RegionModulesController"/>
3324 <Reference name="OpenSim.Framework"/>
3325 <Reference name="OpenSim.Region.Framework"/>
3326 <Reference name="OpenSim.Region.CoreModules"/>
3327 <Reference name="OpenSim.Services.Interfaces"/>
3328
3329 <!-- Unit tests -->
3330 <!-- <Reference name="OpenSim.Tests.Common"/> -->
3331 <Reference name="OpenSim.Tests.Common"/>
3332 <Reference name="Nini" path="../../../bin/"/>
3333 <Reference name="nunit.framework" path="../../../bin/"/>
3334
3335 <Reference name="log4net" path="../../../bin/"/>
3336
3337 <Files>
3338 <Match pattern="*.cs" recurse="false"/>
3339 </Files>
3340 </Project>
3341
3342 <?include file="addon-modules/*/prebuild*.xml" ?>
3304 3343
3305 </Solution> 3344 </Solution>
3306 3345