Пример #1
0
        public void WhenRefreshWhitelist_AndWhitelisted_IpV4_PeerIsBanned_ThenWhitelistDoesNotContainPeer(string bannedIp, string nonBannedIp)
        {
            // Arrange.
            var datetimeProvider = Substitute.For <IDateTimeProvider>();

            datetimeProvider.GetTimeOffset().Returns(new DateTimeOffset(new DateTime(2017, 8, 30, 1, 2, 3)));

            var logger        = Substitute.For <ILogger>();
            var loggerFactory = Substitute.For <ILoggerFactory>();

            loggerFactory.CreateLogger(Arg.Any <string>()).Returns(logger);

            var bannedEndpoint    = new IPEndPoint(IPAddress.Parse(bannedIp), 80);
            var notBannedEndpoint = new IPEndPoint(IPAddress.Parse(nonBannedIp), 80);

            IPeerAddressManager peerAddressManager =
                this.CreateTestPeerAddressManager(new[] { bannedEndpoint, notBannedEndpoint });

            var         dnsServer  = Substitute.For <IDnsServer>();
            IMasterFile masterFile = null;

            dnsServer
            .When(m => m.SwapMasterfile(Arg.Any <IMasterFile>()))
            .Do(x => masterFile = x.Arg <IMasterFile>());

            var nodeSettings = NodeSettings.Default(this.Network);
            var dnsSettings  = new DnsSettings(nodeSettings);

            dnsSettings.DnsHostName = "stratis.test.com";
            var connectionSettings = new ConnectionManagerSettings(nodeSettings);

            peerBanning.IsBanned(bannedEndpoint)
            .Returns(true);

            var whitelistManager = new WhitelistManager(datetimeProvider, loggerFactory, peerAddressManager,
                                                        dnsServer, connectionSettings, dnsSettings, peerBanning);

            // Act.
            whitelistManager.RefreshWhitelist();

            // Assert.
            masterFile.Should().NotBeNull();

            var ipAddressResourceRecords = masterFile
                                           .Get(new Question(new Domain(dnsSettings.DnsHostName), RecordType.ANY))
                                           .OfType <IPAddressResourceRecord>().ToList();

            ipAddressResourceRecords.Single().IPAddress.MapToIPv6()
            .Should().NotBe(bannedEndpoint.Address.MapToIPv6());
        }
