36 lines
1.4 KiB
C#
36 lines
1.4 KiB
C#
using ZB.MOM.WW.Auth.Ldap.Internal;
|
|
|
|
namespace ZB.MOM.WW.Auth.Ldap.Tests;
|
|
|
|
public class LdapEndpointParserTests
|
|
{
|
|
[Theory]
|
|
[InlineData("dc2.example.com", 636, "dc2.example.com", 636)] // bare host -> default port
|
|
[InlineData("dc2.example.com:3894", 636, "dc2.example.com", 3894)] // explicit port wins
|
|
[InlineData(" dc2.example.com : 3894 ", 636, "dc2.example.com", 3894)] // whitespace tolerated
|
|
public void TryParse_ValidEntry_Succeeds(string entry, int defaultPort, string host, int port)
|
|
{
|
|
Assert.True(LdapEndpointParser.TryParse(entry, defaultPort, out var ep, out _));
|
|
Assert.Equal(host, ep.Host);
|
|
Assert.Equal(port, ep.Port);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("")] // empty
|
|
[InlineData(" ")] // whitespace
|
|
[InlineData(":636")] // empty host
|
|
[InlineData("dc2:0")] // port below range
|
|
[InlineData("dc2:65536")] // port above range
|
|
[InlineData("dc2:abc")] // non-numeric port
|
|
[InlineData("2001:db8::1:636")] // IPv6 literal (unsupported, >1 colon)
|
|
public void TryParse_InvalidEntry_Fails(string entry)
|
|
{
|
|
Assert.False(LdapEndpointParser.TryParse(entry, 636, out _, out var error));
|
|
Assert.NotEmpty(error);
|
|
}
|
|
|
|
[Fact]
|
|
public void Endpoint_ToString_IsHostColonPort() =>
|
|
Assert.Equal("dc2:3894", new LdapEndpoint("dc2", 3894).ToString());
|
|
}
|