using VoiceCat.Core; namespace VoiceCat.Tests; public sealed class ServerProfileTests { [Fact] public void ProfilesRoundTripWithoutPasswordMaterial() { string directory = Path.Combine(Path.GetTempPath(), "voicecat-profile-" + Guid.NewGuid().ToString("N")); string path = Path.Combine(directory, "servers.json"); try { var guest = ServerProfile.Create(" voice.example ", 8384, ServerAuthentication.Guest, nickname: " Cat "); var account = ServerProfile.Create("secure.example", 9443, ServerAuthentication.Account, username: " talon "); var store = new ServerProfileStore(path); store.Save([guest, account]); Assert.Equal([guest, account], store.Load()); string json = File.ReadAllText(path); Assert.Contains("\"authentication\": \"Account\"", json); Assert.DoesNotContain("password", json, StringComparison.OrdinalIgnoreCase); } finally { if (Directory.Exists(directory)) Directory.Delete(directory, true); } } [Fact] public void MissingCorruptAndInvalidProfilesDoNotBreakStartup() { string directory = Path.Combine(Path.GetTempPath(), "voicecat-profile-" + Guid.NewGuid().ToString("N")); string path = Path.Combine(directory, "servers.json"); try { var store = new ServerProfileStore(path); Assert.Empty(store.Load()); Directory.CreateDirectory(directory); File.WriteAllText(path, "not json"); Assert.Empty(store.Load()); File.WriteAllText(path, "[{\"id\":\"00000000-0000-0000-0000-000000000000\",\"host\":\"\",\"port\":0,\"authentication\":\"Guest\"}]"); Assert.Empty(store.Load()); } finally { if (Directory.Exists(directory)) Directory.Delete(directory, true); } } [Fact] public void AccountProfilesRequireAUsername() { Assert.Throws(() => ServerProfile.Create("voice.example", 8384, ServerAuthentication.Account)); } }