Beispiel #1
0
        public void EvaluateChallenge_Disposed_Exception()
        {
            var client = CramMD5Client.CreateClient(AuthId, "ldap", "localhost", PasswordBytes, new Hashtable());

            Assert.False(client.IsComplete);
            client.Dispose();
            Assert.True(client.IsComplete);
            Assert.Throws <SaslException>(() => client.EvaluateChallenge(Challenge));
            Assert.True(client.IsComplete);
        }
        public void EvaluateChallenge_Disposed_Exception()
        {
            var client = new CramMD5Client(new SaslCramMd5Request(AuthId, Password));

            Assert.False(client.IsComplete);
            client.Dispose();
            Assert.True(client.IsComplete);
            Assert.Throws <SaslException>(() => client.EvaluateChallenge(Challenge));
            Assert.True(client.IsComplete);
        }
        public void CreateClient_NullOrEmptyPassword_Throws()
        {
            Assert.Throws <SaslException>(() =>
            {
                var client = new CramMD5Client(new SaslCramMd5Request(AuthId, null));
            });

            Assert.Throws <SaslException>(() =>
            {
                var client = new CramMD5Client(new SaslCramMd5Request(AuthId, ""));
            });
        }
        public void CreateClient_NullOrEmptyAuthorizationId_Throws()
        {
            Assert.Throws <SaslException>(() =>
            {
                var client = new CramMD5Client(new SaslCramMd5Request(null, Password));
            });

            Assert.Throws <SaslException>(() =>
            {
                var client = new CramMD5Client(new SaslCramMd5Request("", Password));
            });
        }
Beispiel #5
0
        public void CreateClient_NullOrEmptyPassword_Throws()
        {
            Assert.Throws <SaslException>(() =>
            {
                var client = CramMD5Client.CreateClient("authId", "ldap", "localhost", null, new Hashtable());
            });

            Assert.Throws <SaslException>(() =>
            {
                var client = CramMD5Client.CreateClient("authId", "ldap", "localhost", Array.Empty <byte>(), new Hashtable());
            });
        }
Beispiel #6
0
        public void CreateClient_NullOrEmptyAuthorizationId_Throws()
        {
            Assert.Throws <SaslException>(() =>
            {
                var client = CramMD5Client.CreateClient(null, "ldap", "localhost", new byte[] { 0x00 }, new Hashtable());
            });

            Assert.Throws <SaslException>(() =>
            {
                var client = CramMD5Client.CreateClient("", "ldap", "localhost", new byte[] { 0x00 }, new Hashtable());
            });
        }
        public void EvaluateChallenge_NonEmptyServerResponse_Exception()
        {
            var client = new CramMD5Client(new SaslCramMd5Request(AuthId, Password));

            Assert.False(client.IsComplete);

            // Step 1: State.Initial => State.CramMd5ResponseSent
            var response = client.EvaluateChallenge(Challenge);

            Assert.False(client.IsComplete);
            Assert.Equal((IEnumerable <byte>)ExpectedResponse, response);

            // Step 2: State.CramMd5ResponseSent => State.InvalidServerResponse
            Assert.Throws <SaslException>(() => client.EvaluateChallenge(new byte[] { 0x00 }));
            Assert.True(client.IsComplete);
        }
        public void EvaluateChallenge_Success()
        {
            var client = new CramMD5Client(new SaslCramMd5Request(AuthId, Password));

            Assert.False(client.IsComplete);

            // Step 1: State.Initial => State.CramMd5ResponseSent
            var response = client.EvaluateChallenge(Challenge);

            Assert.False(client.IsComplete);
            Assert.Equal((IEnumerable <byte>)ExpectedResponse, response);

            // Step 2: State.CramMd5ResponseSent => State.ValidServerResponse
            client.EvaluateChallenge(Array.Empty <byte>());
            Assert.True(client.IsComplete);

            // Step 3: State.ValidServerResponse => Exception
            Assert.Throws <SaslException>(() => client.EvaluateChallenge(Array.Empty <byte>()));
        }
        public static ISaslClient CreateClient(string mechanism, string authorizationId, string protocol, string serverName, byte[] credentials, Hashtable props)
        {
            if (!IsSaslMechanismSupported(mechanism))
            {
                return(null);
            }

            switch (mechanism.ToUpperInvariant()) // TODO: Remove this ToUpperInvariant
            {
            case SaslConstants.Mechanism.CramMd5:
                return(CramMD5Client.CreateClient(authorizationId, protocol, serverName, credentials, props));

            //case LdapConstants.SaslMechanism.DigestMd5:
            //case LdapConstants.SaslMechanism.Plain:
            //case LdapConstants.SaslMechanism.GssApi:
            default:
                return(null);
            }
        }