Skip to content

Commit d9e2d55

Browse files
authored
[Infrastructure improvements] (#8275)
* Improved selenium start and tear down * Selenium is set up and torn down in an assembly fixture. * Selenium is initialized lazily and in a non-blocking way. * Selenium processes are tracked as part of the build and their pids written to a file on disk for cleanup in the event of unexpected termination of the test process. * Browser fixture retries with linear backoff to create a remote driver. Under heavy load (like when we are doing a simultaneous NPM restore) the selenium server can become unresponsive so we retry three times, with a longer comand timeout allowance each time up to a max of 3 minutes. * Moved test project setup to build time instead of runtime. * Added target PrepareForTest to create the required files for testing * The template creation folder. * The template props file to use our built packages. * The folder for the custom hive. * Added assembly metadata attributes to find all the data we need to run the tests. * Path to the artifacts shipping packages folder. * Path to the artifacts non-shipping packages folder. * Path to the test templates creation folder. * Path to use for the custom templating hive used in tests. * Proper cleanup as part of the build * Remove the test templates creation folder. * Remove the test packages restore path. * Recreate the test templates creation folder. * Recreate the test packages restore path. * Generated Directory.Build.Props and Directory.Build.Targets in the test templates creation folder. * Cleaned up potentially stale templatetestsprops. * Improved test flows * Initialization is done lazily and asynchronously. * Selenium * Browser fixture * Template initialization. * Flattened test flows to avoid assertions inside deep callstacks. * All assertions happen at the test level with improved error messages. * With the exception of the migrations assertions. * Assertions contain information about which step failed, for what project and what failure details. * Broke down tests to perform individual steps instead of mixing build and publish. * Publish project. * Build project. (Debug) * Run built project. * Run published project. * Concentrated build logic into the Project class. * Context between the different steps of a test is maintained in this class. * All operations that require coordination are performed within this class. * There is a lock for dotnet and a lock for nodejs. When building SPAs we acquire the nodejs lock to correctly prevent multiple runs of nodejs in parallel. [ApiAuthorization template cleanups] * Fix preview3 issues with breaking changes on Entity framework by manually configuring the model in ApiAuthorizationDbContext. * Add app.db to the project file when using local db. * Fix linting errors on angular template. * Fix react tests * Add tests to cover new auth options in the SPA templates.
1 parent 11cb4fe commit d9e2d55

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

src/Data/ApiAuthorizationDbContext.cs

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
45
using System.Threading.Tasks;
56
using IdentityServer4.EntityFramework.Entities;
67
using IdentityServer4.EntityFramework.Extensions;
@@ -49,9 +50,47 @@ public ApiAuthorizationDbContext(
4950
/// <inheritdoc />
5051
protected override void OnModelCreating(ModelBuilder builder)
5152
{
52-
5353
base.OnModelCreating(builder);
54-
builder.ConfigurePersistedGrantContext(_operationalStoreOptions.Value);
54+
ConfigureGrantContext(builder, _operationalStoreOptions.Value);
5555
}
56+
57+
private void ConfigureGrantContext(ModelBuilder modelBuilder, OperationalStoreOptions storeOptions)
58+
{
59+
if (!string.IsNullOrWhiteSpace(storeOptions.DefaultSchema)) modelBuilder.HasDefaultSchema(storeOptions.DefaultSchema);
60+
61+
modelBuilder.Entity<PersistedGrant>(grant =>
62+
{
63+
grant.ToTable("PersistedGrants");
64+
65+
grant.Property(x => x.Key).HasMaxLength(200).ValueGeneratedNever();
66+
grant.Property(x => x.Type).HasMaxLength(50).IsRequired();
67+
grant.Property(x => x.SubjectId).HasMaxLength(200);
68+
grant.Property(x => x.ClientId).HasMaxLength(200).IsRequired();
69+
grant.Property(x => x.CreationTime).IsRequired();
70+
grant.Property(x => x.Data).HasMaxLength(50000).IsRequired();
71+
72+
grant.HasKey(x => x.Key);
73+
74+
grant.HasIndex(x => new { x.SubjectId, x.ClientId, x.Type });
75+
});
76+
77+
modelBuilder.Entity<DeviceFlowCodes>(codes =>
78+
{
79+
codes.ToTable("DeviceCodes");
80+
81+
codes.Property(x => x.DeviceCode).HasMaxLength(200).IsRequired();
82+
codes.Property(x => x.UserCode).HasMaxLength(200).IsRequired();
83+
codes.Property(x => x.SubjectId).HasMaxLength(200);
84+
codes.Property(x => x.ClientId).HasMaxLength(200).IsRequired();
85+
codes.Property(x => x.CreationTime).IsRequired();
86+
codes.Property(x => x.Expiration).IsRequired();
87+
codes.Property(x => x.Data).HasMaxLength(50000).IsRequired();
88+
89+
codes.HasKey(x => new { x.UserCode });
90+
91+
codes.HasIndex(x => x.DeviceCode).IsUnique();
92+
codes.HasIndex(x => x.UserCode).IsUnique();
93+
});
94+
}
5695
}
5796
}

0 commit comments

Comments
 (0)