You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
137 lines
3.9 KiB
137 lines
3.9 KiB
2 years ago
|
using System.IO.Abstractions;
|
||
1 year ago
|
using Recyclarr.Common;
|
||
1 year ago
|
using Recyclarr.Config;
|
||
1 year ago
|
using Recyclarr.Config.Parsing;
|
||
2 years ago
|
|
||
1 year ago
|
namespace Recyclarr.IntegrationTests;
|
||
2 years ago
|
|
||
2 years ago
|
[TestFixture]
|
||
1 year ago
|
public class ConfigurationLoaderSecretsTest : IntegrationTestFixture
|
||
2 years ago
|
{
|
||
|
[Test]
|
||
|
public void Test_secret_loading()
|
||
|
{
|
||
|
var configLoader = Resolve<ConfigurationLoader>();
|
||
|
|
||
1 year ago
|
const string testYml =
|
||
|
"""
|
||
|
sonarr:
|
||
|
instance1:
|
||
|
api_key: !secret api_key
|
||
|
base_url: !secret 123GARBAGE_
|
||
|
release_profiles:
|
||
|
- trash_ids:
|
||
|
- !secret secret_rp
|
||
|
""";
|
||
|
|
||
|
const string secretsYml =
|
||
|
"""
|
||
|
api_key: 95283e6b156c42f3af8a9b16173f876b
|
||
|
123GARBAGE_: 'https://radarr:7878'
|
||
|
secret_rp: 1234567
|
||
|
""";
|
||
2 years ago
|
|
||
2 years ago
|
Fs.AddFile(Paths.AppDataDirectory.File("secrets.yml").FullName, new MockFileData(secretsYml));
|
||
2 years ago
|
var expected = new[]
|
||
|
{
|
||
|
new
|
||
|
{
|
||
|
InstanceName = "instance1",
|
||
|
ApiKey = "95283e6b156c42f3af8a9b16173f876b",
|
||
|
BaseUrl = new Uri("https://radarr:7878"),
|
||
|
ReleaseProfiles = new[]
|
||
|
{
|
||
|
new
|
||
|
{
|
||
|
TrashIds = new[] {"1234567"}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
1 year ago
|
configLoader.Load(() => new StringReader(testYml))
|
||
|
.GetConfigsOfType(SupportedServices.Sonarr)
|
||
|
.Should().BeEquivalentTo(expected);
|
||
2 years ago
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void Throw_when_referencing_invalid_secret()
|
||
|
{
|
||
|
var configLoader = Resolve<ConfigurationLoader>();
|
||
|
|
||
1 year ago
|
const string testYml =
|
||
|
"""
|
||
|
sonarr:
|
||
|
instance2:
|
||
|
api_key: !secret api_key
|
||
|
base_url: fake_url
|
||
|
""";
|
||
2 years ago
|
|
||
|
const string secretsYml = "no_api_key: 95283e6b156c42f3af8a9b16173f876b";
|
||
|
|
||
2 years ago
|
Fs.AddFile(Paths.AppDataDirectory.File("recyclarr.yml").FullName, new MockFileData(secretsYml));
|
||
2 years ago
|
|
||
1 year ago
|
configLoader.Load(() => new StringReader(testYml))
|
||
|
.GetConfigsOfType(SupportedServices.Sonarr)
|
||
|
.Should().BeEmpty();
|
||
2 years ago
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void Throw_when_referencing_secret_without_secrets_file()
|
||
|
{
|
||
|
var configLoader = Resolve<ConfigurationLoader>();
|
||
|
|
||
1 year ago
|
const string testYml =
|
||
|
"""
|
||
|
sonarr:
|
||
|
instance3:
|
||
|
api_key: !secret api_key
|
||
|
base_url: fake_url
|
||
|
""";
|
||
2 years ago
|
|
||
1 year ago
|
configLoader.Load(() => new StringReader(testYml))
|
||
|
.GetConfigsOfType(SupportedServices.Sonarr)
|
||
|
.Should().BeEmpty();
|
||
2 years ago
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void No_config_loaded_when_secret_value_is_not_scalar()
|
||
|
{
|
||
|
var configLoader = Resolve<ConfigurationLoader>();
|
||
|
|
||
1 year ago
|
const string testYml =
|
||
|
"""
|
||
|
sonarr:
|
||
|
instance4:
|
||
|
api_key: !secret { property: value }
|
||
|
base_url: fake_url
|
||
|
""";
|
||
2 years ago
|
|
||
1 year ago
|
configLoader.Load(() => new StringReader(testYml))
|
||
|
.GetConfigsOfType(SupportedServices.Sonarr)
|
||
|
.Should().BeEmpty();
|
||
2 years ago
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void No_config_loaded_when_resolved_value_is_not_correct()
|
||
|
{
|
||
|
var configLoader = Resolve<ConfigurationLoader>();
|
||
|
|
||
1 year ago
|
const string testYml =
|
||
|
"""
|
||
|
sonarr:
|
||
|
instance5:
|
||
|
api_key: fake_key
|
||
|
base_url: fake_url
|
||
|
release_profiles: !secret bogus_profile
|
||
|
""";
|
||
2 years ago
|
|
||
|
const string secretsYml = @"bogus_profile: 95283e6b156c42f3af8a9b16173f876b";
|
||
|
|
||
2 years ago
|
Fs.AddFile(Paths.AppDataDirectory.File("recyclarr.yml").FullName, new MockFileData(secretsYml));
|
||
1 year ago
|
configLoader.Load(() => new StringReader(testYml))
|
||
|
.GetConfigsOfType(SupportedServices.Sonarr)
|
||
|
.Should().BeEmpty();
|
||
2 years ago
|
}
|
||
|
}
|