Пример #2
0
        public void WhenRefreshWhitelist_AndInactivePeersInWhitelist_ThenWhitelistDoesNotContainInactivePeers()
        {
            // Arrange.
            Mock <IDateTimeProvider> mockDateTimeProvider = new Mock <IDateTimeProvider>();

            Mock <ILogger>        mockLogger        = new Mock <ILogger>();
            Mock <ILoggerFactory> mockLoggerFactory = new Mock <ILoggerFactory>();

            mockLoggerFactory.Setup(l => l.CreateLogger(It.IsAny <string>())).Returns(mockLogger.Object);
            ILoggerFactory loggerFactory = mockLoggerFactory.Object;

            mockDateTimeProvider.Setup(d => d.GetTimeOffset()).Returns(new DateTimeOffset(new DateTime(2017, 8, 30, 1, 2, 3))).Verifiable();
            IDateTimeProvider dateTimeProvider = mockDateTimeProvider.Object;

            int inactiveTimePeriod = 3000;

            IPAddress      activeIpAddressOne      = IPAddress.Parse("::ffff:192.168.0.1");
            NetworkAddress activeNetworkAddressOne = new NetworkAddress(activeIpAddressOne, 80);

            IPAddress      activeIpAddressTwo      = IPAddress.Parse("::ffff:192.168.0.2");
            NetworkAddress activeNetworkAddressTwo = new NetworkAddress(activeIpAddressTwo, 80);

            IPAddress      activeIpAddressThree      = IPAddress.Parse("::ffff:192.168.0.3");
            NetworkAddress activeNetworkAddressThree = new NetworkAddress(activeIpAddressThree, 80);

            IPAddress      activeIpAddressFour      = IPAddress.Parse("::ffff:192.168.0.4");
            NetworkAddress activeNetworkAddressFour = new NetworkAddress(activeIpAddressFour, 80);

            List <Tuple <NetworkAddress, DateTimeOffset> > activeTestDataSet = new List <Tuple <NetworkAddress, DateTimeOffset> >()
            {
                new Tuple <NetworkAddress, DateTimeOffset> (activeNetworkAddressOne, dateTimeProvider.GetTimeOffset().AddSeconds(-inactiveTimePeriod).AddSeconds(10)),
                new Tuple <NetworkAddress, DateTimeOffset>(activeNetworkAddressTwo, dateTimeProvider.GetTimeOffset().AddSeconds(-inactiveTimePeriod).AddSeconds(20)),
                new Tuple <NetworkAddress, DateTimeOffset>(activeNetworkAddressThree, dateTimeProvider.GetTimeOffset().AddSeconds(-inactiveTimePeriod).AddSeconds(30)),
                new Tuple <NetworkAddress, DateTimeOffset>(activeNetworkAddressFour, dateTimeProvider.GetTimeOffset().AddSeconds(-inactiveTimePeriod).AddSeconds(40))
            };

            IPAddress      inactiveIpAddressOne      = IPAddress.Parse("::ffff:192.168.100.1");
            NetworkAddress inactiveNetworkAddressOne = new NetworkAddress(inactiveIpAddressOne, 80);

            IPAddress      inactiveIpAddressTwo      = IPAddress.Parse("::ffff:192.168.100.2");
            NetworkAddress inactiveNetworkAddressTwo = new NetworkAddress(inactiveIpAddressTwo, 80);

            IPAddress      inactiveIpAddressThree      = IPAddress.Parse("::ffff:192.168.100.3");
            NetworkAddress inactiveNetworkAddressThree = new NetworkAddress(inactiveIpAddressThree, 80);

            List <Tuple <NetworkAddress, DateTimeOffset> > inactiveTestDataSet = new List <Tuple <NetworkAddress, DateTimeOffset> >()
            {
                new Tuple <NetworkAddress, DateTimeOffset> (inactiveNetworkAddressOne, dateTimeProvider.GetTimeOffset().AddSeconds(-inactiveTimePeriod).AddSeconds(-10)),
                new Tuple <NetworkAddress, DateTimeOffset>(inactiveNetworkAddressTwo, dateTimeProvider.GetTimeOffset().AddSeconds(-inactiveTimePeriod).AddSeconds(-20)),
                new Tuple <NetworkAddress, DateTimeOffset>(inactiveNetworkAddressThree, dateTimeProvider.GetTimeOffset().AddSeconds(-inactiveTimePeriod).AddSeconds(-30))
            };

            IPeerAddressManager peerAddressManager = this.CreateTestPeerAddressManager(activeTestDataSet.Concat(inactiveTestDataSet).ToList());

            IMasterFile       spiedMasterFile = null;
            Mock <IDnsServer> mockDnsServer   = new Mock <IDnsServer>();

            mockDnsServer.Setup(d => d.SwapMasterfile(It.IsAny <IMasterFile>()))
            .Callback <IMasterFile>(m =>
            {
                spiedMasterFile = m;
            })
            .Verifiable();

            NodeSettings nodeSettings = NodeSettings.Default();
            DnsSettings  dnsSettings  = new Mock <DnsSettings>().Object;

            dnsSettings.DnsPeerBlacklistThresholdInSeconds = inactiveTimePeriod;
            dnsSettings.DnsHostName = "Purple.test.com";

            WhitelistManager whitelistManager = new WhitelistManager(dateTimeProvider, loggerFactory, peerAddressManager, mockDnsServer.Object, nodeSettings, dnsSettings);

            // Act.
            whitelistManager.RefreshWhitelist();

            // Assert.
            spiedMasterFile.Should().NotBeNull();

            Question question = new Question(new Domain(dnsSettings.DnsHostName), RecordType.AAAA);
            IList <IResourceRecord> resourceRecords = spiedMasterFile.Get(question);

            resourceRecords.Should().NotBeNullOrEmpty();

            IList <IPAddressResourceRecord> ipAddressResourceRecords = resourceRecords.OfType <IPAddressResourceRecord>().ToList();

            ipAddressResourceRecords.Should().HaveSameCount(activeTestDataSet);

            foreach (Tuple <NetworkAddress, DateTimeOffset> testData in activeTestDataSet)
            {
                ipAddressResourceRecords.SingleOrDefault(i => i.IPAddress.Equals(testData.Item1.Endpoint.Address)).Should().NotBeNull("the ip address is active and should be in DNS");
            }

            foreach (Tuple <NetworkAddress, DateTimeOffset> testData in inactiveTestDataSet)
            {
                ipAddressResourceRecords.SingleOrDefault(i => i.IPAddress.Equals(testData.Item1.Endpoint.Address)).Should().BeNull("the ip address is inactive and should not be returned from DNS");
            }
        }
