Exemplo n.º 1
0
            public void UrlFound_LogsShortCodeAndURLAndTrackingId()
            {
                var testShortCode = "sk";
                var testUrl       = "http://SeanKilleen.com";
                var testGaCode    = "12345";

                _mockRepo.Setup(x => x.GetByShortCode(It.IsAny <string>()))
                .Returns(new ShortLinkItem(testShortCode, testUrl));

                _mockGaOptions.Setup(x => x.Value)
                .Returns(new GoogleAnalyticsOptions {
                    TrackingPropertyId = testGaCode
                });

                // need to recreate SUT instead of setup because .Value is used in the Ctor,
                // meaning we can't just overwrite it with a Mock.
                var sut = new RedirectController(
                    _mockRepo.Object,
                    _mockLogger.Object,
                    _mockRedirectOptions.Object,
                    _mockGaOptions.Object);

                sut.Index("thisCodeDoesntMatter");

                _mockLogger.Verify(x => x.Information("Redirecting {shortCode} to {redirectUrl} using tracking Id {gaTrackingId}", testShortCode, testUrl, testGaCode));
            }
Exemplo n.º 2
0
            public Index()
            {
                _mockRedirectOptions.Setup(x => x.Value).Returns(new RedirectOptions());
                _mockGaOptions.Setup(x => x.Value).Returns(new GoogleAnalyticsOptions());

                _sut = new RedirectController(_mockRepo.Object, _mockLogger.Object, _mockRedirectOptions.Object, _mockGaOptions.Object);
            }
        public HttpResponseMessage SaveRedirect(MappingModel model)
        {
            var map = new Mapping();

            map.SourceUrl = model.SourceUrl.Trim();
            if (!string.IsNullOrEmpty(model.TargetUrl))
            {
                map.TargetUrl = model.TargetUrl;
            }
            else if (model.TargetTabId > 0)
            {
                map.TargetTabId = model.TargetTabId;
                map.TargetUrl   = DotNetNuke.Common.Globals.NavigateURL(map.TargetTabId, PortalSettings, "");
            }
            else
            {
                // keep giving 404
                map.EnableLogging = false;
            }
            if (map != null)
            {
                map.UseRegex = false;
                var cfg = RedirectConfig.Instance;
                cfg.Mappings.Add(map);
                cfg.ToFile(Common.RedirectConfigFile());
                RedirectConfig.Reload(PortalSettings.PortalId);
            }

            // set handledon/handledby in table
            RedirectController.SetHandledUrl(model.SourceUrl);

            return(Request.CreateResponse(HttpStatusCode.OK, new {}));
        }
Exemplo n.º 4
0
        public void ViewWithPath()
        {
            var testee = new RedirectController();

            var result = testee.ViewWithPath();

            result.ViewName.Should().Be("~/Views/Derived/Index.cshtml");
        }
Exemplo n.º 5
0
        public void ViewName()
        {
            var testee = new RedirectController();

            var result = testee.ViewName();

            result.ViewName.Should().Be("ViewName");
        }
Exemplo n.º 6
0
        public void PermanentRedirectToController()
        {
            var testee = new RedirectController();

            var result = testee.Permanentedirect();

            result.Permanent.Should().BeTrue();
            result.Url.Should().Be("/Redirected/Index");
        }
Exemplo n.º 7
0
        public void RedirectToRoute()
        {
            var testee = new RedirectController();

            var result = testee.RedirectToRoute();

            result.Permanent.Should().BeFalse();
            ((string)result.RouteValues["controller"]).Should().Be("Redirected");
            ((string)result.RouteValues["action"]).Should().Be("Index");
        }
        public HttpResponseMessage GetUnhandledUrls()
        {
            var _config = new Components.Config(ActiveModule.ModuleSettings, ActiveModule.ModuleID, ActiveModule.TabModuleID);
            var data    = RedirectController.GetTopUnhandledUrls(PortalSettings.PortalId, Constants.UnhandledUrlsMaxDays, _config.NoOfEntries);

            var retval = new UnhandledUrlsModel();

            data.ForEach(u => retval.Urls.Add(new UnhandledUrlModel(u)));

            return(Request.CreateResponse(HttpStatusCode.OK, retval));
        }
    public void RedirectController_TopicRedirect_ReturnsRedirectResult() {

      var controller            = new RedirectController(_topicRepository);
      var result                = controller.Redirect(11110) as RedirectResult;

      controller.Dispose();

      Assert.IsNotNull(result);
      Assert.IsTrue(result.Permanent);
      Assert.AreEqual<string>("/Web/Web_1/Web_1_1/Web_1_1_1/", result.Url);

    }
