Files
ThreadPilot/Tests/ThreadPilot.Core.Tests/SecurityServiceTests.cs
T
PrimeBuild-pc c9253f879d Enhance CI/release workflow and app robustness
Add comprehensive CI and release improvements (coverage collection, Codecov upload, SBOM generation), split release workflow into build/smoke-test/release stages with deterministic version resolution, artifact uploads, winget manifest updates and changelog generation. Add a pre-commit hook to block large or unwanted artifacts. Introduce runtime improvements: smoke-test startup mode, improved unhandled/dispatcher/task-exception reporting, ThreadPilotException error codes, single-instance behavior adjustments, and logging enhancements. UI and UX changes include a new Logs tab and LogViewer wiring, DWM title-bar theming helper, navigation serialization/unsaved-changes guard, system-tray update backoff logic, and related viewmodel/service integrations. Also add installer template, helper classes, tests, docs, packaging and build scripts, and minor .gitignore updates.
2026-04-15 22:38:35 +02:00

78 lines
2.4 KiB
C#

/*
* ThreadPilot - security service unit tests.
*/
namespace ThreadPilot.Core.Tests
{
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using ThreadPilot.Services;
/// <summary>
/// Unit tests for <see cref="SecurityService"/> validation behavior.
/// </summary>
public sealed class SecurityServiceTests
{
/// <summary>
/// Ensures protected processes cannot be modified.
/// </summary>
[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);
}
/// <summary>
/// Ensures known-safe process operations remain allowed.
/// </summary>
[Fact]
public void ValidateProcessOperation_ReturnsTrue_ForAllowedOperationOnRegularProcess()
{
var service = CreateService();
var allowed = service.ValidateProcessOperation("notepad", "SetProcessAffinity");
Assert.True(allowed);
}
/// <summary>
/// Ensures invalid process operations are rejected.
/// </summary>
[Fact]
public void ValidateProcessOperation_ReturnsFalse_ForInvalidOperation()
{
var service = CreateService();
var allowed = service.ValidateProcessOperation("notepad", "TerminateProcess");
Assert.False(allowed);
}
/// <summary>
/// Ensures elevated operation validation tolerates log-control characters.
/// </summary>
[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<IEnhancedLoggingService>(MockBehavior.Loose);
return new SecurityService(NullLogger<SecurityService>.Instance, enhancedLogger.Object);
}
}
}