LD-Uninstaller/tests/LDUninstaller.Tests/SafetyBlacklistTests.cs

90 lines
3.5 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.IO;
using LDUninstaller.Core.Junk;
using Xunit;
namespace LDUninstaller.Tests
{
public class SafetyBlacklistTests
{
[Theory]
[InlineData(@"C:\Windows")]
[InlineData(@"C:\Windows\System32")]
[InlineData(@"C:\Windows\System32\drivers\etc")]
[InlineData(@"C:\Program Files\WindowsApps")]
[InlineData(@"C:\ProgramData\Package Cache")]
[InlineData(@"")]
[InlineData(@" ")]
[InlineData(null)]
public void IsDangerousDirectory_CriticalPaths_ReturnsTrue(string? path)
{
bool isDangerous = SafetyBlacklist.IsDangerousDirectory(path!);
Assert.True(isDangerous);
}
[Fact]
public void IsDangerousDirectory_UserRootAndDocuments_Protected()
{
string userProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
string myDocuments = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
Assert.True(SafetyBlacklist.IsDangerousDirectory(userProfile));
Assert.True(SafetyBlacklist.IsDangerousDirectory(myDocuments));
Assert.True(SafetyBlacklist.IsDangerousDirectory(desktop));
}
[Fact]
public void IsDangerousDirectory_SafeAppFolder_ReturnsFalse()
{
string safeAppPath = @"C:\Program Files\VendorXYZ\App123";
Assert.False(SafetyBlacklist.IsDangerousDirectory(safeAppPath));
}
[Theory]
[InlineData(@"HKLM\SYSTEM")]
[InlineData(@"HKLM\SYSTEM\CurrentControlSet\Services")]
[InlineData(@"HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion")]
[InlineData(@"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run")]
[InlineData(@"HKLM_32\SOFTWARE\Microsoft\Windows\CurrentVersion")]
[InlineData(@"HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer")]
public void IsDangerousRegistryKey_CriticalKeys_ReturnsTrue(string regKey)
{
bool isDangerous = SafetyBlacklist.IsDangerousRegistryPath(regKey);
Assert.True(isDangerous);
}
[Theory]
[InlineData(@"HKLM\SOFTWARE\RandomVendor\CleanableApp")]
[InlineData(@"HKLM_32\SOFTWARE\RandomVendor\CleanableApp")]
[InlineData(@"HKCU\SOFTWARE\RandomVendor\CleanableApp")]
public void IsDangerousRegistryKey_SafeKeys_ReturnsFalse(string regKey)
{
bool isDangerous = SafetyBlacklist.IsDangerousRegistryPath(regKey);
Assert.False(isDangerous);
}
[Fact]
public void ExclusionManager_Integration_ProtectsCustomPaths()
{
string testCustomPath = @"D:\MyImportantProjects\CustomWork";
string testChildPath = @"D:\MyImportantProjects\CustomWork\nested\document.docx";
try
{
Assert.False(SafetyBlacklist.IsDangerousDirectory(testChildPath));
// Add to exclusion
ExclusionManager.AddExclusion(testCustomPath, "Birim Testi Koruması");
Assert.True(ExclusionManager.IsExcluded(testCustomPath));
Assert.True(ExclusionManager.IsExcluded(testChildPath));
Assert.True(SafetyBlacklist.IsDangerousDirectory(testChildPath));
}
finally
{
ExclusionManager.RemoveExclusion(testCustomPath);
}
}
}
}