Establish fake_credentials.py file for test credentials (#23001)
This commit is contained in:
Родитель
c6801dc72f
Коммит
6e1f7c02af
|
@ -15,8 +15,8 @@ except ImportError:
|
|||
import mock
|
||||
|
||||
import logging
|
||||
from devtools_testutils import (
|
||||
PowerShellPreparer, ACCOUNT_FAKE_KEY)
|
||||
from devtools_testutils import PowerShellPreparer
|
||||
from devtools_testutils.fake_credentials import STORAGE_ACCOUNT_FAKE_KEY
|
||||
|
||||
try:
|
||||
from cStringIO import StringIO # Python 2
|
||||
|
@ -51,7 +51,7 @@ os.environ['STORAGE_CLIENT_SECRET'] = os.environ.get('STORAGE_CLIENT_SECRET', No
|
|||
ChangeFeedPreparer = functools.partial(
|
||||
PowerShellPreparer, "storage",
|
||||
storage_account_name="storagename",
|
||||
storage_account_key=ACCOUNT_FAKE_KEY,
|
||||
storage_account_key=STORAGE_ACCOUNT_FAKE_KEY,
|
||||
)
|
||||
|
||||
def not_for_emulator(test):
|
||||
|
|
|
@ -9,8 +9,8 @@ from __future__ import division
|
|||
import functools
|
||||
import os
|
||||
import logging
|
||||
from devtools_testutils import (
|
||||
PowerShellPreparer, ACCOUNT_FAKE_KEY)
|
||||
from devtools_testutils import PowerShellPreparer
|
||||
from devtools_testutils.fake_credentials import STORAGE_ACCOUNT_FAKE_KEY
|
||||
|
||||
try:
|
||||
from cStringIO import StringIO # Python 2
|
||||
|
@ -51,15 +51,15 @@ os.environ['STORAGE_CLIENT_SECRET'] = os.environ.get('STORAGE_CLIENT_SECRET', No
|
|||
BlobPreparer = functools.partial(
|
||||
PowerShellPreparer, "storage",
|
||||
storage_account_name="storagename",
|
||||
storage_account_key=ACCOUNT_FAKE_KEY,
|
||||
storage_account_key=STORAGE_ACCOUNT_FAKE_KEY,
|
||||
secondary_storage_account_name="pyrmtstoragestorname",
|
||||
secondary_storage_account_key=ACCOUNT_FAKE_KEY,
|
||||
secondary_storage_account_key=STORAGE_ACCOUNT_FAKE_KEY,
|
||||
blob_storage_account_name="storagenamestorname",
|
||||
blob_storage_account_key=ACCOUNT_FAKE_KEY,
|
||||
blob_storage_account_key=STORAGE_ACCOUNT_FAKE_KEY,
|
||||
versioned_storage_account_name="storagenamestorname",
|
||||
versioned_storage_account_key=ACCOUNT_FAKE_KEY,
|
||||
versioned_storage_account_key=STORAGE_ACCOUNT_FAKE_KEY,
|
||||
premium_storage_account_name='pyacrstoragestorname',
|
||||
premium_storage_account_key=ACCOUNT_FAKE_KEY,
|
||||
premium_storage_account_key=STORAGE_ACCOUNT_FAKE_KEY,
|
||||
storage_resource_group_name="rgname",
|
||||
|
||||
)
|
||||
|
|
|
@ -9,7 +9,8 @@ from __future__ import division
|
|||
import functools
|
||||
import os.path
|
||||
|
||||
from devtools_testutils import PowerShellPreparer, ACCOUNT_FAKE_KEY
|
||||
from devtools_testutils import PowerShellPreparer
|
||||
from devtools_testutils.fake_credentials import STORAGE_ACCOUNT_FAKE_KEY
|
||||
|
||||
try:
|
||||
from cStringIO import StringIO # Python 2
|
||||
|
@ -41,5 +42,5 @@ os.environ['STORAGE_CLIENT_SECRET'] = os.environ.get('STORAGE_CLIENT_SECRET', No
|
|||
DataLakePreparer = functools.partial(
|
||||
PowerShellPreparer, "storage",
|
||||
datalake_storage_account_name="storagename",
|
||||
datalake_storage_account_key=ACCOUNT_FAKE_KEY
|
||||
datalake_storage_account_key=STORAGE_ACCOUNT_FAKE_KEY
|
||||
)
|
||||
|
|
|
@ -15,8 +15,8 @@ except ImportError:
|
|||
import mock
|
||||
|
||||
import logging
|
||||
from devtools_testutils import (
|
||||
PowerShellPreparer, ACCOUNT_FAKE_KEY)
|
||||
from devtools_testutils import PowerShellPreparer
|
||||
from devtools_testutils.fake_credentials import STORAGE_ACCOUNT_FAKE_KEY
|
||||
try:
|
||||
from cStringIO import StringIO # Python 2
|
||||
except ImportError:
|
||||
|
@ -57,11 +57,11 @@ os.environ['STORAGE_CLIENT_SECRET'] = os.environ.get('STORAGE_CLIENT_SECRET', No
|
|||
FileSharePreparer = functools.partial(
|
||||
PowerShellPreparer, "storage",
|
||||
storage_account_name="storagename",
|
||||
storage_account_key=ACCOUNT_FAKE_KEY,
|
||||
storage_account_key=STORAGE_ACCOUNT_FAKE_KEY,
|
||||
premium_storage_file_account_name="pyacrstoragestorname",
|
||||
premium_storage_file_account_key=ACCOUNT_FAKE_KEY,
|
||||
premium_storage_file_account_key=STORAGE_ACCOUNT_FAKE_KEY,
|
||||
secondary_storage_account_name="pyrmtstoragestorname",
|
||||
secondary_storage_account_key=ACCOUNT_FAKE_KEY,
|
||||
secondary_storage_account_key=STORAGE_ACCOUNT_FAKE_KEY,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -14,8 +14,8 @@ try:
|
|||
except ImportError:
|
||||
import mock
|
||||
|
||||
from devtools_testutils import (
|
||||
PowerShellPreparer, ACCOUNT_FAKE_KEY)
|
||||
from devtools_testutils import PowerShellPreparer
|
||||
from devtools_testutils.fake_credentials import STORAGE_ACCOUNT_FAKE_KEY
|
||||
|
||||
try:
|
||||
from cStringIO import StringIO # Python 2
|
||||
|
@ -45,7 +45,7 @@ os.environ['STORAGE_CLIENT_SECRET'] = os.environ.get('STORAGE_CLIENT_SECRET', No
|
|||
QueuePreparer = functools.partial(
|
||||
PowerShellPreparer, "storage",
|
||||
storage_account_name="storagename",
|
||||
storage_account_key=ACCOUNT_FAKE_KEY,
|
||||
storage_account_key=STORAGE_ACCOUNT_FAKE_KEY,
|
||||
)
|
||||
|
||||
def not_for_emulator(test):
|
||||
|
|
|
@ -17,7 +17,15 @@
|
|||
* [`EnvironmentVariableLoader`][env_loader]: Abstract preparer for delivering secrets from environment variables to individual tests
|
||||
* [`RetryCounter`][retry_counter]: Object for counting retries on a request.
|
||||
* [`ResponseCallback`][response_callback]: Object for mocking response callbacks.
|
||||
* [`FakeCredential`][fake_credential]: Fake credential used for authenticating in playback mode.
|
||||
* [`FakeCredential`][fake_credentials]: Fake credential used for authenticating in playback mode.
|
||||
* [`AsyncFakeCredential`][fake_credentials_async]: Fake async credential used for authenticating in playback mode.
|
||||
|
||||
## Fake test credentials
|
||||
|
||||
`devtools_testutils` also provides a central location for storing and fetching fake credentials for use in tests:
|
||||
[`fake_credentials.py`][fake_credentials]. Using credentials from this file helps us keep the repository free from
|
||||
credential leaks and false warnings from the [Credential Scanner (CredScan)][credscan] tool. For more information about
|
||||
the `azure-sdk-for-python`'s use of CredScan, please refer to the [CredScan monitoring guide][credscan_guide].
|
||||
|
||||
|
||||
<!-- LINKS -->
|
||||
|
@ -37,4 +45,7 @@
|
|||
[env_loader]: https://github.com/Azure/azure-sdk-for-python/blob/main/tools/azure-sdk-tools/devtools_testutils/envvariable_loader.py#L15
|
||||
[retry_counter]: https://github.com/Azure/azure-sdk-for-python/blob/ab7e7f1a7b2a6d7255abdc77a40e2d6a86c9de0a/tools/azure-sdk-tools/devtools_testutils/helpers.py#L6
|
||||
[response_callback]: https://github.com/Azure/azure-sdk-for-python/blob/ab7e7f1a7b2a6d7255abdc77a40e2d6a86c9de0a/tools/azure-sdk-tools/devtools_testutils/helpers.py#L14
|
||||
[fake_credential]: https://github.com/Azure/azure-sdk-for-python/blob/65ffc49fbdd0f4f83e68eb5c8e0c6d293f0569cd/tools/azure-sdk-tools/devtools_testutils/fake_credential.py
|
||||
[fake_credentials]: https://github.com/Azure/azure-sdk-for-python/blob/main/tools/azure-sdk-tools/devtools_testutils/fake_credentials.py
|
||||
[fake_credentials_async]: https://github.com/Azure/azure-sdk-for-python/blob/main/tools/azure-sdk-tools/devtools_testutils/fake_credentials_async.py
|
||||
[credscan]: https://aka.ms/credscan
|
||||
[credscan_guide]: https://github.com/Azure/azure-sdk-for-python/blob/18611efee7ecf4e591d59b61ba3762d6bdd86304/doc/dev/credscan_process.md
|
||||
|
|
|
@ -33,7 +33,7 @@ from .sanitizers import (
|
|||
set_bodiless_matcher,
|
||||
)
|
||||
from .helpers import ResponseCallback, RetryCounter
|
||||
from .fake_credential import FakeTokenCredential, ACCOUNT_FAKE_KEY
|
||||
from .fake_credentials import FakeTokenCredential
|
||||
|
||||
__all__ = [
|
||||
"add_body_key_sanitizer",
|
||||
|
@ -71,5 +71,4 @@ __all__ = [
|
|||
"ResponseCallback",
|
||||
"RetryCounter",
|
||||
"FakeTokenCredential",
|
||||
"ACCOUNT_FAKE_KEY"
|
||||
]
|
||||
|
|
|
@ -22,7 +22,7 @@ from .sanitizers import add_general_regex_sanitizer
|
|||
|
||||
try:
|
||||
# Try to import the AsyncFakeCredential, if we cannot assume it is Python 2
|
||||
from .fake_async_credential import AsyncFakeCredential
|
||||
from .fake_credentials_async import AsyncFakeCredential
|
||||
except SyntaxError:
|
||||
pass
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ from . import mgmt_settings_fake as fake_settings
|
|||
|
||||
try:
|
||||
# Try to import the AsyncFakeCredential, if we cannot assume it is Python 2
|
||||
from .fake_async_credential import AsyncFakeCredential
|
||||
from .fake_credentials_async import AsyncFakeCredential
|
||||
except SyntaxError:
|
||||
pass
|
||||
|
||||
|
@ -94,7 +94,8 @@ def get_region_override(default="westus"):
|
|||
|
||||
|
||||
def _is_autorest_v3(client_class):
|
||||
"""IS this client a autorestv3/track2 one?.
|
||||
"""Is this client a autorest v3/track2 one?
|
||||
|
||||
Could be refined later if necessary.
|
||||
"""
|
||||
args = get_arg_spec(client_class.__init__).args
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from azure.core.credentials import AccessToken
|
||||
|
||||
ACCOUNT_FAKE_KEY = "NzhL3hKZbJBuJ2484dPTR+xF30kYaWSSCbs2BzLgVVI1woqeST/1IgqaLm6QAOTxtGvxctSNbIR/1hW8yH+bJg=="
|
||||
STORAGE_ACCOUNT_FAKE_KEY = "NzhL3hKZbJBuJ2484dPTR+xF30kYaWSSCbs2BzLgVVI1woqeST/1IgqaLm6QAOTxtGvxctSNbIR/1hW8yH+bJg=="
|
||||
|
||||
|
||||
class FakeTokenCredential(object):
|
|
@ -2,7 +2,7 @@ import asyncio
|
|||
import functools
|
||||
|
||||
from .. import StorageTestCase
|
||||
from ...fake_async_credential import AsyncFakeCredential
|
||||
from ...fake_credentials_async import AsyncFakeCredential
|
||||
|
||||
from azure_devtools.scenario_tests.patches import mock_in_unit_test
|
||||
from azure_devtools.scenario_tests.utilities import trim_kwargs_from_test_function
|
||||
|
|
Загрузка…
Ссылка в новой задаче