예제 #1
0
 public void ProtocolVersion_SetInvalid_ThrowsLdapException(int value)
 {
     using (var connection = new LdapConnection("server"))
     {
         LdapSessionOptions options = connection.SessionOptions;
         Assert.Throws <LdapException>(() => options.ProtocolVersion = value);
     }
 }
예제 #2
0
 public void HostReachable_Get_ReturnsTrue()
 {
     using (var connection = new LdapConnection("server"))
     {
         LdapSessionOptions options = connection.SessionOptions;
         Assert.True(options.HostReachable);
     }
 }
예제 #3
0
 public void StopTransportLayerSecurity_NotStarted_ThrowsTlsOperationException()
 {
     using (var connection = new LdapConnection("server"))
     {
         LdapSessionOptions options = connection.SessionOptions;
         Assert.Throws <TlsOperationException>(() => options.StopTransportLayerSecurity());
     }
 }
예제 #4
0
 public void SecurityContext_GetNotStarted_ThrowsDirectoryOperationException()
 {
     using (var connection = new LdapConnection("server"))
     {
         LdapSessionOptions options = connection.SessionOptions;
         Assert.Throws <DirectoryOperationException>(() => options.SecurityContext);
     }
 }
예제 #5
0
        public void SaslMethod_Set_ThrowsLdapException()
        {
            using (var connection = new LdapConnection("server"))
            {
                LdapSessionOptions options = connection.SessionOptions;
                Assert.Null(options.SaslMethod);

                Assert.Throws <LdapException>(() => options.SaslMethod = "SaslMethod");
            }
        }
예제 #6
0
        public void ReferralChasing_Set_GetReturnsExpected(ReferralChasingOptions value)
        {
            using (var connection = new LdapConnection("server"))
            {
                LdapSessionOptions options = connection.SessionOptions;
                Assert.Equal(ReferralChasingOptions.All, options.ReferralChasing);

                options.ReferralChasing = value;
                Assert.Equal(value, options.ReferralChasing);
            }
        }
예제 #7
0
        public void LocatorFlag_Set_GetReturnsExpected(LocatorFlags value)
        {
            using (var connection = new LdapConnection("server"))
            {
                LdapSessionOptions options = connection.SessionOptions;
                Assert.Equal(LocatorFlags.None, options.LocatorFlag);

                options.LocatorFlag = value;
                Assert.Equal(value, options.LocatorFlag);
            }
        }
예제 #8
0
        public void ReferralHopLimit_Set_GetReturnsExpected()
        {
            using (var connection = new LdapConnection("server"))
            {
                LdapSessionOptions options = connection.SessionOptions;
                Assert.Equal(32, options.ReferralHopLimit);

                options.ReferralHopLimit = 10;
                Assert.Equal(10, options.ReferralHopLimit);
            }
        }
예제 #9
0
        public void SendTimeout_Set_GetReturnsExpected()
        {
            using (var connection = new LdapConnection("server"))
            {
                LdapSessionOptions options = connection.SessionOptions;
                Assert.Equal(TimeSpan.FromSeconds(-1), options.SendTimeout);

                options.SendTimeout = TimeSpan.FromSeconds(10);
                Assert.Equal(TimeSpan.FromSeconds(10), options.SendTimeout);
            }
        }
예제 #10
0
 public void ReferralCallback_Get_ReturnsException()
 {
     using (var connection = new LdapConnection("server"))
     {
         LdapSessionOptions options = connection.SessionOptions;
         Assert.Null(options.ReferralCallback.DereferenceConnection);
         Assert.Null(options.ReferralCallback.NotifyNewConnection);
         Assert.Null(options.ReferralCallback.QueryForConnection);
         Assert.Same(options.ReferralCallback, options.ReferralCallback);
     }
 }
예제 #11
0
        public void RootDseCache_Set_GetReturnsExpected(bool value)
        {
            using (var connection = new LdapConnection("server"))
            {
                LdapSessionOptions options = connection.SessionOptions;
                Assert.True(options.RootDseCache);

                options.RootDseCache = value;
                Assert.Equal(value, options.RootDseCache);
            }
        }
예제 #12
0
        public void TcpKeepAlive_Set_GetReturnsExpected(bool value)
        {
            using (var connection = new LdapConnection("server"))
            {
                LdapSessionOptions options = connection.SessionOptions;
                Assert.False(options.TcpKeepAlive);

                options.TcpKeepAlive = value;
                Assert.Equal(value, options.TcpKeepAlive);
            }
        }
예제 #13
0
        public void SspiFlag_Set_GetReturnsExpected(int value)
        {
            using (var connection = new LdapConnection("server"))
            {
                LdapSessionOptions options = connection.SessionOptions;
                Assert.Equal(16386, options.SspiFlag);

                options.SspiFlag = value;
                Assert.Equal(value, options.SspiFlag);
            }
        }
예제 #14
0
        public void SecureSocketLayer_Set_GetReturnsExpected(bool value)
        {
            using (var connection = new LdapConnection("server"))
            {
                LdapSessionOptions options = connection.SessionOptions;
                Assert.False(options.SecureSocketLayer);

                options.SecureSocketLayer = value;
                Assert.False(options.SecureSocketLayer);
            }
        }
예제 #15
0
        public void AutoReconnect_Set_GetReturnsExpected(bool value)
        {
            using (var connection = new LdapConnection("server"))
            {
                LdapSessionOptions options = connection.SessionOptions;
                Assert.True(options.AutoReconnect);

                options.AutoReconnect = value;
                Assert.Equal(value, options.AutoReconnect);
            }
        }
