示例#1
0
    public void ShouldAuthenticateRequest_Is_Back_Office()
    {
        var globalSettings = new GlobalSettings();

        var runtime = Mock.Of <IRuntimeState>(x => x.Level == RuntimeLevel.Run);

        GenerateAuthPaths(out var remainingTimeoutSecondsPath, out var isAuthPath);

        var mgr = new BackOfficeCookieManager(
            Mock.Of <IUmbracoContextAccessor>(),
            runtime,
            new UmbracoRequestPaths(
                Options.Create(globalSettings),
                Mock.Of <IHostingEnvironment>(x =>
                                              x.ApplicationVirtualPath == "/" && x.ToAbsolute(globalSettings.UmbracoPath) == "/umbraco" &&
                                              x.ToAbsolute(Constants.SystemDirectories.Install) == "/install")),
            Mock.Of <IBasicAuthService>());

        var result = mgr.ShouldAuthenticateRequest(remainingTimeoutSecondsPath);

        Assert.IsTrue(result);

        result = mgr.ShouldAuthenticateRequest(isAuthPath);
        Assert.IsTrue(result);
    }
        public void ShouldAuthenticateRequest_When_Configured()
        {
            var dbCtx = new Mock <DatabaseContext>(Mock.Of <IScopeProviderInternal>(), Mock.Of <ILogger>(), Mock.Of <ISqlSyntaxProvider>(), "test");

            dbCtx.Setup(x => x.IsDatabaseConfigured).Returns(true);

            var appCtx = new ApplicationContext(
                dbCtx.Object,
                MockHelper.GetMockedServiceContext(),
                CacheHelper.CreateDisabledCacheHelper(),
                new ProfilingLogger(Mock.Of <ILogger>(), Mock.Of <IProfiler>()));

            var umbCtx = UmbracoContext.CreateContext(
                Mock.Of <HttpContextBase>(),
                appCtx,
                new WebSecurity(Mock.Of <HttpContextBase>(), appCtx),
                Mock.Of <IUmbracoSettingsSection>(), new List <IUrlProvider>(), false);

            var mgr = new BackOfficeCookieManager(Mock.Of <IUmbracoContextAccessor>(accessor => accessor.Value == umbCtx));

            var request = new Mock <OwinRequest>();

            request.Setup(owinRequest => owinRequest.Uri).Returns(new Uri("http://localhost/umbraco"));

            var result = mgr.ShouldAuthenticateRequest(
                Mock.Of <IOwinContext>(context => context.Request == request.Object),
                new Uri("http://localhost/umbraco"));

            Assert.IsTrue(result);
        }
        public void ShouldAuthenticateRequest_When_Not_Configured()
        {
            //should force app ctx to show not-configured
            ConfigurationManager.AppSettings.Set("umbracoConfigurationStatus", "");

            var dbCtx = new Mock <DatabaseContext>(Mock.Of <IScopeProviderInternal>(), Mock.Of <ILogger>(), Mock.Of <ISqlSyntaxProvider>(), "test");

            dbCtx.Setup(x => x.IsDatabaseConfigured).Returns(false);

            var appCtx = new ApplicationContext(
                dbCtx.Object,
                MockHelper.GetMockedServiceContext(),
                CacheHelper.CreateDisabledCacheHelper(),
                new ProfilingLogger(Mock.Of <ILogger>(), Mock.Of <IProfiler>()));

            var umbCtx = UmbracoContext.CreateContext(
                Mock.Of <HttpContextBase>(),
                appCtx,
                new WebSecurity(Mock.Of <HttpContextBase>(), appCtx),
                Mock.Of <IUmbracoSettingsSection>(), new List <IUrlProvider>(), false);

            var mgr = new BackOfficeCookieManager(Mock.Of <IUmbracoContextAccessor>(accessor => accessor.Value == umbCtx));

            var result = mgr.ShouldAuthenticateRequest(Mock.Of <IOwinContext>(), new Uri("http://localhost/umbraco"));

            Assert.IsFalse(result);
        }
示例#4
0
        public void ShouldAuthenticateRequest_When_Not_Configured()
        {
            var globalSettings = new GlobalSettings();

            IRuntimeState runtime = Mock.Of <IRuntimeState>(x => x.Level == RuntimeLevel.Install);
            var           mgr     = new BackOfficeCookieManager(
                Mock.Of <IUmbracoContextAccessor>(),
                runtime,
                new UmbracoRequestPaths(Options.Create(globalSettings), TestHelper.GetHostingEnvironment()),
                Mock.Of <IBasicAuthService>());

            var result = mgr.ShouldAuthenticateRequest("/umbraco");

            Assert.IsFalse(result);
        }
