@@ -263,8 +263,10 @@ public async Task DashboardResourceServiceUriIsSet()
263
263
Assert . Equal ( "http://localhost:5000" , config . Single ( e => e . Key == DashboardConfigNames . ResourceServiceUrlName . EnvVarName ) . Value ) ;
264
264
}
265
265
266
- [ Fact ]
267
- public async Task DashboardResource_OtlpHttpEndpoint_CorsEnvVarSet ( )
266
+ [ Theory ]
267
+ [ InlineData ( "*" ) ]
268
+ [ InlineData ( null ) ]
269
+ public async Task DashboardResource_OtlpHttpEndpoint_CorsEnvVarSet ( string ? explicitCorsAllowedOrigins )
268
270
{
269
271
// Arrange
270
272
using var builder = TestDistributedApplicationBuilder . Create ( options => options . DisableDashboard = false ) ;
@@ -277,7 +279,8 @@ public async Task DashboardResource_OtlpHttpEndpoint_CorsEnvVarSet()
277
279
builder . Configuration . AddInMemoryCollection ( new Dictionary < string , string ? >
278
280
{
279
281
[ "ASPNETCORE_URLS" ] = "http://localhost" ,
280
- [ "DOTNET_DASHBOARD_OTLP_HTTP_ENDPOINT_URL" ] = "http://localhost"
282
+ [ "DOTNET_DASHBOARD_OTLP_HTTP_ENDPOINT_URL" ] = "http://localhost" ,
283
+ [ "DOTNET_DASHBOARD_CORS_ALLOWED_ORIGINS" ] = explicitCorsAllowedOrigins
281
284
} ) ;
282
285
283
286
using var app = builder . Build ( ) ;
@@ -295,12 +298,15 @@ public async Task DashboardResource_OtlpHttpEndpoint_CorsEnvVarSet()
295
298
296
299
var config = await EnvironmentVariableEvaluator . GetEnvironmentVariablesAsync ( dashboard , DistributedApplicationOperation . Run , app . Services ) ;
297
300
298
- Assert . Equal ( "http://localhost:8081,http://localhost:58080" , config . Single ( e => e . Key == DashboardConfigNames . DashboardOtlpCorsAllowedOriginsKeyName . EnvVarName ) . Value ) ;
301
+ var expectedAllowedOrigins = ! string . IsNullOrEmpty ( explicitCorsAllowedOrigins ) ? explicitCorsAllowedOrigins : "http://localhost:8081,http://localhost:58080" ;
302
+ Assert . Equal ( expectedAllowedOrigins , config . Single ( e => e . Key == DashboardConfigNames . DashboardOtlpCorsAllowedOriginsKeyName . EnvVarName ) . Value ) ;
299
303
Assert . Equal ( "*" , config . Single ( e => e . Key == DashboardConfigNames . DashboardOtlpCorsAllowedHeadersKeyName . EnvVarName ) . Value ) ;
300
304
}
301
305
302
- [ Fact ]
303
- public async Task DashboardResource_OtlpGrpcEndpoint_CorsEnvVarNotSet ( )
306
+ [ Theory ]
307
+ [ InlineData ( "*" ) ]
308
+ [ InlineData ( null ) ]
309
+ public async Task DashboardResource_OtlpGrpcEndpoint_CorsEnvVarNotSet ( string ? explicitCorsAllowedOrigins )
304
310
{
305
311
// Arrange
306
312
using var builder = TestDistributedApplicationBuilder . Create ( options => options . DisableDashboard = false ) ;
@@ -313,7 +319,8 @@ public async Task DashboardResource_OtlpGrpcEndpoint_CorsEnvVarNotSet()
313
319
builder . Configuration . AddInMemoryCollection ( new Dictionary < string , string ? >
314
320
{
315
321
[ "ASPNETCORE_URLS" ] = "http://localhost" ,
316
- [ "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL" ] = "http://localhost"
322
+ [ "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL" ] = "http://localhost" ,
323
+ [ "DOTNET_DASHBOARD_CORS_ALLOWED_ORIGINS" ] = explicitCorsAllowedOrigins
317
324
} ) ;
318
325
319
326
using var app = builder . Build ( ) ;
0 commit comments