Refactoring
Some checks failed
Dotnet build and test / log-the-inputs (push) Failing after 1s
Dotnet build and test / build (push) Failing after 1s

The main server owns the migrations, it's the server part,
it's simpler.

It's Yavsc, not one of its lib.
This commit is contained in:
Paul Schneider
2025-07-15 19:43:41 +01:00
parent f43fd76baa
commit a9b809f5e5
67 changed files with 131 additions and 165 deletions

View File

@ -8,6 +8,7 @@ using Microsoft.EntityFrameworkCore;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Blog;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -6,6 +6,7 @@ using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Blog;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -10,6 +10,7 @@ namespace Yavsc.Controllers
using Models;
using Yavsc.Helpers;
using Yavsc.Models.Blog;
using Yavsc.Server.Helpers;
[Produces("application/json")]
[Route("~/api/PostTagsApi")]

View File

@ -8,6 +8,7 @@ namespace Yavsc.Controllers
using Microsoft.EntityFrameworkCore;
using Models.Relationship;
using Yavsc.Helpers;
using Yavsc.Server.Helpers;
[Produces("application/json")]
[Route("api/TagsApi")]

View File

@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Yavsc.Api.Helpers;
using Yavsc.Server.Helpers;
using Yavsc.Models;
using Yavsc.Models.Workflow;

View File

@ -15,6 +15,7 @@ namespace Yavsc.Controllers
using Yavsc.Abstract.Identity;
using Microsoft.EntityFrameworkCore;
using Yavsc.Helpers;
using Yavsc.Server.Helpers;
[Produces("application/json")]
[Route("api/bookquery"), Authorize(Roles = "Performer,Administrator")]

View File

@ -10,6 +10,7 @@ using Newtonsoft.Json;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Billing;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Billing;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Market;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -5,6 +5,7 @@ using Microsoft.EntityFrameworkCore;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Messaging;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Haircut;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -22,6 +22,7 @@ namespace Yavsc.ApiControllers
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Authorization;
using Yavsc.Server.Helpers;
[Route("api/haircut")][Authorize]
public class HairCutController : Controller

View File

@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Musical;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Musical;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -8,6 +8,7 @@ using Microsoft.Extensions.Logging;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Identity;
using Yavsc.Server.Helpers;
[Authorize, Route("~/api/gcm")]
public class NativeConfidentialController : Controller

View File

@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -5,6 +5,7 @@ using Microsoft.EntityFrameworkCore;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Access;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Access;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Chat;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Relationship;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore;
using Yavsc.Abstract.Identity;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Market;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -8,6 +8,7 @@ using Microsoft.EntityFrameworkCore;
using Yavsc.Abstract.Identity;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -6,6 +6,7 @@ using System.Linq;
using Yavsc.Models;
using Yavsc.Abstract.Identity;
using Yavsc.Helpers;
using Yavsc.Server.Helpers;
namespace Yavsc.ApiControllers.accounting
{

View File

@ -1,17 +0,0 @@
using System.Security.Claims;
using System.Collections.Generic;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Yavsc.Models;
using Yavsc.Models.Blog;
namespace Yavsc.Api.Helpers
{
public static class UserHelpers
{
public static string? GetUserId(this ClaimsPrincipal user)
{
return user.FindFirstValue("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier");
}
}
}

View File

@ -1,11 +1,6 @@
using System.Security.Claims;
using System.Collections.Generic;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Yavsc.Models;
using Yavsc.Models.Blog;
namespace Yavsc.Helpers
namespace Yavsc.Server.Helpers
{
public static class UserHelpers
{
@ -24,30 +19,5 @@ namespace Yavsc.Helpers
return user.Identity.IsAuthenticated;
}
public static IEnumerable<BlogPost> UserPosts(this ApplicationDbContext dbContext, string posterId, string? readerId)
{
if (readerId == null)
{
var userPosts = dbContext.blogSpotPublications.Include(
b => b.BlogPost
).Where(x => x.BlogPost.AuthorId == posterId)
.Select(x=>x.BlogPost).ToArray();
return userPosts;
}
else
{
long[] readerCirclesMemberships =
dbContext.Circle.Include(c => c.Members)
.Where(c => c.Members.Any(m => m.MemberId == readerId))
.Select(c => c.Id).ToArray();
return dbContext.BlogSpot.Include(
b => b.Author
).Include(p => p.ACL).Where(x => x.Author.Id == posterId &&
(x.ACL.Count == 0 || x.ACL.Any(a => readerCirclesMemberships.Contains(a.CircleId))));
}
}
}
}

