-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVariableSubstitutionTest.cs
More file actions
55 lines (49 loc) · 2.02 KB
/
Copy pathVariableSubstitutionTest.cs
File metadata and controls
55 lines (49 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using EncryptedConfigValue.AspNetCore.Test.Util;
using EncryptedConfigValue.Crypto;
using Shouldly;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Xunit;
namespace EncryptedConfigValue.AspNetCore.Test
{
public class VariableSubstitutionTest
{
public VariableSubstitutionTest()
{
Environment.SetEnvironmentVariable(KeyFileUtils.KeyPathProperty, Path.Combine("Resources", "test.key"));
}
private static WebApplication CreateWebApplication()
{
var builder = WebApplication.CreateBuilder();
builder.Configuration.AddJsonFile(Path.Combine("Resources", "testConfig.json"), optional: false, reloadOnChange: false);
builder.AddEncryptedConfigValueProvider();
return builder.Build();
}
private static readonly WebApplication aspnet = CreateWebApplication();
[Fact]
public void TestCanDecryptValueInConfig()
{
aspnet.Configuration["Unencrypted"].ShouldBe("value");
aspnet.Configuration["Encrypted"].ShouldBe("value");
aspnet.Configuration["EncryptedWithSingleQuote"].ShouldBe("don't use quotes");
aspnet.Configuration["EncryptedWithDoubleQuote"].ShouldBe("double quote is \"");
aspnet.Configuration["EncryptedMalformedYaml"].ShouldBe("[oh dear");
aspnet.Configuration
.GetSection("ArrayWithSomeEncryptedValues")
.GetChildren()
.Select(x => x.Value)
.ToList()
.ShouldBeEquivalentTo(new List<string> { "value", "value", "other value", "[oh dear" });
var person = new Person();
aspnet.Configuration
.GetSection("PocoWithEncryptedValues")
.Bind(person);
person.Username.ShouldBeEquivalentTo("some-user");
person.Password.ShouldBeEquivalentTo("value");
}
}
}