audit, advisories and doctors/setup work
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
<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.AspNetCore.Mvc.Testing" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" />
|
||||
<PackageReference Include="xunit" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\CryptoProLinuxApi.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,77 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using FluentAssertions;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
|
||||
namespace CryptoProLinuxApi.Tests;
|
||||
|
||||
public sealed class CryptoProLinuxApiTests : IClassFixture<WebApplicationFactory<Program>>
|
||||
{
|
||||
private readonly HttpClient _client;
|
||||
|
||||
public CryptoProLinuxApiTests(WebApplicationFactory<Program> factory)
|
||||
{
|
||||
_client = factory.CreateClient();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Health_ReportsStatus()
|
||||
{
|
||||
var response = await _client.GetAsync("/health");
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
using var doc = JsonDocument.Parse(await response.Content.ReadAsStringAsync());
|
||||
doc.RootElement.GetProperty("status").GetString().Should().Be("ok");
|
||||
doc.RootElement.GetProperty("csptest").GetString().Should().NotBeNullOrWhiteSpace();
|
||||
return;
|
||||
}
|
||||
|
||||
response.StatusCode.Should().Be(HttpStatusCode.InternalServerError);
|
||||
var body = await response.Content.ReadAsStringAsync();
|
||||
body.Contains("csptest", StringComparison.OrdinalIgnoreCase).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task License_ReturnsResultShape()
|
||||
{
|
||||
var response = await _client.GetAsync("/license");
|
||||
response.IsSuccessStatusCode.Should().BeTrue();
|
||||
|
||||
using var doc = JsonDocument.Parse(await response.Content.ReadAsStringAsync());
|
||||
doc.RootElement.GetProperty("exitCode").ValueKind.Should().Be(JsonValueKind.Number);
|
||||
doc.RootElement.GetProperty("output").ValueKind.Should().Be(JsonValueKind.String);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Hash_InvalidBase64_ReturnsBadRequest()
|
||||
{
|
||||
var response = await _client.PostAsJsonAsync("/hash", new { data_b64 = "not-base64" });
|
||||
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Hash_ValidBase64_ReturnsResultShape()
|
||||
{
|
||||
var payload = Convert.ToBase64String(Encoding.UTF8.GetBytes("test"));
|
||||
var response = await _client.PostAsJsonAsync("/hash", new { data_b64 = payload });
|
||||
response.IsSuccessStatusCode.Should().BeTrue();
|
||||
|
||||
using var doc = JsonDocument.Parse(await response.Content.ReadAsStringAsync());
|
||||
doc.RootElement.GetProperty("exitCode").ValueKind.Should().Be(JsonValueKind.Number);
|
||||
doc.RootElement.GetProperty("output").ValueKind.Should().Be(JsonValueKind.String);
|
||||
doc.RootElement.GetProperty("digest_b64").ValueKind.Should().BeOneOf(JsonValueKind.Null, JsonValueKind.String);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task KeysetInit_ReturnsResultShape()
|
||||
{
|
||||
var response = await _client.PostAsJsonAsync("/keyset/init", new { name = "test" });
|
||||
response.IsSuccessStatusCode.Should().BeTrue();
|
||||
|
||||
using var doc = JsonDocument.Parse(await response.Content.ReadAsStringAsync());
|
||||
doc.RootElement.GetProperty("exitCode").ValueKind.Should().Be(JsonValueKind.Number);
|
||||
doc.RootElement.GetProperty("output").ValueKind.Should().Be(JsonValueKind.String);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
global using Xunit;
|
||||
Reference in New Issue
Block a user