コード例 #1
0
        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>();

            });
        }
コード例 #2
0
        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);
            });
        }
コード例 #3
0
 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);
     });
 }