fix: enable https listener for windows agent host
This commit is contained in:
parent
3b4febda6b
commit
d6f96f95e5
@ -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());
|
||||
}
|
||||
}
|
||||
@ -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<IOptions<AgentOptions>>().Value;
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
namespace TermRemoteCtl.Agent.IntegrationTests;
|
||||
|
||||
public class UnitTest1
|
||||
{
|
||||
[Fact(Skip = "Placeholder until integration scenarios are defined.")]
|
||||
public void PlaceholderTest()
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -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()
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user