Skip to content

Commit

Permalink
[MicrosoftApiModule] Revert of PR 29035 (demisto#29173)
Browse files Browse the repository at this point in the history
* Revert the 7839428 commit

* Update RN

* Update RN
  • Loading branch information
mmhw authored Aug 23, 2023
1 parent c31a44e commit a0c2258
Show file tree
Hide file tree
Showing 101 changed files with 284 additions and 116 deletions.
33 changes: 2 additions & 31 deletions Packs/ApiModules/Scripts/MicrosoftApiModule/MicrosoftApiModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -735,8 +735,6 @@ def __init__(self, tenant_id: str = '',
self.resources = resources if resources else []
self.resource_to_access_token: dict[str, str] = {}

self.auth_code_reconfigured = False

# for Azure Managed Identities purpose
self.managed_identities_client_id = managed_identities_client_id
self.managed_identities_resource_uri = managed_identities_resource_uri
Expand Down Expand Up @@ -869,11 +867,7 @@ def get_access_token(self, resource: str = '', scope: str | None = None) -> str:

valid_until = integration_context.get(valid_until_keyword)

self.auth_code_reconfigured = self.is_auth_code_reconfigured(integration_context.get('auth_code', ''))
if self.auth_code_reconfigured:
demisto.debug("Auth code reconfigured, saving new auth code to integration context")
integration_context['auth_code'] = self.auth_code
elif access_token and valid_until and self.epoch_seconds() < valid_until:
if access_token and valid_until and self.epoch_seconds() < valid_until:
return access_token

if self.auth_type == OPROXY_AUTH_TYPE:
Expand Down Expand Up @@ -1107,7 +1101,7 @@ def _get_self_deployed_token_auth_code(
data['scope'] = scope

refresh_token = refresh_token or self._get_refresh_token_from_auth_code_param()
if refresh_token and not self.auth_code_reconfigured:
if refresh_token:
data['grant_type'] = REFRESH_TOKEN
data['refresh_token'] = refresh_token
else:
Expand Down Expand Up @@ -1393,29 +1387,6 @@ def start_auth(self, complete_command: str) -> str:
and enter the code **{user_code}** to authenticate.
2. Run the **{complete_command}** command in the War Room."""

def is_auth_code_reconfigured(self, auth_code) -> bool:
"""
Checks if the auth_code is reconfigured by comparing to the self.auth_code from the instance params.
Args:
auth_code: The auth_code form the integration context.
Returns:
bool: True if the auth_code is reconfigured, otherwise False.
"""
# Case of oproxy
if self.auth_type == OPROXY_AUTH_TYPE:
return False
# Case of the next times or after reconfigured the auth_code
if auth_code and self.auth_code:
is_reconfigured = auth_code != self.auth_code
demisto.debug(f'Auth code is reconfigured: {is_reconfigured}')
return is_reconfigured
# Case of the first time or after deleting the auth_code
elif auth_code or self.auth_code:
demisto.debug('Auth code is only in ' + ('integration_context' if auth_code else 'params'))
return True
else:
return False


class NotFoundError(Exception):
"""Exception raised for 404 - Not Found errors.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
CLIENT_ID = 'dummy_client'
CLIENT_SECRET = 'dummy_secret'
APP_URL = 'https://login.microsoftonline.com/dummy_tenant/oauth2/v2.0/token'
AUTH_CODE = 'dummy_auth_code'
REDIRECT_URI = 'https://localhost/myapp'
SCOPE = 'https://graph.microsoft.com/.default'
RESOURCE = 'https://defender.windows.com/shtak'
RESOURCES = ['https://resource1.com', 'https://resource2.com']
Expand Down Expand Up @@ -64,17 +62,15 @@ def oproxy_client_refresh():
)


def self_deployed_client(grant_type=CLIENT_CREDENTIALS):
def self_deployed_client():
tenant_id = TENANT
client_id = CLIENT_ID
client_secret = CLIENT_SECRET
base_url = BASE_URL
auth_code = AUTH_CODE if grant_type == AUTHORIZATION_CODE else ''
resource = RESOURCE
ok_codes = OK_CODES

return MicrosoftClient(self_deployed=True, tenant_id=tenant_id, auth_id=client_id, enc_key=client_secret,
grant_type=grant_type, auth_code=auth_code,
resource=resource, base_url=base_url, verify=True, proxy=False, ok_codes=ok_codes)


Expand Down Expand Up @@ -721,57 +717,11 @@ def test_generate_login_url():
"""
from MicrosoftApiModule import generate_login_url

client = self_deployed_client(grant_type=AUTHORIZATION_CODE)
client = self_deployed_client()

result = generate_login_url(client)

expected_url = f'[login URL](https://login.microsoftonline.com/{TENANT}/oauth2/v2.0/authorize?' \
f'response_type=code&scope=offline_access%20https://graph.microsoft.com/.default' \
f'&client_id={CLIENT_ID}&redirect_uri=https://localhost/myapp)'
assert expected_url in result.readable_output, "Login URL is incorrect"


def test_get_access_token_auth_code_reconfigured(mocker, requests_mock):
"""
Given:
- The auth code was reconfigured
When:
- Calling function get_access_token
Then:
- Ensure the access token is as expected in the body of the request and in the integration context
"""
context = {'auth_code': AUTH_CODE, 'access_token': TOKEN,
'valid_until': 3605, 'current_refresh_token': REFRESH_TOKEN}

mocker.patch.object(demisto, 'getIntegrationContext', return_value=context)
mocker.patch.object(demisto, 'setIntegrationContext')

tenant_id = TENANT
client_id = CLIENT_ID
client_secret = CLIENT_SECRET
base_url = BASE_URL
new_auth_code = 'reconfigured_auth_code'
resource = None
ok_codes = OK_CODES
grant_type = AUTHORIZATION_CODE

client = MicrosoftClient(self_deployed=True, tenant_id=tenant_id, auth_id=client_id, enc_key=client_secret,
grant_type=grant_type, auth_code=new_auth_code,
resource=resource, base_url=base_url, verify=True, proxy=False, ok_codes=ok_codes)

requests_mock.post(
APP_URL,
json={'access_token': TOKEN, 'expires_in': '3600'})

body = {
'client_id': CLIENT_ID,
'client_secret': CLIENT_SECRET,
'redirect_uri': REDIRECT_URI,
'grant_type': AUTHORIZATION_CODE,
'code': new_auth_code,
}

assert client.get_access_token()
req_body = requests_mock._adapter.last_request._request.body
assert urllib.parse.urlencode(body) == req_body
assert demisto.getIntegrationContext().get('auth_code') == new_auth_code
1 change: 1 addition & 0 deletions Packs/AzureActiveDirectory/ReleaseNotes/1_3_16.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
***WARNING: This version is invalid. Please install a different version.***

#### Integrations

Expand Down
6 changes: 6 additions & 0 deletions Packs/AzureActiveDirectory/ReleaseNotes/1_3_17.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#### Integrations

##### Azure Active Directory Identity Protection (Deprecated)

Fixed an issue where instances using version 1.3.16 of the pack could have authentication issues.
2 changes: 1 addition & 1 deletion Packs/AzureActiveDirectory/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Deprecated. Use Microsoft Graph Identity and Access instead.",
"support": "xsoar",
"hidden": true,
"currentVersion": "1.3.16",
"currentVersion": "1.3.17",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down
1 change: 1 addition & 0 deletions Packs/AzureCompute/ReleaseNotes/1_2_13.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
***WARNING: This version is invalid. Please install a different version.***

#### Integrations

Expand Down
6 changes: 6 additions & 0 deletions Packs/AzureCompute/ReleaseNotes/1_2_14.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#### Integrations

##### Azure Compute v2

Fixed an issue where instances using version 1.2.13 of the pack could have authentication issues.
2 changes: 1 addition & 1 deletion Packs/AzureCompute/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Azure Compute",
"description": "Create and Manage Azure Virtual Machines",
"support": "xsoar",
"currentVersion": "1.2.13",
"currentVersion": "1.2.14",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down
1 change: 1 addition & 0 deletions Packs/AzureDataExplorer/ReleaseNotes/1_2_25.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
***WARNING: This version is invalid. Please install a different version.***

#### Integrations

Expand Down
6 changes: 6 additions & 0 deletions Packs/AzureDataExplorer/ReleaseNotes/1_2_26.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#### Integrations

##### Azure Data Explorer

Fixed an issue where instances using version 1.2.25 of the pack could have authentication issues.
2 changes: 1 addition & 1 deletion Packs/AzureDataExplorer/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Azure Data Explorer",
"description": "Use Azure Data Explorer integration to collect and analyze data inside clusters of Azure Data Explorer and manage search queries.",
"support": "xsoar",
"currentVersion": "1.2.25",
"currentVersion": "1.2.26",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down
1 change: 1 addition & 0 deletions Packs/AzureDevOps/ReleaseNotes/1_2_17.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
***WARNING: This version is invalid. Please install a different version.***

#### Integrations

Expand Down
6 changes: 6 additions & 0 deletions Packs/AzureDevOps/ReleaseNotes/1_3_1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#### Integrations

##### AzureDevOps

Fixed an issue where instances using version 1.2.17 of the pack could have authentication issues.
2 changes: 1 addition & 1 deletion Packs/AzureDevOps/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "AzureDevOps",
"description": "Create and manage Git repositories in Azure DevOps Services.",
"support": "xsoar",
"currentVersion": "1.3.0",
"currentVersion": "1.3.1",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down
1 change: 1 addition & 0 deletions Packs/AzureFirewall/ReleaseNotes/1_1_25.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
***WARNING: This version is invalid. Please install a different version.***

#### Integrations

Expand Down
6 changes: 6 additions & 0 deletions Packs/AzureFirewall/ReleaseNotes/1_1_26.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#### Integrations

##### Azure Firewall

Fixed an issue where instances using version 1.1.25 of the pack could have authentication issues.
2 changes: 1 addition & 1 deletion Packs/AzureFirewall/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Azure Firewall",
"description": "Azure Firewall is a cloud-native and intelligent network firewall security service that provides breed threat protection for cloud workloads running in Azure.It's a fully stateful, firewall as a service with built-in high availability and unrestricted cloud scalability.",
"support": "xsoar",
"currentVersion": "1.1.25",
"currentVersion": "1.1.26",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down
1 change: 1 addition & 0 deletions Packs/AzureKeyVault/ReleaseNotes/1_1_26.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
***WARNING: This version is invalid. Please install a different version.***

#### Integrations

Expand Down
6 changes: 6 additions & 0 deletions Packs/AzureKeyVault/ReleaseNotes/1_1_27.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#### Integrations

##### Azure Key Vault

Fixed an issue where instances using version 1.1.26 of the pack could have authentication issues.
2 changes: 1 addition & 1 deletion Packs/AzureKeyVault/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Azure Key Vault",
"description": "Use Key Vault to safeguard and manage cryptographic keys and secrets used by cloud applications and services.",
"support": "xsoar",
"currentVersion": "1.1.26",
"currentVersion": "1.1.27",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down
1 change: 1 addition & 0 deletions Packs/AzureKubernetesServices/ReleaseNotes/1_1_18.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
***WARNING: This version is invalid. Please install a different version.***

#### Integrations

Expand Down
6 changes: 6 additions & 0 deletions Packs/AzureKubernetesServices/ReleaseNotes/1_1_19.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#### Integrations

##### Azure Kubernetes Services

Fixed an issue where instances using version 1.1.18 of the pack could have authentication issues.
2 changes: 1 addition & 1 deletion Packs/AzureKubernetesServices/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Azure Kubernetes Services",
"description": "Deploy and manage containerized applications with a fully managed Kubernetes service.",
"support": "xsoar",
"currentVersion": "1.1.18",
"currentVersion": "1.1.19",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down
1 change: 1 addition & 0 deletions Packs/AzureLogAnalytics/ReleaseNotes/1_1_16.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
***WARNING: This version is invalid. Please install a different version.***

#### Integrations

Expand Down
6 changes: 6 additions & 0 deletions Packs/AzureLogAnalytics/ReleaseNotes/1_1_17.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#### Integrations

##### Azure Log Analytics

Fixed an issue where instances using version 1.1.16 of the pack could have authentication issues.
2 changes: 1 addition & 1 deletion Packs/AzureLogAnalytics/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Azure Log Analytics",
"description": "Log Analytics is a service that helps you collect and analyze data generated by resources in your cloud and on-premises environments.",
"support": "xsoar",
"currentVersion": "1.1.16",
"currentVersion": "1.1.17",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down
1 change: 1 addition & 0 deletions Packs/AzureNetworkSecurityGroups/ReleaseNotes/1_2_18.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
***WARNING: This version is invalid. Please install a different version.***

#### Integrations

Expand Down
6 changes: 6 additions & 0 deletions Packs/AzureNetworkSecurityGroups/ReleaseNotes/1_2_19.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#### Integrations

##### Azure Network Security Groups

Fixed an issue where instances using version 1.2.18 of the pack could have authentication issues.
2 changes: 1 addition & 1 deletion Packs/AzureNetworkSecurityGroups/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Azure Network Security Groups",
"description": "Azure Network Security Groups are used to filter network traffic to and from Azure resources in an Azure virtual network",
"support": "xsoar",
"currentVersion": "1.2.18",
"currentVersion": "1.2.19",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down
1 change: 1 addition & 0 deletions Packs/AzureRiskyUsers/ReleaseNotes/1_1_16.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
***WARNING: This version is invalid. Please install a different version.***

#### Integrations

Expand Down
6 changes: 6 additions & 0 deletions Packs/AzureRiskyUsers/ReleaseNotes/1_1_17.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#### Integrations

##### Azure Risky Users

Fixed an issue where instances using version 1.1.16 of the pack could have authentication issues.
2 changes: 1 addition & 1 deletion Packs/AzureRiskyUsers/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Azure Risky Users",
"description": "Azure Risky Users provides access to all at-risk users and risk detections in Azure AD environment.",
"support": "xsoar",
"currentVersion": "1.1.16",
"currentVersion": "1.1.17",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down
1 change: 1 addition & 0 deletions Packs/AzureSQLManagement/ReleaseNotes/1_1_27.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
***WARNING: This version is invalid. Please install a different version.***

#### Integrations

Expand Down
6 changes: 6 additions & 0 deletions Packs/AzureSQLManagement/ReleaseNotes/1_1_28.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#### Integrations

##### Azure SQL Management

Fixed an issue where instances using version 1.1.27 of the pack could have authentication issues.
2 changes: 1 addition & 1 deletion Packs/AzureSQLManagement/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Azure SQL Management",
"description": "Microsoft Azure SQL Database is a managed cloud database provided as part of Microsoft Azure",
"support": "xsoar",
"currentVersion": "1.1.27",
"currentVersion": "1.1.28",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down
1 change: 1 addition & 0 deletions Packs/AzureSecurityCenter/ReleaseNotes/2_0_8.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
***WARNING: This version is invalid. Please install a different version.***

#### Integrations

Expand Down
10 changes: 10 additions & 0 deletions Packs/AzureSecurityCenter/ReleaseNotes/2_0_9.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

#### Integrations

##### Microsoft Defender for Cloud Event Collector

Fixed an issue where instances using version 2.0.8 of the pack could have authentication issues.

##### Microsoft Defender for Cloud

Fixed an issue where instances using version 2.0.8 of the pack could have authentication issues.
Loading

0 comments on commit a0c2258

Please sign in to comment.