diff --git a/src/SecTester.Runner/SecRunner.cs b/src/SecTester.Runner/SecRunner.cs index e6b6fd4..958ca6a 100644 --- a/src/SecTester.Runner/SecRunner.cs +++ b/src/SecTester.Runner/SecRunner.cs @@ -45,8 +45,13 @@ public async ValueTask DisposeAsync() GC.SuppressFinalize(this); } - public static SecRunner Create(Configuration configuration) + public static async Task Create(Configuration configuration) { + if (configuration.Credentials is null) + { + await configuration.LoadCredentials().ConfigureAwait(false); + } + var collection = new ServiceCollection() .AddSecTesterConfig(configuration) .AddSecTesterBus() diff --git a/test/SecTester.Runner.Tests/SecRunnerTests.cs b/test/SecTester.Runner.Tests/SecRunnerTests.cs index 4ce364c..0b6178d 100644 --- a/test/SecTester.Runner.Tests/SecRunnerTests.cs +++ b/test/SecTester.Runner.Tests/SecRunnerTests.cs @@ -18,6 +18,8 @@ public class SecRunnerTests private readonly IRepeaterFactory _repeaterFactory = Substitute.For(); private readonly IRepeaters _repeatersManager = Substitute.For(); private readonly IScanFactory _scanFactory = Substitute.For(); + private readonly ICredentialProvider _credentialProvider = Substitute.For(); + private readonly SecRunner _sut; public SecRunnerTests() @@ -31,12 +33,43 @@ public SecRunnerTests() public async Task Create_CreatesCompositeRoot() { // act - await using var secRunner = SecRunner.Create(_configuration); + await using var secRunner = await SecRunner.Create(_configuration); // assert secRunner.Should().BeOfType(); } + [Fact] + public async Task Create_AbleToLoadCredentials_CreatesCompositeRoot() + { + // arrange + var configuration = new Configuration(Hostname, + credentialProviders: new List { _credentialProvider }); + + _credentialProvider.Get().Returns(new Credentials(Token)); + + // act + await using var secRunner = await SecRunner.Create(configuration); + + // assert + secRunner.Should().BeOfType(); + await _credentialProvider.Received(1).Get(); + } + + [Fact] + public async Task Create_CouldNotLoadCredentials_ThrowsError() + { + // arrange + var configuration = new Configuration(Hostname, + credentialProviders: new List { _credentialProvider }); + + // act + var act = () => SecRunner.Create(configuration); + + // assert + await act.Should().ThrowAsync("Could not load credentials from any providers"); + } + [Fact] public async Task Init_StartsRepeater() {