Files
ThreadPilot/Tests/ThreadPilot.Core.Tests/ProcessServiceSecurityTests.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

62 lines
2.3 KiB
C#

/*
* ThreadPilot - process service security guard tests.
*/
namespace ThreadPilot.Core.Tests
{
using Moq;
using ThreadPilot.Models;
using ThreadPilot.Services;
/// <summary>
/// Unit tests for security guard behavior in <see cref="ProcessService"/>.
/// </summary>
public sealed class ProcessServiceSecurityTests
{
/// <summary>
/// Ensures protected process priority updates are blocked before mutation.
/// </summary>
[Fact]
public async Task SetProcessPriority_ThrowsUnauthorized_ForProtectedProcess()
{
var security = new Mock<ISecurityService>(MockBehavior.Strict);
security
.Setup(s => s.ValidateProcessOperation("lsass", "SetProcessPriority"))
.Returns(false);
security
.Setup(s => s.AuditElevatedAction("SetProcessPriority", "lsass", false))
.Returns(Task.CompletedTask);
var service = new ProcessService(null, security.Object);
var process = new ProcessModel { Name = "lsass", ProcessId = 500 };
await Assert.ThrowsAsync<UnauthorizedAccessException>(async () =>
await service.SetProcessPriority(process, System.Diagnostics.ProcessPriorityClass.Normal));
security.VerifyAll();
}
/// <summary>
/// Ensures protected process affinity updates are blocked before mutation.
/// </summary>
[Fact]
public async Task SetProcessorAffinity_ThrowsUnauthorized_ForProtectedProcess()
{
var security = new Mock<ISecurityService>(MockBehavior.Strict);
security
.Setup(s => s.ValidateProcessOperation("System", "SetProcessAffinity"))
.Returns(false);
security
.Setup(s => s.AuditElevatedAction("SetProcessAffinity", "System", false))
.Returns(Task.CompletedTask);
var service = new ProcessService(null, security.Object);
var process = new ProcessModel { Name = "System", ProcessId = 4 };
await Assert.ThrowsAsync<UnauthorizedAccessException>(async () =>
await service.SetProcessorAffinity(process, 0x03));
security.VerifyAll();
}
}
}