using System.Runtime.CompilerServices; using ClawdDotNet.Core.Security; namespace ClawdDotNet.Core.Tests.Infrastructure; /// /// Keeps the key of out of the tests. /// /// Two things must come together: /// /// 1. relocates the key once when loading the /// test assembly into a throwaway directory. Without that the tests would create or read /// the real user key — on the development machine as on the /// build server. /// /// 2. Whoever changes the key during a test (for example to check that /// a foreign key does not read) must run in this collection. The store /// is static; without parallelism switched off, such a change would pull the key /// out from under a class running at the same time. Exactly that /// happened between the secret and the backup tests. /// [CollectionDefinition(Name, DisableParallelization = true)] public sealed class SecretKeyCollection { public const string Name = "SecretKey"; [ModuleInitializer] internal static void Init() { SecretKeyStore.UseDirectory(Path.Combine( Path.GetTempPath(), "clawd-tests", "keys", Guid.NewGuid().ToString("N"))); } }