public ImpersonationProcessRunnerTests(ITestOutputHelper helper)
 {
     logger   = helper;
     username = GenerateRandomAlphaString();
     helper.WriteLine(username);
     userManager = new LocalPrincipalManager("IIS_IUSRS");
     userManager.DeleteUser(username);
     creds = userManager.CreateUser(username);
 }
        public LocalPrincipalManagerTests()
        {
            groupManager = new LocalUserGroupManager();
            permissionManager = Substitute.For<IDesktopPermissionManager>();
            RecreateLocalGroup(testGroupName);
            manager = new LocalPrincipalManager(permissionManager, testGroupName);

            TryRemoveLocalUser(testUserName);
        }
Exemple #3
0
        public LocalPrincipalManagerTests()
        {
            groupManager      = new LocalUserGroupManager();
            permissionManager = Substitute.For <IDesktopPermissionManager>();
            RecreateLocalGroup(testGroupName);
            manager = new LocalPrincipalManager(permissionManager, testGroupName);

            TryRemoveLocalUser(testUserName);
        }
Exemple #4
0
            public async Task WhenCredentialsGiven_LoadsUserEnvironment()
            {
                var desktopPermissionManager  = new DesktopPermissionManager();
                LocalPrincipalManager manager = new LocalPrincipalManager(desktopPermissionManager, "IIS_IUSRS");

                string userName = "******";

                if (manager.FindUser(userName) != null)
                {
                    manager.DeleteUser(userName);
                }
                var user = manager.CreateUser(userName);

                desktopPermissionManager.AddDesktopPermission(userName);

                try
                {
                    var si = CreateRunSpec("cmd.exe", new[] { "/C", "set USERNAME" });
                    si.Credentials         = user;
                    si.BufferedInputOutput = true;
                    si.WorkingDirectory    = Environment.SystemDirectory;

                    using (var p = Runner.Run(si))
                    {
                        WaitForGoodExit(p, 1000);

                        var output = await p.StandardOutput.ReadToEndAsync();

                        string expectedUserName = string.Format("USERNAME={0}", user.UserName);
                        Assert.Contains(expectedUserName, output);
                    }
                }
                finally
                {
                    desktopPermissionManager.RemoveDesktopPermission(userName);
                    manager.DeleteUser(userName);
                }
            }
        private void describe_WriteTarStreamToPath()
        {
            string destinationArchiveFileName = null;
            Mock<IContainer> containerMock = null;
            LocalPrincipalManager userManager = null;
            string username = null;

            before = () =>
            {
                Helpers.AssertAdministratorPrivileges();

                userManager = new LocalPrincipalManager();
                var guid = System.Guid.NewGuid().ToString("N");
                username = "******" + guid.Substring(0, 6);
                var credentials = userManager.CreateUser(username);
                containerMock = new Mock<IContainer>();
                containerMock.Setup(x => x.ImpersonateContainerUser(It.IsAny<Action>())).Callback((Action x) => x());

                Directory.CreateDirectory(Path.Combine(inputDir, "fooDir"));
                File.WriteAllText(Path.Combine(inputDir, "content.txt"), "content");
                File.WriteAllText(Path.Combine(inputDir, "fooDir", "content.txt"), "MOAR content");
                new TarStreamService().CreateTarFromDirectory(inputDir, tarFile);
                tarStream = new FileStream(tarFile, FileMode.Open);
            };

            context["when the tar stream contains files and directories"] = () =>
            {
                act = () => tarStreamService.WriteTarStreamToPath(tarStream, containerMock.Object, outputDir);

                it["writes the file to disk"] = () =>
                {
                    File.ReadAllLines(Path.Combine(outputDir, "content.txt")).should_be("content");
                    File.ReadAllLines(Path.Combine(outputDir, "fooDir", "content.txt")).should_be("MOAR content");
                };
            };

            after = () =>
            {
                tarStream.Close();
                File.Delete(tarFile);
                userManager.DeleteUser(username);
            };
        }
 public ImpersonationProcessRunnerTests()
 {
     userManager = new LocalPrincipalManager("IIS_IUSRS");
        userManager.DeleteUser(username);
        creds = userManager.CreateUser(username);
 }
Exemple #7
0
 public ImpersonationProcessRunnerTests()
 {
     userManager = new LocalPrincipalManager("IIS_IUSRS");
     userManager.DeleteUser(username);
     creds = userManager.CreateUser(username);
 }