-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): implement
EnvCredentialProvider
to obtain credentials f…
- Loading branch information
Showing
7 changed files
with
186 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/SecTester.Core/CredentialProviders/EnvCredentialProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace SecTester.Core.CredentialProviders; | ||
|
||
public class EnvCredentialProvider : CredentialProvider | ||
{ | ||
public const string BrightToken = "BRIGHT_TOKEN"; | ||
|
||
public Task<Credentials?> Get() | ||
{ | ||
string token = Environment.GetEnvironmentVariable(BrightToken); | ||
|
||
return Task.FromResult(!string.IsNullOrWhiteSpace(token) ? new Credentials(token) : null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
test/SecTester.Core.Tests/CredentialProviders/EnvCredentialProviderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using SecTester.Core.CredentialProviders; | ||
|
||
namespace SecTester.Core.Tests.CredentialProviders; | ||
|
||
public class EnvCredentialProviderTests | ||
{ | ||
[Fact] | ||
public async Task Get_EnvVariableIsNotProvided_ReturnNull() | ||
{ | ||
// arrange | ||
var envCredentialProvider = new EnvCredentialProvider(); | ||
|
||
// act | ||
var result = await envCredentialProvider.Get(); | ||
|
||
// assert | ||
result.Should().BeNull(); | ||
} | ||
|
||
[Fact] | ||
public async Task Get_GivenEnvVariable_ReturnCredentials() | ||
{ | ||
var oldValue = Environment.GetEnvironmentVariable(EnvCredentialProvider.BrightToken); | ||
|
||
try | ||
{ | ||
// arrange | ||
const string token = "0zmcwpe.nexr.0vlon8mp7lvxzjuvgjy88olrhadhiukk"; | ||
Environment.SetEnvironmentVariable(EnvCredentialProvider.BrightToken, token); | ||
var envCredentialProvider = new EnvCredentialProvider(); | ||
|
||
// act | ||
var result = await envCredentialProvider.Get(); | ||
|
||
// assert | ||
result.Should().BeEquivalentTo(new { Token = token }); | ||
} | ||
finally | ||
{ | ||
Environment.SetEnvironmentVariable(EnvCredentialProvider.BrightToken, oldValue); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters