46 lines
1.6 KiB
C#
46 lines
1.6 KiB
C#
using System.Text.Json;
|
|
using VolcanicCore.Api.Auth;
|
|
using VolcanicCore.Api.Registries;
|
|
using VolcanicCore.Core;
|
|
|
|
namespace VolcanicCore.Tests;
|
|
|
|
public class SchemaSecretPolicyTests
|
|
{
|
|
private sealed class Provider : IConnectionProvider
|
|
{
|
|
public Provider(string id, params string[] secretFields)
|
|
{
|
|
Id = id;
|
|
SecretFields = new HashSet<string>(secretFields, StringComparer.Ordinal);
|
|
}
|
|
public string Id { get; }
|
|
public string DisplayName => Id;
|
|
public JsonSchema ConfigSchema => new(JsonDocument.Parse("{}").RootElement);
|
|
public IReadOnlySet<string> SecretFields { get; }
|
|
public Task<object> OpenAsync(JsonElement config, CancellationToken ct) => Task.FromResult<object>(new());
|
|
public Task CloseAsync(object handle) => Task.CompletedTask;
|
|
}
|
|
|
|
[Fact]
|
|
public void Returns_provider_declared_secret_fields()
|
|
{
|
|
var reg = new ConnectionProviderRegistry(new IConnectionProvider[]
|
|
{
|
|
new Provider("nats", "pass", "token"),
|
|
new Provider("http"),
|
|
});
|
|
var policy = new SchemaSecretPolicy(reg);
|
|
Assert.Equal(new HashSet<string> { "pass", "token" }, (HashSet<string>)policy.SecretFieldsFor("nats"));
|
|
Assert.Empty(policy.SecretFieldsFor("http"));
|
|
}
|
|
|
|
[Fact]
|
|
public void Unknown_provider_returns_empty_set()
|
|
{
|
|
var reg = new ConnectionProviderRegistry(Array.Empty<IConnectionProvider>());
|
|
var policy = new SchemaSecretPolicy(reg);
|
|
Assert.Empty(policy.SecretFieldsFor("nope"));
|
|
}
|
|
}
|