diff options
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs | 126 |
1 files changed, 122 insertions, 4 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs index cb7291a..9b7cab2 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiInventoryTests.cs | |||
@@ -41,9 +41,10 @@ using OpenSim.Region.OptionalModules.World.NPC; | |||
41 | using OpenSim.Region.Framework.Scenes; | 41 | using OpenSim.Region.Framework.Scenes; |
42 | using OpenSim.Region.ScriptEngine.Shared; | 42 | using OpenSim.Region.ScriptEngine.Shared; |
43 | using OpenSim.Region.ScriptEngine.Shared.Api; | 43 | using OpenSim.Region.ScriptEngine.Shared.Api; |
44 | using OpenSim.Region.ScriptEngine.Shared.Instance; | ||
44 | using OpenSim.Services.Interfaces; | 45 | using OpenSim.Services.Interfaces; |
45 | using OpenSim.Tests.Common; | 46 | using OpenSim.Tests.Common; |
46 | using OpenSim.Tests.Common.Mock; | 47 | using PermissionMask = OpenSim.Framework.PermissionMask; |
47 | 48 | ||
48 | namespace OpenSim.Region.ScriptEngine.Shared.Tests | 49 | namespace OpenSim.Region.ScriptEngine.Shared.Tests |
49 | { | 50 | { |
@@ -90,7 +91,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
90 | 91 | ||
91 | // Create an object embedded inside the first | 92 | // Create an object embedded inside the first |
92 | UUID itemId = TestHelpers.ParseTail(0x20); | 93 | UUID itemId = TestHelpers.ParseTail(0x20); |
93 | TaskInventoryHelpers.AddSceneObject(m_scene, so1.RootPart, inventoryItemName, itemId, userId); | 94 | TaskInventoryHelpers.AddSceneObject(m_scene.AssetService, so1.RootPart, inventoryItemName, itemId, userId); |
94 | 95 | ||
95 | LSL_Api api = new LSL_Api(); | 96 | LSL_Api api = new LSL_Api(); |
96 | api.Initialize(m_engine, so1.RootPart, null); | 97 | api.Initialize(m_engine, so1.RootPart, null); |
@@ -130,7 +131,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
130 | 131 | ||
131 | // Create an object embedded inside the first | 132 | // Create an object embedded inside the first |
132 | UUID itemId = TestHelpers.ParseTail(0x20); | 133 | UUID itemId = TestHelpers.ParseTail(0x20); |
133 | TaskInventoryHelpers.AddSceneObject(m_scene, so1.RootPart, inventoryItemName, itemId, user1Id); | 134 | TaskInventoryHelpers.AddSceneObject(m_scene.AssetService, so1.RootPart, inventoryItemName, itemId, user1Id); |
134 | 135 | ||
135 | // Create a second object | 136 | // Create a second object |
136 | SceneObjectGroup so2 = SceneHelpers.CreateSceneObject(1, user2Id, "so2", 0x100); | 137 | SceneObjectGroup so2 = SceneHelpers.CreateSceneObject(1, user2Id, "so2", 0x100); |
@@ -166,5 +167,122 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
166 | Assert.That(copiedItems[0].Name, Is.EqualTo(inventoryItemName)); | 167 | Assert.That(copiedItems[0].Name, Is.EqualTo(inventoryItemName)); |
167 | } | 168 | } |
168 | } | 169 | } |
170 | |||
171 | /// <summary> | ||
172 | /// Test giving inventory from an object to an avatar that is not the object's owner. | ||
173 | /// </summary> | ||
174 | [Test] | ||
175 | public void TestLlGiveInventoryO2DifferentAvatar() | ||
176 | { | ||
177 | TestHelpers.InMethod(); | ||
178 | // TestHelpers.EnableLogging(); | ||
179 | |||
180 | UUID user1Id = TestHelpers.ParseTail(0x1); | ||
181 | UUID user2Id = TestHelpers.ParseTail(0x2); | ||
182 | string inventoryItemName = "item1"; | ||
183 | |||
184 | SceneObjectGroup so1 = SceneHelpers.CreateSceneObject(1, user1Id, "so1", 0x10); | ||
185 | m_scene.AddSceneObject(so1); | ||
186 | LSL_Api api = new LSL_Api(); | ||
187 | api.Initialize(m_engine, so1.RootPart, null); | ||
188 | |||
189 | // Create an object embedded inside the first | ||
190 | UUID itemId = TestHelpers.ParseTail(0x20); | ||
191 | TaskInventoryHelpers.AddSceneObject(m_scene.AssetService, so1.RootPart, inventoryItemName, itemId, user1Id); | ||
192 | |||
193 | UserAccountHelpers.CreateUserWithInventory(m_scene, user2Id); | ||
194 | |||
195 | api.llGiveInventory(user2Id.ToString(), inventoryItemName); | ||
196 | |||
197 | InventoryItemBase receivedItem | ||
198 | = UserInventoryHelpers.GetInventoryItem( | ||
199 | m_scene.InventoryService, user2Id, string.Format("Objects/{0}", inventoryItemName)); | ||
200 | |||
201 | Assert.IsNotNull(receivedItem); | ||
202 | } | ||
203 | |||
204 | /// <summary> | ||
205 | /// Test giving inventory from an object to an avatar that is not the object's owner and where the next | ||
206 | /// permissions do not include mod. | ||
207 | /// </summary> | ||
208 | [Test] | ||
209 | public void TestLlGiveInventoryO2DifferentAvatarNoMod() | ||
210 | { | ||
211 | TestHelpers.InMethod(); | ||
212 | // TestHelpers.EnableLogging(); | ||
213 | |||
214 | UUID user1Id = TestHelpers.ParseTail(0x1); | ||
215 | UUID user2Id = TestHelpers.ParseTail(0x2); | ||
216 | string inventoryItemName = "item1"; | ||
217 | |||
218 | SceneObjectGroup so1 = SceneHelpers.CreateSceneObject(1, user1Id, "so1", 0x10); | ||
219 | m_scene.AddSceneObject(so1); | ||
220 | LSL_Api api = new LSL_Api(); | ||
221 | api.Initialize(m_engine, so1.RootPart, null); | ||
222 | |||
223 | // Create an object embedded inside the first | ||
224 | UUID itemId = TestHelpers.ParseTail(0x20); | ||
225 | TaskInventoryItem tii | ||
226 | = TaskInventoryHelpers.AddSceneObject(m_scene.AssetService, so1.RootPart, inventoryItemName, itemId, user1Id); | ||
227 | tii.NextPermissions &= ~((uint)PermissionMask.Modify); | ||
228 | |||
229 | UserAccountHelpers.CreateUserWithInventory(m_scene, user2Id); | ||
230 | |||
231 | api.llGiveInventory(user2Id.ToString(), inventoryItemName); | ||
232 | |||
233 | InventoryItemBase receivedItem | ||
234 | = UserInventoryHelpers.GetInventoryItem( | ||
235 | m_scene.InventoryService, user2Id, string.Format("Objects/{0}", inventoryItemName)); | ||
236 | |||
237 | Assert.IsNotNull(receivedItem); | ||
238 | Assert.AreEqual(0, receivedItem.CurrentPermissions & (uint)PermissionMask.Modify); | ||
239 | } | ||
240 | |||
241 | [Test] | ||
242 | public void TestLlRemoteLoadScriptPin() | ||
243 | { | ||
244 | TestHelpers.InMethod(); | ||
245 | // TestHelpers.EnableLogging(); | ||
246 | |||
247 | UUID user1Id = TestHelpers.ParseTail(0x1); | ||
248 | UUID user2Id = TestHelpers.ParseTail(0x2); | ||
249 | |||
250 | SceneObjectGroup sourceSo = SceneHelpers.AddSceneObject(m_scene, "sourceSo", user1Id); | ||
251 | m_scene.AddSceneObject(sourceSo); | ||
252 | LSL_Api api = new LSL_Api(); | ||
253 | api.Initialize(m_engine, sourceSo.RootPart, null); | ||
254 | TaskInventoryHelpers.AddScript(m_scene.AssetService, sourceSo.RootPart, "script", "Hello World"); | ||
255 | |||
256 | SceneObjectGroup targetSo = SceneHelpers.AddSceneObject(m_scene, "targetSo", user1Id); | ||
257 | SceneObjectGroup otherOwnedTargetSo = SceneHelpers.AddSceneObject(m_scene, "otherOwnedTargetSo", user2Id); | ||
258 | |||
259 | // Test that we cannot load a script when the target pin has never been set (i.e. it is zero) | ||
260 | api.llRemoteLoadScriptPin(targetSo.UUID.ToString(), "script", 0, 0, 0); | ||
261 | Assert.IsNull(targetSo.RootPart.Inventory.GetInventoryItem("script")); | ||
262 | |||
263 | // Test that we cannot load a script when the given pin does not match the target | ||
264 | targetSo.RootPart.ScriptAccessPin = 5; | ||
265 | api.llRemoteLoadScriptPin(targetSo.UUID.ToString(), "script", 3, 0, 0); | ||
266 | Assert.IsNull(targetSo.RootPart.Inventory.GetInventoryItem("script")); | ||
267 | |||
268 | // Test that we cannot load into a prim with a different owner | ||
269 | otherOwnedTargetSo.RootPart.ScriptAccessPin = 3; | ||
270 | api.llRemoteLoadScriptPin(otherOwnedTargetSo.UUID.ToString(), "script", 3, 0, 0); | ||
271 | Assert.IsNull(otherOwnedTargetSo.RootPart.Inventory.GetInventoryItem("script")); | ||
272 | |||
273 | // Test that we can load a script when given pin and dest pin match. | ||
274 | targetSo.RootPart.ScriptAccessPin = 3; | ||
275 | api.llRemoteLoadScriptPin(targetSo.UUID.ToString(), "script", 3, 0, 0); | ||
276 | TaskInventoryItem insertedItem = targetSo.RootPart.Inventory.GetInventoryItem("script"); | ||
277 | Assert.IsNotNull(insertedItem); | ||
278 | |||
279 | // Test that we can no longer load if access pin is unset | ||
280 | targetSo.RootPart.Inventory.RemoveInventoryItem(insertedItem.ItemID); | ||
281 | Assert.IsNull(targetSo.RootPart.Inventory.GetInventoryItem("script")); | ||
282 | |||
283 | targetSo.RootPart.ScriptAccessPin = 0; | ||
284 | api.llRemoteLoadScriptPin(otherOwnedTargetSo.UUID.ToString(), "script", 3, 0, 0); | ||
285 | Assert.IsNull(otherOwnedTargetSo.RootPart.Inventory.GetInventoryItem("script")); | ||
286 | } | ||
169 | } | 287 | } |
170 | } \ No newline at end of file | 288 | } |