-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'autorestv3' of https://github.com/Azure/autorest.python …
…into inherit_customization * 'autorestv3' of https://github.com/Azure/autorest.python: Add secrets test (#1174) bump testserver version (#1172)
- Loading branch information
Showing
71 changed files
with
2,812 additions
and
1 deletion.
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
53 changes: 53 additions & 0 deletions
53
test/vanilla/legacy/AcceptanceTests/asynctests/test_error_with_secrets.py
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,53 @@ | ||
# -------------------------------------------------------------------------- | ||
# | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# | ||
# The MIT License (MIT) | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the ""Software""), to | ||
# deal in the Software without restriction, including without limitation the | ||
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
# sell copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
# IN THE SOFTWARE. | ||
# | ||
# -------------------------------------------------------------------------- | ||
import pytest | ||
from errorwithsecrets.operations._errorwith_secrets_operations import build_create_secret_request | ||
from errorwithsecrets.aio import ErrorWithSecrets | ||
from azure.core.exceptions import HttpResponseError | ||
|
||
@pytest.fixture | ||
async def client(): | ||
async with ErrorWithSecrets() as client: | ||
yield client | ||
|
||
@pytest.mark.asyncio | ||
async def test_create_secret(client): | ||
request = build_create_secret_request( | ||
headers={"authorization": "SharedKey 1c88a67921784300a462b2cb61da2339"}, | ||
params={"key": "1c88a67921784300a462b2cb61da2339"}, | ||
json={ "key": "1c88a67921784300a462b2cb61da2339" }, | ||
) | ||
response = await client._send_request(request) | ||
response.raise_for_status() | ||
|
||
@pytest.mark.asyncio | ||
async def test_raise_error_with_secrets(client): | ||
with pytest.raises(HttpResponseError) as ex: | ||
await client.get_error_with_secrets() | ||
# The actual test shouldn't have the secrets in the str output | ||
# Until we figure out what to do for Python, just asserting | ||
# what the string currently is for now. | ||
assert "The user 'user@contoso.com' is unauthorized" in str(ex.value) |
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
52 changes: 52 additions & 0 deletions
52
test/vanilla/legacy/AcceptanceTests/test_error_with_secrets.py
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,52 @@ | ||
# -------------------------------------------------------------------------- | ||
# | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# | ||
# The MIT License (MIT) | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the ""Software""), to | ||
# deal in the Software without restriction, including without limitation the | ||
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
# sell copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
# IN THE SOFTWARE. | ||
# | ||
# -------------------------------------------------------------------------- | ||
import pytest | ||
from errorwithsecrets import ErrorWithSecrets | ||
from errorwithsecrets.operations._errorwith_secrets_operations import build_create_secret_request | ||
from azure.core.exceptions import HttpResponseError | ||
|
||
@pytest.fixture | ||
def client(): | ||
with ErrorWithSecrets() as client: | ||
yield client | ||
|
||
|
||
def test_create_secret(client): | ||
request = build_create_secret_request( | ||
headers={"authorization": "SharedKey 1c88a67921784300a462b2cb61da2339"}, | ||
params={"key": "1c88a67921784300a462b2cb61da2339"}, | ||
json={ "key": "1c88a67921784300a462b2cb61da2339" }, | ||
) | ||
response = client._send_request(request) | ||
response.raise_for_status() | ||
|
||
def test_raise_error_with_secrets(client): | ||
with pytest.raises(HttpResponseError) as ex: | ||
client.get_error_with_secrets() | ||
# The actual test shouldn't have the secrets in the str output | ||
# Until we figure out what to do for Python, just asserting | ||
# what the string currently is for now. | ||
assert "The user 'user@contoso.com' is unauthorized" in str(ex.value) |
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
26 changes: 26 additions & 0 deletions
26
test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/__init__.py
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,26 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# Code generated by Microsoft (R) AutoRest Code Generator. | ||
# Changes may cause incorrect behavior and will be lost if the code is regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
from ._errorwith_secrets import ErrorWithSecrets | ||
from ._version import VERSION | ||
|
||
__version__ = VERSION | ||
|
||
try: | ||
from ._patch import __all__ as _patch_all | ||
from ._patch import * # pylint: disable=unused-wildcard-import | ||
except ImportError: | ||
_patch_all = [] | ||
from ._patch import patch_sdk as _patch_sdk | ||
|
||
__all__ = ["ErrorWithSecrets"] | ||
__all__.extend(_patch_all) | ||
|
||
# `._patch.py` is used for handwritten extensions to the generated code | ||
# Example: https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md | ||
_patch_sdk() |
49 changes: 49 additions & 0 deletions
49
...nilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/_configuration.py
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 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# Code generated by Microsoft (R) AutoRest Code Generator. | ||
# Changes may cause incorrect behavior and will be lost if the code is regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from azure.core.configuration import Configuration | ||
from azure.core.pipeline import policies | ||
|
||
from ._version import VERSION | ||
|
||
if TYPE_CHECKING: | ||
# pylint: disable=unused-import,ungrouped-imports | ||
from typing import Any | ||
|
||
|
||
class ErrorWithSecretsConfiguration(Configuration): # pylint: disable=too-many-instance-attributes | ||
"""Configuration for ErrorWithSecrets. | ||
Note that all parameters used to create this instance are saved as instance | ||
attributes. | ||
""" | ||
|
||
def __init__( | ||
self, **kwargs # type: Any | ||
): | ||
# type: (...) -> None | ||
super(ErrorWithSecretsConfiguration, self).__init__(**kwargs) | ||
|
||
kwargs.setdefault("sdk_moniker", "errorwithsecrets/{}".format(VERSION)) | ||
self._configure(**kwargs) | ||
|
||
def _configure( | ||
self, **kwargs # type: Any | ||
): | ||
# type: (...) -> None | ||
self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs) | ||
self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs) | ||
self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs) | ||
self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs) | ||
self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs) | ||
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs) | ||
self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs) | ||
self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs) | ||
self.authentication_policy = kwargs.get("authentication_policy") |
86 changes: 86 additions & 0 deletions
86
...a/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/_errorwith_secrets.py
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,86 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# Code generated by Microsoft (R) AutoRest Code Generator. | ||
# Changes may cause incorrect behavior and will be lost if the code is regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
from copy import deepcopy | ||
from typing import TYPE_CHECKING | ||
|
||
from msrest import Deserializer, Serializer | ||
|
||
from azure.core import PipelineClient | ||
|
||
from . import models | ||
from ._configuration import ErrorWithSecretsConfiguration | ||
from .operations import ErrorWithSecretsOperationsMixin | ||
|
||
if TYPE_CHECKING: | ||
# pylint: disable=unused-import,ungrouped-imports | ||
from typing import Any | ||
|
||
from azure.core.rest import HttpRequest, HttpResponse | ||
|
||
|
||
class ErrorWithSecrets(ErrorWithSecretsOperationsMixin): | ||
"""Tests whether loggers/tracers redact secrets and PII within error responses. | ||
:param base_url: Service URL. Default value is "http://localhost:3000". | ||
:type base_url: str | ||
""" | ||
|
||
def __init__( | ||
self, | ||
base_url="http://localhost:3000", # type: str | ||
**kwargs # type: Any | ||
): | ||
# type: (...) -> None | ||
self._config = ErrorWithSecretsConfiguration(**kwargs) | ||
self._client = PipelineClient(base_url=base_url, config=self._config, **kwargs) | ||
|
||
client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)} | ||
self._serialize = Serializer(client_models) | ||
self._deserialize = Deserializer(client_models) | ||
self._serialize.client_side_validation = False | ||
|
||
def _send_request( | ||
self, | ||
request, # type: HttpRequest | ||
**kwargs # type: Any | ||
): | ||
# type: (...) -> HttpResponse | ||
"""Runs the network request through the client's chained policies. | ||
>>> from azure.core.rest import HttpRequest | ||
>>> request = HttpRequest("GET", "https://www.example.org/") | ||
<HttpRequest [GET], url: 'https://www.example.org/'> | ||
>>> response = client._send_request(request) | ||
<HttpResponse: 200 OK> | ||
For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart | ||
:param request: The network request you want to make. Required. | ||
:type request: ~azure.core.rest.HttpRequest | ||
:keyword bool stream: Whether the response payload will be streamed. Defaults to False. | ||
:return: The response of your network call. Does not do error handling on your response. | ||
:rtype: ~azure.core.rest.HttpResponse | ||
""" | ||
|
||
request_copy = deepcopy(request) | ||
request_copy.url = self._client.format_url(request_copy.url) | ||
return self._client.send_request(request_copy, **kwargs) | ||
|
||
def close(self): | ||
# type: () -> None | ||
self._client.close() | ||
|
||
def __enter__(self): | ||
# type: () -> ErrorWithSecrets | ||
self._client.__enter__() | ||
return self | ||
|
||
def __exit__(self, *exc_details): | ||
# type: (Any) -> None | ||
self._client.__exit__(*exc_details) |
31 changes: 31 additions & 0 deletions
31
test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/_patch.py
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,31 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# | ||
# The MIT License (MIT) | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the ""Software""), to | ||
# deal in the Software without restriction, including without limitation the | ||
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
# sell copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
# IN THE SOFTWARE. | ||
# | ||
# -------------------------------------------------------------------------- | ||
|
||
# This file is used for handwritten extensions to the generated code. Example: | ||
# https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md | ||
def patch_sdk(): | ||
pass |
16 changes: 16 additions & 0 deletions
16
test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/_vendor.py
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 @@ | ||
# -------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# Code generated by Microsoft (R) AutoRest Code Generator. | ||
# Changes may cause incorrect behavior and will be lost if the code is regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
from azure.core.pipeline.transport import HttpRequest | ||
|
||
|
||
def _convert_request(request, files=None): | ||
data = request.content if not files else None | ||
request = HttpRequest(method=request.method, url=request.url, headers=request.headers, data=data) | ||
if files: | ||
request.set_formdata_body(files) | ||
return request |
9 changes: 9 additions & 0 deletions
9
test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/_version.py
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,9 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# Code generated by Microsoft (R) AutoRest Code Generator. | ||
# Changes may cause incorrect behavior and will be lost if the code is regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
VERSION = "0.1.0" |
23 changes: 23 additions & 0 deletions
23
...vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/aio/__init__.py
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,23 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# Code generated by Microsoft (R) AutoRest Code Generator. | ||
# Changes may cause incorrect behavior and will be lost if the code is regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
from ._errorwith_secrets import ErrorWithSecrets | ||
|
||
try: | ||
from ._patch import __all__ as _patch_all | ||
from ._patch import * # pylint: disable=unused-wildcard-import | ||
except ImportError: | ||
_patch_all = [] | ||
from ._patch import patch_sdk as _patch_sdk | ||
|
||
__all__ = ["ErrorWithSecrets"] | ||
__all__.extend(_patch_all) | ||
|
||
# `._patch.py` is used for handwritten extensions to the generated code | ||
# Example: https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md | ||
_patch_sdk() |
Oops, something went wrong.