Skip to content

Commit 51e8477

Browse files
committed
Add Postgres OpenIddict login regression coverage
1 parent 0668c09 commit 51e8477

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

backend/tests/Squidex.Data.Tests/EntityFramework/Migrations/PostgresMigrationTests.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77

88
using Microsoft.EntityFrameworkCore;
99
using Microsoft.Extensions.DependencyInjection;
10+
using OpenIddict.EntityFrameworkCore.Models;
1011
using Squidex.Domain.Apps.Core.TestHelpers;
1112
using Squidex.Infrastructure;
1213
using Squidex.Infrastructure.Migrations;
1314
using Squidex.Infrastructure.Queries;
1415
using Squidex.Providers.Postgres;
1516
using Squidex.Providers.Postgres.App;
1617
using Testcontainers.PostgreSql;
18+
using static OpenIddict.Abstractions.OpenIddictConstants;
1719

1820
namespace Squidex.EntityFramework.Migrations;
1921

@@ -136,4 +138,56 @@ public async Task Should_migrate_when_functions_already_exist()
136138
"SELECT jsonb_exists('{{\"a\":1}}'::jsonb)");
137139
Assert.Equal(-1, result);
138140
}
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+
}
139193
}

0 commit comments

Comments
 (0)