aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Tests/Permissions/DirectTransferTests.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Tests/Permissions/DirectTransferTests.cs')
-rw-r--r--OpenSim/Tests/Permissions/DirectTransferTests.cs208
1 files changed, 34 insertions, 174 deletions
diff --git a/OpenSim/Tests/Permissions/DirectTransferTests.cs b/OpenSim/Tests/Permissions/DirectTransferTests.cs
index 7716776..e103d01 100644
--- a/OpenSim/Tests/Permissions/DirectTransferTests.cs
+++ b/OpenSim/Tests/Permissions/DirectTransferTests.cs
@@ -48,205 +48,65 @@ namespace OpenSim.Tests.Permissions
48 /// Basic scene object tests (create, read and delete but not update). 48 /// Basic scene object tests (create, read and delete but not update).
49 /// </summary> 49 /// </summary>
50 [TestFixture] 50 [TestFixture]
51 public class DirectTransferTests : OpenSimTestCase 51 public class DirectTransferTests
52 { 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 53
57 [SetUp] 54 [SetUp]
58 public override void SetUp() 55 public void SetUp()
59 { 56 {
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 } 57 }
89 58
90 /// <summary> 59 /// <summary>
91 /// Test adding an object to a scene. 60 /// Test giving a C object.
92 /// </summary> 61 /// </summary>
93 [Test] 62 [Test]
94 public void TestGiveCBox() 63 public void TestGiveCBox()
95 { 64 {
96 TestHelpers.InMethod(); 65 TestHelpers.InMethod();
97 66
98 // Create a C Box 67 // C, CT, MC, MCT, MT, T
99 SceneObjectGroup boxC = AddSceneObject("Box C", 10, 1, m_Avatars[0].UUID); 68 string[] names = new string[6] { "Box C", "Box CT", "Box MC", "Box MCT", "Box MT", "Box T"};
100 69 PermissionMask[] perms = new PermissionMask[6] {
101 // field = 16 is NextOwner 70 PermissionMask.Copy,
102 // set = 1 means add the permission; set = 0 means remove permission 71 PermissionMask.Copy | PermissionMask.Transfer,
103 m_Scene.HandleObjectPermissionsUpdate((IClientAPI)m_Avatars[0].ClientView, m_Avatars[0].UUID, 72 PermissionMask.Modify | PermissionMask.Copy,
104 ((IClientAPI)(m_Avatars[0].ClientView)).SessionId, 16, boxC.LocalId, (uint)PermissionMask.Copy, 1); 73 PermissionMask.Modify | PermissionMask.Copy | PermissionMask.Transfer,
105 74 PermissionMask.Modify | PermissionMask.Transfer,
106 m_Scene.HandleObjectPermissionsUpdate((IClientAPI)m_Avatars[0].ClientView, m_Avatars[0].UUID, 75 PermissionMask.Transfer
107 ((IClientAPI)(m_Avatars[0].ClientView)).SessionId, 16, boxC.LocalId, (uint)PermissionMask.Transfer, 0); 76 };
108 PrintPerms(boxC); 77
109 78 for (int i = 0; i < 6; i++)
110 Assert.True((boxC.RootPart.NextOwnerMask & (int)PermissionMask.Copy) != 0); 79 TestOneBox(names[i], perms[i]);
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 } 80 }
150 81
151 private ScenePresence AddScenePresence(string first, string last, UUID id) 82 private void TestOneBox(string name, PermissionMask mask)
152 { 83 {
153 UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(m_Scene, first, last, id, "pw"); 84 InventoryItemBase item = Common.TheInstance.GetItemFromInventory(Common.TheAvatars[0].UUID, "Objects", name);
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 85
171 // If the parts have the same UUID then we will consider them as one and the same 86 Common.TheInstance.GiveInventoryItem(item.ID, Common.TheAvatars[0], Common.TheAvatars[1]);
172 Assert.That(retrievedSo.PrimCount, Is.EqualTo(partsToTestCount));
173 87
174 return so; 88 item = Common.TheInstance.GetItemFromInventory(Common.TheAvatars[1].UUID, "Objects", name);
175 }
176 89
177 private InventoryItemBase TakeCopyToInventory(SceneObjectGroup sog) 90 // Check the receiver
178 { 91 Common.TheInstance.PrintPerms(item);
179 InventoryFolderBase objsFolder = UserInventoryHelpers.GetInventoryFolder(m_Scene.InventoryService, sog.OwnerID, "Objects"); 92 Common.TheInstance.AssertPermissions(mask, (PermissionMask)item.BasePermissions, item.Owner.ToString().Substring(34) + " : " + item.Name);
180 Assert.That(objsFolder, Is.Not.Null);
181 93
182 List<uint> localIds = new List<uint>(); localIds.Add(sog.LocalId); 94 int nObjects = Common.TheScene.GetSceneObjectGroups().Count;
183 m_Scene.DeRezObjects((IClientAPI)m_Avatars[0].ClientView, localIds, sog.UUID, DeRezAction.TakeCopy, objsFolder.ID); 95 // Rez it and check perms in scene too
184 Thread.Sleep(5000); 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));
185 98
186 List<InventoryItemBase> items = m_Scene.InventoryService.GetFolderItems(sog.OwnerID, objsFolder.ID); 99 SceneObjectGroup box = Common.TheScene.GetSceneObjectGroups().Find(sog => sog.OwnerID == Common.TheAvatars[1].UUID && sog.Name == name);
187 InventoryItemBase item = items.Find(i => i.Name == sog.Name); 100 Common.TheInstance.PrintPerms(box);
188 Assert.That(item, Is.Not.Null); 101 Assert.That(box, Is.Not.Null);
189 102
190 return item; 103 // Check Owner permissions
104 Common.TheInstance.AssertPermissions(mask, (PermissionMask)box.EffectiveOwnerPerms, box.OwnerID.ToString().Substring(34) + " : " + box.Name);
191 105
192 } 106 // Check Next Owner permissions
107 Common.TheInstance.AssertPermissions(mask, (PermissionMask)box.RootPart.NextOwnerMask, box.OwnerID.ToString().Substring(34) + " : " + box.Name);
193 108
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 } 109 }
204 110
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 } 111 }
252} \ No newline at end of file 112} \ No newline at end of file