示例#5
0
        public void ShouldAuthenticateRequest_When_Configured()
        {
            var globalSettings = new GlobalSettings();

            IRuntimeState runtime = Mock.Of <IRuntimeState>(x => x.Level == RuntimeLevel.Run);
            var           mgr     = new BackOfficeCookieManager(
                Mock.Of <IUmbracoContextAccessor>(),
                runtime,
                new UmbracoRequestPaths(
                    Options.Create(globalSettings),
                    Mock.Of <IHostingEnvironment>(x => x.ApplicationVirtualPath == "/" && x.ToAbsolute(globalSettings.UmbracoPath) == "/umbraco")),
                Mock.Of <IBasicAuthService>());

            var result = mgr.ShouldAuthenticateRequest("/umbraco");

            Assert.IsTrue(result);
        }
        public void ShouldAuthenticateRequest_When_Not_Configured()
        {
            //should force app ctx to show not-configured
            ConfigurationManager.AppSettings.Set(Constants.AppSettings.ConfigurationStatus, "");

            var globalSettings = TestObjects.GetGlobalSettings();
            var umbracoContext = new UmbracoContext(
                Mock.Of <HttpContextBase>(),
                Mock.Of <IPublishedSnapshotService>(),
                new WebSecurity(Mock.Of <HttpContextBase>(), Current.Services.UserService, globalSettings),
                TestObjects.GetUmbracoSettings(), new List <IUrlProvider>(), Enumerable.Empty <IMediaUrlProvider>(), globalSettings,
                new TestVariationContextAccessor());

            var runtime = Mock.Of <IRuntimeState>(x => x.Level == RuntimeLevel.Install);
            var mgr     = new BackOfficeCookieManager(
                Mock.Of <IUmbracoContextAccessor>(accessor => accessor.UmbracoContext == umbracoContext), runtime, TestObjects.GetGlobalSettings());

            var result = mgr.ShouldAuthenticateRequest(Mock.Of <IOwinContext>(), new Uri("http://localhost/umbraco"));

            Assert.IsFalse(result);
        }
示例#7
0
        public void ShouldAuthenticateRequest_Not_Back_Office()
        {
            var globalSettings = new GlobalSettings();

            IRuntimeState runtime = Mock.Of <IRuntimeState>(x => x.Level == RuntimeLevel.Run);

            var mgr = new BackOfficeCookieManager(
                Mock.Of <IUmbracoContextAccessor>(),
                runtime,
                new UmbracoRequestPaths(
                    Options.Create(globalSettings),
                    Mock.Of <IHostingEnvironment>(x => x.ApplicationVirtualPath == "/" && x.ToAbsolute(globalSettings.UmbracoPath) == "/umbraco" && x.ToAbsolute(Constants.SystemDirectories.Install) == "/install")),
                Mock.Of <IBasicAuthService>());

            var result = mgr.ShouldAuthenticateRequest("/notbackoffice");

            Assert.IsFalse(result);
            result = mgr.ShouldAuthenticateRequest("/umbraco/api/notbackoffice");
            Assert.IsFalse(result);
            result = mgr.ShouldAuthenticateRequest("/umbraco/surface/notbackoffice");
            Assert.IsFalse(result);
        }
        public void ShouldAuthenticateRequest_When_Configured()
        {
            var globalSettings = TestObjects.GetGlobalSettings();
            var umbCtx         = new UmbracoContext(
                Mock.Of <HttpContextBase>(),
                Mock.Of <IPublishedSnapshotService>(),
                new WebSecurity(Mock.Of <HttpContextBase>(), Current.Services.UserService, globalSettings),
                TestObjects.GetUmbracoSettings(), new List <IUrlProvider>(), Enumerable.Empty <IMediaUrlProvider>(), globalSettings,
                new TestVariationContextAccessor());

            var runtime = Mock.Of <IRuntimeState>(x => x.Level == RuntimeLevel.Run);
            var mgr     = new BackOfficeCookieManager(Mock.Of <IUmbracoContextAccessor>(accessor => accessor.UmbracoContext == umbCtx), runtime, TestObjects.GetGlobalSettings());

            var request = new Mock <OwinRequest>();

            request.Setup(owinRequest => owinRequest.Uri).Returns(new Uri("http://localhost/umbraco"));

            var result = mgr.ShouldAuthenticateRequest(
                Mock.Of <IOwinContext>(context => context.Request == request.Object),
                new Uri("http://localhost/umbraco"));

            Assert.IsTrue(result);
        }