static void SetupUser() { var securitySpecsUser = GetSecuritySpecsUser(); var accountExists = SchedulerSteps.AccountExists(securitySpecsUser); if (!accountExists) { try { SchedulerSteps.CreateLocalWindowsAccount(GetSecuritySpecsUser(), GetSecuritySpecsPassword(), GetUserGroup()); } catch (Exception ex) { Console.WriteLine(@"error creating user" + ex.Message); } } }
public void WhenConnectedAsUserPartOf(string userGroup) { if (SchedulerSteps.AccountExists("SpecsUser")) { if (!IsUserInGroup("SpecsUser", userGroup)) { try { SecurityIdentifier id = SchedulerSteps.GetUserSecurityIdentifier("SpecsUser"); PrincipalContext context = new PrincipalContext(ContextType.Machine); UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(context, IdentityType.Sid, id.Value); SchedulerSteps.AddUserToGroup(userGroup, context, userPrincipal); } catch (Exception) { Assert.Fail("User not found"); } } } else { SchedulerSteps.CreateLocalWindowsAccount("SpecsUser", "T35t3r!@#", userGroup); } var reconnectModel = new EnvironmentModel(Guid.NewGuid(), new ServerProxy(AppSettings.LocalHost, "SpecsUser", "T35t3r!@#")) { Name = "Other Connection" }; try { reconnectModel.Connect(); } catch (UnauthorizedAccessException) { Assert.Fail("Connection unauthorized when connecting to local Warewolf server as user who is part of '" + userGroup + "' user group."); } ScenarioContext.Current.Add("currentEnvironment", reconnectModel); }