Пример #1
0
    public EchoMessageHandlerTests(ITestOutputHelper logger)
    {
        // Pick a directory to isolate this test's input/output.
        // Precreate it, so that we exercise the library's willingness to create just one directory deeper.
        this.tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
        Directory.CreateDirectory(this.tempDir);

        this.mockHandler = new MockInnerHandler();
        this.StartNewSession();
        this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
    }
Пример #2
0
        public void MessageHandler_Should_Not_Add_Principal_If_Auth_Header_Missing()
        {
            //Setup
            MockInnerHandler innerhandler = new MockInnerHandler();

            innerhandler.Message = new HttpResponseMessage(HttpStatusCode.OK);

            HttpMessageInvoker client = new HttpMessageInvoker(new BasicAuthenticationMessageHandler {
                InnerHandler = innerhandler, MembershipService = new MockMembershipService(), RoleService = new MockRoleService()
            });
            HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, "http://localhost/api/projects");

            //Action
            HttpResponseMessage message = client.SendAsync(requestMessage, new CancellationToken(false)).Result;

            //Assert
            Assert.AreEqual(HttpStatusCode.OK, message.StatusCode);
            Assert.AreEqual(String.Empty, Thread.CurrentPrincipal.Identity.Name);
        }
Пример #3
0
        public void MessageHandler_Should_Not_Add_Principal_If_Wrong_Password()
        {
            //Setup
            MockInnerHandler innerhandler = new MockInnerHandler();

            innerhandler.Message = new HttpResponseMessage(HttpStatusCode.OK);

            HttpMessageInvoker client = new HttpMessageInvoker(new BasicAuthenticationMessageHandler {
                InnerHandler = innerhandler, MembershipService = new MockMembershipService(), RoleService = new MockRoleService()
            });
            HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, "http://localhost/api/projects");

            var usernamepwd   = Convert.ToBase64String(Encoding.UTF8.GetBytes("james:wrongPassword"));
            var authorization = new AuthenticationHeaderValue("Basic", usernamepwd);

            requestMessage.Headers.Authorization = authorization;

            //Action
            HttpResponseMessage message = client.SendAsync(requestMessage, new CancellationToken(false)).Result;

            //Assert
            Assert.AreEqual(HttpStatusCode.OK, message.StatusCode);
            Assert.AreEqual(String.Empty, Thread.CurrentPrincipal.Identity.Name);
        }