Skip to content

Commit

Permalink
Fix/[XSUP-33100]/GitHub/Payload too large (demisto#33045)
Browse files Browse the repository at this point in the history
* CR change user agent and remove data in get request

* add ut

* add ut

* revert

* RN

* revert

* RN
  • Loading branch information
MosheEichler authored Feb 28, 2024
1 parent d61a8fe commit ecfbdda
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Packs/GitHub/Integrations/GitHub/GitHub.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def http_request(method, url_suffix, params=None, data=None, headers=None, is_ra
BASE_URL + url_suffix,
verify=USE_SSL,
params=params,
data=json.dumps(data),
data=json.dumps(data) if data else None,
headers=headers or HEADERS
)
if res.status_code >= 400:
Expand Down
2 changes: 1 addition & 1 deletion Packs/GitHub/Integrations/GitHub/GitHub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3662,7 +3662,7 @@ script:
- contextPath: GitHub.Workflow.updated_at
description: Datetime the GitHub workflow was updated at.
type: Date
dockerimage: demisto/auth-utils:1.0.0.76157
dockerimage: demisto/auth-utils:1.0.0.88424
isfetch: true
runonce: false
script: '-'
Expand Down
45 changes: 44 additions & 1 deletion Packs/GitHub/Integrations/GitHub/GitHub_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from CommonServerPython import CommandResults
from GitHub import main, list_branch_pull_requests, list_all_projects_command, \
add_issue_to_project_board_command, get_path_data, github_releases_list_command, get_branch_command, \
list_issue_comments
list_issue_comments, http_request
import GitHub

REGULAR_BASE_URL = 'https://api.github.com'
Expand Down Expand Up @@ -504,3 +504,46 @@ def test_github_list_workflow(mocker):

mocker_results.assert_called_once()
assert mocker_results.call_args[0][0].outputs[0]['head_branch'] == 'master'


def test_http_request():
"""
Given:
- A body of a post request
When:
- Calling the 'http_request' function
Then:
- Ensure the correctness of the request body.
"""

GitHub.BASE_URL = REGULAR_BASE_URL
GitHub.USE_SSL = ''
GitHub.HEADERS = {}

# Test HTTP request with data equal to 'dictionary'
with requests_mock.Mocker() as m:
mock_req = m.post(f'{REGULAR_BASE_URL}/test', json={})
response = http_request('POST', '/test', data={'test_key': 'test_value'})
assert response == {}
assert mock_req.last_request.text == '{"test_key": "test_value"}'

# Test HTTP request with data equal to empty 'dictionary'
with requests_mock.Mocker() as m:
mock_req = m.post(f'{REGULAR_BASE_URL}/test', json={})
response = http_request('POST', '/test', data={})
assert response == {}
assert not mock_req.last_request.text

# Test HTTP request with data equal to 'null'
with requests_mock.Mocker() as m:
mock_req = m.post(f'{REGULAR_BASE_URL}/test', json={})
response = http_request('POST', '/test', data='null')
assert response == {}
assert mock_req.last_request.text == '"null"'

# Test HTTP request with data equal to 'None'
with requests_mock.Mocker() as m:
mock_req = m.post(f'{REGULAR_BASE_URL}/test', json={})
response = http_request('POST', '/test', data=None)
assert response == {}
assert not mock_req.last_request.text
7 changes: 7 additions & 0 deletions Packs/GitHub/ReleaseNotes/2_0_29.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

#### Integrations

##### GitHub

- Updated the Docker image to: *demisto/auth-utils:1.0.0.88424*.
- Fixed an issue where some commands failed on http requests with the get method.
2 changes: 1 addition & 1 deletion Packs/GitHub/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "GitHub",
"description": "Manage GitHub issues and pull requests directly from Cortex XSOAR",
"support": "xsoar",
"currentVersion": "2.0.28",
"currentVersion": "2.0.29",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down

0 comments on commit ecfbdda

Please sign in to comment.