-
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.
- Loading branch information
1 parent
26ee0fd
commit 8b9a03a
Showing
5 changed files
with
135 additions
and
90 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
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,49 @@ | ||
package cloudencrypt | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_AzureEncryptor(t *testing.T) { | ||
t.Parallel() | ||
|
||
ctx := context.Background() | ||
|
||
err := os.Setenv("AZURE_TENANT_ID", os.Getenv("TEST_AZURE_TENANT_ID")) | ||
require.NoError(t, err) | ||
|
||
err = os.Setenv("AZURE_CLIENT_ID", os.Getenv("TEST_AZURE_CLIENT_ID")) | ||
require.NoError(t, err) | ||
|
||
err = os.Setenv("AZURE_CLIENT_SECRET", os.Getenv("TEST_AZURE_CLIENT_SECRET")) | ||
require.NoError(t, err) | ||
|
||
vaultURL := os.Getenv("TEST_AZURE_KEY_VAULT_URL") | ||
if vaultURL == "" { | ||
require.Fail(t, "TEST_AZURE_KEY_VAULT_URL is empty") | ||
} | ||
|
||
encryptor, err := NewAzureEncryptor(ctx, vaultURL, "jt-") | ||
require.NoError(t, err) | ||
|
||
meta := MetadataKV{ | ||
Key: "metakey", | ||
Value: "metavalue", | ||
} | ||
|
||
encrypted, err := encryptor.Encrypt(ctx, []byte("Lorem ipsum"), meta) | ||
require.NoError(t, err) | ||
|
||
_, err = encryptor.Decrypt(ctx, encrypted) | ||
assert.ErrorContains(t, err, "decryption failed") | ||
|
||
decrypted, err := encryptor.Decrypt(ctx, encrypted, meta) | ||
assert.NoError(t, err) | ||
|
||
assert.Equal(t, []byte("Lorem ipsum"), decrypted) | ||
} |
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
Oops, something went wrong.