API key protection
This commit is contained in:
parent
cd72b7b9aa
commit
38bb7e40ef
7 changed files with 143 additions and 19 deletions
|
|
@ -18,6 +18,8 @@ namespace Isn.tests
|
|||
{
|
||||
private readonly HttpListener listener;
|
||||
private readonly Task listenerTask;
|
||||
private readonly string configDirectory;
|
||||
private readonly string originalConfigDirectory;
|
||||
|
||||
public LocalSourceFixture()
|
||||
{
|
||||
|
|
@ -64,6 +66,11 @@ namespace Isn.tests
|
|||
}
|
||||
});
|
||||
|
||||
configDirectory = Path.Combine(Path.GetTempPath(), $"isn-tests-{Guid.NewGuid():N}");
|
||||
Directory.CreateDirectory(configDirectory);
|
||||
originalConfigDirectory = Environment.GetEnvironmentVariable("ISN_CONFIG_DIR");
|
||||
Environment.SetEnvironmentVariable("ISN_CONFIG_DIR", configDirectory);
|
||||
|
||||
SourceUrl = prefix + "index.json";
|
||||
ConfigureIsnSettings(SourceUrl);
|
||||
Program.LoadConfig();
|
||||
|
|
@ -84,6 +91,12 @@ namespace Isn.tests
|
|||
{
|
||||
}
|
||||
}
|
||||
|
||||
Environment.SetEnvironmentVariable("ISN_CONFIG_DIR", originalConfigDirectory);
|
||||
if (Directory.Exists(configDirectory))
|
||||
{
|
||||
Directory.Delete(configDirectory, recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
private static int GetFreePort()
|
||||
|
|
@ -95,12 +108,8 @@ namespace Isn.tests
|
|||
return port;
|
||||
}
|
||||
|
||||
private static void ConfigureIsnSettings(string sourceUrl)
|
||||
private void ConfigureIsnSettings(string sourceUrl)
|
||||
{
|
||||
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
||||
var configDirectory = Path.Combine(home, ".isn");
|
||||
Directory.CreateDirectory(configDirectory);
|
||||
|
||||
var configPath = Path.Combine(configDirectory, "config.json");
|
||||
var settings = new Settings
|
||||
{
|
||||
|
|
@ -125,6 +134,44 @@ namespace Isn.tests
|
|||
this.fixture = fixture;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SupportsIsolatedConfigDirectoryOverride()
|
||||
{
|
||||
var tempDir = Path.Combine(Path.GetTempPath(), $"isn-test-{Guid.NewGuid():N}");
|
||||
Directory.CreateDirectory(tempDir);
|
||||
var originalConfigDir = Environment.GetEnvironmentVariable("ISN_CONFIG_DIR");
|
||||
var configFile = Path.Combine(tempDir, "config.json");
|
||||
var expectedSource = "https://example.test/index.json";
|
||||
var settings = new Settings
|
||||
{
|
||||
DataProtectionTitle = "isn",
|
||||
Sources = new Dictionary<string, SourceSettings>
|
||||
{
|
||||
[expectedSource] = new SourceSettings { Alias = "override" }
|
||||
},
|
||||
DefaultSourceKey = expectedSource
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
Environment.SetEnvironmentVariable("ISN_CONFIG_DIR", tempDir);
|
||||
File.WriteAllText(configFile, JsonConvert.SerializeObject(settings, Formatting.Indented));
|
||||
|
||||
Program.LoadConfig();
|
||||
|
||||
Assert.Equal(expectedSource, Program.Settings.DefaultSourceKey);
|
||||
Assert.True(Program.Settings.Sources.ContainsKey(expectedSource));
|
||||
}
|
||||
finally
|
||||
{
|
||||
Environment.SetEnvironmentVariable("ISN_CONFIG_DIR", originalConfigDir);
|
||||
if (Directory.Exists(tempDir))
|
||||
{
|
||||
Directory.Delete(tempDir, recursive: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HaveADefaultDataProtector()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue