|
using System.ServiceModel.Channels;
using BasicAuthenticationUsingWCF;
using NUnit.Framework;
namespace BasicAuthenticationUsingWCFTest
{
[TestFixture]
public class HttpRequestAuthorizationExtractorTest
{
[Test]
public void ShouldExtractBasicAuthorizationHeaderIfExists()
{
const string AuthorizationHeader = "Basic SGVsbG8gQmFzZTY0";
Message dummyMessage = CreateRequestMessage(AuthorizationHeader);
var extractor = new AuthorizationStringExtractor();
string returnedAuthorizationHeader;
bool result = extractor.TryExtractAuthorizationHeader(dummyMessage, out returnedAuthorizationHeader);
Assert.That(returnedAuthorizationHeader, Is.EqualTo(AuthorizationHeader));
Assert.That(result, Is.True);
}
[Test]
public void ShouldValidateIfAuthorizationHeaderExists()
{
Message dummyMessage = CreateNormalRequestMessage();
var extractor = new AuthorizationStringExtractor();
string returnedAuthorizationHeader;
bool result = extractor.TryExtractAuthorizationHeader(dummyMessage, out returnedAuthorizationHeader);
Assert.That(result, Is.False);
}
private static Message CreateRequestMessage(string authorizationheaderToAdd)
{
const string BasicAuthenticationHeaderName = "Authorization";
Message requestMessage = Message.CreateMessage(MessageVersion.None, null);
var requestProperty = new HttpRequestMessageProperty();
requestProperty.Headers.Add(BasicAuthenticationHeaderName, authorizationheaderToAdd);
requestMessage.Properties.Add(HttpRequestMessageProperty.Name, requestProperty);
return requestMessage;
}
private static Message CreateNormalRequestMessage()
{
var requestProperty = new HttpRequestMessageProperty();
Message requestMessage = Message.CreateMessage(MessageVersion.None, null);
requestMessage.Properties.Add(HttpRequestMessageProperty.Name, requestProperty);
return requestMessage;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Patrick Kalkman is a senior Software Architect with more than 20 years professional development experience. He works for
SimpleTechture where he helps teams develop state of the art web applications.
Patrick enjoys writing his
blog. It discusses agile software development. Patrick can be reached at patrick@simpletechture.nl.
Published Windows 8 apps:
Published Windows Phone apps:
Awards:
Best Mobile article of March 2012
Best Mobile article of June 2012