99 lines
3.6 KiB
C#
99 lines
3.6 KiB
C#
using FinalFactory.Rendezvous.Contracts;
|
|
using FinalFactory.Rendezvous.Server.Provisioning;
|
|
|
|
namespace FinalFactory.Rendezvous.Tests.Provisioning;
|
|
|
|
internal static class ProvisioningTestData
|
|
{
|
|
public static readonly DateTimeOffset Now = new(2026, 7, 16, 12, 0, 0, TimeSpan.Zero);
|
|
|
|
public static GamePolicyOptions CreatePolicy(
|
|
string gameId = "space-game",
|
|
string environmentId = "production",
|
|
bool enabled = true) => new()
|
|
{
|
|
GameId = gameId,
|
|
EnvironmentId = environmentId,
|
|
Enabled = enabled,
|
|
ProtocolVersions = [7],
|
|
Regions = ["eu-central"],
|
|
VisibilityModes = [ListingVisibility.Public, ListingVisibility.Unlisted],
|
|
PublisherTrustModes =
|
|
[
|
|
PublisherTrustMode.ManagedDedicated,
|
|
PublisherTrustMode.PlayerGrant,
|
|
PublisherTrustMode.AnonymousUnlisted,
|
|
],
|
|
MetadataValueMaxBytes = new Dictionary<string, int>(StringComparer.Ordinal)
|
|
{
|
|
["map"] = 32,
|
|
["mode"] = 16,
|
|
},
|
|
RequiredMetadataKeys = ["mode"],
|
|
MetadataMaxBytes = 256,
|
|
MetadataMaxKeys = 2,
|
|
MaxListingsPerPrincipal = 10,
|
|
MaxAnonymousListingsPerAddress = 1,
|
|
MaxActiveJoinAttempts = 100,
|
|
FallbackPolicy = FallbackPolicyMode.DedicatedEndpointAllowed,
|
|
};
|
|
|
|
public static SigningKeyOptions CreateKey(
|
|
string keyId = "key-1",
|
|
string secretReference = "secret-1",
|
|
DateTimeOffset? notBefore = null,
|
|
DateTimeOffset? signUntil = null,
|
|
DateTimeOffset? verifyUntil = null,
|
|
bool revoked = false,
|
|
IEnumerable<PrincipalCredentialKind>? credentialKinds = null,
|
|
string? gameId = "space-game",
|
|
string? environmentId = "production") => new()
|
|
{
|
|
KeyId = keyId,
|
|
SecretReference = secretReference,
|
|
CredentialKinds = credentialKinds?.ToList()
|
|
?? [
|
|
PrincipalCredentialKind.DedicatedPublisher,
|
|
PrincipalCredentialKind.PlayerHostGrant,
|
|
],
|
|
GameId = gameId,
|
|
EnvironmentId = environmentId,
|
|
NotBefore = notBefore ?? Now.AddHours(-1),
|
|
SignUntil = signUntil ?? Now.AddHours(1),
|
|
VerifyUntil = verifyUntil ?? Now.AddHours(2),
|
|
Revoked = revoked,
|
|
};
|
|
|
|
public static DictionarySecretProvider CreateSecrets(params string[] references)
|
|
{
|
|
Dictionary<string, byte[]> secrets = new(StringComparer.Ordinal);
|
|
for (int index = 0; index < references.Length; index++)
|
|
{
|
|
secrets.Add(
|
|
references[index],
|
|
Enumerable.Range(1 + index, 32).Select(static value => (byte)value).ToArray());
|
|
}
|
|
|
|
return new DictionarySecretProvider(secrets);
|
|
}
|
|
|
|
public static DedicatedPublisherPrincipal CreateDedicatedPublisher(
|
|
DateTimeOffset? expiresAt = null,
|
|
string gameId = "space-game",
|
|
string environmentId = "production") => new(
|
|
"workload-42",
|
|
expiresAt ?? Now.AddMinutes(10),
|
|
new GameId(gameId),
|
|
new EnvironmentId(environmentId),
|
|
new HashSet<RegionId> { new("eu-central") });
|
|
|
|
public static ProvisioningOptions CreateOptions(SigningKeyOptions? key = null) => new()
|
|
{
|
|
Issuer = "final-factory-rendezvous",
|
|
Audience = "rendezvous-service",
|
|
ClockSkewSeconds = 30,
|
|
SigningKeys = [key ?? CreateKey()],
|
|
Games = [CreatePolicy()],
|
|
};
|
|
}
|