Beispiel #1
0
        public void DiscoveryOptions_Expect_MessageTypeOfDiscover()
        {
            DhcpPacket discoveryPacket = DhcpFakes.FakeDhcpDiscoverPacket();
            var        sut             = _messagerSerializer.ToMessage(discoveryPacket);

            Assert.Equal(DhcpMessageType.Discover, sut.DhcpMessageType);
        }
Beispiel #2
0
        public async void CleanupExpiredLease_Expect_NoExpiredLeases()
        {
            var leaseRepo    = new LeaseRepo(DbConfig);
            var leaseManager = new LeaseManager(DhcpFakes.FakeDhcpConfiguration(), leaseRepo);

            var expiredLease = ModelFakes.GetFakeLease();

            expiredLease.Expiration = DateTime.UtcNow.AddMinutes(-2);

            var validLease = ModelFakes.GetFakeLease();

            validLease.IpAddress       = "10.10.10.11";
            validLease.PhysicalAddress = "332211556677";
            validLease.HostName        = "boot22.local";

            await leaseRepo.Insert(expiredLease).ConfigureAwait(false);

            await leaseRepo.Insert(validLease).ConfigureAwait(false);

            await leaseManager.CleanExpiredLeases();

            var expiredEntity = await leaseRepo.GetByIpAddress(expiredLease.IpAddress).ConfigureAwait(false);

            var validEntity = await leaseRepo.GetByIpAddress(validLease.IpAddress).ConfigureAwait(false);

            Assert.Null(expiredEntity);
            Assert.NotNull(validEntity);
        }
Beispiel #3
0
        public void DiscoveryOptions_Expect_CorrectHostName()
        {
            DhcpPacket discoveryPacket = DhcpFakes.FakeDhcpDiscoverPacket();
            var        sut             = _messagerSerializer.ToMessage(discoveryPacket);

            Assert.Equal("SpeedwayR-11-7A-3C", sut.HostName);
        }
Beispiel #4
0
        public void DiscoveryOptions_Expect_CorrectClientHAddr()
        {
            DhcpPacket      discoveryPacket = DhcpFakes.FakeDhcpDiscoverPacket();
            var             sut             = _messagerSerializer.ToMessage(discoveryPacket);
            PhysicalAddress expeced         = new PhysicalAddress(new byte[] { 0, 22, 37, 17, 122, 60 });

            Assert.Equal(expeced, sut.ClientHardwareAddress);
        }
Beispiel #5
0
        public void DiscoveryCIAddr_Expect_CorrectClientIP()
        {
            DhcpPacket discoveryPacket = DhcpFakes.FakeDhcpDiscoverPacket();

            discoveryPacket.CIAddr = new byte[] { 0, 0, 0, 0 };
            var sut = _messagerSerializer.ToMessage(discoveryPacket);

            Assert.Equal("0.0.0.0", sut.ClientIPAddress.ToString());
        }
Beispiel #6
0
        public void DiscoveryOptions_Expect_CorrectXID()
        {
            DhcpPacket discoveryPacket = DhcpFakes.FakeDhcpDiscoverPacket();

            discoveryPacket.XID = new byte[] { 0x19, 0xe1, 0x79, 0x50 };
            var sut         = _messagerSerializer.ToMessage(discoveryPacket);
            var expectedHex = "19e17950";

            Assert.Equal(expectedHex, sut.TransactionId.ToString("x4"));
        }
Beispiel #7
0
        public async void NoLeases_Expect_NextLeaseToBeStartIpAddress()
        {
            var config       = DhcpFakes.FakeDhcpConfiguration();
            var leaseRepo    = new LeaseRepo(DbConfig);
            var leaseManager = new LeaseManager(config, leaseRepo);

            var nextLease = await leaseManager.GetNextLease().ConfigureAwait(false);

            Assert.Equal(config.StartIpAddress, nextLease);
        }
