diff options
Diffstat (limited to 'OpenSim/Tests')
-rw-r--r-- | OpenSim/Tests/Permissions/DirectTransferTests.cs | 252 |
1 files changed, 252 insertions, 0 deletions
diff --git a/OpenSim/Tests/Permissions/DirectTransferTests.cs b/OpenSim/Tests/Permissions/DirectTransferTests.cs new file mode 100644 index 0000000..7716776 --- /dev/null +++ b/OpenSim/Tests/Permissions/DirectTransferTests.cs | |||
@@ -0,0 +1,252 @@ | |||
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 System.Threading; | ||
32 | using Nini.Config; | ||
33 | using NUnit.Framework; | ||
34 | using OpenMetaverse; | ||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Region.Framework.Scenes; | ||
37 | using OpenSim.Region.CoreModules.World.Permissions; | ||
38 | using OpenSim.Region.CoreModules.Avatar.Inventory.Transfer; | ||
39 | using OpenSim.Region.CoreModules.Framework.InventoryAccess; | ||
40 | using OpenSim.Region.Framework.Scenes.Serialization; | ||
41 | using OpenSim.Services.Interfaces; | ||
42 | using OpenSim.Tests.Common; | ||
43 | using PermissionMask = OpenSim.Framework.PermissionMask; | ||
44 | |||
45 | namespace 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 : OpenSimTestCase | ||
52 | { | ||
53 | private static string Perms = "Owner: {0}; Group: {1}; Everyone: {2}; Next: {3}"; | ||
54 | protected TestScene m_Scene; | ||
55 | private ScenePresence[] m_Avatars = new ScenePresence[3]; | ||
56 | |||
57 | [SetUp] | ||
58 | public override void SetUp() | ||
59 | { | ||
60 | base.SetUp(); | ||
61 | TestHelpers.EnableLogging(); | ||
62 | |||
63 | IConfigSource config = new IniConfigSource(); | ||
64 | config.AddConfig("Messaging"); | ||
65 | config.Configs["Messaging"].Set("InventoryTransferModule", "InventoryTransferModule"); | ||
66 | config.AddConfig("Modules"); | ||
67 | config.Configs["Modules"].Set("InventoryAccessModule", "BasicInventoryAccessModule"); | ||
68 | config.AddConfig("InventoryService"); | ||
69 | config.Configs["InventoryService"].Set("LocalServiceModule", "OpenSim.Services.InventoryService.dll:XInventoryService"); | ||
70 | config.Configs["InventoryService"].Set("StorageProvider", "OpenSim.Tests.Common.dll:TestXInventoryDataPlugin"); | ||
71 | |||
72 | m_Scene = new SceneHelpers().SetupScene("Test", UUID.Random(), 1000, 1000, config); | ||
73 | // Add modules | ||
74 | SceneHelpers.SetupSceneModules(m_Scene, config, new DefaultPermissionsModule(), new InventoryTransferModule(), new BasicInventoryAccessModule()); | ||
75 | |||
76 | // Add 3 avatars | ||
77 | for (int i = 0; i < 3; i++) | ||
78 | { | ||
79 | UUID id = TestHelpers.ParseTail(i+1); | ||
80 | |||
81 | m_Avatars[i] = AddScenePresence("Bot", "Bot_" + i, id); | ||
82 | Assert.That(m_Avatars[i], Is.Not.Null); | ||
83 | Assert.That(m_Avatars[i].IsChildAgent, Is.False); | ||
84 | Assert.That(m_Avatars[i].UUID, Is.EqualTo(id)); | ||
85 | |||
86 | Assert.That(m_Scene.GetScenePresences().Count, Is.EqualTo(i+1)); | ||
87 | } | ||
88 | } | ||
89 | |||
90 | /// <summary> | ||
91 | /// Test adding an object to a scene. | ||
92 | /// </summary> | ||
93 | [Test] | ||
94 | public void TestGiveCBox() | ||
95 | { | ||
96 | TestHelpers.InMethod(); | ||
97 | |||
98 | // Create a C Box | ||
99 | SceneObjectGroup boxC = AddSceneObject("Box C", 10, 1, m_Avatars[0].UUID); | ||
100 | |||
101 | // field = 16 is NextOwner | ||
102 | // set = 1 means add the permission; set = 0 means remove permission | ||
103 | m_Scene.HandleObjectPermissionsUpdate((IClientAPI)m_Avatars[0].ClientView, m_Avatars[0].UUID, | ||
104 | ((IClientAPI)(m_Avatars[0].ClientView)).SessionId, 16, boxC.LocalId, (uint)PermissionMask.Copy, 1); | ||
105 | |||
106 | m_Scene.HandleObjectPermissionsUpdate((IClientAPI)m_Avatars[0].ClientView, m_Avatars[0].UUID, | ||
107 | ((IClientAPI)(m_Avatars[0].ClientView)).SessionId, 16, boxC.LocalId, (uint)PermissionMask.Transfer, 0); | ||
108 | PrintPerms(boxC); | ||
109 | |||
110 | Assert.True((boxC.RootPart.NextOwnerMask & (int)PermissionMask.Copy) != 0); | ||
111 | Assert.True((boxC.RootPart.NextOwnerMask & (int)PermissionMask.Modify) == 0); | ||
112 | Assert.True((boxC.RootPart.NextOwnerMask & (int)PermissionMask.Transfer) == 0); | ||
113 | |||
114 | InventoryItemBase item = TakeCopyToInventory(boxC); | ||
115 | |||
116 | GiveInventoryItem(item.ID, m_Avatars[0], m_Avatars[1]); | ||
117 | |||
118 | item = GetItemFromInventory(m_Avatars[1].UUID, "Objects", "Box C"); | ||
119 | |||
120 | // Check the receiver | ||
121 | PrintPerms(item); | ||
122 | Assert.True((item.BasePermissions & (int)PermissionMask.Copy) != 0); | ||
123 | Assert.True((item.BasePermissions & (int)PermissionMask.Modify) == 0); | ||
124 | Assert.True((item.BasePermissions & (int)PermissionMask.Transfer) == 0); | ||
125 | |||
126 | // Rez it and check perms in scene too | ||
127 | m_Scene.RezObject(m_Avatars[1].ControllingClient, item.ID, UUID.Zero, Vector3.One, Vector3.Zero, UUID.Zero, 0, false, false, false, UUID.Zero); | ||
128 | Assert.That(m_Scene.GetSceneObjectGroups().Count, Is.EqualTo(2)); | ||
129 | SceneObjectGroup copyBoxC = m_Scene.GetSceneObjectGroups().Find(sog => sog.OwnerID == m_Avatars[1].UUID); | ||
130 | PrintPerms(copyBoxC); | ||
131 | Assert.That(copyBoxC, Is.Not.Null); | ||
132 | |||
133 | } | ||
134 | |||
135 | #region Helper Functions | ||
136 | |||
137 | private void PrintPerms(SceneObjectGroup sog) | ||
138 | { | ||
139 | Console.WriteLine("SOG " + sog.Name + ": " + String.Format(Perms, (PermissionMask)sog.EffectiveOwnerPerms, | ||
140 | (PermissionMask)sog.EffectiveGroupPerms, (PermissionMask)sog.EffectiveEveryOnePerms, (PermissionMask)sog.RootPart.NextOwnerMask)); | ||
141 | |||
142 | } | ||
143 | |||
144 | private void PrintPerms(InventoryItemBase item) | ||
145 | { | ||
146 | Console.WriteLine("Inv " + item.Name + ": " + String.Format(Perms, (PermissionMask)item.BasePermissions, | ||
147 | (PermissionMask)item.GroupPermissions, (PermissionMask)item.EveryOnePermissions, (PermissionMask)item.NextPermissions)); | ||
148 | |||
149 | } | ||
150 | |||
151 | private ScenePresence AddScenePresence(string first, string last, UUID id) | ||
152 | { | ||
153 | UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(m_Scene, first, last, id, "pw"); | ||
154 | ScenePresence sp = SceneHelpers.AddScenePresence(m_Scene, id); | ||
155 | Assert.That(m_Scene.AuthenticateHandler.GetAgentCircuitData(id), Is.Not.Null); | ||
156 | |||
157 | return sp; | ||
158 | } | ||
159 | |||
160 | private SceneObjectGroup AddSceneObject(string name, int suffix, int partsToTestCount, UUID ownerID) | ||
161 | { | ||
162 | TestHelpers.InMethod(); | ||
163 | |||
164 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(partsToTestCount, ownerID, name, suffix); | ||
165 | so.Name = name; | ||
166 | so.Description = name; | ||
167 | |||
168 | Assert.That(m_Scene.AddNewSceneObject(so, false), Is.True); | ||
169 | SceneObjectGroup retrievedSo = m_Scene.GetSceneObjectGroup(so.UUID); | ||
170 | |||
171 | // If the parts have the same UUID then we will consider them as one and the same | ||
172 | Assert.That(retrievedSo.PrimCount, Is.EqualTo(partsToTestCount)); | ||
173 | |||
174 | return so; | ||
175 | } | ||
176 | |||
177 | private InventoryItemBase TakeCopyToInventory(SceneObjectGroup sog) | ||
178 | { | ||
179 | InventoryFolderBase objsFolder = UserInventoryHelpers.GetInventoryFolder(m_Scene.InventoryService, sog.OwnerID, "Objects"); | ||
180 | Assert.That(objsFolder, Is.Not.Null); | ||
181 | |||
182 | List<uint> localIds = new List<uint>(); localIds.Add(sog.LocalId); | ||
183 | m_Scene.DeRezObjects((IClientAPI)m_Avatars[0].ClientView, localIds, sog.UUID, DeRezAction.TakeCopy, objsFolder.ID); | ||
184 | Thread.Sleep(5000); | ||
185 | |||
186 | List<InventoryItemBase> items = m_Scene.InventoryService.GetFolderItems(sog.OwnerID, objsFolder.ID); | ||
187 | InventoryItemBase item = items.Find(i => i.Name == sog.Name); | ||
188 | Assert.That(item, Is.Not.Null); | ||
189 | |||
190 | return item; | ||
191 | |||
192 | } | ||
193 | |||
194 | private InventoryItemBase GetItemFromInventory(UUID userID, string folderName, string itemName) | ||
195 | { | ||
196 | InventoryFolderBase objsFolder = UserInventoryHelpers.GetInventoryFolder(m_Scene.InventoryService, userID, folderName); | ||
197 | Assert.That(objsFolder, Is.Not.Null); | ||
198 | List<InventoryItemBase> items = m_Scene.InventoryService.GetFolderItems(userID, objsFolder.ID); | ||
199 | InventoryItemBase item = items.Find(i => i.Name == itemName); | ||
200 | Assert.That(item, Is.Not.Null); | ||
201 | |||
202 | return item; | ||
203 | } | ||
204 | |||
205 | private void GiveInventoryItem(UUID itemId, ScenePresence giverSp, ScenePresence receiverSp) | ||
206 | { | ||
207 | TestClient giverClient = (TestClient)giverSp.ControllingClient; | ||
208 | TestClient receiverClient = (TestClient)receiverSp.ControllingClient; | ||
209 | |||
210 | UUID initialSessionId = TestHelpers.ParseTail(0x10); | ||
211 | byte[] giveImBinaryBucket = new byte[17]; | ||
212 | byte[] itemIdBytes = itemId.GetBytes(); | ||
213 | Array.Copy(itemIdBytes, 0, giveImBinaryBucket, 1, itemIdBytes.Length); | ||
214 | |||
215 | GridInstantMessage giveIm | ||
216 | = new GridInstantMessage( | ||
217 | m_Scene, | ||
218 | giverSp.UUID, | ||
219 | giverSp.Name, | ||
220 | receiverSp.UUID, | ||
221 | (byte)InstantMessageDialog.InventoryOffered, | ||
222 | false, | ||
223 | "inventory offered msg", | ||
224 | initialSessionId, | ||
225 | false, | ||
226 | Vector3.Zero, | ||
227 | giveImBinaryBucket, | ||
228 | true); | ||
229 | |||
230 | giverClient.HandleImprovedInstantMessage(giveIm); | ||
231 | |||
232 | // These details might not all be correct. | ||
233 | GridInstantMessage acceptIm | ||
234 | = new GridInstantMessage( | ||
235 | m_Scene, | ||
236 | receiverSp.UUID, | ||
237 | receiverSp.Name, | ||
238 | giverSp.UUID, | ||
239 | (byte)InstantMessageDialog.InventoryAccepted, | ||
240 | false, | ||
241 | "inventory accepted msg", | ||
242 | initialSessionId, | ||
243 | false, | ||
244 | Vector3.Zero, | ||
245 | null, | ||
246 | true); | ||
247 | |||
248 | receiverClient.HandleImprovedInstantMessage(acceptIm); | ||
249 | } | ||
250 | #endregion | ||
251 | } | ||
252 | } \ No newline at end of file | ||