Files
voice-cat/dotnet/tests/VoiceCat.Tests/ServerProfileTests.cs
T
Talon 52f7f51e59
.NET port / test (macos-latest) (push) Canceled after 0s
.NET port / test (ubuntu-24.04) (push) Canceled after 0s
.NET port / test (windows-latest) (push) Canceled after 0s
.NET port / apple-client (push) Canceled after 0s
.NET port / cpp-conformance (push) Canceled after 0s
Add managed server profiles and account login
2026-09-16 22:13:34 +02:00

51 lines
2.0 KiB
C#

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<ArgumentException>(() => ServerProfile.Create("voice.example", 8384, ServerAuthentication.Account));
}
}