public void ApplyReturnUrlMapping_ReturnUrlNotMapped_ReturnsRedirectUriUnchanged()
        {
            // Arrange
            CookieApplyRedirectContext context = A.Fake <CookieApplyRedirectContext>();

            context.RedirectUri = "https://weee.com/sign-in?ReturnUrl=%2fcontroller1%2faction1";

            IReturnUrlMapping mapping = A.Fake <IReturnUrlMapping>();

            A.CallTo(() => mapping.IsMapped("/mycontroller/myaction")).Returns(false);

            WeeeCookieAuthenticationProvider provider = new WeeeCookieAuthenticationProvider(mapping);

            // Act
            provider.ApplyReturnUrlMapping(context);

            // Assert
            Assert.Equal("https://weee.com/sign-in?ReturnUrl=%2fcontroller1%2faction1", context.RedirectUri);
        }
        public void ApplyReturnUrlMapping_ReturnUrlMappedToNull_ReturnsRedirectUriWithoutReturnUrl()
        {
            // Arrange
            CookieApplyRedirectContext context = A.Fake <CookieApplyRedirectContext>();

            context.RedirectUri = "https://weee.com/sign-in?ReturnUrl=%2fcontroller1%2faction1";

            IReturnUrlMapping mapping = A.Fake <IReturnUrlMapping>();

            A.CallTo(() => mapping.IsMapped("/controller1/action1")).Returns(true);
            A.CallTo(() => mapping.ApplyMap("/controller1/action1")).Returns(null);

            WeeeCookieAuthenticationProvider provider = new WeeeCookieAuthenticationProvider(mapping);

            // Act
            provider.ApplyReturnUrlMapping(context);

            // Assert
            Assert.Equal("https://weee.com/sign-in", context.RedirectUri);
        }
Exemplo n.º 3
0
        public WeeeCookieAuthenticationProvider(IReturnUrlMapping returnUrlMapping)
        {
            this.returnUrlMapping = returnUrlMapping;

            AdminAreaName  = "admin";
            AdminLoginPath = "/admin/account/sign-in";

            OnValidateIdentity = async context =>
            {
                CheckAccessToken(context);
                await IdentityValidationHelper.TransformClaims(context);
            };

            // Add our custom login to the redirect before applying the deafult implementation.
            OnApplyRedirect = (context) =>
            {
                ErrorIfAlreadyAuthenticated(context);
                UpdateRedirectUrlToAdminLoginPageIfNecessary(context);
                ApplyReturnUrlMapping(context);
                defaultImplementation.ApplyRedirect(context);
            };
        }
        public WeeeCookieAuthenticationProvider(IReturnUrlMapping returnUrlMapping)
        {
            this.returnUrlMapping = returnUrlMapping;

            AdminAreaName = "admin";
            AdminLoginPath = "/admin/account/sign-in";

            OnValidateIdentity = async context =>
            {
                CheckAccessToken(context);
                await IdentityValidationHelper.TransformClaims(context);
            };

            // Add our custom login to the redirect before applying the deafult implementation.
            OnApplyRedirect = (context) =>
            {
                ErrorIfAlreadyAuthenticated(context);
                UpdateRedirectUrlToAdminLoginPageIfNecessary(context);
                ApplyReturnUrlMapping(context);
                defaultImplementation.ApplyRedirect(context);
            };
        }