public async Task Match_Document_By_Url_Hide_Top_Level(string urlString, int expectedId)
    {
        GlobalSettings.HideTopLevelNodeFromPath = true;

        var(finder, frequest) = await GetContentFinder(urlString);

        Assert.IsTrue(GlobalSettings.HideTopLevelNodeFromPath);

        // FIXME: debugging - going further down, the routes cache is NOT empty?!
        if (urlString == "/home/sub1")
        {
            Debugger.Break();
        }

        var result = await finder.TryFindContent(frequest);

        if (expectedId > 0)
        {
            Assert.IsTrue(result);
            Assert.AreEqual(expectedId, frequest.PublishedContent.Id);
        }
        else
        {
            Assert.IsFalse(result);
        }
    }
Exemple #2
0
        public async Task DoNotPolluteCache()
        {
            var requestHandlerSettings = new RequestHandlerSettings {
                AddTrailingSlash = true
            };

            GlobalSettings.HideTopLevelNodeFromPath = false;

            SetDomains1();

            const string url = "http://domain1.com/1001-1/1001-1-1";

            // get the nice URL for 100111
            var umbracoContextAccessor = GetUmbracoContextAccessor(url);
            var umbracoContext         = umbracoContextAccessor.GetRequiredUmbracoContext();

            var urlProvider = new DefaultUrlProvider(
                Mock.Of <IOptionsMonitor <RequestHandlerSettings> >(x => x.CurrentValue == requestHandlerSettings),
                Mock.Of <ILogger <DefaultUrlProvider> >(),
                new SiteDomainMapper(),
                umbracoContextAccessor,
                new UriUtility(Mock.Of <IHostingEnvironment>()),
                Mock.Of <ILocalizationService>());
            var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);

            string absUrl = publishedUrlProvider.GetUrl(100111, UrlMode.Absolute);

            Assert.AreEqual("http://domain2.com/1001-1-1/", absUrl);

            const string cacheKeyPrefix = "NuCache.ContentCache.RouteByContent";

            // check that the proper route has been cached
            var cache = (FastDictionaryAppCache)umbracoContext.PublishedSnapshot.ElementsCache;

            var cachedRoutes = cache.Keys.Where(x => x.StartsWith(cacheKeyPrefix)).ToList();
            var cacheKey     = $"{cacheKeyPrefix}[P:100111]";

            Assert.AreEqual("10011/1001-1-1", cache.Get(cacheKey));

            // route a rogue URL
            var publishedRouter = CreatePublishedRouter(umbracoContextAccessor);
            var frequest        = await publishedRouter.CreateRequestAsync(umbracoContext.CleanedUmbracoUrl);

            publishedRouter.FindDomain(frequest);
            Assert.IsTrue(frequest.HasDomain());

            // check that it's been routed
            var lookup = new ContentFinderByUrl(Mock.Of <ILogger <ContentFinderByUrl> >(), umbracoContextAccessor);
            var result = await lookup.TryFindContent(frequest);

            Assert.IsTrue(result);
            Assert.AreEqual(100111, frequest.PublishedContent.Id);

            // has the cache been polluted?
            cachedRoutes = cache.Keys.Where(x => x.StartsWith(cacheKeyPrefix)).ToList();
            Assert.AreEqual("10011/1001-1-1", cache.Get(cacheKey)); // no

            // what's the nice URL now?
            Assert.AreEqual("http://domain2.com/1001-1-1/", publishedUrlProvider.GetUrl(100111)); // good
        }
