Exemplo n.º 1
0
        public async Task PostSessionSingleSignOn_FederatedAuthenticationException_BadRequestResult()
        {
            // Arrange
            var httpRequestMessage = new HttpRequestMessage();

            _authenticationRepositoryMock.Setup(m => m.AuthenticateSamlUserAsync(SamlResponse)).Throws(new FederatedAuthenticationException(FederatedAuthenticationErrorCode.WrongFormat));

            var controller = new SessionsController(_authenticationRepositoryMock.Object, _httpClientProvider, _logMock.Object)
            {
                Request = httpRequestMessage
            };

            // Act
            try
            {
                await controller.PostSessionSingleSignOn(SamlResponse);
            }
            catch (HttpResponseException ex)
            {
                // Assert
                Assert.AreEqual(ex.Response.StatusCode, HttpStatusCode.BadRequest);

                return;
            }

            Assert.Fail("A HttpResponseException was not thrown");
        }
Exemplo n.º 2
0
        public async Task PostSessionSingleSignOn_SessionNotFound_Success()
        {
            // Arrange
            _authenticationRepositoryMock.Setup(m => m.AuthenticateSamlUserAsync(SamlResponse)).ReturnsAsync(_loginUser);

            var token = Guid.NewGuid().ToString();

            var httpClientProvider = new TestHttpClientProvider(request =>
            {
                if (request.Method == HttpMethod.Get)
                {
                    return(new HttpResponseMessage(HttpStatusCode.NotFound));
                }
                var httpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK);
                httpResponseMessage.Headers.Add("Session-Token", token);
                return(httpResponseMessage);
            });

            var controller = new SessionsController(_authenticationRepositoryMock.Object, httpClientProvider, _logMock.Object);

            // Act
            var result = (ResponseMessageResult)await controller.PostSessionSingleSignOn(SamlResponse);

            // Assert
            Assert.AreEqual(HttpStatusCode.OK, result.Response.StatusCode);
            Assert.AreEqual(token, result.Response.Headers.GetValues("Session-Token").FirstOrDefault());
            var expectedToken = await result.Response.Content.ReadAsStringAsync();

            Assert.AreEqual(expectedToken, token);
        }
Exemplo n.º 3
0
        public async Task PostSessionSingleSignOn_FormatException_BadRequestResult()
        {
            // Arrange
            _authenticationRepositoryMock.Setup(m => m.AuthenticateSamlUserAsync(SamlResponse)).Throws(new FormatException());

            var controller = new SessionsController(_authenticationRepositoryMock.Object, _httpClientProvider, _logMock.Object);

            // Act
            IHttpActionResult result = await controller.PostSessionSingleSignOn(SamlResponse);

            // Assert
            Assert.IsInstanceOfType(result, typeof(BadRequestResult));
        }
Exemplo n.º 4
0
        public async Task PostSessionSingleSignOn_ServerError_InternalServerErrorResult()
        {
            // Arrange
            _authenticationRepositoryMock.Setup(m => m.AuthenticateSamlUserAsync(SamlResponse)).ReturnsAsync(_loginUser);

            var httpClientProvider = new TestHttpClientProvider(request => new HttpResponseMessage(HttpStatusCode.NotFound));

            var controller = new SessionsController(_authenticationRepositoryMock.Object, httpClientProvider, _logMock.Object);

            // Act
            IHttpActionResult result = await controller.PostSessionSingleSignOn(SamlResponse);

            // Assert
            Assert.IsInstanceOfType(result, typeof(InternalServerErrorResult));
        }
Exemplo n.º 5
0
        public async Task PostSessionSingleSignOn_SessionFound_ConflictResult()
        {
            // Arrange
            _authenticationRepositoryMock.Setup(m => m.AuthenticateSamlUserAsync(SamlResponse)).ReturnsAsync(_loginUser);

            var token = Guid.NewGuid().ToString();

            var httpClientProvider = new TestHttpClientProvider(request =>
            {
                var httpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK);
                httpResponseMessage.Headers.Add("Session-Token", token);
                return(httpResponseMessage);
            });

            var controller = new SessionsController(_authenticationRepositoryMock.Object, httpClientProvider, _logMock.Object);

            // Act
            IHttpActionResult result = await controller.PostSessionSingleSignOn(SamlResponse);

            // Assert
            Assert.IsInstanceOfType(result, typeof(ConflictResult));
        }