View File

@ -36,6 +36,7 @@ namespace Yavsc
using Models.Chat;
using Yavsc.Abstract.Chat;
using Yavsc.Helpers;
using Yavsc.Server.Helpers;
using Yavsc.Services;
public partial class ChatHub : Hub, IDisposable
{

View File

@ -1,26 +1,2 @@
SOURCE_DIR=../..
MAKEFILE_DIR=$(SOURCE_DIR)/scripts/make
BASERESX=Resources/Yavsc.Models.Relationship.HyperLink.resx \
Resources/Yavsc.Models.Streaming.LiveFlow.resx
BASERESXGEN=$(BASERESX:.resx=.Designer.cs)
include $(MAKEFILE_DIR)/dnx.mk
include $(MAKEFILE_DIR)/versioning.mk
default: all
$(BINTARGETPATH): ../OAuth.AspNet.AuthServer/bin/$(CONFIGURATION)/OAuth.AspNet.AuthServer.dll \
../Yavsc.Abstract/bin/$(CONFIGURATION)/Yavsc.Abstract.dll prepare_code
../OAuth.AspNet.AuthServer/bin/$(CONFIGURATION)/OAuth.AspNet.AuthServer.dll:
make -C ../OAuth.AspNet.AuthServer
../Yavsc.Abstract/bin/$(CONFIGURATION)/Yavsc.Abstract.dll:
make -C ../Yavsc.Abstract
%.Designer.cs: %.resx
strongresbuildercli -l -p -t -r "Yavsc.Server.Resources." $^
prepare_code: $(BASERESXGEN)
all: $(BINTARGETPATH)
listConnections:
dotnet ef migrations list --connection "$(YAVSC_CONNECTION_STRING)"

View File

@ -36,6 +36,10 @@ namespace Yavsc.Models
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
{
}
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
}

View File

