libs.S22.Sasl/Tests/OAuth2Test.cs

29 lines
970 B
C#
Raw Normal View History

2014-01-06 09:27:48 +01:00
using Microsoft.VisualStudio.TestTools.UnitTesting;
using S22.Sasl.Mechanisms;
using System.Text;
namespace S22.Sasl.Test {
/// <summary>
/// Contains unit tests for the SASL XOAUTH2 authentication mechanism.
/// </summary>
[TestClass]
public class OAuth2Test {
/// <summary>
/// Verifies the various parts of a sample authentication exchange
/// directly taken from Google's "XOAUTH2 Mechanism" document
/// ("Initial Client Response").
/// </summary>
[TestMethod]
[TestCategory("OAuth2")]
public void VerifyAuthenticationExchange() {
SaslMechanism m = new SaslOAuth2("someuser@example.com",
"vF9dft4qmTc2Nvb3RlckBhdHRhdmlzdGEuY29tCg==");
string expectedResponse = "user=someuser@example.com\u0001" +
"auth=Bearer vF9dft4qmTc2Nvb3RlckBhdHRhdmlzdGEuY29tCg==\u0001\u0001";
string initialResponse = Encoding.ASCII.GetString(
m.GetResponse(new byte[0]));
Assert.AreEqual<string>(expectedResponse, initialResponse);
}
}
}