using System.Linq;
using System.Text.Json;
using Xunit;
namespace Yh.Platform.AppAuth.Tests;
///
/// AppSignHandler basePath 剥离对拍(验收 P1 修复):
/// 链路 handler(fullUrl) → 剥离 basePath → SignUtil(剥离后 canonicalTarget) → 向量基线(Java 口径)。
/// 证明:经 handler 发出的签名 = Java 客户端对同一 URL 的签名(同 ts 时逐字节一致)。
///
public class AppSignHandlerTests
{
private sealed class CaptureHandler : HttpMessageHandler
{
public HttpRequestMessage? Last { get; private set; }
protected override Task SendAsync(HttpRequestMessage request, CancellationToken ct)
{
Last = request;
return Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK));
}
}
private const string AppKey = "100476";
private const string Secret = "app-secret-100476-yunhai";
private static async Task SendThroughHandlerAsync(AppSignHandler handler, HttpMethod method, string url)
{
using var client = new HttpClient(handler);
var request = new HttpRequestMessage(method, url);
await client.SendAsync(request);
// handler 已把三头写入同一个 request 实例;CaptureHandler 捕获的是该实例
return request;
}
/// 读取请求级向量:固定 ts 后,经 handler 对 fullUrl 的签名须与向量基线(Java 口径)逐字节一致。
public static IEnumerable