示例#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_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();
            }
        }