Beispiel #1
0
 public void ShouldNotRedirectAuthenticatedUser([Substitute] AuthorizationContext filterContext, RedirectUnauthenticatedAttribute redirectUnauthenticated)
 {
     using (new Sitecore.Security.Accounts.UserSwitcher(@"extranet\John", true))
     {
         redirectUnauthenticated.OnAuthorization(filterContext);
         filterContext.Result.Should().BeNull();
     }
 }
Beispiel #2
0
        public void ShouldNotRedirectAuthenticatedUser([Substitute] AuthorizationContext filterContext)
        {
            var urlService = Substitute.For <IGetRedirectUrlService>();
            var redirectUnauthenticated = new RedirectUnauthenticatedAttribute(urlService);

            using (new Sitecore.Security.Accounts.UserSwitcher(@"extranet\John", true))
            {
                redirectUnauthenticated.OnAuthorization(filterContext);
                filterContext.Result.Should().BeNull();
            }
        }
Beispiel #3
0
        public void ShouldRedirectUnauthenticatedUser([Substitute] AuthorizationContext filterContext, string url)
        {
            var urlService = Substitute.For <IGetRedirectUrlService>();

            urlService.GetRedirectUrl(AuthenticationStatus.Unauthenticated, Arg.Any <string>()).Returns(url);
            var redirectUnauthenticated = new RedirectUnauthenticatedAttribute(urlService);

            using (new Sitecore.Security.Accounts.UserSwitcher(@"extranet\John", false))
            {
                redirectUnauthenticated.OnAuthorization(filterContext);
                filterContext.Result.Should().BeOfType <RedirectResult>().Which.Url.Should().Be(url);
            }
        }
Beispiel #4
0
        public void ShouldRedirectUnauthenticatedUser(Database db, [Content] DbItem item, [Substitute] AuthorizationContext filterContext, RedirectUnauthenticatedAttribute redirectUnauthenticated)
        {
            var fakeSite = new FakeSiteContext(new StringDictionary
            {
                {
                    "rootPath", "/sitecore/content"
                },
                {
                    "startItem", item.Name
                }
            }) as SiteContext;

            fakeSite.Database = db;
            Language.Current  = Language.Invariant;

            using (new SiteContextSwitcher(fakeSite))
                using (new Sitecore.Security.Accounts.UserSwitcher(@"extranet\John", false))
                {
                    redirectUnauthenticated.OnAuthorization(filterContext);
                    filterContext.Result.Should().BeOfType <RedirectResult>().Which.Url.Should().Be("/");
                }
        }