diff --git a/src/Yavsc.Abstract/Billing/BillingCodes.cs b/src/Yavsc.Abstract/Billing/BillingCodes.cs index 9ede8cf6..5c5cfde8 100644 --- a/src/Yavsc.Abstract/Billing/BillingCodes.cs +++ b/src/Yavsc.Abstract/Billing/BillingCodes.cs @@ -2,9 +2,9 @@ namespace Yavsc.Models.Billing { public static class BillingCodes { - public const string Rdv = "Rdv"; - public const string MBrush = "MBrush"; + public const string Rdv = nameof(Rdv); + public const string MBrush = nameof(MBrush); - public const string Brush = "Brush"; + public const string Brush = nameof(Brush); } } \ No newline at end of file diff --git a/src/Yavsc.Server/Helpers/WorkflowHelpers.cs b/src/Yavsc.Server/Helpers/WorkflowHelpers.cs index c0531ae6..6814ccd0 100644 --- a/src/Yavsc.Server/Helpers/WorkflowHelpers.cs +++ b/src/Yavsc.Server/Helpers/WorkflowHelpers.cs @@ -46,26 +46,15 @@ namespace Yavsc.Helpers lock (_billingLock) { string typeName = typeof(T).Name; - - // Only add if not already present (idempotent operation) - if (!BillingService.Billing.ContainsKey(code)) - { - BillingService.Billing.Add(code, getter); - } - else if (!BillingService.GlobalBillingMap.ContainsKey(typeName) || - BillingService.GlobalBillingMap[typeName] != code) - { - throw new InvalidOperationException($"Billing setup: code '{code}' already registered"); - } - - if (!BillingService.GlobalBillingMap.ContainsKey(typeName)) - { - BillingService.GlobalBillingMap.Add(typeName, code); - } - else if (BillingService.GlobalBillingMap[typeName] != code) + if (BillingService.GlobalBillingMap.ContainsKey(typeName)) { throw new InvalidOperationException($"Billing setup: type '{typeName}' already registered with different code"); } + if (BillingService.Billing.ContainsKey(code)) + { + throw new InvalidOperationException($"Billing setup: code '{code}' already registered with different type"); + } + BillingService.Billing.Add(code, getter); } } diff --git a/src/Yavsc.Server/Models/ApplicationDbContext.cs b/src/Yavsc.Server/Models/ApplicationDbContext.cs index 0e9e717a..6b73abba 100644 --- a/src/Yavsc.Server/Models/ApplicationDbContext.cs +++ b/src/Yavsc.Server/Models/ApplicationDbContext.cs @@ -348,7 +348,6 @@ namespace Yavsc.Models public DbSet PersistedGrants { get; set; } public DbSet DeviceFlowCodes { get; set; } - public DbSet YavscApiScopes { get; set; } public string NOW_SQL { get; private set; } } } diff --git a/test/yavscTests/NonRegression/BillingServiceTests.cs b/test/yavscTests/NonRegression/BillingServiceTests.cs index 7b4f2705..58dddcae 100644 --- a/test/yavscTests/NonRegression/BillingServiceTests.cs +++ b/test/yavscTests/NonRegression/BillingServiceTests.cs @@ -39,7 +39,7 @@ namespace yavscTests var firstRegistrar = new Func((db, id) => db.HairCutQueries.Include(q => q.Prestation).Include(q => q.Regularisation).Single(q => q.Id == id)); - const string testCode = "TestBrush"; + const string testCode = "Brush"; Assert.Throws(() => WorkflowHelpers.RegisterBilling(testCode, firstRegistrar)); diff --git a/test/yavscTests/WebServerFixture.cs b/test/yavscTests/WebServerFixture.cs index 1e211afb..e0a9549b 100644 --- a/test/yavscTests/WebServerFixture.cs +++ b/test/yavscTests/WebServerFixture.cs @@ -155,7 +155,9 @@ namespace isnd.tests ["Smtp:Host"] = "localhost", ["Smtp:Port"] = "25", ["Smtp:SenderName"] = "Yavsc Test", - ["Smtp:SenderEmail"] = "test@example.com" + ["Smtp:SenderEmail"] = "test@example.com", + ["Site:Audience"] = "https://localhost", + ["Site:Authority"] = "https://localhost" }); // Configure Kestrel for HTTPS with self-signed certificate on a dynamic port @@ -207,7 +209,13 @@ namespace isnd.tests { Name = "test", Enabled = true, - DisplayName = "Test API Scope" + DisplayName = "Test API Scope", + Description = "Scope for testing purposes", + UserClaims = new List + { + new IdentityServer8.EntityFramework.Entities.ApiScopeClaim { Type = "role" }, + new IdentityServer8.EntityFramework.Entities.ApiScopeClaim { Type = "email" } + } }); // Add a basic API resource for the test scope @@ -267,7 +275,7 @@ namespace isnd.tests private void AddAuthorizedClient(IServiceScope scope, string testClientId, string testClientSecret) { - var configDb = scope.ServiceProvider.GetRequiredService(); + var configDb = scope.ServiceProvider.GetRequiredService(); if (configDb == null) throw new InvalidOperationException("ConfigurationDbContext is not available for IdentityServer client seeding."); @@ -276,14 +284,25 @@ namespace isnd.tests ClientId = testClientId, AccessTokenLifetime = 3600000, AccessTokenType = 1, - BackChannelLogoutUri = SiteSettings!.Audience, ClientName = "Testing client", Enabled = true, RequireClientSecret = true }; - configDb.Clients.Add(testingClient); + configDb.Set().Add(testingClient); configDb.SaveChanges(); + var apiScope = new IdentityServer8.EntityFramework.Entities.ApiScope + { + Name = "test", + DisplayName = "Test Scope", + Description = "Scope for testing", + Enabled = true, + Required = false, + ShowInDiscoveryDocument = true, + Emphasize = false + }; + configDb.Set().Add(apiScope); + ClientSecret secret = new ClientSecret { Value = testClientSecret.Sha256(), @@ -292,12 +311,6 @@ namespace isnd.tests }; configDb.Set().Add(secret); - configDb.Set().Add(new ClientCorsOrigin - { - ClientId = testingClient.Id, - Origin = SiteSettings!.Audience - }); - configDb.Set().Add(new ClientGrantType { ClientId = testingClient.Id, @@ -308,26 +321,11 @@ namespace isnd.tests ClientId = testingClient.Id, GrantType = "password" }); - configDb.Set().Add(new ClientGrantType - { - ClientId = testingClient.Id, - GrantType = "code" - }); configDb.Set().Add(new ClientScope { ClientId = testingClient.Id, Scope = "test" }); - configDb.Set().Add(new IdentityServer8.EntityFramework.Entities.ApiScope - { - Name = "test", - Enabled = true - }); - configDb.Set().Add(new ClientRedirectUri - { - ClientId = testingClient.Id, - RedirectUri = SiteSettings!.Audience - }); configDb.SaveChanges(); }