예제 #16
0
        public void PingKeepAliveTimeout_Set_GetReturnsExpected()
        {
            using (var connection = new LdapConnection("server"))
            {
                LdapSessionOptions options = connection.SessionOptions;
                Assert.Equal(TimeSpan.FromMinutes(2), options.PingKeepAliveTimeout);

                options.PingKeepAliveTimeout = TimeSpan.FromSeconds(10);
                Assert.Equal(TimeSpan.FromSeconds(10), options.PingKeepAliveTimeout);
            }
        }
예제 #17
0
        public void HostName_Set_GetReturnsExpected()
        {
            using (var connection = new LdapConnection("server"))
            {
                LdapSessionOptions options = connection.SessionOptions;
                Assert.Null(options.HostName); //TODO: will fail with openLdap/*nix, "ldap_init" sets LDAP_OPT_HOST_NAME, so HostName=="server:389"

                options.HostName = "HostName";
                Assert.Equal("HostName", options.HostName);

                options.HostName = null;
                Assert.Equal("HostName", options.HostName);
            }
        }
예제 #18
0
        public void VerifyServerCertificate_Set_GetReturnsExpected()
        {
            using (var connection = new LdapConnection("server"))
            {
                LdapSessionOptions options = connection.SessionOptions;
                Assert.Null(options.VerifyServerCertificate);

                options.VerifyServerCertificate = VerifyServerCertificate;
                Assert.Equal(VerifyServerCertificate, options.VerifyServerCertificate);

                options.VerifyServerCertificate = null;
                Assert.Null(options.VerifyServerCertificate);
            }
        }
예제 #19
0
        public void QueryClientCertificate_Set_GetReturnsExpected()
        {
            using (var connection = new LdapConnection("server"))
            {
                LdapSessionOptions options = connection.SessionOptions;
                Assert.Null(options.QueryClientCertificate);

                options.QueryClientCertificate = QueryClientCertificate;
                Assert.Equal(QueryClientCertificate, options.QueryClientCertificate);

                options.QueryClientCertificate = null;
                Assert.Null(options.QueryClientCertificate);
            }
        }
예제 #20
0
        public void ProtocolVersion_Set_GetReturnsExpected()
        {
            using (var connection = new LdapConnection("server"))
            {
                LdapSessionOptions options = connection.SessionOptions;
                Assert.Equal(2, options.ProtocolVersion);

                options.ProtocolVersion = 3;
                Assert.Equal(3, options.ProtocolVersion);

                options.ProtocolVersion = 2;
                Assert.Equal(2, options.ProtocolVersion);
            }
        }
예제 #21
0
        public void DomainName_Set_GetReturnsExpected()
        {
            using (var connection = new LdapConnection("server"))
            {
                LdapSessionOptions options = connection.SessionOptions;
                Assert.Null(options.DomainName);

                options.DomainName = "DomainName";
                Assert.Equal("DomainName", options.DomainName);

                options.DomainName = null;
                Assert.Null(options.DomainName);
            }
        }
예제 #22
0
        private void lockedLdapBind(LdapConnection current, NetworkCredential creds, ContextOptions contextOptions)
        {
            AuthType       authType;
            bool           flag;
            bool           flag1;
            LdapConnection ldapConnection = current;

            if ((ContextOptions.SimpleBind & contextOptions) > 0)
            {
                authType = AuthType.Basic;
            }
            else
            {
                authType = AuthType.Negotiate;
            }
            ldapConnection.AuthType = authType;
            LdapSessionOptions sessionOptions = current.SessionOptions;

            if ((ContextOptions.Signing & contextOptions) > 0)
            {
                flag = true;
            }
            else
            {
                flag = false;
            }
            sessionOptions.Signing = flag;
            LdapSessionOptions ldapSessionOption = current.SessionOptions;

            if ((ContextOptions.Sealing & contextOptions) > 0)
            {
                flag1 = true;
            }
            else
            {
                flag1 = false;
            }
            ldapSessionOption.Sealing = flag1;
            if (creds.UserName != null || creds.Password != null)
            {
                current.Bind(creds);
                return;
            }
            else
            {
                current.Bind();
                return;
            }
        }
예제 #23
0
        public void ReferralCallback_Set_GetReturnsExpected()
        {
            using (var connection = new LdapConnection("server"))
            {
                LdapSessionOptions options = connection.SessionOptions;
                var value = new ReferralCallback
                {
                    DereferenceConnection = ReferralCallbackTests.DereferenceConnection,
                    NotifyNewConnection   = ReferralCallbackTests.NotifyNewConnection,
                    QueryForConnection    = ReferralCallbackTests.QueryForConnection
                };
                options.ReferralCallback = value;
                Assert.Same(value, options.ReferralCallback);

                options.ReferralCallback = null;
                Assert.Null(options.ReferralCallback);
            }
        }
예제 #24
0
        public static LdapConnection Connect()
        {
            LdapConnection ldapConnection = null;

            try
            {
                LdapDirectoryIdentifier ldapIdentifier = new LdapDirectoryIdentifier(server, portNumber, true, false);
                ldapConnection            = new LdapConnection(ldapIdentifier);
                ldapConnection.Credential = new NetworkCredential(userName, password);
                ldapConnection.AuthType   = AuthType.Basic;
                LdapSessionOptions options = ldapConnection.SessionOptions;
                options.ProtocolVersion = 3;
                ldapConnection.Bind();
                return(ldapConnection);
            }
            catch (Exception e)
            {
                _logger.Error("Error connecting to LDAP server: " + e);
                throw e;
            }
        }