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 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 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()); }); }
public void EvaluateChallenge_NonEmptyServerResponse_Exception() { var client = CramMD5Client.CreateClient(AuthId, "ldap", "localhost", PasswordBytes, new Hashtable()); 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 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); } }