Skip to content

Commit

Permalink
Added DangerousAcceptAnyServerCertificateValidator setting
Browse files Browse the repository at this point in the history
  • Loading branch information
pm7y committed Oct 17, 2023
1 parent 790927d commit cda01e3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ An example of one topic with one subscriber is shown below.
- `false` (the default) subscription validation will be attempted each time the simulator starts.
- `true` to disable subscription validation.

### App Settings

- `dangerousAcceptAnyServerCertificateValidator`: Set to `true` to accept any server certificate. This is useful when testing with self signed certificates.

#### Subscription Validation

When a subscription is added to Azure Event Grid it first sends a validation event to the subscription endpoint. The validation event contains a `validationCode` which the subscription endpoint must echo back. If this does not occur then Azure Event Grid will not enable the subscription.
Expand Down
14 changes: 12 additions & 2 deletions src/AzureEventGridSimulator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading;
Expand Down Expand Up @@ -175,7 +176,16 @@ private static WebApplicationBuilder ConfigureWebHost(string[] args, IConfigurat

builder.Services.AddSimulatorSettings(configuration);
builder.Services.AddMediatR(o=> o.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()));
builder.Services.AddHttpClient();

var httpClientBuilder = builder.Services.AddHttpClient(nameof(AzureEventGridSimulator));
if (configuration.GetValue<bool>("dangerousAcceptAnyServerCertificateValidator"))

Check warning on line 181 in src/AzureEventGridSimulator/Program.cs

View workflow job for this annotation

GitHub Actions / test-release (windows-latest)

Using member 'Microsoft.Extensions.Configuration.ConfigurationBinder.GetValue<T>(IConfiguration, String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. In case the type is non-primitive, the trimmer cannot statically analyze the object's type so its members may be trimmed.

Check warning on line 181 in src/AzureEventGridSimulator/Program.cs

View workflow job for this annotation

GitHub Actions / test-release (ubuntu-latest)

Using member 'Microsoft.Extensions.Configuration.ConfigurationBinder.GetValue<T>(IConfiguration, String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. In case the type is non-primitive, the trimmer cannot statically analyze the object's type so its members may be trimmed.

Check warning on line 181 in src/AzureEventGridSimulator/Program.cs

View workflow job for this annotation

GitHub Actions / test-release (macos-latest)

Using member 'Microsoft.Extensions.Configuration.ConfigurationBinder.GetValue<T>(IConfiguration, String)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. In case the type is non-primitive, the trimmer cannot statically analyze the object's type so its members may be trimmed.
{
Log.Warning("DangerousAcceptAnyServerCertificateValidator is enabled. This should only be used for testing purposes");
httpClientBuilder.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler
{
ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator
});
}

builder.Services.AddScoped<SasKeyValidator>();
builder.Services.AddSingleton<ValidationIpAddressProvider>();
Expand All @@ -200,7 +210,7 @@ private static WebApplicationBuilder ConfigureWebHost(string[] args, IConfigurat
.Enrich.WithProperty("MachineName", Environment.MachineName)
.Enrich.WithProperty("Environment", context.Configuration.EnvironmentName())
.Enrich.WithProperty("Application", nameof(AzureEventGridSimulator))
.Enrich.WithProperty("Version", Assembly.GetExecutingAssembly().GetName().Version)
.Enrich.WithProperty("Version", Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "Unknown")
// The sensible defaults
.MinimumLevel.Is(LogEventLevel.Information)
.MinimumLevel.Override("Microsoft", LogEventLevel.Error)
Expand Down

0 comments on commit cda01e3

Please sign in to comment.