Esempio n. 1
0
        public void TestArgumentExceptions()
        {
            var           credentials = new NetworkCredential("username", "password");
            var           uri         = new Uri("smtp://localhost");
            SaslMechanism sasl;

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

            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain((Uri)null, Encoding.UTF8, credentials));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain(uri, null, credentials));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain(uri, Encoding.UTF8, null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain((Uri)null, credentials));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain(uri, null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain((Uri)null, Encoding.UTF8, "username", "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain(uri, null, "username", "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain(uri, Encoding.UTF8, null, "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain(uri, Encoding.UTF8, "username", null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain((Uri)null, "username", "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain(uri, null, "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain(uri, "username", null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain(null, credentials));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain(Encoding.UTF8, null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain(null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain((Encoding)null, "username", "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain(Encoding.UTF8, null, "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain(Encoding.UTF8, "username", null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain(null, "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain("username", null));
        }
Esempio n. 2
0
        public void TestPlainAuth()
        {
            var credentials = new NetworkCredential("username", "password");
            var sasl        = new SaslMechanismPlain(credentials);

            AssertPlain(sasl, "NetworkCredential");

            sasl = new SaslMechanismPlain("username", "password");

            AssertPlain(sasl, "user/pass");
        }
        public void TestPlainAuth()
        {
            const string expected    = "AHVzZXJuYW1lAHBhc3N3b3Jk";
            var          credentials = new NetworkCredential("username", "password");
            var          sasl        = new SaslMechanismPlain(credentials);

            var challenge = sasl.Challenge(string.Empty);

            Assert.AreEqual(expected, challenge, "PLAIN challenge response does not match the expected string.");
            Assert.IsTrue(sasl.IsAuthenticated, "PLAIN should be authenticated.");
        }
Esempio n. 4
0
        static void AssertPlain(SaslMechanismPlain sasl, string prefix)
        {
            const string expected = "AHVzZXJuYW1lAHBhc3N3b3Jk";
            string       challenge;

            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.AreEqual(string.Empty, sasl.Challenge(string.Empty), "{0}: challenge while authenticated.", prefix);
        }
Esempio n. 5
0
        public void TestArgumentExceptions()
        {
            var           credentials = new NetworkCredential("username", "password");
            var           uri         = new Uri("smtp://localhost");
            SaslMechanism sasl;

            Assert.Throws <ArgumentNullException> (() => new SaslException(null, SaslErrorCode.MissingChallenge, "message"));

            sasl = new SaslMechanismCramMd5(uri, credentials);
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismCramMd5(null, credentials));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismCramMd5(uri, null));
            Assert.Throws <NotSupportedException> (() => sasl.Challenge(null));

            sasl = new SaslMechanismDigestMd5(uri, credentials);
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismDigestMd5(null, credentials));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismDigestMd5(uri, null));
            Assert.Throws <NotSupportedException> (() => sasl.Challenge(null));

            sasl = new SaslMechanismLogin(uri, credentials);
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismLogin(uri, null, credentials));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismLogin(null, credentials));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismLogin(uri, null));
            Assert.Throws <NotSupportedException> (() => sasl.Challenge(null));

            sasl = new SaslMechanismNtlm(uri, credentials);
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismNtlm(null, credentials));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismNtlm(uri, null));
            Assert.DoesNotThrow(() => sasl.Challenge(null));

            sasl = new SaslMechanismOAuth2(uri, credentials);
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismOAuth2(null, credentials));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismOAuth2(uri, null));
            Assert.DoesNotThrow(() => sasl.Challenge(null));

            sasl = new SaslMechanismPlain(uri, credentials);
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain(uri, null, credentials));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain(null, credentials));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain(uri, null));
            Assert.DoesNotThrow(() => sasl.Challenge(null));

            sasl = new SaslMechanismScramSha1(uri, credentials);
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismScramSha1(null, credentials));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismScramSha1(uri, null));
            Assert.DoesNotThrow(() => sasl.Challenge(null));

            sasl = new SaslMechanismScramSha256(uri, credentials);
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismScramSha256(null, credentials));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismScramSha256(uri, null));
            Assert.DoesNotThrow(() => sasl.Challenge(null));
        }
Esempio n. 6
0
        public void TestPlainWithAuthorizationId()
        {
            const string expected = "YXV0aHppZAB1c2VybmFtZQBwYXNzd29yZA==";
            var          sasl     = new SaslMechanismPlain("username", "password")
            {
                AuthorizationId = "authzid"
            };
            string challenge;

            Assert.IsTrue(sasl.SupportsInitialResponse, "SupportsInitialResponse");

            challenge = sasl.Challenge(string.Empty);

            Assert.AreEqual(expected, challenge, "challenge response does not match the expected string.");
            Assert.IsTrue(sasl.IsAuthenticated, "should be authenticated.");
            Assert.AreEqual(string.Empty, sasl.Challenge(string.Empty), "challenge while authenticated.");
        }