Exemplo n.º 10
0
        public RedirectControllerSteps()
        {
            var controllerContext = new ControllerContext
            {
                HttpContext = new DefaultHttpContext()
            };

            this.controller = new RedirectController(mockRepository.Object)
            {
                ControllerContext = controllerContext
            };
        }
        public HttpResponseMessage SaveMapping(MappingModel model) // string id, bool useRegex, string sourceUrl, string targetUrl, int targetTabId)
        {
            var map = RedirectConfig.Instance.Mappings.FirstOrDefault(m => m.Id == model.Id);

            if (!string.IsNullOrEmpty(model.Id) && map == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            if (map == null && string.IsNullOrEmpty(model.Id))
            {
                map    = new Mapping();
                map.Id = Guid.NewGuid().ToString();
                RedirectConfig.Instance.Mappings.Add(map);
            }

            map.StatusCode    = model.StatusCode;
            map.SourceUrl     = model.SourceUrl.Trim();
            map.UseRegex      = model.UseRegex;
            map.EnableLogging = model.EnableLogging;
            if (!string.IsNullOrEmpty(model.TargetUrl))
            {
                map.TargetTabId = Null.NullInteger;
                map.TargetUrl   = model.TargetUrl;
            }
            else if (model.TargetTabId > 0)
            {
                map.TargetTabId = model.TargetTabId;
                map.TargetUrl   = DotNetNuke.Common.Globals.NavigateURL(map.TargetTabId, PortalSettings, "");
            }
            else if (model.TargetTabId == -1) // matches with number in js file
            {
                map.TargetTabId = model.TargetTabId;
                map.TargetUrl   = "";
            }
            else if (model.TargetTabId == -2) // matches with number in js file, meaning it needs to be deleted
            {
                // remove mapping
                RedirectConfig.Instance.Mappings.Remove(map);
                map = null;
            }

            RedirectConfig.Instance.ToFile(Common.RedirectConfigFile());
            RedirectConfig.Reload(PortalSettings.PortalId);

            // set handledon/handledby in table
            if (!model.UseRegex)
            {
                RedirectController.SetHandledUrl(model.SourceUrl);
            }

            return(Request.CreateResponse(HttpStatusCode.OK, map == null ? null : new MappingModel(map)));
        }
Exemplo n.º 12
0
        public void RedirectControllerTest_SubpathRelativeMinusValue()
        {
            var appSettings = new AppSettings {
                Structure = "/yyyyMMdd/{filenamebase}.ext"
            };
            var controller = new RedirectController(_fakeSelectorStorage, appSettings);

            controller.ControllerContext.HttpContext = new DefaultHttpContext();
            var result = controller.SubPathRelative(1, true) as JsonResult;

            var today = "/" + DateTime.Now.AddDays(-1).ToString("yyyyMMdd");

            Assert.AreEqual(today, result.Value);
        }
Exemplo n.º 13
0
        public void RedirectControllerTest_SubpathRelativeRedirectToAction()
        {
            var appSettings = new AppSettings {
                Structure = "/yyyyMMdd/{filenamebase}.ext"
            };
            var controller = new RedirectController(_fakeSelectorStorage, appSettings)
            {
                ControllerContext = { HttpContext = new DefaultHttpContext() }
            };
            var result = controller.SubPathRelative(0, false) as RedirectToActionResult;

            var today = "/" + DateTime.Now.ToString("yyyyMMdd");

            Assert.AreEqual(today, result.RouteValues.Values.FirstOrDefault());
        }
Exemplo n.º 14
0
        public void RedirectControllerTest_LargeInt()
        {
            var appSettings = new AppSettings {
                Structure = "/yyyyMMdd/{filenamebase}.ext"
            };
            var controller = new RedirectController(_fakeSelectorStorage, appSettings)
            {
                ControllerContext = { HttpContext = new DefaultHttpContext() }
            };
            var result = controller.SubPathRelative(201801020, true) as JsonResult;
            // 201801020= not a date but a large number ==> fallback to today
            var today = "/" + DateTime.Now.ToString("yyyyMMdd");

            Assert.AreEqual(today, result.Value);
        }
        public void RedirectController_GetWithANonExistingAlias_ReturnsBadRequest()
        {
            // Arrange
            var controller = new RedirectController(dbContext);

            // Act
            var actionResult = controller.Get("unknownAlias");

            // Assert
            actionResult.Should().NotBeNull();
            var badRequestResult = actionResult as BadRequestObjectResult;

            badRequestResult.Should().NotBeNull();
            badRequestResult.Value.Should().Be("Url does not exist!");
        }
Exemplo n.º 16
0
        public async Task GoToPath_MediatorReturnsOkWithUrl_ReturnRedirectResultToPath()
        {
            var mediatorMock     = A.Fake <IMediator>();
            var shortPathFixture = Fixture.Create <string>();
            var pathFixture      = Fixture.Create <Uri>().ToString();

            A.CallTo(
                () => mediatorMock
                .Send(A <GetRedirectPath> .That
                      .Matches(query => query.ShortPath == shortPathFixture)
                      , CancellationToken.None))
            .Returns(Task.FromResult(Result.Ok(pathFixture)));
            var sut    = new RedirectController(mediatorMock);
            var result = await sut.GoToPath(shortPathFixture);

            result.Should().BeAssignableTo <RedirectResult>();
            result.As <RedirectResult>().Url.Should().Be(pathFixture);
        }
Exemplo n.º 17
0
        public async Task GoToPath_MediatorReturnsError_ReturnRedirectResultToBadPage()
        {
            var mediatorMock        = A.Fake <IMediator>();
            var shortPathFixture    = Fixture.Create <string>();
            var errorMessageFixture = Fixture.Create <string>();

            A.CallTo(
                () => mediatorMock
                .Send(A <GetRedirectPath> .That
                      .Matches(query => query.ShortPath == shortPathFixture)
                      , CancellationToken.None))
            .Returns(Task.FromResult(Result.Fail <string>(errorMessageFixture)));
            var sut    = new RedirectController(mediatorMock);
            var result = await sut.GoToPath(shortPathFixture);

            result.Should().BeAssignableTo <ViewResult>();
            result.As <ViewResult>().ViewName.Should().Be("BadPage");
        }
Exemplo n.º 18
0
        private void Page_PreRender(object sender, EventArgs e)
        {
            string incoming = (string)HttpContext.Current.Items["40F_SEO_IncomingUrl"];

            // check if IIS/ASP.NET/DNN already found this to be a 404
            if (Response.Status == "404 Not Found")
            {
                if (Response.StatusCode == (int)HttpStatusCode.NotFound && !string.IsNullOrEmpty(incoming))
                {
                    Common.Logger.Debug($"Logging redirect from Context_EndRequest. incoming:[{incoming}]");
                    RedirectController.AddRedirectLog(PortalId, incoming, "");
                }
            }

            // DNN returns 200 for static files that are actually 404's
            if (RedirectController.RequestHas404Detected() && Response.StatusCode == (int)HttpStatusCode.OK)
            {
                //RedirectController.AddRedirectLog(PortalId, incoming, "");
                RedirectController.SetStatus404();
            }
        }
Exemplo n.º 19
0
            public void UrlFound_PopulatesViewModelCorrectly()
            {
                var testShortCode     = "sk";
                var testUrl           = "http://SeanKilleen.com";
                var testGaCode        = "12345";
                var testSecondsToWait = 3;

                _mockRepo.Setup(x => x.GetByShortCode(It.IsAny <string>()))
                .Returns(new ShortLinkItem(testShortCode, testUrl));

                _mockGaOptions.Setup(x => x.Value)
                .Returns(new GoogleAnalyticsOptions {
                    TrackingPropertyId = testGaCode
                });

                _mockRedirectOptions.Setup(x => x.Value)
                .Returns(new RedirectOptions {
                    SecondsToWaitForAnalytics = testSecondsToWait
                });

                // need to recreate SUT instead of setup because .Value is used in the Ctor,
                // meaning we can't just overwrite it with a Mock.
                var sut = new RedirectController(
                    _mockRepo.Object,
                    _mockLogger.Object,
                    _mockRedirectOptions.Object,
                    _mockGaOptions.Object);

                var result = sut.Index(testShortCode);

                var viewResult = Assert.IsType <ViewResult>(result);

                var model = Assert.IsAssignableFrom <RedirectViewModel>(
                    viewResult.ViewData.Model);

                model.ShortLinkCode.Should().Be(testShortCode);
                model.NumberOfSecondsToWait.Should().Be(testSecondsToWait);
                model.TrackingCode.Should().Be(testGaCode);
                model.Url.Should().Be(testUrl);
            }
Exemplo n.º 20
0
            public async Task UrlFound_PopulatesViewModelCorrectly(string testShortCode, string testUrl, string testGaCode,
                                                                   int testSecondsToWait, string testImageUrl, string testTitle, string testDescription)
            {
                _mockRepo.Setup(x => x.GetByShortCode(It.IsAny <string>()))
                .Returns(Task.FromResult(new ShortLinkItem(testShortCode, testUrl, testImageUrl, testTitle, testDescription)));

                _mockGaOptions.Setup(x => x.Value)
                .Returns(new GoogleAnalyticsOptions {
                    TrackingPropertyId = testGaCode
                });

                _mockRedirectOptions.Setup(x => x.Value)
                .Returns(new RedirectOptions {
                    SecondsToWaitForAnalytics = testSecondsToWait
                });

                // need to recreate SUT instead of setup because .Value is used in the Ctor,
                // meaning we can't just overwrite it with a Mock.
                var sut = new RedirectController(
                    _mockRepo.Object,
                    _mockLogger.Object,
                    _mockRedirectOptions.Object,
                    _mockGaOptions.Object);

                var result = await sut.Index(testShortCode);

                var viewResult = Assert.IsType <ViewResult>(result);

                var model = Assert.IsAssignableFrom <RedirectViewModel>(
                    viewResult.ViewData.Model);

                model.ShortLinkCode.Should().Be(testShortCode);
                model.NumberOfSecondsToWait.Should().Be(testSecondsToWait);
                model.TrackingCode.Should().Be(testGaCode);
                model.ImageUrl.Should().Be(testImageUrl);
                model.Title.Should().Be(testTitle);
                model.Description.Should().Be(testDescription);
                model.Url.Should().Be(testUrl);
            }
        public void RedirectController_GetWithAnExistingAlias_RedirectsToAUrl()
        {
            // Arrange
            var alias       = "123abc";
            var redirectUrl = "http://www.google.com";

            dbContext.ShortUrls.Add(new Models.ShortUrl {
                Id = Guid.NewGuid(), Alias = alias, OriginalUrl = redirectUrl
            });
            dbContext.SaveChanges();
            var controller = new RedirectController(dbContext);

            // Act
            var actionResult = controller.Get(alias);

            // Assert
            actionResult.Should().NotBeNull();
            var redirectResult = actionResult as RedirectResult;

            redirectResult.Should().NotBeNull();
            redirectResult.Url.Should().Be(redirectUrl);
        }
Exemplo n.º 22
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            Page.PreRender += Page_PreRender;
            // as of dnn 7.1, when using Advanced FriendlyURLs, there needs to be a setting in Portalsettings for 404 pages
            // here we're checking that

            var ver = DotNetNuke.Application.DotNetNukeContext.Current.Application.Version;

            if ((UserInfo.IsSuperUser || UserInfo.IsInRole(PortalSettings.AdministratorRoleName)) && (ver.Major == 7 && ver.Minor < 3))
            {
                if (PortalController.GetPortalSettingAsInteger("AUM_ErrorPage404", PortalId, Null.NullInteger) <= 0)
                {
                    Controls.Add(
                        new LiteralControl(String.Format("<p class=\"NormalRed\">{0}</p>",
                                                         Localization.GetString("Dnn404PortalSettingAbsent.Text", LocalResourceFile))));
                }
            }

            // if it's not a 404, we only want to log when the requested URL is for a deeper level than the page itself is
            //// TODO: This doesn't work as intended, so it's gone
            //// so OnlyLogwhen404 should be true if the request is for the same or higher level
            ////Request.RawUrl.Count(t => t == '/') <= PortalSettings.ActiveTab.Level + 1;
            var onlyLogWhen404 = true;

            Common.Logger.Debug($"Calling DoRedirect From View.ascx OnInit");
            RedirectController.DoRedirect(LoggingPlaceholder.Controls, true, onlyLogWhen404);

            if (!IsPostBack)
            {
                if (TabPermissionController.CanAdminPage())
                {
                    UnhandledUrlsPanel.Visible = true;
                }
            }
        }
Exemplo n.º 23
0
 void Awake()
 {
     playerGameController = GameObject.FindObjectOfType(typeof(PlayGameController)) as PlayGameController;
     rediectController = GameObject.FindObjectOfType(typeof(RedirectController)) as RedirectController;
 }