增加Shop API

This commit is contained in:
chfei committed 2026-10-29 11:34:35 +08:00
1 parent 3769193696
commit 5d017740c6
83 files changed
+4451 -696

No files matched your search

@@ -12,27 +12,30 @@ namespace Store.Users.Tests;
public sealed class DevelopmentTokenTests
{
[Theory]
[InlineData("Development", true, "test-fixed-token", "admin")]
[InlineData("Development", true, "incorrect-token", "")]
[InlineData("Development", false, "test-fixed-token", "")]
[InlineData("Production", true, "test-fixed-token", "")]
public async Task FixedToken_OnlyAuthenticatesWhenEnabledInDevelopment(
string environment, bool enabled, string token, string expectedUser)
[InlineData("Development", true, "test-fixed-token", "test-fixed-token", "admin", "admin")]
[InlineData("Development", true, "incorrect-token", "test-fixed-token", "admin", "")]
[InlineData("Development", true, "TEST-FIXED-TOKEN", "test-fixed-token", "admin", "")]
[InlineData("Development", false, "test-fixed-token", "test-fixed-token", "admin", "")]
[InlineData("Production", true, "test-fixed-token", "test-fixed-token", "admin", "")]
[InlineData("Staging", true, "test-fixed-token", "test-fixed-token", "admin", "")]
[InlineData("Development", true, "test-fixed-token", "", "admin", "")]
[InlineData("Development", true, "test-fixed-token", "test-fixed-token", "", "")]
public async Task FixedToken_OnlyAuthenticatesWhenConfiguredAndEnabledInDevelopment(
string environment, bool enabled, string token, string configuredToken, string userName, string expectedUser)
{
var builder = WebApplication.CreateBuilder(new WebApplicationOptions { EnvironmentName = environment });
builder.WebHost.UseTestServer();
builder.Logging.ClearProviders();
builder.Configuration.AddInMemoryCollection(new Dictionary<string, string?>
{
["Jwt:DevelopmentToken:Enabled"] = enabled.ToString(),
["Jwt:DevelopmentToken:Token"] = "test-fixed-token",
["Jwt:DevelopmentToken:UserName"] = "admin"
["TokenAuth:DevelopmentToken:Enabled"] = enabled.ToString(),
["TokenAuth:DevelopmentToken:Token"] = configuredToken,
["TokenAuth:DevelopmentToken:UserName"] = userName
});
using var db = new FreeSql.FreeSqlBuilder()
.UseConnectionString(FreeSql.DataType.Sqlite, "Data Source=:memory:").Build();
db.CodeFirst.SyncStructure<OnlineUserInfo>();
builder.Services.AddSingleton<IFreeSql>(db);
builder.Services.AddStoreHubJwt(builder.Configuration);
builder.Services.AddStoreHubTokenAuth(builder.Configuration);
await using var app = builder.Build();
app.UseAuthentication();
app.MapGet("/identity", (ICurrentUser user) =>
@@ -42,7 +45,7 @@ public sealed class DevelopmentTokenTests
client.DefaultRequestHeaders.Authorization = new("Bearer", token);
Assert.Equal(expectedUser, await client.GetStringAsync("/identity"));
// 同一凭据不依赖首次请求创建的会话。
// 固定测试凭据不创建数据库会话,重复请求的结果保持一致。
Assert.Equal(expectedUser, await client.GetStringAsync("/identity"));
}
}