/* * ThreadPilot - Core security unit tests. */ namespace ThreadPilot.Core.Tests { using Microsoft.Extensions.Logging.Abstractions; using Moq; using ThreadPilot.Services; public sealed class PowerPlanServiceSecurityTests { [Fact] public async Task ImportCustomPowerPlan_ReturnsFalse_ForRelativePath() { var service = CreateService(); var result = await service.ImportCustomPowerPlan("..\\evil.pow"); Assert.False(result); } [Fact] public async Task ImportCustomPowerPlan_ReturnsFalse_ForInvalidExtension() { var service = CreateService(); var filePath = Path.Combine(Path.GetTempPath(), "threadpilot-test.txt"); await File.WriteAllTextAsync(filePath, "content"); try { var result = await service.ImportCustomPowerPlan(filePath); Assert.False(result); } finally { if (File.Exists(filePath)) { File.Delete(filePath); } } } [Fact] public async Task ImportCustomPowerPlan_ReturnsFalse_ForEmptyFile() { var service = CreateService(); var filePath = Path.Combine(Path.GetTempPath(), $"threadpilot-empty-{Guid.NewGuid():N}.pow"); await File.WriteAllBytesAsync(filePath, []); try { Assert.False(await service.ImportCustomPowerPlan(filePath)); } finally { File.Delete(filePath); } } [Fact] public async Task ImportCustomPowerPlan_ReturnsFalse_ForMissingFile() { var service = CreateService(); var filePath = Path.Combine(Path.GetTempPath(), $"threadpilot-missing-{Guid.NewGuid():N}.pow"); Assert.False(await service.ImportCustomPowerPlan(filePath)); } [Theory] [InlineData("")] [InlineData("invalid-guid")] [InlineData("1234")] public async Task SetActivePowerPlanByGuidAsync_ReturnsFalse_ForInvalidGuid(string guid) { var service = CreateService(); var result = await service.SetActivePowerPlanByGuidAsync(guid); Assert.False(result); } private static PowerPlanService CreateService() { var enhancedLogger = new Mock(MockBehavior.Loose); return new PowerPlanService(NullLogger.Instance, enhancedLogger.Object); } } }