diff --git a/test/Server.IntegrationTest/Server.cs b/test/Server.IntegrationTest/Server.cs index 403ccdb3d3..073dbffb5a 100644 --- a/test/Server.IntegrationTest/Server.cs +++ b/test/Server.IntegrationTest/Server.cs @@ -1,7 +1,6 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc.Testing; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; +using Microsoft.AspNetCore.TestHost; namespace Bit.Server.IntegrationTest; @@ -13,32 +12,34 @@ public class Server : WebApplicationFactory public bool? WebVault { get; set; } public string? AppIdLocation { get; set; } - protected override void ConfigureWebHost(IWebHostBuilder builder) + protected override IWebHostBuilder? CreateWebHostBuilder() { - base.ConfigureWebHost(builder); - - builder.ConfigureLogging(logging => + var args = new List { - logging.SetMinimumLevel(LogLevel.Debug); - }); - - var config = new Dictionary - { - {"contentRoot", ContentRoot}, - {"webRoot", WebRoot}, - {"serveUnknown", ServeUnknown.ToString().ToLowerInvariant()}, + "/contentRoot", + ContentRoot ?? "", + "/webRoot", + WebRoot ?? "", + "/serveUnknown", + ServeUnknown.ToString().ToLowerInvariant(), }; if (WebVault.HasValue) { - config["webVault"] = WebVault.Value.ToString().ToLowerInvariant(); + args.Add("/webVault"); + args.Add(WebVault.Value.ToString().ToLowerInvariant()); } if (!string.IsNullOrEmpty(AppIdLocation)) { - config["appIdLocation"] = AppIdLocation; + args.Add("/appIdLocation"); + args.Add(AppIdLocation); } - builder.UseConfiguration(new ConfigurationBuilder().AddInMemoryCollection(config).Build()); + var builder = WebHostBuilderFactory.CreateFromTypesAssemblyEntryPoint([.. args]) + ?? throw new InvalidProgramException("Could not create builder from assembly."); + + builder.UseSetting("TEST_CONTENTROOT_SERVER", ContentRoot); + return builder; } } diff --git a/util/Server/Program.cs b/util/Server/Program.cs index a2d7e5f687..3d563830ab 100644 --- a/util/Server/Program.cs +++ b/util/Server/Program.cs @@ -6,6 +6,13 @@ namespace Bit.Server; public class Program { public static void Main(string[] args) + { + var builder = CreateWebHostBuilder(args); + var host = builder.Build(); + host.Run(); + } + + public static IWebHostBuilder CreateWebHostBuilder(string[] args) { var config = new ConfigurationBuilder() .AddCommandLine(args) @@ -37,7 +44,6 @@ public class Program builder.UseWebRoot(webRoot); } - var host = builder.Build(); - host.Run(); + return builder; } }