Changeset 6457 for branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Tests/ServiceTests.cs
- Timestamp:
- 06/20/11 17:04:35 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Services.Hive.Tests/ServiceTests.cs
r6452 r6457 26 26 using HeuristicLab.Services.Hive.Common.DataTransfer; 27 27 using HeuristicLab.Services.Hive.Common.ServiceContracts; 28 using HeuristicLab.Services.Hive.Tests.Mocks; 28 29 using Microsoft.VisualStudio.TestTools.UnitTesting; 29 30 using DT = HeuristicLab.Services.Hive.Common.DataTransfer; … … 32 33 [TestClass] 33 34 public class ServiceTests { 35 // use the mock service locator to modify service properties (such as current user) 36 private static MockServiceLocator mockServiceLocator; 34 37 35 38 [ClassInitialize] 36 39 public static void MyClassInitialize(TestContext testContext) { 37 ServiceLocator.Instance = new MockServiceLocator(ServiceLocator.Instance); 40 mockServiceLocator = new MockServiceLocator(ServiceLocator.Instance); 41 ServiceLocator.Instance = mockServiceLocator; 38 42 } 39 43 … … 47 51 48 52 // create hive experiment 49 DT.HiveExperiment experiment = new DT.HiveExperiment() { 50 Name = "TestExperiment", 51 Description = "" 52 }; 53 DT.HiveExperiment experiment = new DT.HiveExperiment() { Name = "TestExperiment", Description = "" }; 53 54 54 55 // create job 55 DT.Job job = new DT.Job() { 56 CoresNeeded = 1, 57 MemoryNeeded = 0, 58 Priority = 0 59 }; 56 DT.Job job = new DT.Job() { CoresNeeded = 1, MemoryNeeded = 0, Priority = 0 }; 60 57 job.State = JobState.Offline; 61 58 job.StateLog.Add(new StateLog { State = JobState.Offline, DateTime = DateTime.Now }); … … 78 75 plugin1.DateCreated = DateTime.Now; 79 76 plugin1.Hash = hash; 80 77 81 78 DT.PluginData pluginData1 = new DT.PluginData(); 82 79 pluginData1.FileName = "Tests.MyPlugin-1.0.dll"; … … 206 203 207 204 // create hive experiment 208 DT.HiveExperiment experiment = new DT.HiveExperiment() { 209 Name = "TestExperiment", 210 Description = "" 211 }; 205 DT.HiveExperiment experiment = new DT.HiveExperiment() { Name = "TestExperiment", Description = "" }; 212 206 213 207 // create parent job … … 304 298 service.DeleteSlave(slave.Id); 305 299 } 300 301 302 [TestMethod] 303 public void TestHiveExperimentPermissions() { 304 var service = GetLocalService(); 305 mockServiceLocator.SetCurrentUser(MockAuthorizationManager.MockUserId1); 306 307 // create hive experiment 308 DT.HiveExperiment e1 = new DT.HiveExperiment() { Name = "TestExperiment", Description = "" }; 309 e1.Id = service.AddHiveExperiment(e1); 310 311 var e1loaded = service.GetHiveExperiment(e1.Id); 312 Assert.AreEqual(Permission.Full, e1loaded.Permission); 313 314 // change to user2 315 mockServiceLocator.SetCurrentUser(MockAuthorizationManager.MockUserId2); 316 e1loaded = service.GetHiveExperiment(e1.Id); 317 Assert.AreEqual(null, e1loaded); // no access 318 319 // user2 should not be able to grant permissions 320 try { 321 service.GrantPermission(e1.Id, MockAuthorizationManager.MockUserId2, Permission.ReadOnly); 322 Assert.Fail("Should not be possible to grant permission due to missing permission for User2"); 323 } 324 catch { /* ok, cool */ } 325 326 // switch back to user1 (owner) and grant user2 permissions 327 mockServiceLocator.SetCurrentUser(MockAuthorizationManager.MockUserId1); 328 service.GrantPermission(e1.Id, MockAuthorizationManager.MockUserId2, Permission.ReadOnly); 329 330 // back to user2 331 mockServiceLocator.SetCurrentUser(MockAuthorizationManager.MockUserId2); 332 e1loaded = service.GetHiveExperiment(e1.Id); 333 Assert.AreEqual(Permission.ReadOnly, e1loaded.Permission); 334 335 // user2 should still not be able to grant permissions 336 try { 337 service.GrantPermission(e1.Id, MockAuthorizationManager.MockUserId2, Permission.ReadOnly); 338 Assert.Fail("Should not be possible to grant permission due to missing permission for User2"); 339 } 340 catch { /* ok, cool */ } 341 342 // back to user1 343 mockServiceLocator.SetCurrentUser(MockAuthorizationManager.MockUserId1); 344 service.GrantPermission(e1.Id, MockAuthorizationManager.MockUserId2, Permission.Full); 345 346 // back to user2 347 mockServiceLocator.SetCurrentUser(MockAuthorizationManager.MockUserId2); 348 e1loaded = service.GetHiveExperiment(e1.Id); 349 Assert.AreEqual(Permission.Full, e1loaded.Permission); 350 351 // grant rights to user3, now this should be possible due to full permissions 352 service.GrantPermission(e1.Id, MockAuthorizationManager.MockUserId3, Permission.ReadOnly); 353 354 // back to user1 and revoke rights for user2 355 mockServiceLocator.SetCurrentUser(MockAuthorizationManager.MockUserId1); 356 service.RevokePermission(e1.Id, MockAuthorizationManager.MockUserId2); 357 358 // back to user2 359 mockServiceLocator.SetCurrentUser(MockAuthorizationManager.MockUserId2); 360 e1loaded = service.GetHiveExperiment(e1.Id); 361 Assert.AreEqual(null, e1loaded); // no access 362 363 service.DeleteHiveExperiment(e1.Id); 364 } 306 365 } 307 366 }
Note: See TracChangeset
for help on using the changeset viewer.