Пример #1
0
        public async Task ProcessContext_ValidAuthStatus_InvalidAuthResponseProvided()
        {
            // Arrange
            string accessToken  = "accessToken";
            string refreshToken = "refreshToken";
            Mock <IAuthService>    authServiceMock = GetValidAuthService(accessToken, refreshToken);
            RequestPipelineManager service         = new RequestPipelineManager(authServiceMock.Object);
            HttpContext            context         = GetRequestWithTokens();

            // Act
            HttpContext processedContext = service.ProcessRequest(context);

            // Assert
            Assert.IsNotEmpty(processedContext.Response.Headers);
            bool hasRespons = processedContext.Response.Headers.TryGetValue(Strings.AuthenticationResponseKey, out StringValues values);

            Assert.IsTrue(hasRespons);
            Assert.IsNotEmpty(values);
            Assert.AreEqual(Strings.AuthenticationSuccesful, values[0]);

            bool hasAccessToken = processedContext.Response.Headers.TryGetValue(Strings.AccessTokenKey, out StringValues accessTokenValues);

            Assert.IsTrue(hasAccessToken);
            Assert.IsNotEmpty(accessToken);
            Assert.AreEqual(accessToken, accessTokenValues[0]);

            bool hasRefreshToken = processedContext.Response.Headers.TryGetValue(Strings.RefreshTokenKey, out StringValues refreshTokenValues);

            Assert.IsTrue(hasRefreshToken);
            Assert.IsNotEmpty(refreshTokenValues);
            Assert.AreEqual(refreshToken, refreshTokenValues[0]);

            Assert.AreEqual((int)HttpStatusCode.Accepted, processedContext.Response.StatusCode);
        }
Пример #2
0
        public async Task ProcessContext_InvalidAuthStatus_InvalidAuthResponseProvided()
        {
            // Arrange
            Mock <IAuthService>    authServiceMock = GetInvalidAuthService();
            RequestPipelineManager service         = new RequestPipelineManager(authServiceMock.Object);
            HttpContext            context         = GetRequestWithTokens();

            // Act
            HttpContext processedContext = service.ProcessRequest(context);

            // Assert
            Assert.IsNotEmpty(processedContext.Response.Headers);
            bool hasRespons = processedContext.Response.Headers.TryGetValue(Strings.AuthenticationResponseKey, out StringValues values);

            Assert.IsTrue(hasRespons);
            Assert.IsNotEmpty(values);
            Assert.AreEqual(Strings.InvalidAccessAndRefreshTokens, values[0]);
            Assert.AreEqual((int)HttpStatusCode.Unauthorized, processedContext.Response.StatusCode);
        }
Пример #3
0
        public async Task ProcessContext_NoAccessTokenHeader_ResponseWithMissingTokensHeader()
        {
            // Arrange
            Mock <RequestDelegate> delegateMock    = new Mock <RequestDelegate>();
            Mock <IAuthService>    authServiceMock = new Mock <IAuthService>();
            RequestPipelineManager service         = new RequestPipelineManager(authServiceMock.Object);
            HttpContext            context         = new DefaultHttpContext();

            // Act
            HttpContext processedContext = service.ProcessRequest(context);

            // Assert
            Assert.IsNotEmpty(processedContext.Response.Headers);
            bool hasRespons = processedContext.Response.Headers.TryGetValue(Strings.AuthenticationResponseKey, out StringValues values);

            Assert.IsTrue(hasRespons);
            Assert.IsNotEmpty(values);
            Assert.AreEqual(Strings.AccessOrRefreshTokenNotProvided, values[0]);
            Assert.AreEqual((int)HttpStatusCode.BadRequest, processedContext.Response.StatusCode);
        }