DuendeSoftware / Support

Support for Duende Software products
21 stars 0 forks source link

Problem with LicenseValidator? #70

Closed hugoqribeiro closed 2 years ago

hugoqribeiro commented 2 years ago

I'm getting the following exception when running integration tests against our server using version 6.1.0:

System.NullReferenceException : Object reference not set to an instance of an object.

The stack trace is the following:

   at Duende.IdentityServer.Validation.LicenseValidator.ValidateLicense() in /_/src/IdentityServer/Validation/Default/LicenseValidator.cs:line 95
   at Microsoft.AspNetCore.Builder.IdentityServerApplicationBuilderExtensions.Validate(IApplicationBuilder app) in /_/src/IdentityServer/Configuration/IdentityServerApplicationBuilderExtensions.cs:line 74
   at Microsoft.AspNetCore.Builder.IdentityServerApplicationBuilderExtensions.UseIdentityServer(IApplicationBuilder app, IdentityServerMiddlewareOptions options) in /_/src/IdentityServer/Configuration/IdentityServerApplicationBuilderExtensions.cs:line 35
   at Primavera.IdentityServer.Server.Host.Startup.UseDuendeIdentityServer(IApplicationBuilder app) in D:\a\1\s\src\server\Host\CustomCode\Startup.cs:line 477
   at Primavera.IdentityServer.Server.Host.Startup.UseRouting(IApplicationBuilder app, HostConfiguration hostConfiguration) in D:\a\1\s\src\server\Host\CustomCode\Startup.cs:line 227
   at Primavera.IdentityServer.Server.Host.StartupBase.Configure(IApplicationBuilder app, HostConfiguration hostConfiguration, ILogger`1 logger) in D:\a\1\s\src\server\Host\GeneratedCode\Startup.gen.cs:line 222
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
   at Microsoft.ApplicationInsights.AspNetCore.ApplicationInsightsStartupFilter.<>c__DisplayClass2_0.<Configure>b__0(IApplicationBuilder app)
   at Microsoft.Extensions.DependencyInjection.AutoRegisterMiddleware.<>c__DisplayClass4_0.<Configure>b__0(IApplicationBuilder app)
   at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.WebHost.BuildApplication()
   at Microsoft.AspNetCore.Hosting.WebHost.StartAsync(CancellationToken cancellationToken)
   at Microsoft.AspNetCore.TestHost.TestServer..ctor(IWebHostBuilder builder, IFeatureCollection featureCollection)
   at Microsoft.AspNetCore.TestHost.TestServer..ctor(IWebHostBuilder builder)
   at Primavera.Hydrogen.DesignTime.IntegrationTesting.AspNetCore.WebApplicationTestHostBuilder.Build[THost]()
   at Primavera.Hydrogen.DesignTime.IntegrationTesting.AspNetCore.WebApplicationTestHostBuilder.Build()
   at Primavera.IdentityServer.Server.Integration.Tests.Fixtures.IntegrationInMemoryTestFixture.BuildApplication() in D:\a\1\s\src\server\Tests\Integration.Tests\CustomCode\_Fixtures\IntegrationInMemoryTestFixture.cs:line 50
   at Primavera.IdentityServer.Server.Integration.Tests.IntegrationTestFixtureBase.Initialize() in D:\a\1\s\src\server\Tests\Integration.Tests\GeneratedCode\Fixtures.gen.cs:line 265
   at Primavera.IdentityServer.Server.Integration.Tests.IntegrationTestFixtureBase.get_Application() in D:\a\1\s\src\server\Tests\Integration.Tests\GeneratedCode\Fixtures.gen.cs:line 95
   at Primavera.IdentityServer.Server.Integration.Tests.Controllers.HttpTelemetryTests.HttpTelemetry_OtherEndpoint_Success_RequestBody_NotTracked() in D:\a\1\s\src\server\Tests\Integration.Tests\CustomCode\HttpTelemetryTests.cs:line 257
--- End of stack trace from previous location ---

It is not easy to reproduce and debug because it does not happen every time we run the tests.

Identity Server is configured in the integration tests using in-memory stores and the developer signing credential without any license.

services
    .AddIdentityServer()
    .AddInMemoryIdentityResources(...)
    .AddInMemoryApiScopes(...)
    .AddInMemoryApiResources(...)
    .AddInMemoryClients(...)
    .AddDeveloperSigningCredential(
        persistKey: false,
        fileName: string.Concat(Guid.NewGuid().ToString(), ".rsa"));

Any idea of what might be causing this?

brockallen commented 2 years ago

Hmm, odd. Are you sure you don't have some test that is setting the LicenseKey on the IdentityServerOptions somewhere? If not, then I don't see why that should throw NRE, since the internal license value is always null and thus the code should be exiting early (before line 95).

brockallen commented 2 years ago

Any update @hugoqribeiro?

brockallen commented 2 years ago

Closing. If you still have issues, feel free to reopen.