mirror of
https://github.com/bitwarden/server.git
synced 2026-01-31 14:13:18 +08:00
Add some integration tests for the Server project (#6839)
* Add some integration tests for the Server project * Not sure why this project got removed? * Format * capture debug output * Update tests to work with the now legacy WebHostBuilder - I accidentally had the updated Program locally and that was why tests were working for me locally * Formatting...again
This commit is contained in:
45
test/Server.IntegrationTest/Server.cs
Normal file
45
test/Server.IntegrationTest/Server.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
|
||||
namespace Bit.Server.IntegrationTest;
|
||||
|
||||
public class Server : WebApplicationFactory<Program>
|
||||
{
|
||||
public string? ContentRoot { get; set; }
|
||||
public string? WebRoot { get; set; }
|
||||
public bool ServeUnknown { get; set; }
|
||||
public bool? WebVault { get; set; }
|
||||
public string? AppIdLocation { get; set; }
|
||||
|
||||
protected override IWebHostBuilder? CreateWebHostBuilder()
|
||||
{
|
||||
var args = new List<string>
|
||||
{
|
||||
"/contentRoot",
|
||||
ContentRoot ?? "",
|
||||
"/webRoot",
|
||||
WebRoot ?? "",
|
||||
"/serveUnknown",
|
||||
ServeUnknown.ToString().ToLowerInvariant(),
|
||||
};
|
||||
|
||||
if (WebVault.HasValue)
|
||||
{
|
||||
args.Add("/webVault");
|
||||
args.Add(WebVault.Value.ToString().ToLowerInvariant());
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(AppIdLocation))
|
||||
{
|
||||
args.Add("/appIdLocation");
|
||||
args.Add(AppIdLocation);
|
||||
}
|
||||
|
||||
var builder = WebHostBuilderFactory.CreateFromTypesAssemblyEntryPoint<Program>([.. args])
|
||||
?? throw new InvalidProgramException("Could not create builder from assembly.");
|
||||
|
||||
builder.UseSetting("TEST_CONTENTROOT_SERVER", ContentRoot);
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user