{
public static class ChainTests
{
- internal static bool CanModifyStores { get; } = TestEnvironmentConfiguration.CanModifyStores;
-
private static bool TrustsMicrosoftDotComRoot
{
get
}
}
+ [Fact]
[PlatformSpecific(TestPlatforms.AnyUnix)]
- [ConditionalFact(nameof(CanModifyStores))]
public static void VerifyChainFromHandle_Unix()
{
using (var microsoftDotCom = new X509Certificate2(TestData.MicrosoftDotComSslCertBytes))
}
}
- [ConditionalFact(nameof(TrustsMicrosoftDotComRoot), nameof(CanModifyStores))]
+ [ConditionalFact(nameof(TrustsMicrosoftDotComRoot))]
[OuterLoop(/* Modifies user certificate store */)]
public static void BuildChain_MicrosoftDotCom_WithRootCertInUserAndSystemRootCertStores()
{
<Link>Common\System\IO\PersistedFiles.Names.Unix.cs</Link>
</Compile>
<Compile Include="HostnameMatchTests.Unix.cs" />
- <Compile Include="TestEnvironmentConfiguration.Unix.cs" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetsOSX)' == 'true'">
<Compile Include="X509StoreMutableTests.OSX.cs" />
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.IO;
-
-namespace System.Security.Cryptography.X509Certificates.Tests
-{
- internal static partial class TestEnvironmentConfiguration
- {
- static partial void DetermineCanModifyStores(ref bool canModify)
- {
- try
- {
- canModify = DetermineCanModifyStores();
- }
- catch
- {
- // This is a little counterintuitive. If the capability probe fails,
- // assert that the feature works. Then we'll hopefully get diagnosable
- // errors out of the test failures.
- canModify = true;
- }
- }
-
- private static bool DetermineCanModifyStores()
- {
- // Check the directory permissions and whether the filesystem supports chmod.
- // The only real expected failure from this method is that at the very end
- // `stat.Mode == mode` will fail, because fuseblk (NTFS) returns success on chmod,
- // but is a no-op.
-
- uint userId = Interop.Sys.GetEUid();
- string certStoresFeaturePath = PersistedFiles.GetUserFeatureDirectory("cryptography", "x509stores");
-
- Directory.CreateDirectory(certStoresFeaturePath);
-
- // Check directory permissions:
-
- Interop.Sys.FileStatus dirStat;
- if (Interop.Sys.Stat(certStoresFeaturePath, out dirStat) != 0)
- {
- return false;
- }
-
- if (dirStat.Uid != userId)
- {
- return false;
- }
-
- if ((dirStat.Mode & (int)Interop.Sys.Permissions.S_IRWXU) != (int)Interop.Sys.Permissions.S_IRWXU)
- {
- return false;
- }
-
- string probeFilename =
- Path.Combine(certStoresFeaturePath, $"{Guid.NewGuid().ToString("N")}.chmod");
-
- try
- {
- using (FileStream stream = new FileStream(probeFilename, FileMode.Create))
- {
- Interop.Sys.FileStatus stat;
- if (Interop.Sys.FStat(stream.SafeFileHandle, out stat) != 0)
- {
- return false;
- }
-
- if (stat.Uid != userId)
- {
- return false;
- }
-
- // The product code here has a lot of stuff it does.
- // This capabilities probe will just check that chmod works.
- int mode = stat.Mode;
-
- // Flip all of the O bits.
- mode ^= (int)Interop.Sys.Permissions.S_IRWXO;
-
- if (Interop.Sys.FChMod(stream.SafeFileHandle, mode) < 0)
- {
- return false;
- }
-
- // Verify the chmod applied.
- if (Interop.Sys.FStat(stream.SafeFileHandle, out stat) != 0)
- {
- return false;
- }
-
- // On fuseblk (NTFS) this will return false, because the fchmod
- // call returned success without being able to actually apply
- // mode-bits.
- return stat.Mode == mode;
- }
- }
- finally
- {
- try
- {
- File.Delete(probeFilename);
- }
- catch
- {
- // Ignore any failure on delete.
- }
- }
- }
- }
-}
namespace System.Security.Cryptography.X509Certificates.Tests
{
- internal static partial class TestEnvironmentConfiguration
+ internal static class TestEnvironmentConfiguration
{
- internal static bool CanModifyStores { get; }
-
internal static bool RunManualTests { get; } =
!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("CRYPTOGRAPHY_MANUAL_TESTS"));
-
- static TestEnvironmentConfiguration()
- {
- bool canModifyStores = true;
- DetermineCanModifyStores(ref canModifyStores);
- CanModifyStores = canModifyStores;
- }
-
- static partial void DetermineCanModifyStores(ref bool canModify);
}
}
[Collection("X509Filesystem")]
public static class X509FilesystemTests
{
- private static bool CanModifyStores { get; } = TestEnvironmentConfiguration.CanModifyStores;
private static bool RunManualTests { get; } = TestEnvironmentConfiguration.RunManualTests;
[OuterLoop]
});
}
- [ConditionalFact(nameof(CanModifyStores))]
+ [Fact]
[OuterLoop(/* Alters user/machine state */)]
private static void X509Store_AddOne()
{
});
}
- [ConditionalFact(nameof(CanModifyStores))]
+ [Fact]
[OuterLoop(/* Alters user/machine state */)]
private static void X509Store_AddOneAfterUpgrade()
{
});
}
- [ConditionalFact(nameof(CanModifyStores))]
+ [Fact]
[OuterLoop(/* Alters user/machine state */)]
private static void X509Store_DowngradePermissions()
{
});
}
- [ConditionalFact(nameof(CanModifyStores))]
+ [Fact]
[OuterLoop(/* Alters user/machine state */)]
private static void X509Store_AddAfterDispose()
{
});
}
- [ConditionalFact(nameof(CanModifyStores))]
+ [Fact]
[OuterLoop(/* Alters user/machine state */)]
private static void X509Store_AddAndClear()
{
});
}
- [ConditionalFact(nameof(CanModifyStores))]
+ [Fact]
[OuterLoop(/* Alters user/machine state */)]
private static void X509Store_AddDuplicate()
{
});
}
- [ConditionalFact(nameof(CanModifyStores))]
+ [Fact]
[OuterLoop(/* Alters user/machine state */)]
private static void X509Store_AddTwo()
{
});
}
- [ConditionalFact(nameof(CanModifyStores))]
+ [Fact]
[OuterLoop(/* Alters user/machine state */)]
private static void X509Store_AddTwo_UpgradePrivateKey()
{
});
}
- [ConditionalFact(nameof(CanModifyStores))]
+ [Fact]
[OuterLoop(/* Alters user/machine state */)]
private static void X509Store_AddTwo_UpgradePrivateKey_NoDowngrade()
{
});
}
- [ConditionalFact(nameof(CanModifyStores))]
+ [Fact]
[OuterLoop(/* Alters user/machine state */)]
private static void X509Store_DistinctCollections()
{
});
}
- [ConditionalFact(nameof(CanModifyStores))]
+ [Fact]
[OuterLoop(/* Alters user/machine state */)]
private static void X509Store_Add4_Remove1()
{
});
}
- [ConditionalTheory(nameof(CanModifyStores))]
+ [Theory]
[OuterLoop(/* Alters user/machine state */)]
[InlineData(false)]
[InlineData(true)]
});
}
- [ConditionalFact(nameof(CanModifyStores))]
+ [Fact]
[OuterLoop( /* Alters user/machine state */)]
private static void X509Store_FiltersDuplicateOnLoad()
{