37 lines
1.1 KiB
C#
37 lines
1.1 KiB
C#
using Microsoft.Extensions.Logging.Abstractions;
|
|||
|
|
|
||
|
|
using PrivaPub.Federation.Moderation;
|
||
|
|
using PrivaPub.Models.Federation;
|
||
|
|
|
||
|
|
namespace PrivaPub.Tests.Federation
|
||
|
|
{
|
||
|
|
public class DomainBlocksTests
|
||
|
|
{
|
||
|
|
[Fact]
|
||
|
|
public void A_block_covers_subdomains_but_not_lookalikes()
|
||
|
|
{
|
||
|
|
var blocks = new DomainBlocks(NullLogger<DomainBlocks>.Instance);
|
||
|
|
blocks.Load(new[] { new DomainBlock { Domain = "evil.example", Severity = DomainBlockSeverity.Silence } });
|
||
|
|
|
||
|
|
Assert.NotNull(blocks.Find("evil.example"));
|
||
|
|
Assert.NotNull(blocks.Find("A.Evil.Example."));
|
||
|
|
Assert.Null(blocks.Find("notevil.example"));
|
||
|
|
Assert.False(blocks.IsSuspended("evil.example"));
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public void A_suspension_is_found_from_any_subdomain()
|
||
|
|
{
|
||
|
|
var blocks = new DomainBlocks(NullLogger<DomainBlocks>.Instance);
|
||
|
|
blocks.Load(new[]
|
||
|
|
{
|
||
|
|
new DomainBlock { Domain = " Spam.Example. ", Severity = DomainBlockSeverity.Suspend },
|
||
|
|
new DomainBlock { Domain = "", Severity = DomainBlockSeverity.Suspend }
|
||
|
|
});
|
||
|
|
|
||
|
|
Assert.True(blocks.IsSuspended("deep.inside.spam.example"));
|
||
|
|
Assert.False(blocks.IsSuspended("example"));
|
||
|
|
Assert.Null(blocks.Find(default));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|