/// <summary> /// Do a test action against read only file system (for Unix). /// </summary> /// <param name="testAction">Test action to perform. The string argument will be read only directory.</param> /// <param name="subDirectoryName">Optional subdirectory to create.</param> protected void ReadOnly_FileSystemHelper(Action <string> testAction, string subDirectoryName = null) { // Set up read only file system // Set up the source directory string sourceDirectory = GetTestFilePath(); if (subDirectoryName == null) { Directory.CreateDirectory(sourceDirectory); } else { string sourceSubDirectory = Path.Combine(sourceDirectory, subDirectoryName); Directory.CreateDirectory(sourceSubDirectory); } // Set up the target directory and mount as a read only string readOnlyDirectory = GetTestFilePath(); Directory.CreateDirectory(readOnlyDirectory); Assert.Equal(0, AdminHelpers.RunAsSudo($"mount --bind {sourceDirectory} {readOnlyDirectory}")); try { Assert.Equal(0, AdminHelpers.RunAsSudo($"mount -o remount,ro,bind {sourceDirectory} {readOnlyDirectory}")); testAction(readOnlyDirectory); } finally { // Clean up test environment Assert.Equal(0, AdminHelpers.RunAsSudo($"umount {readOnlyDirectory}")); } }
public void Dispose() { if (AdminHelpers.IsProcessElevated()) { ExtractAndCompileMof("CleanUp.mof"); } }
public void ClearLogTest() { if (!AdminHelpers.IsProcessElevated()) { return; } string source = Guid.NewGuid().ToString("N"); string logName = Guid.NewGuid().ToString("N"); try { EventLog.CreateEventSource(source, logName); using (EventLog myLog = new EventLog()) { myLog.Source = source; myLog.WriteEntry("Writing to event log."); Assert.True(myLog.Entries.Count != 0); myLog.Clear(); Assert.Equal(0, myLog.Entries.Count); } } finally { EventLog.DeleteEventSource(source); } }
public MofFixture() { if (AdminHelpers.IsProcessElevated()) { ExtractAndCompileMof("WmiEBvt.mof"); } }
public void DeleteUnregisteredSource() { if (!AdminHelpers.IsProcessElevated()) { return; } Assert.Throws <System.ArgumentException>(() => EventLog.DeleteEventSource(Guid.NewGuid().ToString("N"))); }
public void CheckSourceExistsArgumentNull() { if (!AdminHelpers.IsProcessElevated()) { return; } Assert.False(EventLog.SourceExists(null)); }
private static int RunSetupScript(string args = null) { try { return(AdminHelpers.RunAsSudo($"bash {ScriptName} {args}")); } catch { // Could not find the file return(1); } }
void Application_AcquireRequestState(object sender, EventArgs e) { // Ако има право на достъп, трябва да има и UserID if (HttpSession.IsAuthenticated && (HttpSession.UserID == 0)) { FormsAuthentication.SignOut(); string loginUrl = FormsAuthentication.LoginUrl + "?ReturnUrl=" + HttpUtility.UrlEncode(Request.FilePath); Response.Redirect(loginUrl, true); } // Ако няма ID на саита if (HttpSession.CurrentSiteID == 0) { HttpSession.CurrentSiteID = AdminHelpers.GetMainSiteID(); } }
public void CheckSourceExistenceAndDeletion() { if (!AdminHelpers.IsProcessElevated()) { return; } string source = Guid.NewGuid().ToString("N"); try { EventLog.CreateEventSource(source, "MyNewLog"); Assert.True(EventLog.SourceExists(source)); } finally { EventLog.DeleteEventSource(source); } Assert.False(EventLog.SourceExists(source)); }
public void DeleteLogTest() { if (!AdminHelpers.IsProcessElevated()) { return; } string source = Guid.NewGuid().ToString("N"); string logName = Guid.NewGuid().ToString("N"); try { EventLog.CreateEventSource(source, logName); Assert.True(EventLog.Exists(logName)); } finally { EventLog.Delete(logName); Assert.False(EventLog.Exists(logName)); } }