|
7 | 7 |
|
8 | 8 | using Microsoft.EntityFrameworkCore; |
9 | 9 | using Microsoft.Extensions.DependencyInjection; |
| 10 | +using OpenIddict.EntityFrameworkCore.Models; |
10 | 11 | using Squidex.Domain.Apps.Core.TestHelpers; |
11 | 12 | using Squidex.Infrastructure; |
12 | 13 | using Squidex.Infrastructure.Migrations; |
13 | 14 | using Squidex.Infrastructure.Queries; |
14 | 15 | using Squidex.Providers.Postgres; |
15 | 16 | using Squidex.Providers.Postgres.App; |
16 | 17 | using Testcontainers.PostgreSql; |
| 18 | +using static OpenIddict.Abstractions.OpenIddictConstants; |
17 | 19 |
|
18 | 20 | namespace Squidex.EntityFramework.Migrations; |
19 | 21 |
|
@@ -136,4 +138,56 @@ public async Task Should_migrate_when_functions_already_exist() |
136 | 138 | "SELECT jsonb_exists('{{\"a\":1}}'::jsonb)"); |
137 | 139 | Assert.Equal(-1, result); |
138 | 140 | } |
| 141 | + |
| 142 | + [Fact] |
| 143 | + public async Task Should_allow_openiddict_tokens_without_application() |
| 144 | + { |
| 145 | + var services = |
| 146 | + new ServiceCollection() |
| 147 | + .AddDbContextFactory<PostgresAppDbContext>(b => |
| 148 | + { |
| 149 | + b.UseNpgsql(postgreSql.GetConnectionString(), options => |
| 150 | + { |
| 151 | + options.UseNetTopologySuite(); |
| 152 | + }); |
| 153 | + }) |
| 154 | + .AddSingleton<ConnectionStringParser, PostgresConnectionStringParser>() |
| 155 | + .AddSingleton(TestUtils.DefaultSerializer) |
| 156 | + .AddSingleton<DatabaseMigrator<PostgresAppDbContext>>() |
| 157 | + .BuildServiceProvider(); |
| 158 | + |
| 159 | + var databaseMigrator = services.GetRequiredService<DatabaseMigrator<PostgresAppDbContext>>(); |
| 160 | + var databaseFactory = services.GetRequiredService<IDbContextFactory<PostgresAppDbContext>>(); |
| 161 | + |
| 162 | + await databaseMigrator.InitializeAsync(default); |
| 163 | + |
| 164 | + await using var dbContext = await databaseFactory.CreateDbContextAsync(); |
| 165 | + |
| 166 | + var authorization = new OpenIddictEntityFrameworkCoreAuthorization |
| 167 | + { |
| 168 | + Id = Guid.NewGuid().ToString(), |
| 169 | + ApplicationId = null, |
| 170 | + CreationDate = DateTime.UtcNow, |
| 171 | + Status = Statuses.Valid, |
| 172 | + Subject = "admin@squidex.io", |
| 173 | + Type = AuthorizationTypes.Permanent, |
| 174 | + }; |
| 175 | + |
| 176 | + var token = new OpenIddictEntityFrameworkCoreToken |
| 177 | + { |
| 178 | + Id = Guid.NewGuid().ToString(), |
| 179 | + ApplicationId = null, |
| 180 | + Authorization = authorization, |
| 181 | + CreationDate = DateTime.UtcNow, |
| 182 | + ExpirationDate = DateTime.UtcNow.AddMinutes(5), |
| 183 | + Status = Statuses.Valid, |
| 184 | + Subject = "admin@squidex.io", |
| 185 | + Type = "authorization_code", |
| 186 | + }; |
| 187 | + |
| 188 | + dbContext.Set<OpenIddictEntityFrameworkCoreAuthorization>().Add(authorization); |
| 189 | + dbContext.Set<OpenIddictEntityFrameworkCoreToken>().Add(token); |
| 190 | + |
| 191 | + await dbContext.SaveChangesAsync(); |
| 192 | + } |
139 | 193 | } |
0 commit comments