public void Is_Reserved_By_Default_Back_Office_Route(string url, bool isReserved) { var globalSettings = new GlobalSettings { ReservedPaths = string.Empty, ReservedUrls = string.Empty }; var routingSettings = new WebRoutingSettings { TryMatchingEndpointsForAllPages = true }; var endpoint1 = CreateEndpoint( "umbraco/{action?}/{id?}", new { controller = "BackOffice" }); var endpointDataSource = new DefaultEndpointDataSource(endpoint1); var routableDocFilter = new RoutableDocumentFilter( new TestOptionsSnapshot <GlobalSettings>(globalSettings), Options.Create(routingSettings), GetHostingEnvironment(), endpointDataSource); Assert.AreEqual( !isReserved, // not reserved if it's a document request routableDocFilter.IsDocumentRequest(url)); }
public async Task Match_Document_By_Url_With_Template(string urlAsString) { var globalSettings = new GlobalSettings { HideTopLevelNodeFromPath = false }; var template1 = CreateTemplate("test"); var template2 = CreateTemplate("blah"); var umbracoContext = GetUmbracoContext(urlAsString, template1.Id, globalSettings: globalSettings); var publishedRouter = CreatePublishedRouter(GetUmbracoContextAccessor(umbracoContext)); var reqBuilder = await publishedRouter.CreateRequestAsync(umbracoContext.CleanedUmbracoUrl); var webRoutingSettings = new WebRoutingSettings(); var lookup = new ContentFinderByUrlAndTemplate( LoggerFactory.CreateLogger <ContentFinderByUrlAndTemplate>(), ServiceContext.FileService, ServiceContext.ContentTypeService, GetUmbracoContextAccessor(umbracoContext), Microsoft.Extensions.Options.Options.Create(webRoutingSettings)); var result = lookup.TryFindContent(reqBuilder); IPublishedRequest frequest = reqBuilder.Build(); Assert.IsTrue(result); Assert.IsNotNull(frequest.PublishedContent); var templateAlias = frequest.GetTemplateAlias(); Assert.IsNotNull(templateAlias); Assert.AreEqual("blah".ToUpperInvariant(), templateAlias.ToUpperInvariant()); }
/// <summary> /// Initializes a new instance of the <see cref="PublishedRouter" /> class. /// </summary> public PublishedRouter( IOptionsMonitor <WebRoutingSettings> webRoutingSettings, ContentFinderCollection contentFinders, IContentLastChanceFinder contentLastChanceFinder, IVariationContextAccessor variationContextAccessor, IProfilingLogger proflog, ILogger <PublishedRouter> logger, IPublishedUrlProvider publishedUrlProvider, IRequestAccessor requestAccessor, IPublishedValueFallback publishedValueFallback, IFileService fileService, IContentTypeService contentTypeService, IUmbracoContextAccessor umbracoContextAccessor, IEventAggregator eventAggregator) { _webRoutingSettings = webRoutingSettings.CurrentValue ?? throw new ArgumentNullException(nameof(webRoutingSettings)); _contentFinders = contentFinders ?? throw new ArgumentNullException(nameof(contentFinders)); _contentLastChanceFinder = contentLastChanceFinder ?? throw new ArgumentNullException(nameof(contentLastChanceFinder)); _profilingLogger = proflog ?? throw new ArgumentNullException(nameof(proflog)); _variationContextAccessor = variationContextAccessor ?? throw new ArgumentNullException(nameof(variationContextAccessor)); _logger = logger; _publishedUrlProvider = publishedUrlProvider; _requestAccessor = requestAccessor; _publishedValueFallback = publishedValueFallback; _fileService = fileService; _contentTypeService = contentTypeService; _umbracoContextAccessor = umbracoContextAccessor; _eventAggregator = eventAggregator; webRoutingSettings.OnChange(x => _webRoutingSettings = x); }
private bool _readonly; // after prepared /// <summary> /// Initializes a new instance of the <see cref="PublishedRequest" /> class. /// </summary> public PublishedRequestOld(IPublishedRouter publishedRouter, IUmbracoContext umbracoContext, IOptions <WebRoutingSettings> webRoutingSettings, Uri?uri = null) { UmbracoContext = umbracoContext ?? throw new ArgumentNullException(nameof(umbracoContext)); _publishedRouter = publishedRouter ?? throw new ArgumentNullException(nameof(publishedRouter)); _webRoutingSettings = webRoutingSettings.Value; Uri = uri ?? umbracoContext.CleanedUmbracoUrl; }
[TestCase("/Home/Sub1/Blah")] // different cases public async Task Match_Document_By_Url_With_Template(string urlAsString) { GlobalSettings.HideTopLevelNodeFromPath = false; var umbracoContextAccessor = GetUmbracoContextAccessor(urlAsString); var umbracoContext = umbracoContextAccessor.GetRequiredUmbracoContext(); var publishedRouter = CreatePublishedRouter(umbracoContextAccessor); var frequest = await publishedRouter.CreateRequestAsync(umbracoContext.CleanedUmbracoUrl); var webRoutingSettings = new WebRoutingSettings(); var lookup = new ContentFinderByUrlAndTemplate( Mock.Of <ILogger <ContentFinderByUrlAndTemplate> >(), _fileService, ContentTypeService, umbracoContextAccessor, Mock.Of <IOptionsMonitor <WebRoutingSettings> >(x => x.CurrentValue == webRoutingSettings)); var result = await lookup.TryFindContent(frequest); var request = frequest.Build(); Assert.IsTrue(result); Assert.IsNotNull(frequest.PublishedContent); var templateAlias = request.GetTemplateAlias(); Assert.IsNotNull(templateAlias); Assert.AreEqual("blah".ToUpperInvariant(), templateAlias.ToUpperInvariant()); }
public TemplateRenderer( IUmbracoContextAccessor umbracoContextAccessor, IPublishedRouter publishedRouter, IFileService fileService, ILocalizationService textService, IOptionsMonitor <WebRoutingSettings> webRoutingSettings, IHttpContextAccessor httpContextAccessor, ICompositeViewEngine viewEngine, IModelMetadataProvider modelMetadataProvider, ITempDataDictionaryFactory tempDataDictionaryFactory) { _umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor)); _publishedRouter = publishedRouter ?? throw new ArgumentNullException(nameof(publishedRouter)); _fileService = fileService ?? throw new ArgumentNullException(nameof(fileService)); _languageService = textService ?? throw new ArgumentNullException(nameof(textService)); _webRoutingSettings = webRoutingSettings.CurrentValue ?? throw new ArgumentNullException(nameof(webRoutingSettings)); _httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor)); _viewEngine = viewEngine ?? throw new ArgumentNullException(nameof(viewEngine)); _modelMetadataProvider = modelMetadataProvider; _tempDataDictionaryFactory = tempDataDictionaryFactory; webRoutingSettings.OnChange(x => _webRoutingSettings = x); }
public void Is_Reserved_By_Route(string url, bool isReserved) { var globalSettings = new GlobalSettings { ReservedPaths = string.Empty, ReservedUrls = string.Empty }; var routingSettings = new WebRoutingSettings { TryMatchingEndpointsForAllPages = true }; RouteEndpoint endpoint1 = CreateEndpoint( "Umbraco/RenderMvc/{action?}/{id?}", new { controller = "RenderMvc" }, 0); RouteEndpoint endpoint2 = CreateEndpoint( "api/{controller?}/{id?}", new { action = "Index" }, 1); var endpointDataSource = new DefaultEndpointDataSource(endpoint1, endpoint2); var routableDocFilter = new RoutableDocumentFilter( Options.Create(globalSettings), Options.Create(routingSettings), GetHostingEnvironment(), endpointDataSource); Assert.AreEqual( !isReserved, // not reserved if it's a document request routableDocFilter.IsDocumentRequest(url)); }
/// <summary> /// Initializes a new instance of the <see cref="AspNetCoreRequestAccessor"/> class. /// </summary> public AspNetCoreRequestAccessor( IHttpContextAccessor httpContextAccessor, IOptions <WebRoutingSettings> webRoutingSettings) { _httpContextAccessor = httpContextAccessor; _webRoutingSettings = webRoutingSettings.Value; }
/// <summary> /// Initializes a new instance of the <see cref="AspNetCoreRequestAccessor"/> class. /// </summary> public AspNetCoreRequestAccessor( IHttpContextAccessor httpContextAccessor, IOptionsMonitor <WebRoutingSettings> webRoutingSettings) { _httpContextAccessor = httpContextAccessor; _webRoutingSettings = webRoutingSettings.CurrentValue; webRoutingSettings.OnChange(x => _webRoutingSettings = x); }
/// <summary> /// Initializes a new instance of the <see cref="RoutableDocumentFilter"/> class. /// </summary> public RoutableDocumentFilter(IOptions <GlobalSettings> globalSettings, IOptions <WebRoutingSettings> routingSettings, IHostingEnvironment hostingEnvironment, EndpointDataSource endpointDataSource) { _globalSettings = globalSettings.Value; _routingSettings = routingSettings.Value; _hostingEnvironment = hostingEnvironment; _endpointDataSource = endpointDataSource; _endpointDataSource.GetChangeToken().RegisterChangeCallback(EndpointsChanged, null); }
public void Ensure_Image_Sources() { // setup a mock URL provider which we'll use for testing var mediaType = new PublishedContentType(Guid.NewGuid(), 777, "image", PublishedItemType.Media, Enumerable.Empty <string>(), Enumerable.Empty <PublishedPropertyType>(), ContentVariation.Nothing); var media = new Mock <IPublishedContent>(); media.Setup(x => x.ContentType).Returns(mediaType); var mediaUrlProvider = new Mock <IMediaUrlProvider>(); mediaUrlProvider.Setup(x => x.GetMediaUrl(It.IsAny <IPublishedContent>(), It.IsAny <string>(), It.IsAny <UrlMode>(), It.IsAny <string>(), It.IsAny <Uri>())) .Returns(UrlInfo.Url("/media/1001/my-image.jpg")); var umbracoContextAccessor = new TestUmbracoContextAccessor(); IUmbracoContextFactory umbracoContextFactory = TestUmbracoContextFactory.Create( umbracoContextAccessor: umbracoContextAccessor); var webRoutingSettings = new WebRoutingSettings(); var publishedUrlProvider = new UrlProvider( umbracoContextAccessor, Options.Create(webRoutingSettings), new UrlProviderCollection(() => Enumerable.Empty <IUrlProvider>()), new MediaUrlProviderCollection(() => new[] { mediaUrlProvider.Object }), Mock.Of <IVariationContextAccessor>()); using (UmbracoContextReference reference = umbracoContextFactory.EnsureUmbracoContext()) { var mediaCache = Mock.Get(reference.UmbracoContext.Media); mediaCache.Setup(x => x.GetById(It.IsAny <Guid>())).Returns(media.Object); var imageSourceParser = new HtmlImageSourceParser(publishedUrlProvider); var result = imageSourceParser.EnsureImageSources(@"<p> <div> <img src="""" /> </div></p> <p> <div><img src="""" data-udi=""umb://media/81BB2036-034F-418B-B61F-C7160D68DCD4"" /></div> </p> <p> <div><img src=""?width=100"" data-udi=""umb://media/81BB2036-034F-418B-B61F-C7160D68DCD4"" /></div> </p>"); Assert.AreEqual( @"<p> <div> <img src="""" /> </div></p> <p> <div><img src=""/media/1001/my-image.jpg"" data-udi=""umb://media/81BB2036-034F-418B-B61F-C7160D68DCD4"" /></div> </p> <p> <div><img src=""/media/1001/my-image.jpg?width=100"" data-udi=""umb://media/81BB2036-034F-418B-B61F-C7160D68DCD4"" /></div> </p>", result); } }
public override void SetUp() { base.SetUp(); _globalSettings = new GlobalSettings(); _webRoutingSettings = new WebRoutingSettings(); _requestHandlerSettings = new RequestHandlerSettings { AddTrailingSlash = true }; }
/// <summary> /// Initializes a new instance of the <see cref="ContentFinderByIdPath"/> class. /// </summary> public ContentFinderByIdPath( IOptions <WebRoutingSettings> webRoutingSettings, ILogger <ContentFinderByIdPath> logger, IRequestAccessor requestAccessor, IUmbracoContextAccessor umbracoContextAccessor) { _webRoutingSettings = webRoutingSettings.Value ?? throw new System.ArgumentNullException(nameof(webRoutingSettings)); _logger = logger ?? throw new System.ArgumentNullException(nameof(logger)); _requestAccessor = requestAccessor ?? throw new System.ArgumentNullException(nameof(requestAccessor)); _umbracoContextAccessor = umbracoContextAccessor ?? throw new System.ArgumentNullException(nameof(umbracoContextAccessor)); }
private IPublishedUrlProvider GetPublishedUrlProvider(IUmbracoContext umbracoContext, DefaultUrlProvider urlProvider) { var webRoutingSettings = new WebRoutingSettings(); return(new UrlProvider( new TestUmbracoContextAccessor(umbracoContext), Options.Create(webRoutingSettings), new UrlProviderCollection(() => new[] { urlProvider }), new MediaUrlProviderCollection(() => Enumerable.Empty <IMediaUrlProvider>()), Mock.Of <IVariationContextAccessor>())); }
private IPublishedUrlProvider GetPublishedUrlProvider(IUmbracoContext umbracoContext) { var webRoutingSettings = new WebRoutingSettings(); return(new UrlProvider( new TestUmbracoContextAccessor(umbracoContext), Microsoft.Extensions.Options.Options.Create(webRoutingSettings), new UrlProviderCollection(Enumerable.Empty <IUrlProvider>()), new MediaUrlProviderCollection(new [] { _mediaUrlProvider }), Mock.Of <IVariationContextAccessor>() )); }
public void ParseLocalLinks(string input, string result) { // setup a mock URL provider which we'll use for testing var contentUrlProvider = new Mock <IUrlProvider>(); contentUrlProvider .Setup(x => x.GetUrl(It.IsAny <IPublishedContent>(), It.IsAny <UrlMode>(), It.IsAny <string>(), It.IsAny <Uri>())) .Returns(UrlInfo.Url("/my-test-url")); var contentType = new PublishedContentType(Guid.NewGuid(), 666, "alias", PublishedItemType.Content, Enumerable.Empty <string>(), Enumerable.Empty <PublishedPropertyType>(), ContentVariation.Nothing); var publishedContent = new Mock <IPublishedContent>(); publishedContent.Setup(x => x.Id).Returns(1234); publishedContent.Setup(x => x.ContentType).Returns(contentType); var mediaType = new PublishedContentType(Guid.NewGuid(), 777, "image", PublishedItemType.Media, Enumerable.Empty <string>(), Enumerable.Empty <PublishedPropertyType>(), ContentVariation.Nothing); var media = new Mock <IPublishedContent>(); media.Setup(x => x.ContentType).Returns(mediaType); var mediaUrlProvider = new Mock <IMediaUrlProvider>(); mediaUrlProvider.Setup(x => x.GetMediaUrl(It.IsAny <IPublishedContent>(), It.IsAny <string>(), It.IsAny <UrlMode>(), It.IsAny <string>(), It.IsAny <Uri>())) .Returns(UrlInfo.Url("/media/1001/my-image.jpg")); var umbracoContextAccessor = new TestUmbracoContextAccessor(); IUmbracoContextFactory umbracoContextFactory = TestUmbracoContextFactory.Create( umbracoContextAccessor: umbracoContextAccessor); var webRoutingSettings = new WebRoutingSettings(); var publishedUrlProvider = new UrlProvider( umbracoContextAccessor, Microsoft.Extensions.Options.Options.Create(webRoutingSettings), new UrlProviderCollection(() => new[] { contentUrlProvider.Object }), new MediaUrlProviderCollection(() => new[] { mediaUrlProvider.Object }), Mock.Of <IVariationContextAccessor>()); using (UmbracoContextReference reference = umbracoContextFactory.EnsureUmbracoContext()) { var contentCache = Mock.Get(reference.UmbracoContext.Content); contentCache.Setup(x => x.GetById(It.IsAny <int>())).Returns(publishedContent.Object); contentCache.Setup(x => x.GetById(It.IsAny <Guid>())).Returns(publishedContent.Object); var mediaCache = Mock.Get(reference.UmbracoContext.Media); mediaCache.Setup(x => x.GetById(It.IsAny <int>())).Returns(media.Object); mediaCache.Setup(x => x.GetById(It.IsAny <Guid>())).Returns(media.Object); var linkParser = new HtmlLocalLinkParser(umbracoContextAccessor, publishedUrlProvider); var output = linkParser.EnsureInternalLinks(input); Assert.AreEqual(result, output); } }
/// <summary> /// Initializes a new instance of the <see cref="ContentFinderByUrlAndTemplate"/> class. /// </summary> public ContentFinderByUrlAndTemplate( ILogger <ContentFinderByUrlAndTemplate> logger, IFileService fileService, IContentTypeService contentTypeService, IUmbracoContextAccessor umbracoContextAccessor, IOptions <WebRoutingSettings> webRoutingSettings) : base(logger, umbracoContextAccessor) { _logger = logger; _fileService = fileService; _contentTypeService = contentTypeService; _webRoutingSettings = webRoutingSettings.Value; }
protected virtual void ComposeWeb() { // imported from TestWithSettingsBase // which was inherited by TestWithApplicationBase so pretty much used everywhere Current.UmbracoContextAccessor = new TestUmbracoContextAccessor(); // web Builder.Services.AddUnique(Current.UmbracoContextAccessor); Builder.Services.AddUnique <IBackOfficeSecurityAccessor>(Mock.Of <IBackOfficeSecurityAccessor>()); Builder.Services.AddUnique <IPublishedRouter, PublishedRouter>(); Builder.WithCollectionBuilder <ContentFinderCollectionBuilder>(); Builder.DataValueReferenceFactories(); Builder.Services.AddUnique <IContentLastChanceFinder, TestLastChanceFinder>(); Builder.Services.AddUnique <IVariationContextAccessor, TestVariationContextAccessor>(); Builder.Services.AddUnique <IPublishedSnapshotAccessor, TestPublishedSnapshotAccessor>(); Builder.Services.AddUnique <IImageDimensionExtractor, ImageDimensionExtractor>(); Builder.Services.AddUnique <IPublishedSnapshotAccessor, TestPublishedSnapshotAccessor>(); Builder.SetCultureDictionaryFactory <DefaultCultureDictionaryFactory>(); Builder.Services.AddSingleton(f => f.GetRequiredService <ICultureDictionaryFactory>().CreateDictionary()); // register back office sections in the order we want them rendered Builder.WithCollectionBuilder <SectionCollectionBuilder>().Append <ContentSection>() .Append <MediaSection>() .Append <SettingsSection>() .Append <PackagesSection>() .Append <UsersSection>() .Append <MembersSection>() .Append <FormsSection>() .Append <TranslationSection>(); Builder.Services.AddUnique <ISectionService, SectionService>(); Builder.Services.AddUnique <HtmlLocalLinkParser>(); Builder.Services.AddUnique <IBackOfficeSecurity, BackOfficeSecurity>(); Builder.Services.AddUnique <IEmailSender, EmailSender>(); Builder.Services.AddUnique <HtmlUrlParser>(); Builder.Services.AddUnique <HtmlImageSourceParser>(); Builder.Services.AddUnique <RichTextEditorPastedImages>(); Builder.Services.AddUnique <IPublishedValueFallback, NoopPublishedValueFallback>(); var webRoutingSettings = new WebRoutingSettings(); Builder.Services.AddUnique <IPublishedUrlProvider>(factory => new UrlProvider( factory.GetRequiredService <IUmbracoContextAccessor>(), Microsoft.Extensions.Options.Options.Create(webRoutingSettings), new UrlProviderCollection(Enumerable.Empty <IUrlProvider>()), new MediaUrlProviderCollection(Enumerable.Empty <IMediaUrlProvider>()), factory.GetRequiredService <IVariationContextAccessor>())); }
private IHostingEnvironment CreateHostingEnvironment(string virtualPath = "") { var hostingSettings = new HostingSettings { ApplicationVirtualPath = virtualPath }; var webRoutingSettings = new WebRoutingSettings(); var mockedOptionsMonitorOfHostingSettings = Mock.Of <IOptionsMonitor <HostingSettings> >(x => x.CurrentValue == hostingSettings); var mockedOptionsMonitorOfWebRoutingSettings = Mock.Of <IOptionsMonitor <WebRoutingSettings> >(x => x.CurrentValue == webRoutingSettings); return(new TestHostingEnvironment( mockedOptionsMonitorOfHostingSettings, mockedOptionsMonitorOfWebRoutingSettings, _hostEnvironment)); }
/// <summary> /// Initializes a new instance of the <see cref="ContentFinderByUrlAndTemplate"/> class. /// </summary> public ContentFinderByUrlAndTemplate( ILogger <ContentFinderByUrlAndTemplate> logger, IFileService fileService, IContentTypeService contentTypeService, IUmbracoContextAccessor umbracoContextAccessor, IOptionsMonitor <WebRoutingSettings> webRoutingSettings) : base(logger, umbracoContextAccessor) { _logger = logger; _fileService = fileService; _contentTypeService = contentTypeService; _webRoutingSettings = webRoutingSettings.CurrentValue; webRoutingSettings.OnChange(x => _webRoutingSettings = x); }
/// <summary> /// Initializes a new instance of the <see cref="ContentFinderByIdPath" /> class. /// </summary> public ContentFinderByIdPath( IOptionsMonitor <WebRoutingSettings> webRoutingSettings, ILogger <ContentFinderByIdPath> logger, IRequestAccessor requestAccessor, IUmbracoContextAccessor umbracoContextAccessor) { _webRoutingSettings = webRoutingSettings.CurrentValue ?? throw new ArgumentNullException(nameof(webRoutingSettings)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _requestAccessor = requestAccessor ?? throw new ArgumentNullException(nameof(requestAccessor)); _umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor)); webRoutingSettings.OnChange(x => _webRoutingSettings = x); }
public async Task Lookup_By_Id(string urlAsString, int nodeMatch) { var umbracoContext = GetUmbracoContext(urlAsString); var publishedRouter = CreatePublishedRouter(GetUmbracoContextAccessor(umbracoContext)); var frequest = await publishedRouter.CreateRequestAsync(umbracoContext.CleanedUmbracoUrl); var webRoutingSettings = new WebRoutingSettings(); var lookup = new ContentFinderByIdPath(Microsoft.Extensions.Options.Options.Create(webRoutingSettings), LoggerFactory.CreateLogger <ContentFinderByIdPath>(), Factory.GetRequiredService <IRequestAccessor>(), GetUmbracoContextAccessor(umbracoContext)); var result = lookup.TryFindContent(frequest); Assert.IsTrue(result); Assert.AreEqual(frequest.PublishedContent.Id, nodeMatch); }
public UsersController( MediaFileManager mediaFileManager, IOptionsSnapshot <ContentSettings> contentSettings, IHostingEnvironment hostingEnvironment, ISqlContext sqlContext, IImageUrlGenerator imageUrlGenerator, IOptionsSnapshot <SecuritySettings> securitySettings, IEmailSender emailSender, IBackOfficeSecurityAccessor backofficeSecurityAccessor, AppCaches appCaches, IShortStringHelper shortStringHelper, IUserService userService, ILocalizedTextService localizedTextService, IUmbracoMapper umbracoMapper, IOptionsSnapshot <GlobalSettings> globalSettings, IBackOfficeUserManager backOfficeUserManager, ILoggerFactory loggerFactory, LinkGenerator linkGenerator, IBackOfficeExternalLoginProviders externalLogins, UserEditorAuthorizationHelper userEditorAuthorizationHelper, IPasswordChanger <BackOfficeIdentityUser> passwordChanger, IHttpContextAccessor httpContextAccessor, IOptions <WebRoutingSettings> webRoutingSettings) { _mediaFileManager = mediaFileManager; _contentSettings = contentSettings.Value; _hostingEnvironment = hostingEnvironment; _sqlContext = sqlContext; _imageUrlGenerator = imageUrlGenerator; _securitySettings = securitySettings.Value; _emailSender = emailSender; _backofficeSecurityAccessor = backofficeSecurityAccessor; _appCaches = appCaches; _shortStringHelper = shortStringHelper; _userService = userService; _localizedTextService = localizedTextService; _umbracoMapper = umbracoMapper; _globalSettings = globalSettings.Value; _userManager = backOfficeUserManager; _loggerFactory = loggerFactory; _linkGenerator = linkGenerator; _externalLogins = externalLogins; _userEditorAuthorizationHelper = userEditorAuthorizationHelper; _passwordChanger = passwordChanger; _logger = _loggerFactory.CreateLogger <UsersController>(); _httpContextAccessor = httpContextAccessor; _webRoutingSettings = webRoutingSettings.Value; }
/// <summary> /// HACK: returns an AspNetCoreHostingEnvironment that doesn't monitor changes to configuration.<br /> /// We require this to create a TypeLoader during ConfigureServices.<br /> /// Instances returned from this method shouldn't be registered in the service collection. /// </summary> private static IHostingEnvironment GetTemporaryHostingEnvironment( IWebHostEnvironment webHostEnvironment, IConfiguration config) { HostingSettings hostingSettings = config.GetSection(Constants.Configuration.ConfigHosting).Get <HostingSettings>() ?? new HostingSettings(); var wrappedHostingSettings = new OptionsMonitorAdapter <HostingSettings>(hostingSettings); WebRoutingSettings webRoutingSettings = config.GetSection(Constants.Configuration.ConfigWebRouting).Get <WebRoutingSettings>() ?? new WebRoutingSettings(); var wrappedWebRoutingSettings = new OptionsMonitorAdapter <WebRoutingSettings>(webRoutingSettings); return(new AspNetCoreHostingEnvironment( wrappedHostingSettings, wrappedWebRoutingSettings, webHostEnvironment)); }
protected virtual void ComposeSettings() { var contentSettings = new ContentSettings(); var coreDebugSettings = new CoreDebugSettings(); var globalSettings = new GlobalSettings(); var nuCacheSettings = new NuCacheSettings(); var requestHandlerSettings = new RequestHandlerSettings(); var userPasswordConfigurationSettings = new UserPasswordConfigurationSettings(); var webRoutingSettings = new WebRoutingSettings(); Builder.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(contentSettings)); Builder.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(coreDebugSettings)); Builder.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(globalSettings)); Builder.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(nuCacheSettings)); Builder.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(requestHandlerSettings)); Builder.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(userPasswordConfigurationSettings)); Builder.Services.AddTransient(x => Microsoft.Extensions.Options.Options.Create(webRoutingSettings)); }
public override void Setup() { base.Setup(); _webRoutingSettings = new WebRoutingSettings(); _requestHandlerSettings = new RequestHandlerSettings { AddTrailingSlash = true }; GlobalSettings.HideTopLevelNodeFromPath = false; string xml = PublishedContentXml.BaseWebTestXml(1234); IEnumerable <ContentNodeKit> kits = PublishedContentXmlAdapter.GetContentNodeKits( xml, TestHelper.ShortStringHelper, out ContentType[] contentTypes, out DataType[] dataTypes).ToList();
public AuthenticationController( IBackOfficeSecurityAccessor backofficeSecurityAccessor, IBackOfficeUserManager backOfficeUserManager, IBackOfficeSignInManager signInManager, IUserService userService, ILocalizedTextService textService, IUmbracoMapper umbracoMapper, IOptionsSnapshot <GlobalSettings> globalSettings, IOptionsSnapshot <SecuritySettings> securitySettings, ILogger <AuthenticationController> logger, IIpResolver ipResolver, IOptionsSnapshot <UserPasswordConfigurationSettings> passwordConfiguration, IEmailSender emailSender, ISmsSender smsSender, IHostingEnvironment hostingEnvironment, LinkGenerator linkGenerator, IBackOfficeExternalLoginProviders externalAuthenticationOptions, IBackOfficeTwoFactorOptions backOfficeTwoFactorOptions, IHttpContextAccessor httpContextAccessor, IOptions <WebRoutingSettings> webRoutingSettings, ITwoFactorLoginService twoFactorLoginService) { _backofficeSecurityAccessor = backofficeSecurityAccessor; _userManager = backOfficeUserManager; _signInManager = signInManager; _userService = userService; _textService = textService; _umbracoMapper = umbracoMapper; _globalSettings = globalSettings.Value; _securitySettings = securitySettings.Value; _logger = logger; _ipResolver = ipResolver; _passwordConfiguration = passwordConfiguration.Value; _emailSender = emailSender; _smsSender = smsSender; _hostingEnvironment = hostingEnvironment; _linkGenerator = linkGenerator; _externalAuthenticationOptions = externalAuthenticationOptions; _backOfficeTwoFactorOptions = backOfficeTwoFactorOptions; _httpContextAccessor = httpContextAccessor; _webRoutingSettings = webRoutingSettings.Value; _twoFactorLoginService = twoFactorLoginService; }
public async Task Lookup_By_Id(string urlAsString, int nodeMatch) { var umbracoContextAccessor = GetUmbracoContextAccessor(urlAsString); var umbracoContext = umbracoContextAccessor.GetRequiredUmbracoContext(); var publishedRouter = CreatePublishedRouter(umbracoContextAccessor); var frequest = await publishedRouter.CreateRequestAsync(umbracoContext.CleanedUmbracoUrl); var webRoutingSettings = new WebRoutingSettings(); var lookup = new ContentFinderByIdPath( Mock.Of <IOptionsMonitor <WebRoutingSettings> >(x => x.CurrentValue == webRoutingSettings), Mock.Of <ILogger <ContentFinderByIdPath> >(), Mock.Of <IRequestAccessor>(), umbracoContextAccessor); var result = await lookup.TryFindContent(frequest); Assert.IsTrue(result); Assert.AreEqual(frequest.PublishedContent.Id, nodeMatch); }
/// <summary> /// Gets the application URI, will use the one specified in settings if present /// </summary> public static Uri GetApplicationUri(this HttpRequest request, WebRoutingSettings routingSettings) { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (routingSettings == null) { throw new ArgumentNullException(nameof(routingSettings)); } if (string.IsNullOrEmpty(routingSettings.UmbracoApplicationUrl)) { var requestUri = new Uri(request.GetDisplayUrl()); // Create a new URI with the relative uri as /, this ensures that only the base path is returned. return(new Uri(requestUri, "/")); } return(new Uri(routingSettings.UmbracoApplicationUrl)); }
private IOptionsMonitor <WebRoutingSettings> GetIOptionsMonitorOfWebRoutingSettings() { var webRoutingSettings = new WebRoutingSettings(); return(Mock.Of <IOptionsMonitor <WebRoutingSettings> >(x => x.CurrentValue == webRoutingSettings)); }