Beispiel #8
0
        public async void KeepLeaseWithNoMatch_Expect_RequestAccepted()
        {
            var leaseRepo    = new LeaseRepo(DbConfig);
            var leaseManager = new LeaseManager(DhcpFakes.FakeDhcpConfiguration(), leaseRepo);

            var ipAddress       = IPAddress.Parse("10.10.10.10");
            var hostName        = "myserver.local";
            var physicalAddress = PhysicalAddress.Parse("000000000000");

            bool keepLeaseResponse = await leaseManager.KeepLeaseRequest(ipAddress, physicalAddress, hostName).ConfigureAwait(false);

            Assert.True(keepLeaseResponse);
        }
Beispiel #9
0
        public async void InsertLease_Expect_NextLeaseToBeNextIpAddress()
        {
            var config       = DhcpFakes.FakeDhcpConfiguration();
            var nextIp       = config.StartIpAddress.ToNextIpAddress();
            var leaseRepo    = new LeaseRepo(DbConfig);
            var leaseManager = new LeaseManager(DhcpFakes.FakeDhcpConfiguration(), leaseRepo);

            var lease = ModelFakes.GetFakeLease(config.StartIpAddress.ToString());
            await leaseRepo.Insert(lease).ConfigureAwait(false);

            var nextLease = await leaseManager.GetNextLease();

            Assert.Equal(nextIp, nextLease);
        }
Beispiel #10
0
        public async void KeepLeaseWithMatch_WrongMAC_Expect_RequestRejected()
        {
            var leaseRepo    = new LeaseRepo(DbConfig);
            var leaseManager = new LeaseManager(DhcpFakes.FakeDhcpConfiguration(), leaseRepo);

            var ipAddress        = IPAddress.Parse("10.10.10.10");
            var hostName         = "myserver.local";
            var physicalAddress  = PhysicalAddress.Parse("000000000000");
            var physicalAddress2 = PhysicalAddress.Parse("999999999999");

            await leaseManager.AddLease(ipAddress, physicalAddress, hostName).ConfigureAwait(false);

            var keepLeaseResponse = await leaseManager.KeepLeaseRequest(ipAddress, physicalAddress2, hostName).ConfigureAwait(false);

            Assert.False(keepLeaseResponse);
        }
Beispiel #11
0
        public async void RemoveLease_Expect_NoLeaseInDb()
        {
            var leaseRepo    = new LeaseRepo(DbConfig);
            var leaseManager = new LeaseManager(DhcpFakes.FakeDhcpConfiguration(), leaseRepo);

            var ipAddress       = IPAddress.Parse("10.10.10.10");
            var hostName        = "myserver.local";
            var physicalAddress = PhysicalAddress.Parse("000000000000");

            await leaseManager.AddLease(ipAddress, physicalAddress, hostName).ConfigureAwait(false);

            await leaseManager.RemoveLease(ipAddress).ConfigureAwait(false);

            var entity = await leaseRepo.GetByIpAddress(ipAddress).ConfigureAwait(false);

            Assert.Null(entity);
        }
Beispiel #12
0
        public async void AddLease_Expect_LeaseInDb()
        {
            var leaseRepo    = new LeaseRepo(DbConfig);
            var leaseManager = new LeaseManager(DhcpFakes.FakeDhcpConfiguration(), leaseRepo);

            var ipAddress       = IPAddress.Parse("10.10.10.10");
            var hostName        = "myserver.local";
            var physicalAddress = PhysicalAddress.Parse("000000000000");

            await leaseManager.AddLease(ipAddress, physicalAddress, hostName).ConfigureAwait(false);

            var entity = await leaseRepo.GetByIpAddress(ipAddress).ConfigureAwait(false);

            Assert.Equal(ipAddress.ToString(), entity.IpAddress);
            Assert.Equal(physicalAddress.ToString(), entity.PhysicalAddress);
            Assert.Equal(hostName, entity.HostName);
        }