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); }
public void UserHasAProfileLoaded() { Container1 = CreateContainer(Container1Handle); var exePath = Container1.Directory.MapUserPath("x509app.exe"); var compilerPath = Path.Combine(RuntimeEnvironment.GetRuntimeDirectory(), "csc.exe"); var srcPath = Path.Combine(Environment.CurrentDirectory, "..", "..", "fixtures", "x509app.cs"); var compileProcess = new Process() { StartInfo = new ProcessStartInfo() { FileName = compilerPath, Arguments = "/out:" + exePath + " " + srcPath, RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, } }; compileProcess.Start(); string output = compileProcess.StandardOutput.ReadToEnd(); string err = compileProcess.StandardOutput.ReadToEnd(); compileProcess.WaitForExit(); if (compileProcess.ExitCode != 0) { logger.WriteLine(output); logger.WriteLine(err); } Assert.Equal(0, compileProcess.ExitCode); var pSpec = new ProcessSpec { ExecutablePath = exePath, DisablePathMapping = true, }; var io = new StringProcessIO(); Container1.Run(pSpec, io).WaitForExit(); output = io.Output.ToString(); err = io.Error.ToString(); if (output.Contains("FAILURE")) { logger.WriteLine(output); logger.WriteLine(err); } Assert.Contains("SUCCESS", output); var username = "******" + Container1.Id; Container1.Destroy(); Container1Handle = null; var userDir = Path.Combine(Environment.GetEnvironmentVariable("SYSTEMDRIVE") + @"\", "Users", username); Assert.False(Directory.Exists(userDir)); }
public void UniqueUserPerContainer() { Container1 = CreateContainer(Container1Handle); Container2 = CreateContainer(Container2Handle); var pSpec = new ProcessSpec { ExecutablePath = "whoami.exe", DisablePathMapping = true, Privileged = false }; var io1 = new StringProcessIO(); var io2 = new StringProcessIO(); Container1.Run(pSpec, io1).WaitForExit(); Container2.Run(pSpec, io2).WaitForExit(); var user1 = io1.Output.ToString(); var user2 = io2.Output.ToString(); Assert.NotEmpty(user1); Assert.NotEmpty(user2); Assert.NotEqual(user1, user2); }
public void StartShortLivedTask() { Container1 = CreateContainer(Container1Handle); var pSpec = new ProcessSpec { ExecutablePath = "cmd.exe", DisablePathMapping = true, Arguments = new string[] { "/C \"set CONTAINER_HANDLE && set PROC_ENV\"" }, Environment = new Dictionary <string, string> { { "PROC_ENV", "VAL1" } }, }; // RUN THE SHORT LIVED PROCESS var io = new StringProcessIO(); var process = Container1.Run(pSpec, io); int exitCode; bool exited = process.TryWaitForExit(2000, out exitCode); var output = io.Output.ToString().Trim(); var error = io.Error.ToString().Trim(); // VERIFY THE PROCESS RAN AND EXITED Assert.True(exited); Assert.Equal(exitCode, 0); // VERIFY THE ENVIRONMENT WAS SET Assert.Contains("CONTAINER_HANDLE=" + Container1.Handle, output); Assert.Contains("PROC_ENV=VAL1", output); }
public void StartAndStopLongRunningProcess() { Container1 = CreateContainer(Container1Handle); var pSpec = new ProcessSpec { ExecutablePath = "ping.exe", DisablePathMapping = true, Arguments = new string[] { "127.0.0.1", "-n", "-1" }, }; // START THE LONG RUNNING PROCESS var io = new StringProcessIO(); var process = Container1.Run(pSpec, io); int exitCode; bool exited = process.TryWaitForExit(500, out exitCode); // VERIFY IT HASNT EXITED YET Assert.False(exited); var actualProcess = Process.GetProcessById(process.Id); Assert.False(actualProcess.HasExited); // KILL THE PROCESS AND WAIT FOR EXIT process.Kill(); exited = process.TryWaitForExit(2000, out exitCode); // VERIFY THE PROCESS WAS KILLED Assert.True(exited); Assert.True(actualProcess.HasExited); Assert.True(io.Output.ToString().Length > 0); }
public void Enforced() { Container1 = CreateContainer(Container1Handle); Container1.LimitDisk(10 * 1024); var pSpec = new ProcessSpec { ExecutablePath = "cmd", DisablePathMapping = true, Privileged = false, WorkingDirectory = Container1.Directory.UserPath, }; var io1 = new StringProcessIO(); var passed = 0; var failed = 0; for (int i = 0; i < 20; i++) { pSpec.Arguments = new[] { "/C", "echo Hi Bob > bob" + i + ".txt" }; var proc = Container1.Run(pSpec, io1); var exitCode = proc.WaitForExit(); if (exitCode == 0) { passed++; } else { failed++; } } Assert.Equal(13, passed); Assert.Equal(7, failed); }
public void FindMissingProcess() { Container1 = CreateContainer(Container1Handle); var foundProcessByPid = Container1.FindProcessById(-1); Assert.Null(foundProcessByPid); }
public void BasicNullTest() { var obj = new Container1(); var v = new Core.Validator(); ValidationResult res = v.ValidateObject(obj); Assert.IsFalse(res, "Property is null should not validate"); }
public void CanSetLargeQuota() { const ulong limit = 7UL * 1024 * 1024 * 1024; Container1 = CreateContainer(Container1Handle); Container1.LimitDisk(limit); Assert.Equal(limit, Container1.CurrentDiskLimit()); }
public void GuardDoesNotKeepTheContainerJobObjectOpen() { Container1.StartGuard(); var username = ContainerUsername(Container1); var userPids = UserPids(username); }
public void BasicFieldGraphTestRecursive() { var obj = new Container1(); obj.containedField = new Contained1(); var v = new Core.Validator(); ValidationResult res = v.ValidateObject(obj, ValidationFlags.StopOnFirstError | ValidationFlags.RecursiveValidation); Assert.IsFalse(res, "Object does not works for recursive validation"); }
public void StartAndStopLauncher() { Container1 = CreateContainer(Container1Handle); var pSpec = new ProcessSpec { ExecutablePath = @"cmd.exe", DisablePathMapping = true, Arguments = new string[] { "/C ping.exe 127.0.0.1 -n 1000" }, }; // START THE LONG RUNNING PROCESS var io = new StringProcessIO(); var process = Container1.Run(pSpec, io); int exitCode; bool exited = process.TryWaitForExit(500, out exitCode); // VERIFY IT HASNT EXITED YET Assert.False(exited); var actualProcess = Process.GetProcessById(process.Id); var childProcess = Process.GetProcesses().FirstOrDefault(x => { // Get some basic information about the process PROCESS_BASIC_INFORMATION pbi = new PROCESS_BASIC_INFORMATION(); try { uint bytesWritten; NtQueryInformationProcess(x.Handle, 0, ref pbi, (uint)Marshal.SizeOf(pbi), out bytesWritten); // == 0 is OK // Is it a child process of the process we're trying to terminate? return((int)pbi.InheritedFromUniqueProcessId == process.Id); } catch (Exception) { return(false); } }); Assert.False(actualProcess.HasExited); Assert.False(childProcess.HasExited); // KILL THE PROCESS AND WAIT FOR EXIT process.Kill(); exited = process.TryWaitForExit(2000, out exitCode); // VERIFY THE PROCESS WAS KILLED Assert.True(exited); Assert.True(actualProcess.HasExited); Assert.True(childProcess.HasExited); Assert.True(io.Output.ToString().Length > 0); }
public void BasicFieldGraphTestValidationResult() { var obj = new Container1(); obj.containedField = new Contained1(); obj.containedField.requiredProperty = "This is valid"; var v = new Core.Validator(); ValidationResult res = v.ValidateObject(obj, ValidationFlags.StopOnFirstError | ValidationFlags.RecursiveValidation); Assert.IsTrue(res, "Object field should validate."); }
public void DeletingContainer_DeletesDiskQuota() { Container1 = CreateContainer(Container1Handle); Container1.LimitDisk(5000); Assert.Equal(5000UL, Container1.CurrentDiskLimit()); ContainerService.DestroyContainer(Container1Handle); Assert.Equal(0UL, Container1.CurrentDiskLimit()); }
public void BasicFieldGraphTestRecursive() { var obj = new Container1(); obj.containedField = new Contained1(); var v = new Core.Validator(); ValidationResult res = v.ValidateObject(obj, ValidationFlags.StopOnFirstError | ValidationFlags.RecursiveValidation); Assert.IsFalse(res, "Object does not works for recursive validation"); }
public void ReturnsPropertiesInContainerInfo() { Container1 = CreateContainer(ContainerSpec); Container1.SetProperty("Foo", "The quick brown fox..."); Container1.SetProperty("Bar", "...jumped over the lazy dog."); var info = Container1.GetInfo(); Assert.Equal("The quick brown fox...", info.Properties["Foo"]); Assert.Equal("...jumped over the lazy dog.", info.Properties["Bar"]); }
public void BasicFieldGraphTestValidationError() { var obj = new Container1(); obj.containedField = new Contained1(); var v = new Core.Validator(); ValidationResult res = v.ValidateObject(obj); Assert.IsTrue(res, "Validate object method defaults to not validate contained objects"); res = v.ValidateObject(obj.containedField); Assert.IsFalse(res, "inner object must not validate"); }
public StartGuard() { Container1 = CreateContainer(Container1Handle); var pSpec = new ProcessSpec { ExecutablePath = @"cmd.exe", DisablePathMapping = true, Arguments = new string[] { "/C ping.exe 127.0.0.1 -n 1000" }, }; var io = new StringProcessIO(); Container1.Run(pSpec, io); }
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); }
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]))); }
public void PersistsProperties() { Container1 = CreateContainer(ContainerSpec); Container1.SetProperty("Phrase", "The quick brown fox..."); var value = Container1.GetProperty("Phrase"); Assert.Equal("The quick brown fox...", value); Container1.RemoveProperty("Phrase"); value = Container1.GetProperty("Phrase"); Assert.Null(value); }
public static void Test() { var container1 = new Container1 { Name = "name", ProductId = 101, Common = new CommonFields { Id = "1401", Time = DateTime.Today.Ticks } }; var container2 = new Container2 { Group = Guid.NewGuid(), Common = new CommonFields { Id = "2401", Time = DateTime.Today.Ticks } }; Test(container1); Test(container2); }
public void SetsPropertiesOnCreation() { ContainerSpec.Properties = new Dictionary <string, string> { { "Foo", "The quick brown fox..." }, { "Bar", "...jumped over the lazy dog." }, }; Container1 = CreateContainer(ContainerSpec); var fooValue = Container1.GetProperty("Foo"); var barValue = Container1.GetProperty("Bar"); Assert.Equal("The quick brown fox...", fooValue); Assert.Equal("...jumped over the lazy dog.", barValue); }
public void ContainerUserInContainerGroup() { Container1 = CreateContainer(Container1Handle); var pSpec = new ProcessSpec { ExecutablePath = "whoami.exe", DisablePathMapping = true, Arguments = new string[] { "/GROUPS" } }; var io = new StringProcessIO(); Container1.Run(pSpec, io).WaitForExit(); var groupOutput = io.Output.ToString(); Assert.Contains(UserGroupName, groupOutput); }
public void ContainerUserImpersonationDisabled() { Container1 = CreateContainer(Container1Handle); var pSpec = new ProcessSpec { ExecutablePath = "whoami.exe", DisablePathMapping = true, Arguments = new string[] { "/priv", "/fo", "csv" } }; var io = new StringProcessIO(); Container1.Run(pSpec, io).WaitForExit(); var privilegeOutput = io.Output.ToString(); Assert.Matches("\"SeImpersonatePrivilege\",[^,]+,\"Disabled\"", privilegeOutput); }
public void RunExecutablePathsWithDriveLetter() { Container1 = CreateContainer(Container1Handle); var pSpec = new ProcessSpec { ExecutablePath = @"C:\Windows\System32\cmd.exe", DisablePathMapping = false, Arguments = new string[] { "/c", "echo", "test-run" } }; var io = new StringProcessIO(); Container1.Run(pSpec, io).WaitForExit(); var output = io.Output.ToString(); Assert.Contains("test-run", output); }
public void PutsEscapedUserProcessesBackIntoJobObject() { Container1.StartGuard(); // ping.exe is a Console app. Windows will start a conhost for ping.exe which // is by default outside job objects. We want to assert that all processes // including conhost is added back to the JobObject. var username = ContainerUsername(Container1); var userPids = UserPids(username); var pidsInJob = new List <int>(); var sw = Stopwatch.StartNew(); while (userPids.Count != pidsInJob.Count && sw.ElapsedMilliseconds < 1000) { pidsInJob = new JobObject(Container1.Id).GetProcessIds().ToList(); } pidsInJob.Sort(); Assert.Equal(userPids, pidsInJob); }
public void FindAndKillProcess() { Container1 = CreateContainer(Container1Handle); 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 foundProcessByPid = Container1.FindProcessById(process.Id); // KILL THE PROCESS AND WAIT FOR EXIT foundProcessByPid.Kill(); int exitCode; var exited = process.TryWaitForExit(2000, out exitCode); // VERIFY THE PROCESS WAS KILLED Assert.True(exited); }
public void Delete() { float delay = 0.3f * HexGrid.GameSpeed; foundationPart = null; if (weapon1 != null) { HexGrid.Destroy(weapon1.gameObject, delay); weapon1 = null; } if (extractor1 != null) { HexGrid.Destroy(extractor1.gameObject, delay); extractor1 = null; } if (container != null) { HexGrid.Destroy(container.gameObject, delay); container = null; } if (assembler != null) { HexGrid.Destroy(assembler.gameObject, delay); assembler = null; } if (reactor1 != null) { HexGrid.Destroy(reactor1.gameObject, delay); reactor1 = null; } if (engine1 != null) { HexGrid.Destroy(engine1.gameObject, delay); engine1 = null; } }
public void BasicFieldGraphTestValidationResult() { var obj = new Container1(); obj.containedField = new Contained1(); obj.containedField.requiredProperty = "This is valid"; var v = new Core.Validator(); ValidationResult res = v.ValidateObject(obj, ValidationFlags.StopOnFirstError | ValidationFlags.RecursiveValidation); Assert.IsTrue(res, "Object field should validate."); }
public void BasicFieldGraphTestValidationError() { var obj = new Container1(); obj.containedField = new Contained1(); var v = new Core.Validator(); ValidationResult res = v.ValidateObject(obj); Assert.IsTrue(res, "Validate object method defaults to not validate contained objects"); res = v.ValidateObject(obj.containedField); Assert.IsFalse(res, "inner object must not validate"); }
public Nested(Container1 parent) { _parent = parent; }
public void Assemble() { MoveUpdateStats stats = MoveUpdateStats; if (stats == null) { return; } if (currentPos == null) { return; } /* * NextMove.Stats.EngineLevel * NextMove.Stats.ArmorLevel ** * NextMove.Stats.ContainerLevel * NextMove.Stats.ExtractorLevel * NextMove.Stats.WeaponLevel * NextMove.Stats.ReactorLevel * NextMove.Stats.ProductionLevel */ HexCell targetCell = HexGrid.GroundCells[currentPos]; // Place the engine if (stats.EngineLevel > 0) { if (engine1 == null && stats.EngineLevel == 1) { engine1 = HexGrid.InstantiatePrefab <Engine1>("Engine1"); engine1.UnitFrame = this; engine1.UnitId = UnitId; engine1.name = UnitId + "-Engine"; foundationPart = engine1; SetPlayerColor(playerId, engine1.gameObject); unitLayout.PlaceOnGround(engine1, targetCell, HexGrid); } } else { if (foundationPart != null && engine1 == foundationPart) { ReparentParts(); foundationPart = null; } if (engine1 != null) { HexGrid.Destroy(engine1.gameObject); engine1 = null; } } // Place big extractor if (stats.ExtractorLevel > 0) { if (extractor1 == null && stats.ExtractorLevel == 1) { if (foundationPart == null) { extractor1 = HexGrid.InstantiatePrefab <Extractor1>("ExtractorGround1"); unitLayout.PlaceOnGround(extractor1, targetCell, HexGrid); foundationPart = extractor1; extractor1.name = UnitId + "-Extractor"; extractor1.UnitFrame = this; SetPlayerColor(playerId, extractor1.gameObject); } } } else { if (foundationPart != null && extractor1 == foundationPart) { ReparentParts(); foundationPart = null; } if (extractor1 != null) { HexGrid.Destroy(extractor1.gameObject); extractor1 = null; } } if (stats.ProductionLevel > 0) { if (assembler == null || assembler.Level != stats.ProductionLevel) { if (assembler != null) { HexGrid.Destroy(assembler.gameObject); assembler = null; } assembler = HexGrid.InstantiatePrefab <Assembler1>("Assembler" + stats.ProductionLevel); assembler.UnitFrame = this; assembler.Level = stats.ProductionLevel; assembler.name = UnitId + "-Assembler"; SetPlayerColor(playerId, assembler.gameObject); if (foundationPart == null) { unitLayout.PlaceOnGround(assembler, targetCell, HexGrid); foundationPart = assembler; } else { if (unitLayout.frame1 != null) { HexGrid.Destroy(unitLayout.frame1.gameObject); unitLayout.frame1 = null; } unitLayout.PlaceBigPart(assembler, foundationPart, targetCell, HexGrid); } } } else { if (assembler != null) { HexGrid.Destroy(assembler.gameObject); assembler = null; } } if (stats.ContainerLevel > 0) { if (container == null || container.Level != stats.ContainerLevel) { if (container != null) { HexGrid.Destroy(container.gameObject); container = null; } container = HexGrid.InstantiatePrefab <Container1>("Container" + stats.ContainerLevel); container.UnitFrame = this; container.name = UnitId + "-Container"; container.Level = stats.ContainerLevel; SetPlayerColor(playerId, container.gameObject); if (foundationPart is Extractor1) { if (stats.ProductionLevel > 0) { // Put it on top of the assembler unitLayout.PlaceOnTop(container, foundationPart, targetCell, HexGrid, 0.6f); } else { unitLayout.PlaceOnTop(container, foundationPart, targetCell, HexGrid, 0.3f); } } else { if (foundationPart == null) { unitLayout.PlaceOnGround(container, targetCell, HexGrid); foundationPart = container; } else { // Blueprint if (!unitLayout.PlaceContainer(container, foundationPart, targetCell, HexGrid)) { } //unitLayout.PlacePart(container, foundationPart, targetCell, HexGrid); } } } container.UpdateContent(stats.ContainerFull); } else { if (container != null) { HexGrid.Destroy(container.gameObject); container = null; } } if (stats.ReactorLevel > 0) { if (reactor1 == null && stats.ReactorLevel == 1) { reactor1 = HexGrid.InstantiatePrefab <Reactor1>("Reactor1"); reactor1.UnitFrame = this; reactor1.name = UnitId + "-Reactor1"; SetPlayerColor(playerId, reactor1.gameObject); if (foundationPart is Extractor1) { if (stats.ProductionLevel > 0 && stats.ContainerLevel > 0) { // Put it on top of the container unitLayout.PlaceOnTop(reactor1, foundationPart, targetCell, HexGrid, 0.8f); } else { unitLayout.PlaceBigPart(reactor1, foundationPart, targetCell, HexGrid); } } else { if (foundationPart == null) { unitLayout.PlaceOnGround(reactor1, targetCell, HexGrid); foundationPart = reactor1; } else { unitLayout.PlacePart(reactor1, foundationPart, targetCell, HexGrid); } } } } else { if (reactor1 != null) { HexGrid.Destroy(reactor1.gameObject); reactor1 = null; } } if (stats.WeaponLevel > 0) { if (weapon1 == null && stats.WeaponLevel == 1) { weapon1 = HexGrid.InstantiatePrefab <Weapon1>("Weapon1"); weapon1.UnitFrame = this; weapon1.name = UnitId + "-Weapon"; SetPlayerColor(playerId, weapon1.gameObject); if (foundationPart == null) { unitLayout.PlaceOnGround(weapon1, targetCell, HexGrid); foundationPart = weapon1; } else if (foundationPart is Extractor1) { unitLayout.PlaceBigPart(weapon1, foundationPart, targetCell, HexGrid); } else { if (!unitLayout.PlaceWeapon(weapon1, foundationPart, targetCell, HexGrid)) { } } } weapon1.UpdateContent(stats.WeaponLoaded); } else { if (weapon1 != null) { HexGrid.Destroy(weapon1.gameObject); weapon1 = null; } } // Place small extractor if (stats.ExtractorLevel > 0) { if (extractor1 == null && stats.ExtractorLevel == 1) { if (foundationPart != null) { extractor1 = HexGrid.InstantiatePrefab <Extractor1>("Extractor1"); unitLayout.PlacePart(extractor1, foundationPart, targetCell, HexGrid); extractor1.name = UnitId + "-Extractor"; extractor1.UnitFrame = this; SetPlayerColor(playerId, extractor1.gameObject); } } } }
public Nested(Container1 parent) { _parent = parent; }
public void BasicNullTest() { var obj = new Container1(); var v = new Core.Validator(); ValidationResult res = v.ValidateObject(obj); Assert.IsFalse(res, "Property is null should not validate"); }