private static bool IsRedirectAllowed(string url, HttpApplication app, PortalSettings portalSettings)
        {
            var urlAction = new UrlAction(app.Request);

            urlAction.SetRedirectAllowed(url, new FriendlyUrlSettings(portalSettings.PortalId));
            return(urlAction.RedirectAllowed);
        }
Ejemplo n.º 2
0
        public void CheckForRedirects_WithUmlautUrls_DontRedirectInfinitely()
        {
            // Arrange
            const string CheckForRedirectsMethodName = "CheckForRedirects";
            const string HostSettingsTableName       = "HostSettings";
            const string PortalSettingsTableName     = "PortalSettings";
            const string LanguagesTableName          = "Languages";
            const string TabsTableName                 = "Tabs";
            const string TabUrlsTableName              = "TabUrls";
            const string PortalsTableName              = "Portals";
            const string TabSettingsTableName          = "TabSettings";
            const string PortalAliasTableName          = "PortalAlias";
            const string ExtensionUrlProviderTableName = "ExtensionUrlProvider";
            const string HttpScheme     = "http";
            const string HttpsScheme    = "https";
            const string UriUrl         = HttpScheme + "://" + GenericHost + "/über-uns/ctl/module/moduleid/466?returnurl=/über-uns";
            const string FullUrl        = HttpScheme + "://" + GenericHost + "/%C3%BCber-uns/ctl/module/moduleid/466?returnurl=/%C3%BCber-uns";
            const string RewritePath    = "Default.aspx?TabId=1&ctl=module&moduleid=466&returnurl=/%C3%BCber-uns&language=en-US";
            const string SampleHttpsUrl = HttpsScheme + "://google.com";
            const string PortalSettingsControllerRegistrationName = "PortalSettingsController";
            const string DNNPlatformText    = "DNN Platform";
            const string WebsiteText        = "Website";
            const string ApplicationPath    = "/";
            const string UrlRewriteItemName = "UrlRewrite:OriginalUrl";

            ComponentFactory.Container = null;
            PortalController.ClearInstance();
            Host.PerformanceSetting = Globals.PerformanceSettings.ModerateCaching;
            var uri             = new Uri(Assembly.GetExecutingAssembly().CodeBase);
            var path            = HttpUtility.UrlDecode(Path.GetFullPath(uri.AbsolutePath));
            var websiteRootPath = path.Substring(0, path.IndexOf(DNNPlatformText, StringComparison.Ordinal));
            var physicalAppPath = Path.Combine(websiteRootPath, WebsiteText);
            var simulator       = new HttpSimulator(ApplicationPath, physicalAppPath);

            simulator.SimulateRequest(new Uri(SampleHttpsUrl));
            HttpContext.Current.Items.Add(UrlRewriteItemName, FullUrl);
            var serviceCollection = new ServiceCollection();

            serviceCollection.AddTransient(container => Mock.Of <IHostSettingsService>());
            serviceCollection.AddTransient(container => Mock.Of <IApplicationStatusInfo>());
            serviceCollection.AddTransient(container => Mock.Of <INavigationManager>());
            serviceCollection.AddTransient(container => Mock.Of <IPortalAliasService>());
            MockComponentProvider.CreateNew <CachingProvider>();
            MockComponentProvider.CreateNew <DataProvider>();
            MockComponentProvider.CreateNew <LoggingProvider>();
            MockComponentProvider.CreateNew <PortalSettingsController>(PortalSettingsControllerRegistrationName);
            var dataProvider      = MockComponentProvider.CreateDataProvider();
            var hostSettingsTable = new DataTable(HostSettingsTableName);

            dataProvider
            .Setup(s => s.GetHostSettings())
            .Returns(() => hostSettingsTable.CreateDataReader());
            var portalSettingsTable = new DataTable(PortalSettingsTableName);

            dataProvider
            .Setup(s => s.GetPortalSettings(
                       It.IsAny <int>(),
                       It.IsAny <string>()))
            .Returns(() => portalSettingsTable.CreateDataReader());
            var languagesTable = new DataTable(LanguagesTableName);

            dataProvider
            .Setup(s => s.GetLanguagesByPortal(It.IsAny <int>()))
            .Returns(() => languagesTable.CreateDataReader());
            var tabsTable = new DataTable(TabsTableName);

            FillTabsTable(tabsTable);
            dataProvider
            .Setup(s => s.GetTabs(It.IsAny <int>()))
            .Returns(() => tabsTable.CreateDataReader());
            dataProvider
            .Setup(s => s.GetTabCustomAliases(It.IsAny <int>()))
            .Returns(() => tabsTable.CreateDataReader());
            var tabUrlsTable = new DataTable(TabUrlsTableName);

            dataProvider
            .Setup(s => s.GetTabPaths(
                       It.IsAny <int>(),
                       It.IsAny <string>()))
            .Returns(() => tabUrlsTable.CreateDataReader());
            dataProvider
            .Setup(s => s.GetTabUrls(It.IsAny <int>()))
            .Returns(() => tabUrlsTable.CreateDataReader());
            var tabSettingsTable = new DataTable(TabSettingsTableName);

            dataProvider
            .Setup(s => s.GetTabSettings(It.IsAny <int>()))
            .Returns(() => tabSettingsTable.CreateDataReader());
            var portalsTable = new DataTable(PortalsTableName);

            FillPortalsTable(portalsTable);
            dataProvider
            .Setup(s => s.GetPortals(It.IsAny <string>()))
            .Returns(() => portalsTable.CreateDataReader());
            var extensionUrlProviderTable = new DataTable(ExtensionUrlProviderTableName);

            dataProvider
            .Setup(s => s.GetExtensionUrlProviders(It.IsAny <int>()))
            .Returns(() => extensionUrlProviderTable.CreateDataReader());
            var portalAliasTable = new DataTable(PortalAliasTableName);

            FillPortalAliasTable(portalAliasTable);
            dataProvider
            .Setup(s => s.GetPortalAliases())
            .Returns(() => portalAliasTable.CreateDataReader());
            Globals.DependencyProvider = serviceCollection.BuildServiceProvider();
            var urlRewriter             = new AdvancedUrlRewriter();
            var checkForRedirectsMethod = typeof(AdvancedUrlRewriter)
                                          .GetMethod(
                CheckForRedirectsMethodName,
                BindingFlags.Static | BindingFlags.NonPublic);
            var requestUri            = new Uri(UriUrl);
            var queryStringCollection = new NameValueCollection();
            var friendlyUrlSettings   = new FriendlyUrlSettings(GenericPortalId);
            var urlAction             = new UrlAction(
                HttpScheme,
                string.Empty,
                string.Empty)
            {
                TabId          = GenericTabId,
                Action         = ActionType.CheckFor301,
                PortalId       = GenericPortalId,
                IsSSLOffloaded = true,
                PortalAlias    = new PortalAliasInfo
                {
                    HTTPAlias = GenericHost,
                },
                DoRewrite   = true,
                RewritePath = RewritePath
            };

            urlAction.SetRedirectAllowed(string.Empty, friendlyUrlSettings);
            var requestType     = string.Empty;
            var portalHomeTabId = GenericTabId;

            // Act
            var isRedirected = checkForRedirectsMethod.Invoke(
                urlRewriter,
                new object[]
            {
                requestUri,
                FullUrl,
                queryStringCollection,
                urlAction,
                requestType,
                friendlyUrlSettings,
                portalHomeTabId
            });

            // Assert
            Assert.AreEqual(false, isRedirected);
        }