Пример #3
0
        public void WhenRefreshWhitelist_AndOwnIPInPeers_AndAreRunningFullNode_ThenWhitelistDoesContainOwnIP()
        {
            // Arrange.
            Mock <IDateTimeProvider> mockDateTimeProvider = new Mock <IDateTimeProvider>();

            Mock <ILogger>        mockLogger        = new Mock <ILogger>();
            Mock <ILoggerFactory> mockLoggerFactory = new Mock <ILoggerFactory>();

            mockLoggerFactory.Setup(l => l.CreateLogger(It.IsAny <string>())).Returns(mockLogger.Object);
            ILoggerFactory loggerFactory = mockLoggerFactory.Object;

            mockDateTimeProvider.Setup(d => d.GetTimeOffset()).Returns(new DateTimeOffset(new DateTime(2017, 8, 30, 1, 2, 3))).Verifiable();
            IDateTimeProvider dateTimeProvider = mockDateTimeProvider.Object;

            int inactiveTimePeriod = 5000;

            IPAddress      activeIpAddressOne      = IPAddress.Parse("::ffff:192.168.0.1");
            NetworkAddress activeNetworkAddressOne = new NetworkAddress(activeIpAddressOne, 80);

            IPAddress      activeIpAddressTwo      = IPAddress.Parse("::ffff:192.168.0.2");
            NetworkAddress activeNetworkAddressTwo = new NetworkAddress(activeIpAddressTwo, 80);

            IPAddress      activeIpAddressThree      = IPAddress.Parse("::ffff:192.168.0.3");
            NetworkAddress activeNetworkAddressThree = new NetworkAddress(activeIpAddressThree, 80);

            IPAddress      externalIPAdress       = IPAddress.Parse("::ffff:192.168.99.99");
            int            externalPort           = 80;
            NetworkAddress externalNetworkAddress = new NetworkAddress(externalIPAdress, externalPort);

            List <Tuple <NetworkAddress, DateTimeOffset> > activeTestDataSet = new List <Tuple <NetworkAddress, DateTimeOffset> >()
            {
                new Tuple <NetworkAddress, DateTimeOffset> (activeNetworkAddressOne, dateTimeProvider.GetTimeOffset().AddSeconds(-inactiveTimePeriod).AddSeconds(10)),
                new Tuple <NetworkAddress, DateTimeOffset>(activeNetworkAddressTwo, dateTimeProvider.GetTimeOffset().AddSeconds(-inactiveTimePeriod).AddSeconds(20)),
                new Tuple <NetworkAddress, DateTimeOffset>(activeNetworkAddressThree, dateTimeProvider.GetTimeOffset().AddSeconds(-inactiveTimePeriod).AddSeconds(30)),
                new Tuple <NetworkAddress, DateTimeOffset> (externalNetworkAddress, dateTimeProvider.GetTimeOffset().AddSeconds(-inactiveTimePeriod).AddSeconds(40))
            };

            IPeerAddressManager peerAddressManager = this.CreateTestPeerAddressManager(activeTestDataSet);

            string[] args = new string[] {
                $"-dnspeeractivethreshold={inactiveTimePeriod.ToString()}",
                $"-externalip={externalNetworkAddress.Endpoint.Address.ToString()}",
                $"-port={externalPort.ToString()}",
            };

            IMasterFile       spiedMasterFile = null;
            Mock <IDnsServer> mockDnsServer   = new Mock <IDnsServer>();

            mockDnsServer.Setup(d => d.SwapMasterfile(It.IsAny <IMasterFile>()))
            .Callback <IMasterFile>(m =>
            {
                spiedMasterFile = m;
            })
            .Verifiable();

            Network      network      = Network.PurpleTest;
            NodeSettings nodeSettings = new NodeSettings(network.Name, network).LoadArguments(args);
            DnsSettings  dnsSettings  = new Mock <DnsSettings>().Object;

            dnsSettings.DnsFullNode = true;
            dnsSettings.DnsPeerBlacklistThresholdInSeconds = inactiveTimePeriod;
            dnsSettings.DnsHostName = "Purple.test.com";

            WhitelistManager whitelistManager = new WhitelistManager(dateTimeProvider, loggerFactory, peerAddressManager, mockDnsServer.Object, nodeSettings, dnsSettings);

            // Act.
            whitelistManager.RefreshWhitelist();

            // Assert.
            spiedMasterFile.Should().NotBeNull();

            Question question = new Question(new Domain(dnsSettings.DnsHostName), RecordType.AAAA);
            IList <IResourceRecord> resourceRecords = spiedMasterFile.Get(question);

            resourceRecords.Should().NotBeNullOrEmpty();

            IList <IPAddressResourceRecord> ipAddressResourceRecords = resourceRecords.OfType <IPAddressResourceRecord>().ToList();

            ipAddressResourceRecords.Should().HaveSameCount(activeTestDataSet);

            foreach (Tuple <NetworkAddress, DateTimeOffset> testData in activeTestDataSet)
            {
                ipAddressResourceRecords.SingleOrDefault(i => i.IPAddress.Equals(testData.Item1.Endpoint.Address)).Should().NotBeNull();
            }
        }
        public void WhenRefreshWhitelist_AndActivePeersAvailable_ThenWhitelistContainsActivePeers()
        {
            // Arrange.
            Mock <IDateTimeProvider> mockDateTimeProvider = new Mock <IDateTimeProvider>();

            Mock <ILogger>        mockLogger        = new Mock <ILogger>();
            Mock <ILoggerFactory> mockLoggerFactory = new Mock <ILoggerFactory>();

            mockLoggerFactory.Setup(l => l.CreateLogger(It.IsAny <string>())).Returns(mockLogger.Object);
            ILoggerFactory loggerFactory = mockLoggerFactory.Object;

            mockDateTimeProvider.Setup(d => d.GetTimeOffset()).Returns(new DateTimeOffset(new DateTime(2017, 8, 30, 1, 2, 3))).Verifiable();
            IDateTimeProvider dateTimeProvider = mockDateTimeProvider.Object;

            int inactiveTimePeriod = 2000;

            IPAddress activeIpAddressOne = IPAddress.Parse("::ffff:192.168.0.1");
            var       activeEndpointOne  = new IPEndPoint(activeIpAddressOne, 80);

            IPAddress activeIpAddressTwo = IPAddress.Parse("::ffff:192.168.0.2");
            var       activeEndpointTwo  = new IPEndPoint(activeIpAddressTwo, 80);

            IPAddress activeIpAddressThree = IPAddress.Parse("::ffff:192.168.0.3");
            var       activeEndpointThree  = new IPEndPoint(activeIpAddressThree, 80);

            IPAddress activeIpAddressFour = IPAddress.Parse("::ffff:192.168.0.4");
            var       activeEndpointFour  = new IPEndPoint(activeIpAddressFour, 80);

            var testDataSet = new List <Tuple <IPEndPoint, DateTimeOffset> >()
            {
                new Tuple <IPEndPoint, DateTimeOffset> (activeEndpointOne, dateTimeProvider.GetTimeOffset().AddSeconds(-inactiveTimePeriod).AddSeconds(10)),
                new Tuple <IPEndPoint, DateTimeOffset>(activeEndpointTwo, dateTimeProvider.GetTimeOffset().AddSeconds(-inactiveTimePeriod).AddSeconds(20)),
                new Tuple <IPEndPoint, DateTimeOffset>(activeEndpointThree, dateTimeProvider.GetTimeOffset().AddSeconds(-inactiveTimePeriod).AddSeconds(30)),
                new Tuple <IPEndPoint, DateTimeOffset>(activeEndpointFour, dateTimeProvider.GetTimeOffset().AddSeconds(-inactiveTimePeriod).AddSeconds(40))
            };

            IPeerAddressManager peerAddressManager = this.CreateTestPeerAddressManager(testDataSet);

            IMasterFile       spiedMasterFile = null;
            Mock <IDnsServer> mockDnsServer   = new Mock <IDnsServer>();

            mockDnsServer.Setup(d => d.SwapMasterfile(It.IsAny <IMasterFile>()))
            .Callback <IMasterFile>(m =>
            {
                spiedMasterFile = m;
            })
            .Verifiable();

            NodeSettings nodeSettings = NodeSettings.Default();
            DnsSettings  dnsSettings  = new Mock <DnsSettings>().Object;

            dnsSettings.DnsPeerBlacklistThresholdInSeconds = inactiveTimePeriod;
            dnsSettings.DnsHostName = "stratis.test.com";
            ConnectionManagerSettings connectionSettings = new ConnectionManagerSettings();

            connectionSettings.Load(nodeSettings);

            WhitelistManager whitelistManager = new WhitelistManager(dateTimeProvider, loggerFactory, peerAddressManager, mockDnsServer.Object, connectionSettings, dnsSettings);

            // Act.
            whitelistManager.RefreshWhitelist();

            // Assert.
            spiedMasterFile.Should().NotBeNull();

            Question question = new Question(new Domain(dnsSettings.DnsHostName), RecordType.AAAA);
            IList <IResourceRecord> resourceRecords = spiedMasterFile.Get(question);

            resourceRecords.Should().NotBeNullOrEmpty();

            IList <IPAddressResourceRecord> ipAddressResourceRecords = resourceRecords.OfType <IPAddressResourceRecord>().ToList();

            ipAddressResourceRecords.Should().HaveSameCount(testDataSet);

            foreach (Tuple <IPEndPoint, DateTimeOffset> testData in testDataSet)
            {
                ipAddressResourceRecords.SingleOrDefault(i => i.IPAddress.Equals(testData.Item1.Address)).Should().NotBeNull();
            }
        }
