예제 #1
0
        public void TestAnonymousAuth()
        {
            var credentials = new NetworkCredential("username", "password");
            var sasl        = new SaslMechanismAnonymous(credentials);

            AssertAnonymous(sasl, "NetworkCredential");

            sasl = new SaslMechanismAnonymous("username");

            AssertAnonymous(sasl, "user");
        }
예제 #2
0
        public void TestArgumentExceptions()
        {
            var           credentials = new NetworkCredential("username", "password");
            SaslMechanism sasl;

            sasl = new SaslMechanismAnonymous(credentials);
            Assert.DoesNotThrow(() => sasl.Challenge(null));

            Assert.Throws <ArgumentNullException> (() => new SaslMechanismAnonymous(null, credentials));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismAnonymous(Encoding.UTF8, (NetworkCredential)null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismAnonymous((NetworkCredential)null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismAnonymous(null, "username"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismAnonymous(Encoding.UTF8, (string)null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismAnonymous((string)null));
        }
예제 #3
0
        static void AssertAnonymous(SaslMechanismAnonymous sasl, string prefix)
        {
            const string expected = "dXNlcm5hbWU=";
            string       challenge;

            Assert.IsFalse(sasl.SupportsChannelBinding, "{0}: SupportsChannelBinding", prefix);
            Assert.IsTrue(sasl.SupportsInitialResponse, "{0}: SupportsInitialResponse", prefix);

            challenge = sasl.Challenge(string.Empty);

            Assert.AreEqual(expected, challenge, "{0}: challenge response does not match the expected string.", prefix);
            Assert.IsTrue(sasl.IsAuthenticated, "{0}: should be authenticated.", prefix);
            Assert.IsFalse(sasl.NegotiatedChannelBinding, "{0}: NegotiatedChannelBinding", prefix);
            Assert.IsFalse(sasl.NegotiatedSecurityLayer, "{0}: NegotiatedSecurityLayer", prefix);

            Assert.AreEqual(string.Empty, sasl.Challenge(string.Empty), "{0}: challenge while authenticated.", prefix);
        }