public void TestLockdown() { using (ShimsContext.Create()) { PrisonTestsHelper.PrisonLockdownFakes(); string createdUser = null; string userProfileDestination = null; bool saveWasInvoked = false; ShimWindowsUsersAndGroups.CreateUserStringString = (username, password) => { createdUser = username; return; }; ShimPrison.AllInstances.ChangeRegistryUserProfileString = (pris, destination) => { userProfileDestination = destination; return; }; ShimXmlObjectSerializer.AllInstances.WriteObjectStreamObject = (data, writeStream, fakePrison) => { saveWasInvoked = true; return; }; Prison prison = new Prison(); prison.Tag = "uhtst"; PrisonRules prisonRules = new PrisonRules(); prisonRules.CellType = RuleType.None; prisonRules.PrisonHomePath = @"c:\prison_tests\p3"; prison.Lockdown(prisonRules); Assert.AreEqual(createdUser, prison.User.Username); Assert.IsTrue(createdUser.Contains(prison.Tag)); // The user profile has to be moved in the prison home dir Assert.IsTrue(userProfileDestination.Contains(prisonRules.PrisonHomePath)); Assert.IsTrue(saveWasInvoked); } }
public void PrisonApplyNetworkAppTest() { using (ShimsContext.Create()) { PrisonTestsHelper.PrisonLockdownFakes(); PrisonTestsHelper.ApplyNetworkRuleFakes(); ManagementObject mobj = null; ShimManagementObject.AllInstances.Put = (@this) => { mobj = @this; return(new ShimManagementPath()); }; Prison prison = new Prison(); prison.Tag = "uhtst"; PrisonRules prisonRules = new PrisonRules(); prisonRules.CellType = RuleType.None; prisonRules.CellType |= RuleType.Network; prisonRules.UrlPortAccess = 56444; prisonRules.AppPortOutboundRateLimitBitsPerSecond = 500; prisonRules.PrisonHomePath = @"c:\prison_tests\p3"; prison.Lockdown(prisonRules); Assert.AreEqual(mobj["ThrottleRateAction"].ToString(), 500.ToString()); Assert.IsTrue(mobj["URIMatchCondition"].ToString().Contains(56444.ToString())); } }
public void PrisonInitFilesystemTest() { using (ShimsContext.Create()) { PrisonTestsHelper.InitFilesystemRuleFakes(); Prison prison = new Prison(); prison.Tag = "uhtst"; Prison.Init(); } }
public void TestPrisonNetworkListCellInstances() { using (ShimsContext.Create()) { string username = "******"; PrisonTestsHelper.ListNetworkRuleFakes(username); Prison prison = new Prison(); prison.Tag = "uhtst"; Dictionary <RuleType, RuleInstanceInfo[]> rules = Prison.ListCellInstances(); Assert.AreEqual(username, rules[RuleType.Network][0].Name); } }
public void TestListPrisonUsers() { string username = "******"; string[] newwinusers = { "Administrator", "Guest", "openshift_service", username }; using (ShimsContext.Create()) { ShimWindowsUsersAndGroups.GetUsers = () => { return(newwinusers); }; PrisonTestsHelper.PersistanceReadDataFake(username); PrisonUser[] users = PrisonUser.ListUsers(); Assert.IsTrue(users.Length == Array.FindAll(newwinusers, user => user.StartsWith("prison")).Length); } }
public void PrisonApplyWindowStationTest() { using (ShimsContext.Create()) { int winStationPtr = 2658; PrisonTestsHelper.PrisonLockdownFakes(); PrisonTestsHelper.ApplyWindowStationRuleFakes(winStationPtr); string username = null; ShimWindowStation.NativeOpenWindowStationString = (user) => { username = user; return(new IntPtr(winStationPtr)); }; ShimWindowStation.NativeCreateWindowStationString = (user) => { username = user; return(new IntPtr(winStationPtr)); }; Prison prison = new Prison(); prison.Tag = "uhtst"; PrisonRules prisonRules = new PrisonRules(); prisonRules.CellType = RuleType.None; prisonRules.CellType |= RuleType.WindowStation; prisonRules.PrisonHomePath = @"c:\prison_tests\p3"; prison.Lockdown(prisonRules); Native.PROCESS_INFORMATION processInfo = new Native.PROCESS_INFORMATION { hProcess = new IntPtr(2400), hThread = new IntPtr(2416), dwProcessId = 5400, dwThreadId = 4544 }; PrisonTestsHelper.PrisonCreateProcessAsUserFakes(processInfo); ShimPrison.GetCurrentSessionId = () => { return(0); }; ShimProcess.GetProcessByIdInt32 = (id) => { return(new Process()); }; ShimJobObject.AllInstances.AddProcessProcess = (jobObject, proc) => { return; }; ShimPrison.AllInstances.AddProcessToGuardJobObjectProcess = (fakePrison, proc) => { return; }; ShimPrison.AllInstances.ResumeProcessProcess = (fakePrison, pProcess) => { }; Process process = prison.Execute( @"c:\windows\system32\cmd.exe", @"/c echo test"); Assert.AreEqual(prison.desktopName, string.Format(@"{0}\Default", username)); } }
public void PrisonApplyFilesystemTest() { using (ShimsContext.Create()) { PrisonTestsHelper.PrisonLockdownFakes(); PrisonTestsHelper.ApplyFilesystemFakes(); Prison prison = new Prison(); prison.Tag = "uhtst"; PrisonRules prisonRules = new PrisonRules(); prisonRules.CellType = RuleType.None; prisonRules.CellType |= RuleType.Filesystem; prisonRules.PrisonHomePath = @"c:\prison_tests\p3"; prison.Lockdown(prisonRules); } }
public void PrisonReattachWindowStationTest() { using (ShimsContext.Create()) { PrisonTestsHelper.PrisonLockdownFakes(); PrisonTestsHelper.ApplyWindowStationRuleFakes(2658); Prison prison = new Prison(); prison.Tag = "uhtst"; PrisonRules prisonRules = new PrisonRules(); prisonRules.CellType = RuleType.None; prisonRules.CellType |= RuleType.WindowStation; prisonRules.PrisonHomePath = @"c:\prison_tests\p3"; prison.Lockdown(prisonRules); prison.Reattach(); } }
public void TestPrisonHttpsysListCellInstances() { using (ShimsContext.Create()) { PrisonTestsHelper.ListHttpsysRuleFakes(); Prison prison = new Prison(); prison.Tag = "uhtst"; Dictionary <RuleType, RuleInstanceInfo[]> rules = Prison.ListCellInstances(); Assert.AreEqual(1, rules[RuleType.Httpsys].Length); foreach (var url in rules[RuleType.Httpsys]) { Assert.IsTrue(url.Name.Contains(prison.Tag)); } } }
public void TestDestroy() { using (ShimsContext.Create()) { PrisonTestsHelper.PrisonLockdownFakes(); Prison prison = new Prison(); prison.Tag = "uhtst"; PrisonRules prisonRules = new PrisonRules(); prisonRules.CellType = RuleType.None; prisonRules.PrisonHomePath = @"c:\prison_tests\p3"; prison.Lockdown(prisonRules); PrisonTestsHelper.PrisonDestroyFakes(); prison.Destroy(); } }
public void TestLoadPrisonAndAttach() { using (ShimsContext.Create()) { PrisonTestsHelper.PrisonLockdownFakes(); Prison prison = new Prison(); prison.Tag = "uhtst"; PrisonRules prisonRules = new PrisonRules(); prisonRules.CellType = RuleType.None; prisonRules.PrisonHomePath = @"c:\prison_tests\p3"; prison.Lockdown(prisonRules); PrisonTestsHelper.PrisonLoadFakes(prison.ID); Prison prisonLoaded = Prison.LoadPrisonAndAttach(prison.ID); Assert.IsTrue(prisonLoaded != null); Assert.IsTrue(prisonLoaded.ID == prison.ID); } }
public void PrisonDestroyHttpsysTest() { using (ShimsContext.Create()) { PrisonTestsHelper.PrisonLockdownFakes(); PrisonTestsHelper.ApplyHttpsysFakes(); Prison prison = new Prison(); prison.Tag = "uhtst"; PrisonRules prisonRules = new PrisonRules(); prisonRules.CellType = RuleType.None; prisonRules.CellType |= RuleType.Httpsys; prisonRules.UrlPortAccess = 5400; prisonRules.PrisonHomePath = @"c:\prison_tests\p3"; prison.Lockdown(prisonRules); PrisonTestsHelper.PrisonDestroyFakes(); PrisonTestsHelper.HttpsysRemovePortAccessFakes(); prison.Destroy(); } }
public void PrisonApplyHttpsysTest() { using (ShimsContext.Create()) { PrisonTestsHelper.PrisonLockdownFakes(); PrisonTestsHelper.ApplyHttpsysFakes(); string addPortCommand = null; ShimCommand.ExecuteCommandString = (command) => { addPortCommand = command; return(0); }; Prison prison = new Prison(); prison.Tag = "uhtst"; PrisonRules prisonRules = new PrisonRules(); prisonRules.CellType = RuleType.None; prisonRules.CellType |= RuleType.Httpsys; prisonRules.UrlPortAccess = 5400; prisonRules.PrisonHomePath = @"c:\prison_tests\p3"; prison.Lockdown(prisonRules); Assert.IsTrue(addPortCommand.Contains(prisonRules.UrlPortAccess.ToString())); } }
public void PrisonApplyDiskTest() { using (ShimsContext.Create()) { PrisonTestsHelper.PrisonLockdownFakes(); PrisonTestsHelper.ApplyDiskRuleFakes(); long quotaSetTo = 0; ShimDisk.ShimDiskQuotaManager.SetDiskQuotaLimitStringStringInt64 = (WindowsUsername, Path, DiskQuotaBytes) => { quotaSetTo = DiskQuotaBytes; return; }; Prison prison = new Prison(); prison.Tag = "uhtst"; PrisonRules prisonRules = new PrisonRules(); prisonRules.CellType = RuleType.None; prisonRules.CellType |= RuleType.Disk; prisonRules.DiskQuotaBytes = 500; prisonRules.PrisonHomePath = @"c:\prison_tests\p3"; prison.Lockdown(prisonRules); Assert.AreEqual(quotaSetTo, 500); } }
public void PrisonDestroyNetworkTest() { using (ShimsContext.Create()) { PrisonTestsHelper.PrisonLockdownFakes(); PrisonTestsHelper.ApplyNetworkRuleFakes(); Prison prison = new Prison(); prison.Tag = "uhtst"; PrisonRules prisonRules = new PrisonRules(); prisonRules.CellType = RuleType.None; prisonRules.CellType |= RuleType.Network; prisonRules.NetworkOutboundRateLimitBitsPerSecond = 500; prisonRules.PrisonHomePath = @"c:\prison_tests\p3"; prison.Lockdown(prisonRules); PrisonTestsHelper.PrisonDestroyFakes(); ShimNetwork.RemoveOutboundThrottlePolicyString = (username) => { return; }; prison.Destroy(); } }
public void TestCreatePrisonUserOK() { using (ShimsContext.Create()) { string newuser = string.Empty; ShimWindowsUsersAndGroups.ExistsUserString = (username) => { return(false); }; ShimWindowsUsersAndGroups.CreateUserStringString = (username, password) => { newuser = username; return; }; ShimWindowsUsersAndGroups.GetLocalUserSidString = (username) => { return("a string"); }; ShimPersistence.SaveValueStringStringObject = (group, key, value) => { return; }; PrisonUser user = new PrisonUser("untst"); user.Create(); ShimWindowsUsersAndGroups.GetUsers = () => { return(new string [] { "Administrator", "Guest", "openshift_service", newuser }); }; PrisonTestsHelper.PersistanceReadDataFake(newuser); PrisonUser[] users = PrisonUser.ListUsers("untst"); Assert.IsTrue(Array.Find(users, u => u.Username == user.Username) != null); } }
public void TestPrisonWindowStationkListCellInstances() { using (ShimsContext.Create()) { var fakedStations = new List <string>() { "WinSta0", "WinStaLalala" }; PrisonTestsHelper.ListWindowStationRuleFakes(fakedStations); Prison prison = new Prison(); prison.Tag = "uhtst"; Dictionary <RuleType, RuleInstanceInfo[]> rules = Prison.ListCellInstances(); Assert.AreEqual(fakedStations.Count, rules[RuleType.WindowStation].Length); foreach (var wstation in rules[RuleType.WindowStation]) { Assert.IsTrue(fakedStations.Contains(wstation.Name)); } } }
public void TestLoad() { using (ShimsContext.Create()) { PrisonTestsHelper.PrisonLockdownFakes(); Prison prison = new Prison(); prison.Tag = "uhtst"; PrisonRules prisonRules = new PrisonRules(); prisonRules.CellType = RuleType.None; prisonRules.PrisonHomePath = @"c:\prison_tests\p3"; prison.Lockdown(prisonRules); PrisonTestsHelper.PrisonLoadFakes(prison.ID); Prison[] prisons = Prison.Load(); Assert.AreEqual(prisons.Length, 1); foreach (var prisonItem in prisons) { Assert.IsTrue(prisonItem.ID == prison.ID); } } }