public void TestExchange() { using (var client = new CRAMMD5Mechanism()) { Assert.AreEqual(SaslExchangeStatus.None, client.ExchangeStatus); client.Credential = new NetworkCredential("tim", "tanstaaftanstaaf"); byte[] serverChallenge; byte[] clientResponse; serverChallenge = Convert.FromBase64String("PDE4OTYuNjk3MTcwOTUyQHBvc3RvZmZpY2UucmVzdG9uLm1jaS5uZXQ+"); Assert.AreEqual(SaslExchangeStatus.Succeeded, client.Exchange(serverChallenge, out clientResponse)); Assert.AreEqual(SaslExchangeStatus.Succeeded, client.ExchangeStatus); BytesAssert.AreEqual(Convert.FromBase64String("dGltIGI5MTNhNjAyYzdlZGE3YTQ5NWI0ZTZlNzMzNGQzODkw"), clientResponse); try { client.Exchange(serverChallenge, out clientResponse); Assert.Fail("InvalidOperationException not thrown"); } catch (InvalidOperationException) { } } }
public void TestCredentialNotSet() { using (var client = new CRAMMD5Mechanism()) { byte[] clientResponse; client.Exchange(new byte[0], out clientResponse); } }
public void TestGetInitialResponse() { using (var client = new CRAMMD5Mechanism()) { Assert.AreEqual(SaslExchangeStatus.None, client.ExchangeStatus); Assert.IsFalse(client.ClientFirst); client.Credential = new NetworkCredential("tim", "tanstaaftanstaaf"); byte[] initialResponse; client.GetInitialResponse(out initialResponse); } }
public void TestInitialize() { using (var client = new CRAMMD5Mechanism()) { Assert.AreEqual(SaslExchangeStatus.None, client.ExchangeStatus); client.Credential = new NetworkCredential("tim", "tanstaaftanstaaf"); byte[] serverChallenge; byte[] clientResponseFirst; serverChallenge = Convert.FromBase64String("PDE4OTYuNjk3MTcwOTUyQHBvc3RvZmZpY2UucmVzdG9uLm1jaS5uZXQ+"); Assert.AreEqual(SaslExchangeStatus.Succeeded, client.Exchange(serverChallenge, out clientResponseFirst)); Assert.AreEqual(SaslExchangeStatus.Succeeded, client.ExchangeStatus); client.Initialize(); Assert.AreEqual(SaslExchangeStatus.None, client.ExchangeStatus); byte[] clientResponseSecond; Assert.AreEqual(SaslExchangeStatus.Succeeded, client.Exchange(serverChallenge, out clientResponseSecond)); Assert.AreEqual(SaslExchangeStatus.Succeeded, client.ExchangeStatus); Assert.AreEqual(clientResponseFirst, clientResponseSecond); } }
private void ExchangeEmptyCredentialProperty(NetworkCredential credential) { using (var client = new CRAMMD5Mechanism()) { Assert.AreEqual(SaslExchangeStatus.None, client.ExchangeStatus); client.Credential = credential; byte[] serverChallenge; byte[] clientResponse; serverChallenge = Convert.FromBase64String("PDE4OTYuNjk3MTcwOTUyQHBvc3RvZmZpY2UucmVzdG9uLm1jaS5uZXQ+"); Assert.AreEqual(SaslExchangeStatus.Failed, client.Exchange(serverChallenge, out clientResponse)); Assert.AreEqual(SaslExchangeStatus.Failed, client.ExchangeStatus); Assert.IsNull(clientResponse); try { client.Exchange(serverChallenge, out clientResponse); Assert.Fail("InvalidOperationException not thrown"); } catch (InvalidOperationException) { } } }
public void TestIsPlainText() { Assert.IsFalse(SaslClientMechanism.IsMechanismPlainText("CRAM-MD5")); using (var client = new CRAMMD5Mechanism()) { Assert.IsFalse(client.IsPlainText); } }