I configure my CORS settings according to the example here: https://stackoverflow.com/a/65039768/10069673
public void ConfigureServices(IServiceCollection services)
{
// ...
services.AddCors(options =>
{
options.AddPolicy(name: "AllowedCorsOrigins",
builder =>
{
builder
.SetIsOriginAllowed(IsOriginAllowed)
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials();
});
});
// ...
I would like to write a unit test to verify that CORS is configured correctly. IsOriginAllowed is a private function, therefore I can't call it directly in a unit test.
Can I use the IServiceCollection object or a mock of the interface to check if a URI is allowed/blocked by the previously configured CORS settings?