Exemplo n.º 1
0
        public FirewallManagerTests()
        {
            var permissionManager = Substitute.For <IDesktopPermissionManager>();

            userManager = new LocalPrincipalManager(permissionManager, null);

            var helper = new ContainerHandleHelper();
            var guid   = System.Guid.NewGuid().ToString("N");

            Username = "******" + helper.GenerateId(guid);
            userManager.CreateUser(Username);
        }
Exemplo n.º 2
0
        public GuardAcceptanceTests()
        {
            this.userManager = new LocalPrincipalManager();
            userManager.CreateUser(username);

            this.jobObject = new JobObject(username);
            var guardExePath = Path.Combine(Directory.GetCurrentDirectory(), "Guard.exe");

            this.guardProcess = Process.Start(new ProcessStartInfo()
            {
                FileName  = guardExePath,
                Arguments = String.Format("{0} {1}", username, username),
            });
        }
        public GuardAcceptanceTests()
        {
            this.userManager = new LocalPrincipalManager();
               userManager.CreateUser(username);

               this.jobObject = new JobObject(username);
               var guardExePath = Path.Combine(Directory.GetCurrentDirectory(), "Guard.exe");

               this.guardProcess = Process.Start(new ProcessStartInfo()
               {
               FileName = guardExePath,
               Arguments = String.Format("{0} {1}", username, username),
               });
        }
Exemplo n.º 4
0
        public ContainerUser(string uniqueId, bool shouldCreate = false)
        {
            if (uniqueId.IsNullOrWhiteSpace())
            {
                throw new ArgumentNullException("uniqueId");
            }
            this.uniqueId = uniqueId;

            if (uniqueIdValidator.IsMatch(uniqueId))
            {
                this.userName = CreateUserName(uniqueId);
            }
            else
            {
                throw new ArgumentException("uniqueId must be 8 or more word characters.");
            }

            var principalManager = new LocalPrincipalManager();

            if (shouldCreate)
            {
                /*
                 * TODO: this means that we can't retrieve a user's password if restoring a container.
                 * This should be OK when we move to the "separate process for container" model since the separate
                 * process will be installed as a service and the password will only need to be known at install
                 * time.
                 */
                var userData = principalManager.CreateUser(this.userName);
                if (userData == null)
                {
                    throw new ArgumentException(String.Format("Could not create user '{0}'", this.userName));
                }
                else
                {
                    this.userName = userData.UserName;
                    this.password = userData.Password;
                }
            }
            else
            {
                string foundUser = principalManager.FindUser(this.userName);
                if (foundUser == null)
                {
                    throw new ArgumentException(String.Format("Could not find user '{0}'", this.userName));
                }
            }

            AddDesktopPermission(this.userName);
        }
Exemplo n.º 5
0
        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);
            };
        }