Esempio n. 7
0
        public void TestPlainAuth()
        {
            var credentials = new NetworkCredential("username", "password");
            var sasl        = new SaslMechanismPlain(credentials);
            var uri         = new Uri("smtp://localhost");

            AssertPlain(sasl, "NetworkCredential");

            sasl = new SaslMechanismPlain("username", "password");

            AssertPlain(sasl, "user/pass");

            sasl = new SaslMechanismPlain(uri, credentials);

            AssertPlain(sasl, "uri/credentials");

            sasl = new SaslMechanismPlain(uri, "username", "password");

            AssertPlain(sasl, "uri/user/pass");
        }
        public void TestArgumentExceptions()
        {
            var           credentials = new NetworkCredential("username", "password");
            var           uri         = new Uri("smtp://localhost");
            SaslMechanism sasl;

            Assert.Throws <ArgumentNullException> (() => new SaslException(null, SaslErrorCode.MissingChallenge, "message"));

            sasl = new SaslMechanismCramMd5(credentials);
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismCramMd5(null, credentials));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismCramMd5(uri, null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismCramMd5(null, "username", "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismCramMd5(uri, null, "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismCramMd5(uri, "username", null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismCramMd5(null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismCramMd5(null, "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismCramMd5("username", null));
            Assert.Throws <NotSupportedException> (() => sasl.Challenge(null));

            sasl = new SaslMechanismDigestMd5(credentials)
            {
                Uri = uri
            };
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismDigestMd5(null, credentials));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismDigestMd5(uri, null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismDigestMd5(null, "username", "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismDigestMd5(uri, (string)null, "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismDigestMd5(uri, "username", null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismDigestMd5(null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismDigestMd5(null, "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismDigestMd5("username", null));
            Assert.Throws <NotSupportedException> (() => sasl.Challenge(null));

            sasl = new SaslMechanismLogin(credentials);
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismLogin((Uri)null, Encoding.UTF8, credentials));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismLogin(uri, null, credentials));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismLogin(uri, Encoding.UTF8, null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismLogin((Uri)null, credentials));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismLogin(uri, null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismLogin((Uri)null, Encoding.UTF8, "username", "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismLogin(uri, null, "username", "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismLogin(uri, Encoding.UTF8, null, "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismLogin(uri, Encoding.UTF8, "username", null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismLogin((Uri)null, "username", "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismLogin(uri, null, "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismLogin(uri, "username", null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismLogin(null, credentials));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismLogin(Encoding.UTF8, null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismLogin(null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismLogin((Encoding)null, "username", "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismLogin(Encoding.UTF8, null, "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismLogin(Encoding.UTF8, "username", null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismLogin(null, "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismLogin("username", null));
            Assert.Throws <NotSupportedException> (() => sasl.Challenge(null));

            sasl = new SaslMechanismNtlm(credentials);
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismNtlm((Uri)null, credentials));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismNtlm(uri, null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismNtlm((Uri)null, "username", "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismNtlm(uri, (string)null, "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismNtlm(uri, "username", null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismNtlm(null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismNtlm(null, "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismNtlm("username", null));
            Assert.DoesNotThrow(() => sasl.Challenge(null));

            sasl = new SaslMechanismOAuth2(credentials);
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismOAuth2((Uri)null, credentials));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismOAuth2(uri, null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismOAuth2((Uri)null, "username", "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismOAuth2(uri, (string)null, "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismOAuth2(uri, "username", null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismOAuth2(null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismOAuth2(null, "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismOAuth2("username", null));
            Assert.DoesNotThrow(() => sasl.Challenge(null));

            sasl = new SaslMechanismPlain(credentials);
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain((Uri)null, Encoding.UTF8, credentials));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain(uri, null, credentials));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain(uri, Encoding.UTF8, null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain((Uri)null, credentials));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain(uri, null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain((Uri)null, Encoding.UTF8, "username", "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain(uri, null, "username", "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain(uri, Encoding.UTF8, null, "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain(uri, Encoding.UTF8, "username", null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain((Uri)null, "username", "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain(uri, null, "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain(uri, "username", null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain(null, credentials));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain(Encoding.UTF8, null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain(null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain((Encoding)null, "username", "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain(Encoding.UTF8, null, "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain(Encoding.UTF8, "username", null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain(null, "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismPlain("username", null));
            Assert.DoesNotThrow(() => sasl.Challenge(null));

            sasl = new SaslMechanismScramSha1(credentials);
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismScramSha1(null, credentials));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismScramSha1(uri, null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismScramSha1(null, "username", "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismScramSha1(uri, (string)null, "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismScramSha1(uri, "username", null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismScramSha1(null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismScramSha1((string)null, "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismScramSha1("username", null));
            Assert.DoesNotThrow(() => sasl.Challenge(null));

            sasl = new SaslMechanismScramSha256(credentials);
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismScramSha256(null, credentials));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismScramSha256(uri, null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismScramSha256(null, "username", "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismScramSha256(uri, (string)null, "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismScramSha256(uri, "username", null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismScramSha256(null));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismScramSha256((string)null, "password"));
            Assert.Throws <ArgumentNullException> (() => new SaslMechanismScramSha256("username", null));
            Assert.DoesNotThrow(() => sasl.Challenge(null));

            Assert.Throws <ArgumentNullException> (() => SaslMechanism.Create(null, uri, Encoding.UTF8, credentials));
            Assert.Throws <ArgumentNullException> (() => SaslMechanism.Create("PLAIN", null, Encoding.UTF8, credentials));
            Assert.Throws <ArgumentNullException> (() => SaslMechanism.Create("PLAIN", uri, null, credentials));
            Assert.Throws <ArgumentNullException> (() => SaslMechanism.Create("PLAIN", uri, Encoding.UTF8, null));

            Assert.Throws <ArgumentNullException> (() => SaslMechanism.Create(null, uri, credentials));
            Assert.Throws <ArgumentNullException> (() => SaslMechanism.Create("PLAIN", null, credentials));
            Assert.Throws <ArgumentNullException> (() => SaslMechanism.Create("PLAIN", uri, null));

            Assert.Throws <ArgumentNullException> (() => SaslMechanism.SaslPrep(null));
        }