Skip to content

Commit ad352ae

Browse files
committed
override ToString() in the implementation classes of IAccessRule
1 parent 8f797be commit ad352ae

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

src/Smdn.Net.MuninNode/Smdn.Net.MuninNode.AccessRules/AddressListAccessRule.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,7 @@ public bool IsAcceptable(IPEndPoint remoteEndPoint)
5252

5353
return false;
5454
}
55+
56+
public override string ToString()
57+
=> $"{{{nameof(AddressListAccessRule)}: {nameof(addressListAllowFrom)}={string.Join(", ", addressListAllowFrom)}; {nameof(shouldConsiderIPv4MappedIPv6Address)}={shouldConsiderIPv4MappedIPv6Address}}}";
5558
}

src/Smdn.Net.MuninNode/Smdn.Net.MuninNode.AccessRules/LoopbackOnlyAccessRule.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ public bool IsAcceptable(IPEndPoint remoteEndPoint)
1212
=> IPAddress.IsLoopback(
1313
(remoteEndPoint ?? throw new ArgumentNullException(nameof(remoteEndPoint))).Address
1414
);
15+
16+
public override string ToString()
17+
=> nameof(LoopbackOnlyAccessRule);
1518
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// SPDX-FileCopyrightText: 2025 smdn <smdn@smdn.jp>
2+
// SPDX-License-Identifier: MIT
3+
using System;
4+
using System.Net;
5+
6+
using NUnit.Framework;
7+
8+
namespace Smdn.Net.MuninNode.AccessRules;
9+
10+
[TestFixture]
11+
public class AddressListAccessRuleTests {
12+
[Test]
13+
public new void ToString()
14+
{
15+
const string AllowFromAddressString = "192.0.2.1";
16+
17+
var options = new MuninNodeOptions().AllowFrom([IPAddress.Parse(AllowFromAddressString)]);
18+
19+
Assert.That(options.AccessRule!.ToString(), Is.Not.Empty);
20+
Assert.That(options.AccessRule!.ToString(), Does.Contain("AddressListAccessRule"));
21+
Assert.That(options.AccessRule!.ToString(), Does.Contain(AllowFromAddressString));
22+
}
23+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// SPDX-FileCopyrightText: 2025 smdn <smdn@smdn.jp>
2+
// SPDX-License-Identifier: MIT
3+
using System;
4+
using System.Net;
5+
6+
using NUnit.Framework;
7+
8+
namespace Smdn.Net.MuninNode.AccessRules;
9+
10+
[TestFixture]
11+
public class LoopbackOnlyAccessRuleTests {
12+
[Test]
13+
public new void ToString()
14+
{
15+
var options = new MuninNodeOptions().AllowFromLoopbackOnly();
16+
17+
Assert.That(options.AccessRule!.ToString(), Is.Not.Empty);
18+
Assert.That(options.AccessRule!.ToString(), Does.Contain("LoopbackOnlyAccessRule"));
19+
}
20+
}

0 commit comments

Comments
 (0)