Skip to content
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

identity_vscode_credential #10840

Merged
merged 82 commits into from
Apr 30, 2020
Merged
Changes from 1 commit
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
0002805
identity_win_vscode_credential
xiangyan99 Apr 14, 2020
b1e79de
remove used import
xiangyan99 Apr 14, 2020
13fd676
update
xiangyan99 Apr 15, 2020
d356ba6
update
xiangyan99 Apr 15, 2020
41b0394
update
xiangyan99 Apr 15, 2020
526470d
update
xiangyan99 Apr 15, 2020
dc671f2
update
xiangyan99 Apr 15, 2020
5a47894
update shared requirements
xiangyan99 Apr 15, 2020
c797482
add async credential and tests
xiangyan99 Apr 15, 2020
25de404
update dev_requirements
xiangyan99 Apr 15, 2020
f48fdd4
add try in import
xiangyan99 Apr 15, 2020
a77e336
not raise
xiangyan99 Apr 15, 2020
9f5ad5d
update
xiangyan99 Apr 15, 2020
d155f80
mac os support
xiangyan99 Apr 15, 2020
015f1f7
update
xiangyan99 Apr 15, 2020
bfa2ea1
update msal version
xiangyan99 Apr 15, 2020
16873bd
roll back msal change
xiangyan99 Apr 15, 2020
58844b9
remove dependency on pywin32
xiangyan99 Apr 16, 2020
05694a9
update
xiangyan99 Apr 16, 2020
671d5ea
update
xiangyan99 Apr 16, 2020
921b7a2
update
xiangyan99 Apr 16, 2020
3911b88
add tests
xiangyan99 Apr 16, 2020
f313ba4
add pygobject dependency
xiangyan99 Apr 16, 2020
283a055
linux support
xiangyan99 Apr 16, 2020
9974361
update
xiangyan99 Apr 16, 2020
4e7b9c4
updates
xiangyan99 Apr 16, 2020
bbe7a20
updates
xiangyan99 Apr 16, 2020
94b152b
pylint fix
xiangyan99 Apr 16, 2020
657617c
updates
xiangyan99 Apr 17, 2020
426dea7
updates
xiangyan99 Apr 17, 2020
f9a2abf
updates
xiangyan99 Apr 17, 2020
593a62f
update tests
xiangyan99 Apr 17, 2020
0805e74
format
xiangyan99 Apr 17, 2020
eaf10cb
add type checking
xiangyan99 Apr 17, 2020
e1dab12
refactor code
xiangyan99 Apr 17, 2020
9c33cfd
remove unused import
xiangyan99 Apr 17, 2020
d072e20
updates
xiangyan99 Apr 17, 2020
6024a9a
remove pygobject dependency
xiangyan99 Apr 17, 2020
a63e157
updates
xiangyan99 Apr 18, 2020
a8d45c0
typo
xiangyan99 Apr 18, 2020
2fca38a
update tests
xiangyan99 Apr 18, 2020
3866a93
update mac tests
xiangyan99 Apr 18, 2020
ebb5df2
add linux tests
xiangyan99 Apr 18, 2020
595cdea
updates
xiangyan99 Apr 18, 2020
246ab2d
updates
xiangyan99 Apr 18, 2020
af482e6
clean up
xiangyan99 Apr 18, 2020
57953ba
mock patch not work well on async 3.8+
xiangyan99 Apr 18, 2020
022f376
refactor code
xiangyan99 Apr 21, 2020
7e15ddd
pylint
xiangyan99 Apr 21, 2020
975f6ed
pylint
xiangyan99 Apr 21, 2020
767906f
add tests for win apis
xiangyan99 Apr 22, 2020
1e10649
use __module__
xiangyan99 Apr 22, 2020
cf54345
update
xiangyan99 Apr 22, 2020
e43a74f
update
xiangyan99 Apr 22, 2020
4fe1be3
add tests
xiangyan99 Apr 22, 2020
0fd89e6
typo
xiangyan99 Apr 22, 2020
5524ea9
update
xiangyan99 Apr 22, 2020
ff9d532
update
xiangyan99 Apr 22, 2020
e6b83ca
update
xiangyan99 Apr 22, 2020
9232a3b
Update sdk/identity/azure-identity/tests/test_vscode_credential.py
xiangyan99 Apr 23, 2020
9ea845e
updates
xiangyan99 Apr 23, 2020
77f8838
update
xiangyan99 Apr 23, 2020
0f69230
update
xiangyan99 Apr 23, 2020
ec1f0a3
update
xiangyan99 Apr 27, 2020
4fadaf3
update
xiangyan99 Apr 27, 2020
435fdce
update
xiangyan99 Apr 27, 2020
cb74ce2
updates
xiangyan99 Apr 28, 2020
a402f3b
update
xiangyan99 Apr 28, 2020
853dd3e
update
xiangyan99 Apr 28, 2020
54d1b48
update
xiangyan99 Apr 29, 2020
75624b8
disable on 2.7
xiangyan99 Apr 29, 2020
ed1db0c
raise on Python 2.7 Linux
xiangyan99 Apr 29, 2020
6fc8708
fix typo
xiangyan99 Apr 29, 2020
7d36ad5
update
xiangyan99 Apr 29, 2020
6f8ae61
update
xiangyan99 Apr 30, 2020
42270b8
check error
xiangyan99 Apr 30, 2020
5c8bcec
update
xiangyan99 Apr 30, 2020
77cc4d8
add vs code credential to default
xiangyan99 Apr 30, 2020
10a9e43
Merge branch 'master' into identity_vcode_credential
xiangyan99 Apr 30, 2020
ff8e1c7
update
xiangyan99 Apr 30, 2020
8efee5c
update
xiangyan99 Apr 30, 2020
a5dc253
updates
xiangyan99 Apr 30, 2020
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
Prev Previous commit
Next Next commit
add tests
xiangyan99 committed Apr 16, 2020
commit 3911b88a694a05b3e28b81ea26c34d733fdadd17
Original file line number Diff line number Diff line change
@@ -67,6 +67,8 @@ def from_dict(cls, credential):
_advapi.CredReadW.argtypes = [wt.LPCWSTR, wt.DWORD, wt.DWORD, ct.POINTER(_PCREDENTIAL)]
_advapi.CredReadW.restype = wt.BOOL
_advapi.CredFree.argtypes = [_PCREDENTIAL]
_advapi.CredDeleteW.restype = wt.BOOL
_advapi.CredDeleteW.argtypes = [wt.LPCWSTR, wt.DWORD, wt.DWORD]


