generated from devantler-tech/dotnet-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add EditAsync method to ISecretManager and implement in SOPSLoc…
…alAgeSecretManager (#164) Signed-off-by: Nikolai Emil Damm <neq@energinet.dk>
- Loading branch information
Showing
3 changed files
with
55 additions
and
0 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
40 changes: 40 additions & 0 deletions
40
Devantler.SecretManager.SOPS.LocalAge.Tests/SOPSLocalAgeSecretManagerTests/EditAsyncTests.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,40 @@ | ||
namespace Devantler.SecretManager.SOPS.LocalAge.Tests.SOPSLocalAgeSecretManagerTests; | ||
|
||
/// <summary> | ||
/// Tests for <see cref="SOPSLocalAgeSecretManager.EncryptAsync(string, string, CancellationToken)"/>. | ||
/// </summary> | ||
[Collection("SOPSLocalAgeSecretManager")] | ||
public class EditAsyncTests | ||
{ | ||
readonly SOPSLocalAgeSecretManager _secretManager = new(); | ||
|
||
/// <summary> | ||
/// Tests that <see cref="SOPSLocalAgeSecretManager.EncryptAsync(string, string, CancellationToken)"/> encrypts a file with a public key. | ||
/// </summary> | ||
/// <returns></returns> | ||
[Fact] | ||
public async Task EncryptAsync_GivenPathAndPublicKey_ReturnsEncryptedString() | ||
{ | ||
// Arrange | ||
var key = await _secretManager.CreateKeyAsync(); | ||
string plainText = """ | ||
secret: | | ||
AGE-SECRET-KEY-1VZQ | ||
"""; | ||
string filePath = Path.GetTempPath() + "edit-async-test.yaml"; | ||
File.WriteAllText(filePath, plainText); | ||
|
||
// Act | ||
string encryptedText = await _secretManager.EncryptAsync(filePath, key.PublicKey); | ||
async Task task() => await _secretManager.EditAsync(filePath); | ||
|
||
// Assert | ||
Assert.NotEqual(plainText, encryptedText); | ||
var exception = await Record.ExceptionAsync(async () => await Task.WhenAny(task(), Task.Delay(5000))); | ||
Assert.Null(exception); | ||
|
||
// Cleanup | ||
_ = await _secretManager.DeleteKeyAsync(key); | ||
} | ||
} | ||
|
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