feat(release): add reproducible signed artifacts (#19)
This commit is contained in:
@@ -1,30 +1,69 @@
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace FinalFactory.Rendezvous.Tests.Contracts;
|
||||
|
||||
internal static class ContractTestFiles
|
||||
{
|
||||
public static string Read(string fileName) => File
|
||||
.ReadAllText(Path.Combine(Directory, fileName))
|
||||
.ReadAllText(Path.Combine(DirectoryFor(fileName), fileName))
|
||||
.TrimEnd('\r', '\n');
|
||||
|
||||
public static string Directory
|
||||
{
|
||||
get
|
||||
{
|
||||
return VersionedDirectory(Property("RendezvousMajorVersion"));
|
||||
}
|
||||
}
|
||||
|
||||
public static string OpenApiDocument
|
||||
{
|
||||
get
|
||||
{
|
||||
string httpVersion = Property("HttpContractVersion");
|
||||
return Path.Combine(RepositoryRoot, $"docs/api/rendezvous-v{httpVersion}.json");
|
||||
}
|
||||
}
|
||||
|
||||
private static string DirectoryFor(string fileName)
|
||||
{
|
||||
string property = fileName switch
|
||||
{
|
||||
"client-public-api.txt" or "contracts-public-api.txt" => "RendezvousMajorVersion",
|
||||
"connection-ticket.json" => "ConnectionTicketFormatVersion",
|
||||
_ when fileName.EndsWith(".hex", StringComparison.Ordinal) => "UdpContractVersion",
|
||||
_ when fileName.EndsWith(".json", StringComparison.Ordinal) => "HttpContractVersion",
|
||||
_ => throw new InvalidOperationException($"No contract version dimension maps {fileName}."),
|
||||
};
|
||||
return VersionedDirectory(Property(property));
|
||||
}
|
||||
|
||||
private static string VersionedDirectory(string version) => Path.Combine(
|
||||
RepositoryRoot,
|
||||
$"tests/FinalFactory.Rendezvous.Tests/TestData/Contracts/v{version}");
|
||||
|
||||
private static string Property(string name)
|
||||
{
|
||||
XDocument versions = XDocument.Load(Path.Combine(RepositoryRoot, "eng/Versions.props"));
|
||||
return versions.Descendants(name).Single().Value;
|
||||
}
|
||||
|
||||
private static string RepositoryRoot
|
||||
{
|
||||
get
|
||||
{
|
||||
DirectoryInfo? directory = new(AppContext.BaseDirectory);
|
||||
while (directory is not null)
|
||||
{
|
||||
string solution = Path.Combine(directory.FullName, "Rendezvous.slnx");
|
||||
if (File.Exists(solution))
|
||||
if (File.Exists(Path.Combine(directory.FullName, "Rendezvous.slnx")))
|
||||
{
|
||||
return Path.Combine(
|
||||
directory.FullName,
|
||||
"tests/FinalFactory.Rendezvous.Tests/TestData/Contracts/v1");
|
||||
return directory.FullName;
|
||||
}
|
||||
|
||||
directory = directory.Parent;
|
||||
}
|
||||
|
||||
throw new DirectoryNotFoundException("Could not locate contract test data.");
|
||||
throw new DirectoryNotFoundException("Could not locate repository root.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,12 +40,10 @@ public sealed class OpenApiCompatibilityTests
|
||||
];
|
||||
|
||||
[Fact]
|
||||
public void GeneratedOpenApiContainsTheFrozenV1Surface()
|
||||
public void GeneratedOpenApiContainsTheFrozenVersionedSurface()
|
||||
{
|
||||
string path = Path.Combine(
|
||||
ContractTestFiles.Directory,
|
||||
"../../../../../docs/api/rendezvous-v1.json");
|
||||
using JsonDocument document = JsonDocument.Parse(File.ReadAllText(Path.GetFullPath(path)));
|
||||
using JsonDocument document = JsonDocument.Parse(
|
||||
File.ReadAllText(ContractTestFiles.OpenApiDocument));
|
||||
JsonElement root = document.RootElement;
|
||||
|
||||
Assert.Equal("3.1.1", root.GetProperty("openapi").GetString());
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Text.Json;
|
||||
using FinalFactory.Rendezvous.Client;
|
||||
using FinalFactory.Rendezvous.Contracts;
|
||||
|
||||
@@ -22,6 +23,20 @@ public sealed class TraversalTokenCodecTests
|
||||
Assert.DoesNotContain(encoded, decoded.ToString(), StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ConnectionTicketMatchesTheVersionedV1Vector()
|
||||
{
|
||||
using JsonDocument vector = JsonDocument.Parse(ContractTestFiles.Read("connection-ticket.json"));
|
||||
JsonElement root = vector.RootElement;
|
||||
JoinAttemptId attemptId = new(Guid.Parse(root.GetProperty("attemptId").GetString()!));
|
||||
string authenticator = root.GetProperty("derivedAuthenticator").GetString()!;
|
||||
|
||||
string ticket = NatIntroductionTokenCodec.Encode(attemptId, authenticator);
|
||||
|
||||
Assert.Equal(root.GetProperty("connectionTicket").GetString(), ticket);
|
||||
Assert.Equal(root.GetProperty("digest").GetString(), NatIntroductionTokenCodec.ComputeDigest(ticket));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IntroductionTokenRejectsNonCanonicalOrAlteredFields()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user