Skip to content

seg fault on debian #11887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ def _get_refresh_token(service_name, account_name):
if sys.version_info[0] < 3:
raise NotImplementedError("Not supported on Python 2.7")

try:
import platform
distro = platform.uname()
if sys.version_info >= (3, 8) and not ("redhat" in distro or "ubuntu" in distro):
raise NotImplementedError("Not supported")
except Exception: # pylint: disable=broad-except
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're anticipating errors from indexing distro here, "redhat" in distro or "ubuntu" in distro might be better.

raise NotImplementedError("Not supported")

err = ct.c_int()
schema = _libsecret.secret_schema_new(
_c_str("org.freedesktop.Secret.Generic"), 2, _c_str("service"), 0, _c_str("account"), 0, None
Expand All @@ -92,7 +100,5 @@ def get_credentials():
environment_name = _get_user_settings()
credentials = _get_refresh_token(VSCODE_CREDENTIALS_SECTION, environment_name)
return credentials
except NotImplementedError: # pylint:disable=try-except-raise
raise
except Exception: # pylint: disable=broad-except
return None
29 changes: 29 additions & 0 deletions sdk/identity/azure-identity/tests/test_vscode_credential.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,35 @@ def test_no_obtain_token_if_cached():
assert mock_client.obtain_token_by_refresh_token.call_count == 0


@pytest.mark.skipif(not sys.platform.startswith("linux"), reason="This test only runs on Linux")
def test_distro():
from azure.identity._credentials.linux_vscode_adapter import _get_refresh_token
expected_token = AccessToken("token", 42)

mock_client = mock.Mock(spec=object)
mock_client.obtain_token_by_refresh_token = mock.Mock(return_value=expected_token)
mock_client.get_cached_access_token = mock.Mock(return_value="VALUE")

with mock.patch("platform.uname",
return_value=('Linux', 'redhat', '4.18.0-193.el8.x86_64',
'#1 SMP Fri Mar 27 14:35:58 UTC 2020', 'x86_64', 'x86_64')):
credential = VSCodeCredential(_client=mock_client)
token = credential.get_token("scope")

with mock.patch("platform.uname",
return_value=('Linux', 'ubuntu', '5.3.0-1022-azure',
'#23~18.04.1-Ubuntu SMP Mon May 11 11:55:56 UTC 2020', 'x86_64', 'x86_64')):
credential = VSCodeCredential(_client=mock_client)
token = credential.get_token("scope")

with mock.patch("platform.uname",
return_value=('Linux', 'deb', '4.19.0-9-cloud-amd64',
'#1 SMP Debian 4.19.118-2 (2020-04-29)', 'x86_64', '')):
if sys.version_info[0] == 3 and sys.version_info[1] == 8:
with pytest.raises(NotImplementedError):
credential = _get_refresh_token("test", "test")


@pytest.mark.skipif(not sys.platform.startswith("darwin"), reason="This test only runs on MacOS")
def test_mac_keychain_valid_value():
with mock.patch("msal_extensions.osx.Keychain.get_generic_password", return_value="VALUE"):
Expand Down