Normalize base address in Node class to ensure consistent URI formatting
- Implemented `NormalizeBaseAddress` method to add a trailing slash to the `BaseAddress` when necessary, preventing issues with relative path merging in 3x-ui deployments. - Updated `Register` and `UpdateAddress` methods to utilize the normalization logic, ensuring that both methods handle base address input consistently. - Added unit tests to verify the normalization behavior for various input scenarios, enhancing the reliability of node address management. - Updated domain model documentation to reflect the new normalization behavior for `BaseAddress`.
This commit is contained in:
@@ -35,6 +35,29 @@ public class NodeTests
|
||||
);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("https://host.example.com/benis", "https://host.example.com/benis/")]
|
||||
[InlineData("https://host.example.com/benis/", "https://host.example.com/benis/")]
|
||||
[InlineData("https://host.example.com", "https://host.example.com/")]
|
||||
public void Register_NormalizesBaseAddressToTrailingSlash(string input, string expected)
|
||||
{
|
||||
var node = Node.Register("Node", new Uri(input), Credentials, null);
|
||||
|
||||
Assert.Equal(expected, node.BaseAddress.ToString());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("https://host.example.com/benis", "https://host.example.com/benis/")]
|
||||
[InlineData("https://host.example.com/benis/", "https://host.example.com/benis/")]
|
||||
public void UpdateAddress_NormalizesBaseAddressToTrailingSlash(string input, string expected)
|
||||
{
|
||||
var node = Node.Register("Node", new Uri("https://old.example.com"), Credentials, null);
|
||||
|
||||
node.UpdateAddress(new Uri(input));
|
||||
|
||||
Assert.Equal(expected, node.BaseAddress.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UpdateDetails_ChangesNameAndLocation()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user