Exemple #3
0
        public void Match_Document_By_Url_Hide_Top_Level(string urlString, int expectedId)
        {
            var globalSettingsMock = Mock.Get(Factory.GetInstance <IGlobalSettings>()); //this will modify the IGlobalSettings instance stored in the container

            globalSettingsMock.Setup(x => x.HideTopLevelNodeFromPath).Returns(true);

            var umbracoContext  = GetUmbracoContext(urlString, globalSettings: globalSettingsMock.Object);
            var publishedRouter = CreatePublishedRouter();
            var frequest        = publishedRouter.CreateRequest(umbracoContext);
            var lookup          = new ContentFinderByUrl(Logger);

            Assert.IsTrue(Current.Configs.Global().HideTopLevelNodeFromPath);

            // fixme debugging - going further down, the routes cache is NOT empty?!
            if (urlString == "/home/sub1")
            {
                System.Diagnostics.Debugger.Break();
            }

            var result = lookup.TryFindContent(frequest);

            if (expectedId > 0)
            {
                Assert.IsTrue(result);
                Assert.AreEqual(expectedId, frequest.PublishedContent.Id);
            }
            else
            {
                Assert.IsFalse(result);
            }
        }
        public void DoNotPolluteCache()
        {
            var globalSettings = Mock.Get(Factory.GetInstance <IGlobalSettings>()); //this will modify the IGlobalSettings instance stored in the container

            globalSettings.Setup(x => x.UseDirectoryUrls).Returns(true);
            globalSettings.Setup(x => x.HideTopLevelNodeFromPath).Returns(false);

            var settings = SettingsForTests.GenerateMockUmbracoSettings();
            var request  = Mock.Get(settings.RequestHandler);

            request.Setup(x => x.UseDomainPrefixes).Returns(true);

            SetDomains1();

            const string url = "http://domain1.com/1001-1/1001-1-1";

            // get the nice url for 100111
            var umbracoContext = GetUmbracoContext(url, 9999, umbracoSettings: settings, urlProviders: new []
            {
                new DefaultUrlProvider(settings.RequestHandler, Logger, globalSettings.Object, new SiteDomainHelper())
            }, globalSettings: globalSettings.Object);

            Assert.AreEqual("http://domain2.com/1001-1-1/", umbracoContext.UrlProvider.GetUrl(100111, true));

            // check that the proper route has been cached
            var cache = umbracoContext.ContentCache as PublishedContentCache;

            if (cache == null)
            {
                throw new Exception("Unsupported IPublishedContentCache, only the Xml one is supported.");
            }
            var cachedRoutes = cache.RoutesCache.GetCachedRoutes();

            Assert.AreEqual("10011/1001-1-1", cachedRoutes[100111]);

            // route a rogue url
            var publishedRouter = CreatePublishedRouter();
            var frequest        = publishedRouter.CreateRequest(umbracoContext);

            publishedRouter.FindDomain(frequest);
            Assert.IsTrue(frequest.HasDomain);

            // check that it's been routed
            var lookup = new ContentFinderByUrl(Logger);
            var result = lookup.TryFindContent(frequest);

            Assert.IsTrue(result);
            Assert.AreEqual(100111, frequest.PublishedContent.Id);

            // has the cache been polluted?
            cachedRoutes = cache.RoutesCache.GetCachedRoutes();
            Assert.AreEqual("10011/1001-1-1", cachedRoutes[100111]); // no
            //Assert.AreEqual("1001/1001-1/1001-1-1", cachedRoutes[100111]); // yes

            // what's the nice url now?
            Assert.AreEqual("http://domain2.com/1001-1-1/", umbracoContext.UrlProvider.GetUrl(100111)); // good
            //Assert.AreEqual("http://domain1.com/1001-1/1001-1-1", routingContext.NiceUrlProvider.GetNiceUrl(100111, true)); // bad
        }