@ -5,6 +5,7 @@ using Microsoft.Extensions.Options;
using rules;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Server.Helpers;
namespace Yavsc.Services
{

View File

@ -1,66 +0,0 @@
using IdentityServer8.Models;
using IdentityServer8.Stores;
using Microsoft.EntityFrameworkCore;
using Yavsc.Models;
namespace Yavsc.Services;
public class YavscClientStore : IClientStore
{
ApplicationDbContext _context=null;
public YavscClientStore(ApplicationDbContext context)
{
_context = context;
}
async Task<Client> IClientStore.FindClientByIdAsync(string clientId)
{
var app = await _context.Applications.FirstOrDefaultAsync(c=>c.Id == clientId);
if (app == null) return null;
Client client = new()
{
ClientId = app.Id,
ClientName = app.DisplayName,
AbsoluteRefreshTokenLifetime = app.RefreshTokenLifeTime,
AccessTokenLifetime = app.AccessTokenLifetime,
AllowedGrantTypes =
[
GrantType.AuthorizationCode,
GrantType.DeviceFlow,
GrantType.ClientCredentials
],
ClientSecrets = [
new Secret(app.Secret),
]
};
switch(app.Type)
{
case Models.Auth.ApplicationTypes.NativeConfidential:
client.AccessTokenType = AccessTokenType.Reference;
client.AllowedGrantTypes =
[
GrantType.DeviceFlow
];
client.AllowedScopes = [] ;
break;
case Models.Auth.ApplicationTypes.JavaScript:
default:
client.AccessTokenType = AccessTokenType.Jwt;
client.AllowedGrantTypes =
[
GrantType.AuthorizationCode,
GrantType.ClientCredentials
];
client.AllowedScopes = ["openid", "profile"];
break;
}
return client;
}
}

View File

@ -27,6 +27,7 @@ using IdentityModel;
using System.Security.Cryptography;
using System.Text.Unicode;
using System.Text;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -16,6 +16,7 @@ using Yavsc.Services;
using Yavsc.ViewModels.Manage;
using Microsoft.AspNetCore.Identity.UI.Services;
using Microsoft.AspNetCore.Authorization;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{
@ -709,7 +710,8 @@ namespace Yavsc.Controllers
private async Task<ApplicationUser> GetCurrentUserAsync()
{
return await _dbContext.Users.Include(u => u.PostalAddress).FirstOrDefaultAsync(u => u.Id == User.GetUserId());
return await _dbContext.Users.Include(u => u.PostalAddress)
.FirstOrDefaultAsync(u => u.Id == User.GetUserId());
}
#endregion

View File

@ -7,6 +7,7 @@ using Microsoft.EntityFrameworkCore;
using Yavsc.Abstract.Identity;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Server.Helpers;
using Yavsc.ViewModels;
using Yavsc.ViewModels.Administration;

View File

@ -9,6 +9,7 @@ using Yavsc.Server.Settings;
using Microsoft.EntityFrameworkCore;
using Yavsc.Helpers;
using Yavsc.Server.Models.Calendar;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -10,6 +10,7 @@ using Microsoft.Extensions.Options;
using Microsoft.EntityFrameworkCore;
using Yavsc.ViewModels.Blog;
using Yavsc.Server.Exceptions;
using Yavsc.Server.Helpers;
// For more information on enabling Web API for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860

View File

@ -5,6 +5,7 @@ using Microsoft.EntityFrameworkCore;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Relationship;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -6,6 +6,7 @@ using Microsoft.EntityFrameworkCore;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Relationship;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -5,6 +5,7 @@ using Microsoft.EntityFrameworkCore;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Blog;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -4,6 +4,7 @@ using Yavsc.Abstract.Models.Messaging;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Messaging;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -9,6 +9,7 @@ namespace Yavsc.Controllers
using Models;
using Models.Workflow;
using Yavsc.Helpers;
using Yavsc.Server.Helpers;
[Authorize("AdministratorOnly")]
public class ActivityController : Controller

View File

@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Auth;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Workflow;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -16,6 +16,7 @@ namespace Yavsc.Controllers
using Models.Workflow;
using Services;
using Yavsc.Interface;
using Yavsc.Server.Helpers;
using Yavsc.Settings;
public class CommandController : Controller

View File

@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Workflow;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -13,6 +13,7 @@ namespace Yavsc.Controllers
using System.Threading.Tasks;
using Yavsc.Helpers;
using Microsoft.EntityFrameworkCore;
using Yavsc.Server.Helpers;
[Authorize]
public class DoController : Controller

View File

@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Forms;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -5,6 +5,7 @@ namespace Yavsc.Controllers
using Models;
using Models.Musical;
using Yavsc.Helpers;
using Yavsc.Server.Helpers;
public class MusicalTendenciesController : Controller
{

View File

@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Mvc;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Billing;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -7,6 +7,7 @@ namespace Yavsc.Controllers.Generic
using Microsoft.EntityFrameworkCore;
using Models;
using Yavsc.Helpers;
using Yavsc.Server.Helpers;
using Yavsc.Services;
[Authorize]

View File

@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Drawing;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -26,6 +26,7 @@ namespace Yavsc.Controllers
using Yavsc.Interface;
using Yavsc.Settings;
using Yavsc.Abstract.Models.Messaging;
using Yavsc.Server.Helpers;
public class HairCutCommandController : CommandController
{

View File

@ -5,6 +5,7 @@ using Microsoft.EntityFrameworkCore;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Haircut;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Mvc.Localization;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.Extensions.Options;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -5,6 +5,7 @@ using Yavsc.Models;
using Yavsc.Server.Models.IT.SourceCode;
using Yavsc.Helpers;
using Microsoft.EntityFrameworkCore;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -6,6 +6,7 @@ using Microsoft.EntityFrameworkCore;
using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Musical.Profiles;
using Yavsc.Server.Helpers;
namespace Yavsc.Controllers
{

View File

@ -7,6 +7,7 @@ namespace Yavsc.Controllers
using Models;
using Models.Musical;
using Yavsc.Helpers;
using Yavsc.Server.Helpers;
public class InstrumentsController : Controller
{

View File

@ -6,6 +6,7 @@ using Yavsc.Helpers;
using Yavsc.Migrations;
using Yavsc.Models;
using Yavsc.Models.Blog;
using Yavsc.Server.Helpers;
using Yavsc.ViewModels.Auth;
namespace Yavsc.Extensions;

View File

@ -1,10 +1,32 @@
using System.Security.Claims;
using Microsoft.EntityFrameworkCore;
using Yavsc.Models;
using Yavsc.Models.Blog;
namespace Yavsc.Helpers
{
public static class UserHelpers
{
public static IEnumerable<BlogPost> UserPosts(this ApplicationDbContext dbContext, string posterId, string? readerId)
{
if (readerId == null)
{
var userPosts = dbContext.blogSpotPublications.Include(
b => b.BlogPost
).Where(x => x.BlogPost.AuthorId == posterId)
.Select(x => x.BlogPost).ToArray();
return userPosts;
}
else
{
long[] readerCirclesMemberships =
dbContext.Circle.Include(c => c.Members)
.Where(c => c.Members.Any(m => m.MemberId == readerId))
.Select(c => c.Id).ToArray();
return dbContext.BlogSpot.Include(
b => b.Author
).Include(p => p.ACL).Where(x => x.Author.Id == posterId &&
(x.ACL.Count == 0 || x.ACL.Any(a => readerCirclesMemberships.Contains(a.CircleId))));
}
}
}
}

View File

@ -9,6 +9,7 @@ using Yavsc.Helpers;
using Yavsc.Models;
using Yavsc.Models.Blog;
using Yavsc.Server.Exceptions;
using Yavsc.Server.Helpers;
using Yavsc.ViewModels.Auth;
using Yavsc.ViewModels.Blog;

View File

@ -49,10 +49,8 @@ namespace Yavsc.Services
public static ConcurrentDictionary<string, ChatRoomInfo> Channels = new ConcurrentDictionary<string, ChatRoomInfo>();
readonly ApplicationDbContext _dbContext;
readonly IStringLocalizer _localizer;
public HubConnectionManager(IServiceScopeFactory ssf )
{
var scope = ssf.CreateScope();
_dbContext = scope.ServiceProvider.GetService<ApplicationDbContext>();
var loggerFactory = scope.ServiceProvider.GetService<ILoggerFactory>();

View File

@ -23,8 +23,15 @@ public class ClientStore : IClientStore
ClientId = clientFromDb.Id,
ClientName = clientFromDb.DisplayName,
ClientSecrets = { new Secret(clientFromDb.Secret.Sha256()) },
AllowedGrantTypes =[ GrantType.ClientCredentials, GrantType.DeviceFlow],
AllowedScopes = ["openid", "profile", "scope1"]
AllowedGrantTypes =
[
GrantType.AuthorizationCode,
GrantType.DeviceFlow,
GrantType.ClientCredentials
],
AllowedScopes = ["openid", "profile", "scope1"],
AbsoluteRefreshTokenLifetime = clientFromDb.RefreshTokenLifeTime,
AccessTokenLifetime = clientFromDb.AccessTokenLifetime
};
}
}

View File

@ -29,6 +29,7 @@
@using Microsoft.AspNetCore.Html;
@using Microsoft.AspNetCore.Identity;
@using Yavsc.Helpers;
@using Yavsc.Server.Helpers;
@using PayPal.PayPalAPIInterfaceService.Model;
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

View File

@ -30,10 +30,13 @@ namespace yavscTests
{
try
{
var serverUrl = _serverFixture.Addresses.FirstOrDefault();
String auth = _serverFixture.SiteSettings.Authority;
var oauthor = new OAuthenticator(clientId, clientSecret, scope,
new Uri(authorizeUrl), new Uri(redirectUrl), new Uri(accessTokenUrl));
var oauthor = new OAuthenticator(_serverFixture.TestClientId, _serverFixture.TestClientSecret,
"profile",
new Uri(serverUrl), new Uri(serverUrl), new Uri(serverUrl+"/connect/token"));
var query = new Dictionary<string, string>
{
["Username"] = userName,

View File

@ -17,6 +17,7 @@ using yavscTests.Settings;
using Yavsc.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Mvc.ModelBinding.Binders;
using Yavsc.Models.Auth;
namespace isnd.tests
{
@ -32,6 +33,7 @@ namespace isnd.tests
public IConfigurationRoot Configuration { get; private set; }
private WebApplication app;
public string TestClientId { get; private set; }
public IServiceProvider Services { get; private set; }
public string TestingUserName { get; private set; }
@ -41,6 +43,7 @@ namespace isnd.tests
public SiteSettings SiteSettings { get => siteSettings; set => siteSettings = value; }
public MailSender MailSender { get; internal set; }
public TestingSetup? TestingSetup { get; internal set; }
public string TestClientSecret { get; private set; } = "TestClientSecret";
public WebServerFixture()
{
@ -56,14 +59,14 @@ namespace isnd.tests
public async Task SetupHost()
{
var builder = WebApplication.CreateBuilder();
Configuration = builder.Configuration
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables()
.Build();
this.app = builder.ConfigureWebAppServices();
this.app = builder.ConfigureWebAppServices();
Services = app.Services;
using (var migrationScope = app.Services.CreateScope())
{
@ -73,8 +76,8 @@ namespace isnd.tests
await app.ConfigurePipeline();
app.UseSession();
await app.StartAsync();
var logFactory = app.Services.GetRequiredService<ILoggerFactory>();
Logger = logFactory.CreateLogger<WebServerFixture>();
@ -94,14 +97,28 @@ namespace isnd.tests
scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
//dbContext.Database.EnsureCreated();
dbContext.Database.Migrate();
TestingUserName = "Tester";
TestingUser = dbContext.Users.FirstOrDefault(u => u.UserName == TestingUserName);
EnsureUser(TestingUserName);
ServicePointManager.ServerCertificateValidationCallback =
(sender, cert, chain, sslPolicyErrors) => true;
TestingUserName = "Tester";
TestClientId = "testClientId";
TestingUser = await dbContext.Users.FirstOrDefaultAsync(u => u.UserName == TestingUserName);
EnsureUser(TestingUserName);
// ensure a client
var testClient = await dbContext.Client.FirstOrDefaultAsync((c) => c.Id == TestClientId);
if (testClient == null)
{
testClient = new Yavsc.Models.Auth.Client
{
Id = TestClientId,
DisplayName = "Testing Client",
Secret = TestClientSecret,
Active = true,
Type = ApplicationTypes.NativeConfidential,
AccessTokenLifetime = 900,
RefreshTokenLifeTime = 15000
};
dbContext.Client.Add(testClient);
dbContext.SaveChanges();
}
}
public void EnsureUser(string testingUserName)
@ -113,7 +130,6 @@ namespace isnd.tests
var userManager =
scope.ServiceProvider.GetRequiredService<UserManager<ApplicationUser>>();
TestingUser = new ApplicationUser
{
UserName = testingUserName,
@ -130,7 +146,5 @@ namespace isnd.tests
TestingUser = dbContext.Users.FirstOrDefault(u => u.UserName == testingUserName);
}
}
}
}