Пример #1
0
            public void Stop_StillWorks_Eventually()
            {
                Container1 = CreateContainer(Container1Handle);
                string userid = null;

                Container1.ImpersonateContainerUser(() =>
                {
                    userid = WindowsIdentity.GetCurrent().User.ToString();
                });
                var pSpec = new ProcessSpec
                {
                    ExecutablePath     = "cmd.exe",
                    DisablePathMapping = true,
                    Arguments          = new string[] { @"/C ""FOR /L %% IN () DO ping 127.0.0.1 -n 2""" },
                };

                // START THE LONG RUNNING PROCESS
                var io          = new StringProcessIO();
                var process     = Container1.Run(pSpec, io);
                var realProcess = Process.GetProcessById(process.Id);

                Process containerHost = FindProcessByUserAndName(userid, "IronFrame.Host");

                ProcessInfoHelper.SuspendProcess(containerHost.Id);

                Container1.Stop(true);

                Assert.True(realProcess.HasExited);
            }
Пример #2
0
            public void RunsActionsInContextOfUser()
            {
                Container1 = CreateContainer(ContainerSpec);
                var path = Container1.Directory.MapUserPath("hi");

                Container1.ImpersonateContainerUser(() => File.WriteAllText(path, "foobar"));

                string user =
                    File.GetAccessControl(path)
                    .GetOwner(typeof(System.Security.Principal.NTAccount))
                    .ToString();

                Assert.EndsWith("c_" + Container1.Id, user);
            }
Пример #3
0
            public void Enforced()
            {
                if (Environment.GetEnvironmentVariable("APPVEYOR") != null)
                {
                    return;
                }

                const ulong diskLimit = (ulong)7e+6;

                Container1 = CreateContainer(Container1Handle);
                Container1.LimitDisk(diskLimit);

                Container1.ImpersonateContainerUser(() => File.WriteAllBytes(Container1.Directory.MapUserPath("file.txt"), new byte[diskLimit]));
                Assert.Throws <IOException>(() => Container1.ImpersonateContainerUser(() => File.WriteAllBytes(Container1.Directory.MapUserPath("file.txt"), new byte[diskLimit + 1024])));
            }