From 3b4febda6bf749481eacadec1d7834a37b401da7 Mon Sep 17 00:00:00 2001 From: sladro Date: Fri, 27 Mar 2026 11:07:16 +0800 Subject: [PATCH] fix: restore windows agent https port contract --- .../src/TermRemoteCtl.Agent/Configuration/AgentOptions.cs | 2 +- .../AgentOptionsServiceCollectionExtensions.cs | 2 +- .../Configuration/AgentOptionsValidator.cs | 4 ++-- apps/windows_agent/src/TermRemoteCtl.Agent/Program.cs | 2 +- .../src/TermRemoteCtl.Agent/appsettings.json | 2 +- .../Configuration/AgentOptionsPipelineTests.cs | 8 ++++---- .../Configuration/AgentOptionsValidatorTests.cs | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/apps/windows_agent/src/TermRemoteCtl.Agent/Configuration/AgentOptions.cs b/apps/windows_agent/src/TermRemoteCtl.Agent/Configuration/AgentOptions.cs index c75a8bb..530892b 100644 --- a/apps/windows_agent/src/TermRemoteCtl.Agent/Configuration/AgentOptions.cs +++ b/apps/windows_agent/src/TermRemoteCtl.Agent/Configuration/AgentOptions.cs @@ -8,7 +8,7 @@ public sealed class AgentOptions public string BindAddress { get; set; } = "0.0.0.0"; - public int Port { get; set; } + public int HttpsPort { get; set; } public int WebSocketFrameFlushMilliseconds { get; set; } diff --git a/apps/windows_agent/src/TermRemoteCtl.Agent/Configuration/AgentOptionsServiceCollectionExtensions.cs b/apps/windows_agent/src/TermRemoteCtl.Agent/Configuration/AgentOptionsServiceCollectionExtensions.cs index e4b7604..912e681 100644 --- a/apps/windows_agent/src/TermRemoteCtl.Agent/Configuration/AgentOptionsServiceCollectionExtensions.cs +++ b/apps/windows_agent/src/TermRemoteCtl.Agent/Configuration/AgentOptionsServiceCollectionExtensions.cs @@ -17,7 +17,7 @@ public static class AgentOptionsServiceCollectionExtensions { options.DataRoot = effectiveOptions.DataRoot; options.BindAddress = effectiveOptions.BindAddress; - options.Port = effectiveOptions.Port; + options.HttpsPort = effectiveOptions.HttpsPort; options.WebSocketFrameFlushMilliseconds = effectiveOptions.WebSocketFrameFlushMilliseconds; options.RingBufferLineLimit = effectiveOptions.RingBufferLineLimit; }) diff --git a/apps/windows_agent/src/TermRemoteCtl.Agent/Configuration/AgentOptionsValidator.cs b/apps/windows_agent/src/TermRemoteCtl.Agent/Configuration/AgentOptionsValidator.cs index 5037b34..f3ff91e 100644 --- a/apps/windows_agent/src/TermRemoteCtl.Agent/Configuration/AgentOptionsValidator.cs +++ b/apps/windows_agent/src/TermRemoteCtl.Agent/Configuration/AgentOptionsValidator.cs @@ -13,9 +13,9 @@ public sealed class AgentOptionsValidator : IValidateOptions failures.Add("Agent:DataRoot must be configured."); } - if (options.Port is < 1 or > 65535) + if (options.HttpsPort is < 1 or > 65535) { - failures.Add("Agent:Port must be between 1 and 65535."); + failures.Add("Agent:HttpsPort must be between 1 and 65535."); } if (options.WebSocketFrameFlushMilliseconds <= 0) diff --git a/apps/windows_agent/src/TermRemoteCtl.Agent/Program.cs b/apps/windows_agent/src/TermRemoteCtl.Agent/Program.cs index 394c926..869cddd 100644 --- a/apps/windows_agent/src/TermRemoteCtl.Agent/Program.cs +++ b/apps/windows_agent/src/TermRemoteCtl.Agent/Program.cs @@ -4,7 +4,7 @@ using TermRemoteCtl.Agent.Configuration; var builder = WebApplication.CreateBuilder(args); var agentOptions = builder.Services.AddAgentOptions(builder.Configuration); -builder.WebHost.UseUrls($"http://{agentOptions.BindAddress}:{agentOptions.Port}"); +builder.WebHost.UseUrls($"http://{agentOptions.BindAddress}:{agentOptions.HttpsPort}"); var app = builder.Build(); agentOptions = app.Services.GetRequiredService>().Value; diff --git a/apps/windows_agent/src/TermRemoteCtl.Agent/appsettings.json b/apps/windows_agent/src/TermRemoteCtl.Agent/appsettings.json index 2f0f67e..aa50ffe 100644 --- a/apps/windows_agent/src/TermRemoteCtl.Agent/appsettings.json +++ b/apps/windows_agent/src/TermRemoteCtl.Agent/appsettings.json @@ -2,7 +2,7 @@ "Agent": { "DataRoot": "C:\\ProgramData\\TermRemoteCtl", "BindAddress": "0.0.0.0", - "Port": 9443, + "HttpsPort": 9443, "WebSocketFrameFlushMilliseconds": 33, "RingBufferLineLimit": 4000 } diff --git a/apps/windows_agent/tests/TermRemoteCtl.Agent.Tests/Configuration/AgentOptionsPipelineTests.cs b/apps/windows_agent/tests/TermRemoteCtl.Agent.Tests/Configuration/AgentOptionsPipelineTests.cs index ff891b2..1403818 100644 --- a/apps/windows_agent/tests/TermRemoteCtl.Agent.Tests/Configuration/AgentOptionsPipelineTests.cs +++ b/apps/windows_agent/tests/TermRemoteCtl.Agent.Tests/Configuration/AgentOptionsPipelineTests.cs @@ -14,7 +14,7 @@ public class AgentOptionsPipelineTests var configuration = BuildConfiguration(new Dictionary { ["Agent:BindAddress"] = "127.0.0.1", - ["Agent:Port"] = "9443", + ["Agent:HttpsPort"] = "9443", ["Agent:WebSocketFrameFlushMilliseconds"] = "33", ["Agent:RingBufferLineLimit"] = "4000" }); @@ -33,17 +33,17 @@ public class AgentOptionsPipelineTests } [Theory] - [InlineData("0", "33", "Port")] + [InlineData("0", "33", "HttpsPort")] [InlineData("9443", "0", "WebSocketFrameFlushMilliseconds")] public void ResolveOptions_Fails_When_Config_Is_Invalid( - string port, + string httpsPort, string flushMilliseconds, string expectedFailure) { var configuration = BuildConfiguration(new Dictionary { ["Agent:BindAddress"] = "127.0.0.1", - ["Agent:Port"] = port, + ["Agent:HttpsPort"] = httpsPort, ["Agent:WebSocketFrameFlushMilliseconds"] = flushMilliseconds, ["Agent:RingBufferLineLimit"] = "4000" }); diff --git a/apps/windows_agent/tests/TermRemoteCtl.Agent.Tests/Configuration/AgentOptionsValidatorTests.cs b/apps/windows_agent/tests/TermRemoteCtl.Agent.Tests/Configuration/AgentOptionsValidatorTests.cs index 1820931..533015a 100644 --- a/apps/windows_agent/tests/TermRemoteCtl.Agent.Tests/Configuration/AgentOptionsValidatorTests.cs +++ b/apps/windows_agent/tests/TermRemoteCtl.Agent.Tests/Configuration/AgentOptionsValidatorTests.cs @@ -11,7 +11,7 @@ public class AgentOptionsValidatorTests { DataRoot = "", BindAddress = "0.0.0.0", - Port = 9443 + HttpsPort = 9443 }; var validator = new AgentOptionsValidator();