public Task Current_Thread_Principal_Set_When_Authorization_Header_Is_Verified() { string userNamePwd = string.Format("{0}:{1}", UserName, Password); var requestMessage = new HttpRequestMessage(HttpMethod.Get, "http://localhost"); requestMessage.Headers.Authorization=new AuthenticationHeaderValue("Basic",EncodeToBase64(userNamePwd)); var customBasicAuthHandler = new CustomBasicAuthHandler(); return TestHelper.InvokeMessageHandler(requestMessage, customBasicAuthHandler).ContinueWith(t => { t.Status.ShouldBeEquivalentTo(TaskStatus.RanToCompletion); Thread.CurrentPrincipal.Should().NotBeNull(); Thread.CurrentPrincipal.Should().BeAssignableTo<GenericPrincipal>(); }); }
public Task Returns_Unauthorized_If_Authorization_Header_Is_Not_Verified() { string userNamePwd = string.Format("{0}:{1}", "user1", "rockstar"); var requestMessage = new HttpRequestMessage(HttpMethod.Get, "http://localhost"); requestMessage.Headers.Authorization=new AuthenticationHeaderValue("Basic",EncodeToBase64(userNamePwd)); var customBasicAuthHandler = new CustomBasicAuthHandler(); return TestHelper.InvokeMessageHandler(requestMessage, customBasicAuthHandler).ContinueWith(t => { t.Status.ShouldBeEquivalentTo(TaskStatus.RanToCompletion); t.Result.StatusCode.ShouldBeEquivalentTo(HttpStatusCode.Unauthorized); }); }
public Task Returns_Unauthorized_If_Auth_Header_Is_Missing() { var requestMessage = new HttpRequestMessage(HttpMethod.Get, "http://localhost"); var customBasicAuthHandler = new CustomBasicAuthHandler(); return TestHelper.InvokeMessageHandler(requestMessage, customBasicAuthHandler).ContinueWith(t => { t.Status.ShouldBeEquivalentTo(TaskStatus.RanToCompletion); t.Result.StatusCode.ShouldBeEquivalentTo(HttpStatusCode.Unauthorized); }); }