134 lines
3.8 KiB
C#
134 lines
3.8 KiB
C#
using TermRemoteCtl.Agent.Configuration;
|
|
|
|
namespace TermRemoteCtl.Agent.Tests.Configuration;
|
|
|
|
public class AgentOptionsValidatorTests
|
|
{
|
|
[Fact]
|
|
public void Validate_Fails_When_DataRoot_Is_Missing()
|
|
{
|
|
var options = new AgentOptions
|
|
{
|
|
DataRoot = "",
|
|
BindAddress = "0.0.0.0",
|
|
HttpsPort = 9443,
|
|
HttpPort = 5067
|
|
};
|
|
|
|
var validator = new AgentOptionsValidator();
|
|
|
|
var result = validator.Validate("Agent", options);
|
|
|
|
Assert.True(result.Failed);
|
|
Assert.Contains(result.Failures, failure => failure.Contains("DataRoot"));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("")]
|
|
[InlineData("not-an-address")]
|
|
public void Validate_Fails_When_BindAddress_Is_Invalid(string bindAddress)
|
|
{
|
|
var options = new AgentOptions
|
|
{
|
|
DataRoot = "C:\\ProgramData\\TermRemoteCtl",
|
|
BindAddress = bindAddress,
|
|
HttpsPort = 9443,
|
|
HttpPort = 5067,
|
|
WebSocketFrameFlushMilliseconds = 33,
|
|
RingBufferLineLimit = 4000
|
|
};
|
|
|
|
var validator = new AgentOptionsValidator();
|
|
|
|
var result = validator.Validate("Agent", options);
|
|
|
|
Assert.True(result.Failed);
|
|
Assert.Contains(result.Failures, failure => failure.Contains("BindAddress"));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(-1)]
|
|
[InlineData(65536)]
|
|
public void Validate_Fails_When_HttpPort_Is_Invalid(int httpPort)
|
|
{
|
|
var options = new AgentOptions
|
|
{
|
|
DataRoot = "C:\\ProgramData\\TermRemoteCtl",
|
|
BindAddress = "0.0.0.0",
|
|
HttpsPort = 9443,
|
|
HttpPort = httpPort,
|
|
WebSocketFrameFlushMilliseconds = 33,
|
|
RingBufferLineLimit = 4000
|
|
};
|
|
|
|
var validator = new AgentOptionsValidator();
|
|
|
|
var result = validator.Validate("Agent", options);
|
|
|
|
Assert.True(result.Failed);
|
|
Assert.Contains(result.Failures, failure => failure.Contains("HttpPort"));
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_Succeeds_When_HttpsPort_Is_Disabled_And_HttpPort_Is_Configured()
|
|
{
|
|
var options = new AgentOptions
|
|
{
|
|
DataRoot = "C:\\ProgramData\\TermRemoteCtl",
|
|
BindAddress = "localhost",
|
|
HttpsPort = 0,
|
|
HttpPort = 5067,
|
|
WebSocketFrameFlushMilliseconds = 33,
|
|
RingBufferLineLimit = 4000
|
|
};
|
|
|
|
var validator = new AgentOptionsValidator();
|
|
|
|
var result = validator.Validate("Agent", options);
|
|
|
|
Assert.False(result.Failed);
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_Fails_When_Http_And_Https_Are_Both_Disabled()
|
|
{
|
|
var options = new AgentOptions
|
|
{
|
|
DataRoot = "C:\\ProgramData\\TermRemoteCtl",
|
|
BindAddress = "0.0.0.0",
|
|
HttpsPort = 0,
|
|
HttpPort = 0,
|
|
WebSocketFrameFlushMilliseconds = 33,
|
|
RingBufferLineLimit = 4000
|
|
};
|
|
|
|
var validator = new AgentOptionsValidator();
|
|
|
|
var result = validator.Validate("Agent", options);
|
|
|
|
Assert.True(result.Failed);
|
|
Assert.Contains(result.Failures, failure => failure.Contains("HttpsPort") || failure.Contains("HttpPort"));
|
|
}
|
|
|
|
[Fact]
|
|
public void Validate_Fails_When_Http_And_Https_Share_The_Same_Port()
|
|
{
|
|
var options = new AgentOptions
|
|
{
|
|
DataRoot = "C:\\ProgramData\\TermRemoteCtl",
|
|
BindAddress = "localhost",
|
|
HttpsPort = 5067,
|
|
HttpPort = 5067,
|
|
WebSocketFrameFlushMilliseconds = 33,
|
|
RingBufferLineLimit = 4000
|
|
};
|
|
|
|
var validator = new AgentOptionsValidator();
|
|
|
|
var result = validator.Validate("Agent", options);
|
|
|
|
Assert.True(result.Failed);
|
|
Assert.Contains(result.Failures, failure => failure.Contains("must not be the same"));
|
|
}
|
|
}
|