Пример #1
0
        public async Task AuthenticateUser_RequestTokenWithValidAltinnCookie_SblBridgeUnavailable_ReturnsServiceUnavailable()
        {
            // Arrange
            HttpResponseMessage bridgeResponse = new HttpResponseMessage
            {
                StatusCode   = HttpStatusCode.ServiceUnavailable,
                ReasonPhrase = "Service Unavailable"
            };
            SblBridgeResponseException sblBridgeResponseException = new SblBridgeResponseException(bridgeResponse);

            _cookieDecryptionService.Setup(s => s.DecryptTicket(It.IsAny <string>())).ThrowsAsync(sblBridgeResponseException);

            HttpClient client = GetTestClient(_cookieDecryptionService.Object, _userProfileService.Object);

            string             url            = "/authentication/api/v1/authentication?goto=http%3A%2F%2Flocalhost";
            HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, url);

            requestMessage.Headers.Add("Cookie", ".ASPXAUTH=asdasdasd");

            // Act
            HttpResponseMessage response = await client.SendAsync(requestMessage);

            // Assert
            Assert.Equal(HttpStatusCode.ServiceUnavailable, response.StatusCode);
        }
Пример #2
0
        public async Task DecryptTicket_SblBridgeResponseIsServiceUnavailable_ThrowsException()
        {
            // Arrange
            HttpResponseMessage httpResponseMessage = new HttpResponseMessage
            {
                StatusCode   = HttpStatusCode.ServiceUnavailable,
                ReasonPhrase = "Service Unavailable"
            };

            InitializeMocks(httpResponseMessage);

            HttpClient httpClient             = new HttpClient(_handlerMock.Object);
            SblCookieDecryptionService target = new SblCookieDecryptionService(httpClient, _generalSettingsOptions.Object, _logger.Object);

            SblBridgeResponseException actual = null;

            // Act
            try
            {
                await target.DecryptTicket("random and irrelevant bytes");
            }
            catch (SblBridgeResponseException e)
            {
                actual = e;
            }

            // Assert
            _handlerMock.VerifyAll();

            Assert.NotNull(actual);
            Assert.Contains("ServiceUnavailable", actual.Message);
        }
        public void Constructor_WithHttpResponsMessageAndMessage_ExceptionMessageMatchInputMessage()
        {
            // Arrange
            HttpResponseMessage httpResponseMessage = new HttpResponseMessage
            {
                StatusCode   = HttpStatusCode.BadRequest,
                ReasonPhrase = "BadRequest"
            };

            // Act
            var actual = new SblBridgeResponseException(httpResponseMessage, "Message");

            // Assert
            Assert.NotNull(actual);
            Assert.NotNull(actual.Response);
            Assert.Equal("Message", actual.Message);
        }