mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 15:42:48 -05:00
Include Root Certificates in Custom Trust Store (#5624)
* Add new tests * Include root CA's in custom trust store
This commit is contained in:
@ -257,6 +257,41 @@ public class X509ChainCustomizationServiceCollectionExtensionsTests
|
||||
Assert.Equal("Hi", response);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CallHttp_ReachingOutToServerTrustedThroughSystemCA()
|
||||
{
|
||||
var services = CreateServices((gs, environment, config) => { }, services =>
|
||||
{
|
||||
services.Configure<X509ChainOptions>(options =>
|
||||
{
|
||||
options.AdditionalCustomTrustCertificates = [];
|
||||
});
|
||||
});
|
||||
|
||||
var httpClient = services.GetRequiredService<IHttpClientFactory>().CreateClient();
|
||||
|
||||
var response = await httpClient.GetAsync("https://example.com");
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CallHttpWithCustomTrustForSelfSigned_ReachingOutToServerTrustedThroughSystemCA()
|
||||
{
|
||||
var selfSignedCertificate = CreateSelfSignedCert("localhost");
|
||||
var services = CreateServices((gs, environment, config) => { }, services =>
|
||||
{
|
||||
services.Configure<X509ChainOptions>(options =>
|
||||
{
|
||||
options.AdditionalCustomTrustCertificates = [selfSignedCertificate];
|
||||
});
|
||||
});
|
||||
|
||||
var httpClient = services.GetRequiredService<IHttpClientFactory>().CreateClient();
|
||||
|
||||
var response = await httpClient.GetAsync("https://example.com");
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
|
||||
private static async Task<IAsyncDisposable> CreateServerAsync(int port, Action<HttpsConnectionAdapterOptions> configure)
|
||||
{
|
||||
var builder = WebApplication.CreateEmptyBuilder(new WebApplicationOptions());
|
||||
|
Reference in New Issue
Block a user