Пример #1
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();
            }
        }
Пример #2
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();
            }
        }
Пример #3
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);
            }
        }