|
18 | 18 | CLIENT_ID = 'dummy_client'
|
19 | 19 | CLIENT_SECRET = 'dummy_secret'
|
20 | 20 | APP_URL = 'https://login.microsoftonline.com/dummy_tenant/oauth2/v2.0/token'
|
21 |
| -AUTH_CODE = 'dummy_auth_code' |
22 |
| -REDIRECT_URI = 'https://localhost/myapp' |
23 | 21 | SCOPE = 'https://graph.microsoft.com/.default'
|
24 | 22 | RESOURCE = 'https://defender.windows.com/shtak'
|
25 | 23 | RESOURCES = ['https://resource1.com', 'https://resource2.com']
|
@@ -64,17 +62,15 @@ def oproxy_client_refresh():
|
64 | 62 | )
|
65 | 63 |
|
66 | 64 |
|
67 |
| -def self_deployed_client(grant_type=CLIENT_CREDENTIALS): |
| 65 | +def self_deployed_client(): |
68 | 66 | tenant_id = TENANT
|
69 | 67 | client_id = CLIENT_ID
|
70 | 68 | client_secret = CLIENT_SECRET
|
71 | 69 | base_url = BASE_URL
|
72 |
| - auth_code = AUTH_CODE if grant_type == AUTHORIZATION_CODE else '' |
73 | 70 | resource = RESOURCE
|
74 | 71 | ok_codes = OK_CODES
|
75 | 72 |
|
76 | 73 | return MicrosoftClient(self_deployed=True, tenant_id=tenant_id, auth_id=client_id, enc_key=client_secret,
|
77 |
| - grant_type=grant_type, auth_code=auth_code, |
78 | 74 | resource=resource, base_url=base_url, verify=True, proxy=False, ok_codes=ok_codes)
|
79 | 75 |
|
80 | 76 |
|
@@ -721,57 +717,11 @@ def test_generate_login_url():
|
721 | 717 | """
|
722 | 718 | from MicrosoftApiModule import generate_login_url
|
723 | 719 |
|
724 |
| - client = self_deployed_client(grant_type=AUTHORIZATION_CODE) |
| 720 | + client = self_deployed_client() |
725 | 721 |
|
726 | 722 | result = generate_login_url(client)
|
727 | 723 |
|
728 | 724 | expected_url = f'[login URL](https://login.microsoftonline.com/{TENANT}/oauth2/v2.0/authorize?' \
|
729 | 725 | f'response_type=code&scope=offline_access%20https://graph.microsoft.com/.default' \
|
730 | 726 | f'&client_id={CLIENT_ID}&redirect_uri=https://localhost/myapp)'
|
731 | 727 | assert expected_url in result.readable_output, "Login URL is incorrect"
|
732 |
| - |
733 |
| - |
734 |
| -def test_get_access_token_auth_code_reconfigured(mocker, requests_mock): |
735 |
| - """ |
736 |
| - Given: |
737 |
| - - The auth code was reconfigured |
738 |
| - When: |
739 |
| - - Calling function get_access_token |
740 |
| - Then: |
741 |
| - - Ensure the access token is as expected in the body of the request and in the integration context |
742 |
| - """ |
743 |
| - context = {'auth_code': AUTH_CODE, 'access_token': TOKEN, |
744 |
| - 'valid_until': 3605, 'current_refresh_token': REFRESH_TOKEN} |
745 |
| - |
746 |
| - mocker.patch.object(demisto, 'getIntegrationContext', return_value=context) |
747 |
| - mocker.patch.object(demisto, 'setIntegrationContext') |
748 |
| - |
749 |
| - tenant_id = TENANT |
750 |
| - client_id = CLIENT_ID |
751 |
| - client_secret = CLIENT_SECRET |
752 |
| - base_url = BASE_URL |
753 |
| - new_auth_code = 'reconfigured_auth_code' |
754 |
| - resource = None |
755 |
| - ok_codes = OK_CODES |
756 |
| - grant_type = AUTHORIZATION_CODE |
757 |
| - |
758 |
| - client = MicrosoftClient(self_deployed=True, tenant_id=tenant_id, auth_id=client_id, enc_key=client_secret, |
759 |
| - grant_type=grant_type, auth_code=new_auth_code, |
760 |
| - resource=resource, base_url=base_url, verify=True, proxy=False, ok_codes=ok_codes) |
761 |
| - |
762 |
| - requests_mock.post( |
763 |
| - APP_URL, |
764 |
| - json={'access_token': TOKEN, 'expires_in': '3600'}) |
765 |
| - |
766 |
| - body = { |
767 |
| - 'client_id': CLIENT_ID, |
768 |
| - 'client_secret': CLIENT_SECRET, |
769 |
| - 'redirect_uri': REDIRECT_URI, |
770 |
| - 'grant_type': AUTHORIZATION_CODE, |
771 |
| - 'code': new_auth_code, |
772 |
| - } |
773 |
| - |
774 |
| - assert client.get_access_token() |
775 |
| - req_body = requests_mock._adapter.last_request._request.body |
776 |
| - assert urllib.parse.urlencode(body) == req_body |
777 |
| - assert demisto.getIntegrationContext().get('auth_code') == new_auth_code |
0 commit comments