def _cred_write(credential):
@@ -75,6 +77,11 @@ def _cred_write(credential):
_advapi.CredWriteW(cred_ptr, 0)


def _cred_delete(service_name, account_name):
target = u"{}/{}".format(service_name, account_name)
_advapi.CredDeleteW(target, 1, 0)


def _read_credential(service_name, account_name):
target = u"{}/{}".format(service_name, account_name)
cred_ptr = _PCREDENTIAL()
31 changes: 30 additions & 1 deletion sdk/identity/azure-identity/tests/test_win_vscode_credential.py
Original file line number Diff line number Diff line change
@@ -5,12 +5,18 @@
import sys
import pytest
from azure.core.credentials import AccessToken
from azure.identity import CredentialUnavailableError
try:
from unittest.mock import Mock
except ImportError: # python < 3.3
from mock import Mock # type: ignore
if sys.platform.startswith('win'):
from azure.identity._credentials.win_vscode_credential import WinVSCodeCredential, _read_credential, _cred_write
from azure.identity._credentials.win_vscode_credential import (
WinVSCodeCredential,
_read_credential,
_cred_write,
_cred_delete,
)

@pytest.mark.skipif(not sys.platform.startswith('win'), reason="This test only runs on Windows")
def test_win_vscode_credential():
@@ -30,8 +36,31 @@ def test_win_vscode_credential():
token_read = _read_credential(service_name, account_name)
assert token_read == token_written

@pytest.mark.skipif(not sys.platform.startswith('win'), reason="This test only runs on Windows")
def test_credential_unavailable_error():
service_name = u"VS Code Azure"
account_name = u"Azure"
_cred_delete(service_name, account_name)
Copy link
Member

Choose a reason for hiding this comment

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

Does this log me out of the VS Code Azure extension?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes

credential = WinVSCodeCredential()
with pytest.raises(CredentialUnavailableError):
token = credential.get_token("scope")

@pytest.mark.skipif(not sys.platform.startswith('win'), reason="This test only runs on Windows")
def test_get_token():
service_name = u"VS Code Azure"
account_name = u"Azure"
target = u"{}/{}".format(service_name, account_name)
comment = u"comment"
token_written = u"test_refresh_token"
user_name = u"Azure"
credential = {"Type": 0x1,
"TargetName": target,
"UserName": user_name,
"CredentialBlob": token_written,
"Comment": comment,
"Persist": 0x2}
_cred_write(credential)
Copy link
Member

Choose a reason for hiding this comment

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

Does this overwrite my actual token?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes.

Copy link
Member

Choose a reason for hiding this comment

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

As a person who develops on Windows, runs these tests frequently, and uses VS Code, I don't want to kick over the Azure extension every time I pytest 😸

I may be the only such person but setting aside my personal inconvenience, I'm uncomfortable with all these tests mutating the external environment. If tests of the native interfaces were separate from tests of the credentials, the former wouldn't need to interfere with VS Code or each other, and the latter could mock the native interfaces and run on all platforms.


expected_token = AccessToken("token", 42)

mock_client = Mock(spec=object)
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
from helpers_async import wrap_in_future
if sys.platform.startswith('win'):
from azure.identity.aio._credentials.win_vscode_credential import WinVSCodeCredential
from azure.identity._credentials.win_vscode_credential import _cred_write
try:
from unittest.mock import Mock
except ImportError: # python < 3.3
@@ -16,6 +17,20 @@
@pytest.mark.skipif(not sys.platform.startswith('win'), reason="This test only runs on Windows")
@pytest.mark.asyncio
async def test_get_token():
service_name = u"VS Code Azure"
account_name = u"Azure"
target = u"{}/{}".format(service_name, account_name)
comment = u"comment"
token_written = u"test_refresh_token"
user_name = u"Azure"
credential = {"Type": 0x1,
"TargetName": target,
"UserName": user_name,
"CredentialBlob": token_written,
"Comment": comment,
"Persist": 0x2}
_cred_write(credential)

expected_token = AccessToken("token", 42)

mock_client = Mock(spec=object)