feat: add tray remote connection settings

This commit is contained in:
2026-09-20 22:40:42 +08:00
parent baf7a47418
commit 1d5c472e88
5 changed files with 165 additions and 17 deletions
@@ -5,6 +5,7 @@ using System.Text.Json;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection;
using WxAgent.Core;
using WxAgent.Service;
using Xunit;
@@ -92,6 +93,40 @@ public sealed class ServiceBoundaryTests
finally { Directory.Delete(dir, true); }
}
[Fact]
public void EmbeddedRemoteConfigurationIsValidatedWithTheService()
{
var dir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")); Directory.CreateDirectory(dir);
try
{
var options = new ServiceOptions
{
CredentialFile = Path.Combine(dir, "credentials.json"),
DataDirectory = dir,
Remote = new RemoteAgentOptions
{
AuthAddress = "http://10.1.1.104:8090",
Token = "node-token",
NodeId = "node-1",
AllowInsecureHttp = true
}
};
File.WriteAllText(options.CredentialFile, JsonSerializer.Serialize(new[]
{
new ServiceCredential("tray", ServiceOptions.HashToken("local-token"), ["read"], [])
}));
options.Validate();
var invalid = new ServiceOptions
{
CredentialFile = options.CredentialFile,
DataDirectory = options.DataDirectory,
Remote = options.Remote! with { AllowInsecureHttp = false }
};
Assert.Throws<ArgumentException>(() => invalid.Validate());
}
finally { Directory.Delete(dir, true); }
}
[Fact]
public void RuntimeLogWritesFullOperationalMessagesToTheRequestedPath()
{