Пример #1
0
        public void RadiusServer_Nas_HostRefresh()
        {
            // Verify that the server refreshes NAS host name to IP address mappings.
            // I'm going to do this by specifying a NAS host name that does not
            // exist, verify that an authentication fails, then add the host name
            // to the HOSTS file, wait a bit for the server to refresh the mappings
            // and then verify that this worked by making sure that an authentication
            // attempt succeeds.

            RadiusServer         server         = new RadiusServer();
            RadiusServerSettings serverSettings = new RadiusServerSettings();
            RadiusClient         client         = new RadiusClient();
            RadiusClientSettings clientSettings = new RadiusClientSettings(Local_RADIUS, "hello");

            serverSettings.RealmFormat        = RealmFormat.Email;
            serverSettings.DnsRefreshInterval = TimeSpan.FromSeconds(10);
            serverSettings.BkTaskInterval     = TimeSpan.FromSeconds(2);
            serverSettings.Devices.Add(new RadiusNasInfo("nas.test.lilltek.com", "hello"));

            clientSettings.RealmFormat      = RealmFormat.Email;
            clientSettings.PortCount        = 1;
            clientSettings.MaxTransmissions = 1;
            clientSettings.RetryInterval    = TimeSpan.FromSeconds(2);

            try
            {
                server.Start(serverSettings);
                server.LoadAccountsFromString(@"

    // This is a comment line

    r1;jeff;password123
    r2;jeff;passwordXXX
    r1;jane;bigfish
    ");

                client.Open(clientSettings);

                try
                {
                    client.Authenticate("r1", "jeff", "password123");
                    Assert.Fail();
                }
                catch (Exception e)
                {
                    Assert.IsInstanceOfType(e, typeof(TimeoutException));
                }

                EnhancedDns.AddHost("nas.test.lilltek.com", NetHelper.GetActiveAdapter());
                Thread.Sleep(serverSettings.DnsRefreshInterval + serverSettings.BkTaskInterval);

                Assert.IsTrue(client.Authenticate("r1", "jeff", "password123"));
            }
            finally
            {
                EnhancedDns.RemoveHosts();
                server.Stop();
                client.Close();
            }
        }
Пример #2
0
        public void EnhancedDns_HostLookup_Uncached()
        {
            DateTime start;
            string   duration;

            try
            {
                EnhancedDns.EnableCaching = false;
                start = SysTime.Now;

                for (int i = 0; i < 10; i++)
                {
                    EnhancedDns.GetHostByName("localhost");
                    EnhancedDns.GetHostByName("www.google.com");
                    EnhancedDns.GetHostByName("www.microsoft.com");
                    EnhancedDns.GetHostByName("www.ibm.com");
                }

                duration = (SysTime.Now - start).TotalSeconds.ToString();
            }
            finally
            {
                EnhancedDns.Reset();
            }
        }
Пример #3
0
        public void RadiusClient_Interop_AD_IAS()
        {
            if (EnvironmentVars.Get("LT_TESTBIN") == null)
            {
                Assert.Inconclusive("[LT_TESTBIN] environment variable does not exist.");
            }

            if (EnvironmentVars.Get("LT_TEST_AD") == null)
            {
                Assert.Inconclusive("[LT_TEST_AD] environment variable does not exist.");
            }

            var ad = new ADTestSettings();

            if (ad.NasSecret == string.Empty)
            {
                Assert.Inconclusive("AD/IAS Testing is disabled");
                return;
            }

            // Verify that RADIUS client works against AD/IAS.  This requires that
            // the LT_TEST_AD environment variable be set properly as described
            // in the LillTek DevInstall.doc document.  The IAS server must also
            // be manually configured with the NAS shared secret for this client.

            RadiusClient         client         = new RadiusClient();
            NetworkBinding       serverEP       = new NetworkBinding(EnhancedDns.GetHostByName(ad.Servers[0]).AddressList.IPv4Only()[0], NetworkPort.RADIUS);
            RadiusClientSettings clientSettings = new RadiusClientSettings(serverEP, ad.NasSecret);

            clientSettings.RealmFormat = RealmFormat.Email;
            clientSettings.PortCount   = 1;

            try
            {
                client.Open(clientSettings);

                Assert.IsTrue(client.Authenticate(ad.Domain, ad.Account, ad.Password));

                Assert.IsFalse(client.Authenticate(ad.Domain + "x", ad.Account, ad.Password));
                Assert.IsFalse(client.Authenticate(ad.Domain, ad.Account + "x", ad.Password));
                Assert.IsFalse(client.Authenticate(ad.Domain, ad.Account, ad.Password + "x"));
            }
            finally
            {
                client.Close();
            }
        }
Пример #4
0
        /// <summary>
        /// Returns the <see cref="IPEndPoint" /> of the next server in the round robin rotation
        /// or <see cref="NetworkBinding.Any" /> if no server host resolves.  This method assumes that
        /// a lock is already held on the current instance.
        /// </summary>
        /// <param name="serverPos">The current round robin position in the servers list.</param>
        private IPEndPoint GetServerBinding(ref int serverPos)
        {
            NetworkBinding curBinding = servers[serverPos];
            IPHostEntry    entry;

            IPAddress[] addresses;

            if (servers.Length == 1)
            {
                try
                {
                    if (curBinding.IsHost)
                    {
                        entry = EnhancedDns.GetHostByName(curBinding.Host);
                        if (entry == null)
                        {
                            return(NetworkBinding.Any);
                        }

                        addresses = entry.AddressList.IPv4Only();

                        if (addresses.Length == 0)
                        {
                            return(NetworkBinding.Any);
                        }

                        return(new IPEndPoint(addresses[0], curBinding.Port));
                    }
                    else
                    {
                        return(new IPEndPoint(curBinding.Address, curBinding.Port));
                    }
                }
                catch
                {
                    return(NetworkBinding.Any);
                }
            }
            else
            {
                int serverStart = serverPos;

                do
                {
                    if (curBinding.IsHost)
                    {
                        try
                        {
                            entry = EnhancedDns.GetHostByName(curBinding.Host);
                        }
                        catch
                        {
                            entry = null;
                        }

                        serverPos = (++serverPos) % servers.Length;

                        if (entry != null)
                        {
                            addresses = entry.AddressList.IPv4Only();
                            if (addresses.Length > 0)
                            {
                                return(new IPEndPoint(addresses[0], curBinding.Port));
                            }
                        }
                    }
                    else
                    {
                        serverPos = (++serverPos) % servers.Length;
                        return(curBinding);
                    }

                    curBinding = servers[serverPos];
                } while (serverPos != serverStart);

                return(NetworkBinding.Any);
            }
        }
Пример #5
0
        public void EnhancedDns_AddRemoveHosts()
        {
            // Verify that we can modify the HOSTS file.  Note that it may
            // be necessary to disable local Virus and Spyware detection
            // software for this test to pass.

            try
            {
                IPHostEntry entry;

                try
                {
                    Dns.GetHostEntry("test01.test.lilltek.com");
                    Assert.Fail();
                }
                catch (SocketException)
                {
                    // Expecting this to fail
                }

                try
                {
                    Dns.GetHostEntry("test02.test.lilltek.com");
                    Assert.Fail();
                }
                catch (SocketException)
                {
                    // Expecting this to fail
                }

                EnhancedDns.AddHost("test01.test.lilltek.com", IPAddress.Parse("72.0.0.1"));
                EnhancedDns.AddHost("test02.test.lilltek.com", IPAddress.Parse("72.0.0.2"));

                entry = Dns.GetHostEntry("test01.test.lilltek.com");
                Assert.AreEqual(IPAddress.Parse("72.0.0.1"), entry.AddressList[0]);

                entry = Dns.GetHostEntry("test02.test.lilltek.com");
                Assert.AreEqual(IPAddress.Parse("72.0.0.2"), entry.AddressList[0]);

                EnhancedDns.RemoveHosts();

                try
                {
                    Dns.GetHostEntry("test01.test.lilltek.com");
                    Assert.Fail();
                }
                catch (SocketException)
                {
                    // Expecting this to fail
                }

                try
                {
                    Dns.GetHostEntry("test02.test.lilltek.com");
                    Assert.Fail();
                }
                catch (SocketException)
                {
                    // Expecting this to fail
                }
            }
            finally
            {
                EnhancedDns.RemoveHosts();
                EnhancedDns.Reset();
            }
        }