Exemple #5
0
        public async Task DoNotPolluteCache()
        {
            var requestHandlerSettings = new RequestHandlerSettings {
                AddTrailingSlash = true
            };
            var globalSettings = new GlobalSettings {
                HideTopLevelNodeFromPath = false
            };

            SetDomains1();

            const string url = "http://domain1.com/1001-1/1001-1-1";

            // get the nice URL for 100111
            var umbracoContext         = GetUmbracoContext(url, 9999, globalSettings: globalSettings);
            var umbracoContextAccessor = GetUmbracoContextAccessor(umbracoContext);
            var urlProvider            = new DefaultUrlProvider(
                Microsoft.Extensions.Options.Options.Create(requestHandlerSettings),
                LoggerFactory.CreateLogger <DefaultUrlProvider>(),
                new SiteDomainMapper(), umbracoContextAccessor, UriUtility);
            var publishedUrlProvider = GetPublishedUrlProvider(umbracoContext, urlProvider);

            Assert.AreEqual("http://domain2.com/1001-1-1/", publishedUrlProvider.GetUrl(100111, UrlMode.Absolute));

            // check that the proper route has been cached
            var cache = umbracoContext.Content as PublishedContentCache;

            if (cache == null)
            {
                throw new Exception("Unsupported IPublishedContentCache, only the Xml one is supported.");
            }
            var cachedRoutes = cache.RoutesCache.GetCachedRoutes();

            Assert.AreEqual("10011/1001-1-1", cachedRoutes[100111]);

            // route a rogue URL
            var publishedRouter = CreatePublishedRouter(umbracoContextAccessor);
            var frequest        = await publishedRouter.CreateRequestAsync(umbracoContext.CleanedUmbracoUrl);

            publishedRouter.FindDomain(frequest);
            Assert.IsTrue(frequest.HasDomain());

            // check that it's been routed
            var lookup = new ContentFinderByUrl(LoggerFactory.CreateLogger <ContentFinderByUrl>(), GetUmbracoContextAccessor(umbracoContext));
            var result = lookup.TryFindContent(frequest);

            Assert.IsTrue(result);
            Assert.AreEqual(100111, frequest.PublishedContent.Id);

            // has the cache been polluted?
            cachedRoutes = cache.RoutesCache.GetCachedRoutes();
            Assert.AreEqual("10011/1001-1-1", cachedRoutes[100111]); // no
            //Assert.AreEqual("1001/1001-1/1001-1-1", cachedRoutes[100111]); // yes

            // what's the nice URL now?
            Assert.AreEqual("http://domain2.com/1001-1-1/", publishedUrlProvider.GetUrl(100111)); // good
            //Assert.AreEqual("http://domain1.com/1001-1/1001-1-1", routingContext.NiceUrlProvider.GetNiceUrl(100111, true)); // bad
        }
Exemple #6
0
        public void Match_Document_By_Url_With_Special_Characters(string urlString, int expectedId)
        {
            var globalSettingsMock = Mock.Get(Factory.GetInstance <IGlobalSettings>()); //this will modify the IGlobalSettings instance stored in the container

            globalSettingsMock.Setup(x => x.HideTopLevelNodeFromPath).Returns(false);

            var umbracoContext  = GetUmbracoContext(urlString, globalSettings: globalSettingsMock.Object);
            var publishedRouter = CreatePublishedRouter();
            var frequest        = publishedRouter.CreateRequest(umbracoContext);
            var lookup          = new ContentFinderByUrl(Logger);

            var result = lookup.TryFindContent(frequest);

            Assert.IsTrue(result);
            Assert.AreEqual(expectedId, frequest.PublishedContent.Id);
        }
Exemple #7
0
        public void Lookup_SingleDomain(string url, int expectedId)
        {
            SetDomains3();

            var globalSettingsMock = Mock.Get(Factory.GetInstance <IGlobalSettings>()); //this will modify the IGlobalSettings instance stored in the container

            globalSettingsMock.Setup(x => x.HideTopLevelNodeFromPath).Returns(true);

            var umbracoContext  = GetUmbracoContext(url, globalSettings: globalSettingsMock.Object);
            var publishedRouter = CreatePublishedRouter(Factory);
            var frequest        = publishedRouter.CreateRequest(umbracoContext);

            // must lookup domain else lookup by URL fails
            publishedRouter.FindDomain(frequest);

            var lookup = new ContentFinderByUrl(Logger);
            var result = lookup.TryFindContent(frequest);

            Assert.IsTrue(result);
            Assert.AreEqual(expectedId, frequest.PublishedContent.Id);
        }
Exemple #8
0
        public async Task DomainGeneric(string inputUrl, string expectedCulture, int expectedNode)
        {
            SetDomains3();

            var globalSettings = new GlobalSettings {
                HideTopLevelNodeFromPath = false
            };
            var umbracoContext  = GetUmbracoContext(inputUrl, globalSettings: globalSettings);
            var publishedRouter = CreatePublishedRouter(GetUmbracoContextAccessor(umbracoContext), Factory);
            var frequest        = await publishedRouter.CreateRequestAsync(umbracoContext.CleanedUmbracoUrl);

            // lookup domain
            publishedRouter.FindDomain(frequest);
            Assert.IsNotNull(frequest.Domain);

            Assert.AreEqual(expectedCulture, frequest.Culture);

            var finder = new ContentFinderByUrl(LoggerFactory.CreateLogger <ContentFinderByUrl>(), GetUmbracoContextAccessor(umbracoContext));
            var result = finder.TryFindContent(frequest);

            Assert.IsTrue(result);
            Assert.AreEqual(frequest.PublishedContent.Id, expectedNode);
        }