Changeset 1765
- Timestamp:
- 05/08/09 14:08:46 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Security.Core/3.2/SecurityCoreTest.cs
r1738 r1765 5 5 using HeuristicLab.PluginInfrastructure; 6 6 using HeuristicLab.Security.Contracts.BusinessObjects; 7 using HeuristicLab.Hive.Server.Core; 7 8 8 9 namespace HeuristicLab.Security.Core { … … 11 12 AutoRestart = true)] 12 13 class SecurityCoreTest : ApplicationBase { 14 15 SecurityManager manager = new SecurityManager(); 16 PermissionManager permManager = new PermissionManager(); 17 18 13 19 private void testGroups() { 14 SecurityManager manager =15 new SecurityManager();16 20 17 21 User user = new User(); … … 56 60 57 61 private void testPermissions() { 58 SecurityManager manager =59 new SecurityManager();60 61 PermissionManager permManager =62 new PermissionManager();63 62 64 63 Permission permission = new Permission(); … … 99 98 100 99 private void testPermissionsGroup() { 101 SecurityManager manager =102 new SecurityManager();103 104 PermissionManager permManager =105 new PermissionManager();106 100 107 101 User user = new User(); … … 170 164 manager.RemoveUserGroup(group2.Id); 171 165 172 manager.RemovePermission(permission.Id); 173 } 174 166 manager.RemovePermission(permission.Id); 167 } 168 #region TEST DATA INSERT SECTION for MB 169 170 private void InsertTestDataForPermissionCheck() { 171 int numberOfUsers = 10; 172 173 List<User> users = new List<User>(); 174 for (int i = 0; i < numberOfUsers; i++) { 175 users.Add(MB_InsertTestUser()); 176 } 177 MB_AssignGroups(users); 178 179 } 180 181 private User MB_InsertTestUser() { 182 Random rand = new Random(DateTime.Now.Millisecond); 183 int usr = rand.Next(1000); 184 User user = new User(); 185 user.Login = "test" + usr.ToString(); 186 user.SetHashedPassword("test"); 187 user.Name = "test" + usr.ToString(); 188 return manager.AddNewUser(user); 189 } 190 191 /// <summary> 192 /// Splits the given users into two groups and assigns them. Some will be not assigned. 193 /// </summary> 194 /// <param name="users"></param> 195 private void MB_AssignGroups(List<User> users) { 196 UserGroup group01 = new UserGroup(); 197 group01.Name = "Test Group 01"; 198 199 UserGroup group02 = new UserGroup(); 200 group02.Name = "Test Group 02"; 201 202 //three-way split users into group1, group2 and none 203 int idx = users.Count / 3; 204 for (int i = 0; i < idx; i++) { 205 group01.Members.Add(users[i]); 206 } 207 for (int i = idx; i < users.Count / 2; i++) { 208 group02.Members.Add(users[i]); 209 } 210 manager.AddNewUserGroup(group01); 211 manager.AddNewUserGroup(group02); 212 213 } 214 215 private void MB_AddPermission(List<User> users) { 216 if (users.Count < 2) return; 217 Permission permission = new Permission(); 218 //permission.Id = PermissiveSecurityAction.Add_Job; 219 permission.Name = "ADD_JOB"; 220 permission.Description = "Add new jobs"; 221 permission.Plugin = "HeuristicLab.Hive.Server"; 222 223 manager.AddPermission(permission); 224 //grant permission to random users 225 Random rand = new Random(DateTime.Now.Millisecond); 226 for (int i = 0; i < users.Count/2; i++) { 227 int idx = rand.Next(users.Count); 228 manager.GrantPermission(users[i].Id, permission.Id, Guid.Empty); 229 } 230 } 231 232 #endregion 175 233 public override void Run() { 176 testPermissionsGroup(); 234 //testPermissionsGroup(); 235 InsertTestDataForPermissionCheck(); 177 236 } 178 237 }
Note: See TracChangeset
for help on using the changeset viewer.