public void TestSaslPrep() { // The following examples are from rfc4013, Section 3. // # Input Output Comments // - ----- ------ -------- // 1 I<U+00AD>X IX SOFT HYPHEN mapped to nothing Assert.AreEqual("IX", SaslMechanism.SaslPrep("I\u00ADX"), "1"); // 2 user user no transformation Assert.AreEqual("user", SaslMechanism.SaslPrep("user"), "2"); // 3 USER USER case preserved, will not match #2 Assert.AreEqual("USER", SaslMechanism.SaslPrep("USER"), "3"); // 4 <U+00AA> a output is NFKC, input in ISO 8859-1 Assert.AreEqual("a", SaslMechanism.SaslPrep("\u00AA"), "4"); // 5 <U+2168> IX output is NFKC, will match #1 Assert.AreEqual("IX", SaslMechanism.SaslPrep("\u2168"), "5"); // 6 <U+0007> Error - prohibited character try { SaslMechanism.SaslPrep("\u0007"); Assert.Fail("6"); } catch (ArgumentException) { } // 7 <U+0627><U+0031> Error - bidirectional check //try { // SaslMechanism.SaslPrep ("\u0627\u0031"); // Assert.Fail ("7"); //} catch (ArgumentException) { //} }
public void TestArgumentExceptions() { var credentials = new NetworkCredential("username", "password"); Assert.Throws <ArgumentNullException> (() => SaslMechanism.Create(null, Encoding.UTF8, credentials)); Assert.Throws <ArgumentNullException> (() => SaslMechanism.Create("PLAIN", null, credentials)); Assert.Throws <ArgumentNullException> (() => SaslMechanism.Create("PLAIN", Encoding.UTF8, null)); Assert.Throws <ArgumentNullException> (() => SaslMechanism.Create(null, credentials)); Assert.Throws <ArgumentNullException> (() => SaslMechanism.Create("PLAIN", null)); Assert.Throws <ArgumentNullException> (() => SaslMechanism.IsSupported(null)); Assert.Throws <ArgumentNullException> (() => SaslMechanism.SaslPrep(null)); }
public void TestArgumentExceptions() { var credentials = new NetworkCredential("username", "password"); var uri = new Uri("smtp://localhost"); 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)); }
public void TestSaslPrep() { // The following examples are from rfc4013, Section 3. // # Input Output Comments // - ----- ------ -------- // 1 I<U+00AD>X IX SOFT HYPHEN mapped to nothing Assert.AreEqual("IX", SaslMechanism.SaslPrep("I\u00ADX"), "1"); // 2 user user no transformation Assert.AreEqual("user", SaslMechanism.SaslPrep("user"), "2"); // 3 USER USER case preserved, will not match #2 Assert.AreEqual("USER", SaslMechanism.SaslPrep("USER"), "3"); // 4 <U+00AA> a output is NFKC, input in ISO 8859-1 Assert.AreEqual("a", SaslMechanism.SaslPrep("\u00AA"), "4"); // 5 <U+2168> IX output is NFKC, will match #1 Assert.AreEqual("IX", SaslMechanism.SaslPrep("\u2168"), "5"); // 6 <U+0007> Error - prohibited character try { SaslMechanism.SaslPrep("\u0007"); Assert.Fail("6"); } catch (ArgumentException) { } // 7 <U+0627><U+0031> Error - bidirectional check //try { // SaslMechanism.SaslPrep ("\u0627\u0031"); // Assert.Fail ("7"); //} catch (ArgumentException) { //} var prohibited = new char [] { '\uF8FF', '\uDFFF', '\uFFFD', '\u2FFB', '\u200E' }; foreach (var c in prohibited) { try { SaslMechanism.SaslPrep(c.ToString()); Assert.Fail("prohibited: '\\u{0:X}'", c); } catch (ArgumentException) { } } Assert.AreEqual(string.Empty, SaslMechanism.SaslPrep(string.Empty)); Assert.AreEqual("a b", SaslMechanism.SaslPrep("a\u00A0b")); }
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)); }