diff --git a/apps/windows_agent/src/TermRemoteCtl.Agent/Configuration/AgentEndpointConfiguration.cs b/apps/windows_agent/src/TermRemoteCtl.Agent/Configuration/AgentEndpointConfiguration.cs new file mode 100644 index 0000000..0c2956e --- /dev/null +++ b/apps/windows_agent/src/TermRemoteCtl.Agent/Configuration/AgentEndpointConfiguration.cs @@ -0,0 +1,24 @@ +using System.Net; +using Microsoft.AspNetCore.Server.Kestrel.Core; + +namespace TermRemoteCtl.Agent.Configuration; + +public static class AgentEndpointConfiguration +{ + public static Uri BuildListenUri(AgentOptions options) + { + return new UriBuilder(Uri.UriSchemeHttps, options.BindAddress, options.HttpsPort).Uri; + } + + public static void ConfigureHttpsEndpoint(KestrelServerOptions kestrel, AgentOptions options) + { + if (string.Equals(options.BindAddress, "localhost", StringComparison.OrdinalIgnoreCase)) + { + kestrel.ListenLocalhost(options.HttpsPort, listenOptions => listenOptions.UseHttps()); + return; + } + + var address = IPAddress.Parse(options.BindAddress); + kestrel.Listen(address, options.HttpsPort, listenOptions => listenOptions.UseHttps()); + } +} diff --git a/apps/windows_agent/src/TermRemoteCtl.Agent/Program.cs b/apps/windows_agent/src/TermRemoteCtl.Agent/Program.cs index 869cddd..800cabb 100644 --- a/apps/windows_agent/src/TermRemoteCtl.Agent/Program.cs +++ b/apps/windows_agent/src/TermRemoteCtl.Agent/Program.cs @@ -4,7 +4,11 @@ using TermRemoteCtl.Agent.Configuration; var builder = WebApplication.CreateBuilder(args); var agentOptions = builder.Services.AddAgentOptions(builder.Configuration); -builder.WebHost.UseUrls($"http://{agentOptions.BindAddress}:{agentOptions.HttpsPort}"); +// Task 2 uses ASP.NET Core's local development certificate so HttpsPort is a truthful HTTPS listener. +builder.WebHost.ConfigureKestrel(kestrel => +{ + AgentEndpointConfiguration.ConfigureHttpsEndpoint(kestrel, agentOptions); +}); var app = builder.Build(); agentOptions = app.Services.GetRequiredService>().Value; diff --git a/apps/windows_agent/tests/TermRemoteCtl.Agent.IntegrationTests/UnitTest1.cs b/apps/windows_agent/tests/TermRemoteCtl.Agent.IntegrationTests/UnitTest1.cs deleted file mode 100644 index 3b8e06d..0000000 --- a/apps/windows_agent/tests/TermRemoteCtl.Agent.IntegrationTests/UnitTest1.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace TermRemoteCtl.Agent.IntegrationTests; - -public class UnitTest1 -{ - [Fact(Skip = "Placeholder until integration scenarios are defined.")] - public void PlaceholderTest() - { - } -} 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 1403818..ff47ac6 100644 --- a/apps/windows_agent/tests/TermRemoteCtl.Agent.Tests/Configuration/AgentOptionsPipelineTests.cs +++ b/apps/windows_agent/tests/TermRemoteCtl.Agent.Tests/Configuration/AgentOptionsPipelineTests.cs @@ -8,6 +8,25 @@ namespace TermRemoteCtl.Agent.Tests.Configuration; public class AgentOptionsPipelineTests { + [Fact] + public void BuildListenUri_Uses_Https_Scheme_And_HttpsPort() + { + var options = new AgentOptions + { + DataRoot = "C:\\ProgramData\\TermRemoteCtl", + BindAddress = "127.0.0.1", + HttpsPort = 9443, + WebSocketFrameFlushMilliseconds = 33, + RingBufferLineLimit = 4000 + }; + + var uri = AgentEndpointConfiguration.BuildListenUri(options); + + Assert.Equal(Uri.UriSchemeHttps, uri.Scheme); + Assert.Equal("127.0.0.1", uri.Host); + Assert.Equal(9443, uri.Port); + } + [Fact] public void ResolveOptions_Uses_DataRoot_Fallback_When_Config_Omits_DataRoot() {