Пример #5
0
        public void WhenRefreshWhitelist_AndOwnIPInPeers_AndNotRunningFullNode_ThenWhitelistDoesNotContainOwnIP()
        {
            // Arrange.
            var mockDateTimeProvider = new Mock <IDateTimeProvider>();

            var mockLogger        = new Mock <ILogger>();
            var mockLoggerFactory = new Mock <ILoggerFactory>();

            mockLoggerFactory.Setup(l => l.CreateLogger(It.IsAny <string>())).Returns(mockLogger.Object);
            ILoggerFactory loggerFactory = mockLoggerFactory.Object;

            mockDateTimeProvider.Setup(d => d.GetTimeOffset()).Returns(new DateTimeOffset(new DateTime(2017, 8, 30, 1, 2, 3))).Verifiable();
            IDateTimeProvider dateTimeProvider = mockDateTimeProvider.Object;

            int inactiveTimePeriod = 5000;

            IPAddress activeIpAddressOne = IPAddress.Parse("::ffff:192.168.0.1");
            var       activeEndpointOne  = new IPEndPoint(activeIpAddressOne, 80);

            IPAddress activeIpAddressTwo = IPAddress.Parse("::ffff:192.168.0.2");
            var       activeEndpointTwo  = new IPEndPoint(activeIpAddressTwo, 80);

            IPAddress activeIpAddressThree = IPAddress.Parse("::ffff:192.168.0.3");
            var       activeEndpointThree  = new IPEndPoint(activeIpAddressThree, 80);

            var activeTestDataSet = new List <Tuple <IPEndPoint, DateTimeOffset> >()
            {
                new Tuple <IPEndPoint, DateTimeOffset> (activeEndpointOne, dateTimeProvider.GetTimeOffset().AddSeconds(-inactiveTimePeriod).AddSeconds(10)),
                new Tuple <IPEndPoint, DateTimeOffset>(activeEndpointTwo, dateTimeProvider.GetTimeOffset().AddSeconds(-inactiveTimePeriod).AddSeconds(20)),
                new Tuple <IPEndPoint, DateTimeOffset>(activeEndpointThree, dateTimeProvider.GetTimeOffset().AddSeconds(-inactiveTimePeriod).AddSeconds(30)),
            };

            IPAddress externalIPAdress = IPAddress.Parse("::ffff:192.168.99.99");
            int       externalPort     = 80;
            var       externalEndpoint = new IPEndPoint(externalIPAdress, externalPort);

            var externalIPTestDataSet = new List <Tuple <IPEndPoint, DateTimeOffset> >()
            {
                new Tuple <IPEndPoint, DateTimeOffset> (externalEndpoint, dateTimeProvider.GetTimeOffset().AddSeconds(-inactiveTimePeriod).AddSeconds(40)),
            };

            IPeerAddressManager peerAddressManager = this.CreateTestPeerAddressManager(activeTestDataSet.Union(externalIPTestDataSet).ToList());

            var args = new string[] {
                $"-dnspeeractivethreshold={inactiveTimePeriod.ToString()}",
                $"-externalip={externalEndpoint.Address.ToString()}",
                $"-port={externalPort.ToString()}",
            };

            IMasterFile spiedMasterFile = null;
            var         mockDnsServer   = new Mock <IDnsServer>();

            mockDnsServer.Setup(d => d.SwapMasterfile(It.IsAny <IMasterFile>()))
            .Callback <IMasterFile>(m =>
            {
                spiedMasterFile = m;
            })
            .Verifiable();

            Network     network      = KnownNetworks.StratisTest;
            var         nodeSettings = new NodeSettings(network, args: args);
            DnsSettings dnsSettings  = new DnsSettings(NodeSettings.Default(this.Network));

            dnsSettings.DnsPeerBlacklistThresholdInSeconds = inactiveTimePeriod;
            dnsSettings.DnsHostName = "stratis.test.com";
            dnsSettings.DnsFullNode = false;
            ConnectionManagerSettings connectionSettings = new ConnectionManagerSettings(nodeSettings);

            var whitelistManager = new WhitelistManager(dateTimeProvider, loggerFactory, peerAddressManager, mockDnsServer.Object, connectionSettings, dnsSettings, this.peerBanning);

            // Act.
            whitelistManager.RefreshWhitelist();

            // Assert.
            spiedMasterFile.Should().NotBeNull();

            var question = new Question(new Domain(dnsSettings.DnsHostName), RecordType.A);
            IList <IResourceRecord> resourceRecords = spiedMasterFile.Get(question);

            resourceRecords.Should().NotBeNullOrEmpty();

            IList <IPAddressResourceRecord> ipAddressResourceRecords = resourceRecords.OfType <IPAddressResourceRecord>().ToList();

            ipAddressResourceRecords.Should().HaveSameCount(activeTestDataSet);

            foreach (Tuple <IPEndPoint, DateTimeOffset> testData in activeTestDataSet)
            {
                ipAddressResourceRecords.SingleOrDefault(i => i.IPAddress.Equals(testData.Item1.Address.MapToIPv4())).Should().NotBeNull();
            }

            // External IP.
            ipAddressResourceRecords.SingleOrDefault(i => i.IPAddress.Equals(externalEndpoint)).Should().BeNull("the external IP peer should not be in DNS as not running full node.");
        }
