audit, advisories and doctors/setup work
This commit is contained in:
@@ -0,0 +1 @@
|
||||
global using Xunit;
|
||||
@@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<LangVersion>preview</LangVersion>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentAssertions" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" />
|
||||
<PackageReference Include="xunit" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\SimCryptoSmoke.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,65 @@
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace SimCryptoSmoke.Tests;
|
||||
|
||||
public sealed class SimCryptoSmokeTests
|
||||
{
|
||||
[Fact]
|
||||
public void ResolveAlgorithms_UsesProfileDefaults()
|
||||
{
|
||||
var algs = SmokeLogic.ResolveAlgorithms("gost", null);
|
||||
algs.Should().Contain("GOST12-256");
|
||||
algs.Should().Contain("ru.magma.sim");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolveAlgorithms_UsesOverrideList()
|
||||
{
|
||||
var algs = SmokeLogic.ResolveAlgorithms("sm", "ES256,SM2");
|
||||
algs.Should().ContainInOrder(new[] { "ES256", "SM2" });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SignAndVerifyAsync_ReturnsOk()
|
||||
{
|
||||
using var client = new HttpClient(new StubHandler())
|
||||
{
|
||||
BaseAddress = new Uri("http://localhost")
|
||||
};
|
||||
|
||||
var result = await SmokeLogic.SignAndVerifyAsync(client, "SM2", "hello", CancellationToken.None);
|
||||
result.Ok.Should().BeTrue();
|
||||
result.Error.Should().BeEmpty();
|
||||
}
|
||||
|
||||
private sealed class StubHandler : HttpMessageHandler
|
||||
{
|
||||
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
{
|
||||
var path = request.RequestUri?.AbsolutePath ?? string.Empty;
|
||||
if (path.Equals("/sign", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return Task.FromResult(BuildJsonResponse(new { signature_b64 = "c2ln", algorithm = "SM2" }));
|
||||
}
|
||||
|
||||
if (path.Equals("/verify", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return Task.FromResult(BuildJsonResponse(new { ok = true, algorithm = "SM2" }));
|
||||
}
|
||||
|
||||
return Task.FromResult(new HttpResponseMessage(HttpStatusCode.NotFound));
|
||||
}
|
||||
|
||||
private static HttpResponseMessage BuildJsonResponse(object payload)
|
||||
{
|
||||
var json = JsonSerializer.Serialize(payload, new JsonSerializerOptions(JsonSerializerDefaults.Web));
|
||||
return new HttpResponseMessage(HttpStatusCode.OK)
|
||||
{
|
||||
Content = new StringContent(json, Encoding.UTF8, "application/json")
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user