-
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.
Upgrade keyvault secrets library (Azure-Samples#479)
* Upgrade keyvault secrets library * Add comment in test * typo! * Mock SecretClient (Azure-Samples#483) Co-authored-by: Chinedum Echeta <60179183+cecheta@users.noreply.github.com> --------- Co-authored-by: Chinedum Echeta <60179183+cecheta@users.noreply.github.com>
- Loading branch information
1 parent
4b8c2e3
commit 2ddba25
Showing
7 changed files
with
135 additions
and
65 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from unittest.mock import MagicMock, patch | ||
from pytest import MonkeyPatch | ||
from backend.batch.utilities.helpers.EnvHelper import SecretHelper | ||
|
||
|
||
def test_get_secret_returns_value_from_environment_variables(monkeypatch: MonkeyPatch): | ||
# given | ||
secret_name = "MY_SECRET" | ||
expected_value = "my_secret_value" | ||
monkeypatch.setenv(secret_name, expected_value) | ||
secret_helper = SecretHelper() | ||
|
||
# when | ||
actual_value = secret_helper.get_secret(secret_name) | ||
|
||
# then | ||
assert actual_value == expected_value | ||
|
||
|
||
@patch("backend.batch.utilities.helpers.EnvHelper.SecretClient") | ||
def test_get_secret_returns_value_from_secret_client_when_use_key_vault_is_true( | ||
secret_client: MagicMock, monkeypatch: MonkeyPatch | ||
): | ||
# given | ||
secret_name = "MY_SECRET" | ||
expected_value = "my_secret_value" | ||
monkeypatch.setenv("USE_KEY_VAULT", "true") | ||
secret_client.return_value.get_secret.return_value.value = expected_value | ||
secret_helper = SecretHelper() | ||
|
||
# when | ||
actual_value = secret_helper.get_secret(secret_name) | ||
|
||
# then | ||
assert actual_value == expected_value | ||
|
||
|
||
def test_get_secret_returns_empty_string_when_secret_name_is_empty(): | ||
# given | ||
secret_name = "" | ||
expected_value = "" | ||
secret_helper = SecretHelper() | ||
|
||
# when | ||
actual_value = secret_helper.get_secret(secret_name) | ||
|
||
# then | ||
assert actual_value == expected_value |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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