/*
* ThreadPilot - security service unit tests.
*/
namespace ThreadPilot.Core.Tests
{
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using ThreadPilot.Services;
///
/// Unit tests for validation behavior.
///
public sealed class SecurityServiceTests
{
///
/// Ensures protected processes cannot be modified.
///
[Theory]
[InlineData("lsass")]
[InlineData("lsass.exe")]
[InlineData("csrss")]
[InlineData("wininit.exe")]
public void ValidateProcessOperation_ReturnsFalse_ForProtectedProcesses(string processName)
{
var service = CreateService();
var allowed = service.ValidateProcessOperation(processName, "SetProcessPriority");
Assert.False(allowed);
}
///
/// Ensures known-safe process operations remain allowed.
///
[Fact]
public void ValidateProcessOperation_ReturnsTrue_ForAllowedOperationOnRegularProcess()
{
var service = CreateService();
var allowed = service.ValidateProcessOperation("notepad", "SetProcessAffinity");
Assert.True(allowed);
}
///
/// Ensures invalid process operations are rejected.
///
[Fact]
public void ValidateProcessOperation_ReturnsFalse_ForInvalidOperation()
{
var service = CreateService();
var allowed = service.ValidateProcessOperation("notepad", "TerminateProcess");
Assert.False(allowed);
}
///
/// Ensures elevated operation validation tolerates log-control characters.
///
[Fact]
public void ValidateElevatedOperation_ReturnsTrue_ForKnownOperation_WithControlCharacters()
{
var service = CreateService();
var allowed = service.ValidateElevatedOperation("SetProcessPriority\r\n");
Assert.True(allowed);
}
private static SecurityService CreateService()
{
var enhancedLogger = new Mock(MockBehavior.Loose);
return new SecurityService(NullLogger.Instance, enhancedLogger.Object);
}
}
}