예제 #1
0
        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) {
            }
              }
        }
예제 #2
0
        public void TestCredentialNotSet()
        {
            using (var client = new CRAMMD5Mechanism()) {
            byte[] clientResponse;

            client.Exchange(new byte[0], out clientResponse);
              }
        }
예제 #3
0
        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);
              }
        }
예제 #4
0
        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);
              }
        }
예제 #5
0
        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) {
            }
              }
        }
예제 #6
0
        public void TestIsPlainText()
        {
            Assert.IsFalse(SaslClientMechanism.IsMechanismPlainText("CRAM-MD5"));

              using (var client = new CRAMMD5Mechanism()) {
            Assert.IsFalse(client.IsPlainText);
              }
        }