Пример #6
0
        public void WhenRefreshWhitelist_AndActivePeersAvailable_ThenWhitelistContainsActivePeers()
        {
            // Arrange.
            var mockDateTimeProvider = new Mock <IDateTimeProvider>();

            var mockLogger        = new Mock <ILogger>();
            var mockLoggerFactory = new Mock <ILoggerFactory>();

            mockLoggerFactory.Setup(l => l.CreateLogger(It.IsAny <string>())).Returns(mockLogger.Object);
            ILoggerFactory loggerFactory = mockLoggerFactory.Object;

            mockDateTimeProvider.Setup(d => d.GetTimeOffset()).Returns(new DateTimeOffset(new DateTime(2017, 8, 30, 1, 2, 3))).Verifiable();
            IDateTimeProvider dateTimeProvider = mockDateTimeProvider.Object;

            int inactiveTimePeriod = 2000;

            IPAddress activeIpAddressOne = IPAddress.Parse("::ffff:192.168.0.1");
            var       activeEndpointOne  = new IPEndPoint(activeIpAddressOne, 80);

            IPAddress activeIpAddressTwo = IPAddress.Parse("::ffff:192.168.0.2");
            var       activeEndpointTwo  = new IPEndPoint(activeIpAddressTwo, 80);

            IPAddress activeIpAddressThree = IPAddress.Parse("::ffff:192.168.0.3");
            var       activeEndpointThree  = new IPEndPoint(activeIpAddressThree, 80);

            IPAddress activeIpAddressFour = IPAddress.Parse("::ffff:192.168.0.4");
            var       activeEndpointFour  = new IPEndPoint(activeIpAddressFour, 80);

            IPAddress activeIpAddressFive = IPAddress.Parse("2607:f8b0:4009:80e::200e");
            var       activeEndpointFive  = new IPEndPoint(activeIpAddressFive, 80);

            var testDataSet = new List <Tuple <IPEndPoint, DateTimeOffset> >()
            {
                new Tuple <IPEndPoint, DateTimeOffset>(activeEndpointOne, dateTimeProvider.GetTimeOffset().AddSeconds(-inactiveTimePeriod).AddSeconds(10)),
                new Tuple <IPEndPoint, DateTimeOffset>(activeEndpointTwo, dateTimeProvider.GetTimeOffset().AddSeconds(-inactiveTimePeriod).AddSeconds(20)),
                new Tuple <IPEndPoint, DateTimeOffset>(activeEndpointThree, dateTimeProvider.GetTimeOffset().AddSeconds(-inactiveTimePeriod).AddSeconds(30)),
                new Tuple <IPEndPoint, DateTimeOffset>(activeEndpointFour, dateTimeProvider.GetTimeOffset().AddSeconds(-inactiveTimePeriod).AddSeconds(40)),
                new Tuple <IPEndPoint, DateTimeOffset>(activeEndpointFive, dateTimeProvider.GetTimeOffset().AddSeconds(-inactiveTimePeriod).AddSeconds(50))
            };

            // PeerAddressManager does not support IPv4 addresses that are not represented as embedded IPv4 addresses in an IPv6 address.
            IPeerAddressManager peerAddressManager = this.CreateTestPeerAddressManager(testDataSet);

            IMasterFile spiedMasterFile = null;
            var         mockDnsServer   = new Mock <IDnsServer>();

            mockDnsServer.Setup(d => d.SwapMasterfile(It.IsAny <IMasterFile>()))
            .Callback <IMasterFile>(m =>
            {
                spiedMasterFile = m;
            })
            .Verifiable();

            NodeSettings nodeSettings = NodeSettings.Default(this.Network);
            DnsSettings  dnsSettings  = new DnsSettings(NodeSettings.Default(this.Network));

            dnsSettings.DnsPeerBlacklistThresholdInSeconds = inactiveTimePeriod;
            dnsSettings.DnsHostName = "stratis.test.com";
            ConnectionManagerSettings connectionSettings = new ConnectionManagerSettings(nodeSettings);

            var whitelistManager = new WhitelistManager(dateTimeProvider, loggerFactory, peerAddressManager, mockDnsServer.Object, connectionSettings, dnsSettings, this.peerBanning);

            // Act.
            whitelistManager.RefreshWhitelist();

            // Assert.
            spiedMasterFile.Should().NotBeNull();

            // Check for A records (IPv4 embedded in IPv6 and IPv4 addresses).
            var question4 = new Question(new Domain(dnsSettings.DnsHostName), RecordType.A);
            IList <IResourceRecord> resourceRecordsIpv4 = spiedMasterFile.Get(question4);

            resourceRecordsIpv4.Should().NotBeNullOrEmpty();

            IList <IPAddressResourceRecord> ipAddressResourceRecords4 = resourceRecordsIpv4.OfType <IPAddressResourceRecord>().ToList();

            ipAddressResourceRecords4.Should().HaveCount(4);

            // Check for AAAA records (IPv6 addresses).
            var question6 = new Question(new Domain(dnsSettings.DnsHostName), RecordType.AAAA);
            IList <IResourceRecord> resourceRecordsIpv6 = spiedMasterFile.Get(question6);

            resourceRecordsIpv6.Should().NotBeNullOrEmpty();

            IList <IPAddressResourceRecord> ipAddressResourceRecords6 = resourceRecordsIpv6.OfType <IPAddressResourceRecord>().ToList();

            ipAddressResourceRecords6.Should().HaveCount(1);

            foreach (Tuple <IPEndPoint, DateTimeOffset> testData in testDataSet)
            {
                if (testData.Item1.Address.IsIPv4MappedToIPv6)
                {
                    ipAddressResourceRecords4.SingleOrDefault(i => i.IPAddress.Equals(testData.Item1.Address.MapToIPv4())).Should().NotBeNull();
                }
                else
                {
                    ipAddressResourceRecords6.SingleOrDefault(i => i.IPAddress.Equals(testData.Item1.Address)).Should().NotBeNull();
                }
            }
        }