libs.S22.Sasl/Tests/DigestMd5Test.cs

37 lines
1.4 KiB
C#
Raw Permalink Normal View History

2014-01-06 09:27:48 +01:00
using Microsoft.VisualStudio.TestTools.UnitTesting;
using S22.Sasl.Mechanisms;
using System;
using System.Text;
namespace S22.Sasl.Test {
/// <summary>
/// Contains unit tests for the SASL DIGEST-MD5 authentication mechanism.
/// </summary>
[TestClass]
public class DigestMd5Test {
/// <summary>
/// Verifies the various parts of a sample authentication exchange
/// directly taken from RFC 2831 ("4 Example", p. 17-18).
/// </summary>
[TestMethod]
[TestCategory("Digest-Md5")]
public void VerifyAuthenticationExchange() {
SaslMechanism m = new SaslDigestMd5("chris", "secret", "OA6MHXh6VqTrRk");
string initialServer = "realm=\"elwood.innosoft.com\",nonce=\"OA6MG9" +
"tEQGm2hh\",qop=\"auth\",algorithm=md5-sess,charset=utf-8",
expectedResponse = "username=\"chris\",realm=\"elwood.innosoft.com\"," +
"nonce=\"OA6MG9tEQGm2hh\",nc=00000001,cnonce=\"OA6MHXh6VqTrRk\"," +
"digest-uri=\"imap/elwood.innosoft.com\"," +
"response=d388dad90d4bbd760a152321f2143af7,qop=auth";
string initialResponse = Encoding.ASCII.GetString(
m.GetResponse(Encoding.ASCII.GetBytes(initialServer)));
Assert.AreEqual<string>(expectedResponse, initialResponse);
string finalResponse = Encoding.ASCII.GetString(
m.GetResponse(Encoding.ASCII.GetBytes("rspauth=ea40f60335c427b5" +
"527b84dbabcdfffd")));
Assert.AreEqual<string>(String.Empty, finalResponse);
}
}
}