public void Ctor_CreatesValidSecret() { var sut = new PlainTextSecret(); Assert.True(sut.PlainText?.Length > 16); //Assert the secret has a good default length Assert.Equal(44, sut.Value?.Length); //Assert the Hash has been set and is 44 chars long (base64 of Hash). }
public void Value_IsSha256Hash() { var sut = new PlainTextSecret { PlainText = "Hello World!" }; Assert.Equal("f4OxZX/x/FO5LcGBSKHWXfwtSx+j1ncoSt3SABJtkGk=", sut.Value, ignoreCase: true); }
private Task <RetrievedSecrets> RetrieveSecretsCoreAsync(List <RetrieveSecretsRequest> requests, CancellationToken token) { var secrets = new Dictionary <string, Secret>(); foreach (var request in requests) { Secret secret = null; var secretValue = GetSecretStoreValue(request.Name); if (string.IsNullOrEmpty(secretValue)) { // Environment variables are null by default. Skip if that's the case continue; } switch (request.Kind) { case SecretKind.PlainText: // In this case, the value is expected to be an entire connection string secret = new PlainTextSecret(secretValue); break; case SecretKind.SasToken: secret = CreateSasTokenSecret(request, secretValue); break; default: throw new NotSupportedException($"It is expected that all supported credential kinds be handled when creating a DistributedService. {request.Kind} is unhandled."); } Contract.Requires(secret != null); secrets[request.Name] = secret; } return(Task.FromResult(new RetrievedSecrets(secrets))); }