public void HostUrlHelper_should_return_prefixed_dottedhost_if_prefix_defined() { var httpRequestMock = new Mock <HttpRequest>(); httpRequestMock.Setup(s => s.Scheme).Returns("http"); httpRequestMock.Setup(s => s.Host).Returns(new HostString("test_api.msngqf0co2zezf5ihzmkboppdg.ix.internal.cloudapp.net:1234")); var hostUrl = HostUrlHelper.GetHostUrl(httpRequestMock.Object, "https://europe.slamby.com"); hostUrl.Should().Be("https://europe.slamby.com/test_api"); }
public void HostUrlHelper_should_return_prefixed_host_if_prefix_defined() { var httpRequestMock = new Mock <HttpRequest>(); httpRequestMock.Setup(s => s.Scheme).Returns("http"); httpRequestMock.Setup(s => s.Host).Returns(new HostString("test_api:1234")); var hostUrl = HostUrlHelper.GetHostUrl(httpRequestMock.Object, "https://europe.slamby.com"); hostUrl.Should().Be("https://europe.slamby.com/test_api"); }
public void HostUrlHelper_should_return_given_host_if_no_prefix_defined() { var httpRequestMock = new Mock <HttpRequest>(); httpRequestMock.Setup(s => s.Scheme).Returns("https"); httpRequestMock.Setup(s => s.Host).Returns(new HostString("test_api:1234")); var hostUrl = HostUrlHelper.GetHostUrl(httpRequestMock.Object, null); hostUrl.Should().Be("https://test_api:1234"); }
public async Task Invoke(HttpContext context, [FromServices] SiteConfig siteConfig, [FromServices] ISecretManager secretManager) { if (!secretManager.IsSet() && !IsPathInWhiteList(context.Request.Path)) { var hostUrl = HostUrlHelper.GetHostUrl(context.Request, siteConfig.BaseUrlPrefix); var model = ErrorsModel.Create(string.Format(GlobalResources.SecretIsNotSetVisit_0_ForSetup, $"{hostUrl}/setup")); var response = JsonConvert.SerializeObject(model); context.Response.StatusCode = StatusCodes.Status412PreconditionFailed; context.Response.ContentType = "application/json"; context.Response.ContentLength = response.Length; await context.Response.WriteAsync(response); return; } await _next.Invoke(context); }
public string GetHostUrl() { return(HostUrlHelper.GetHostUrl(contextAccessor.HttpContext.Request, siteConfig.BaseUrlPrefix)); }
public async Task Invoke(HttpContext context) { context.Request.PathBase = HostUrlHelper.GetPathBase(context.Request, siteConfig.BaseUrlPrefix); // Call next Middleware await next(context); }