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

Send data in POST requests to data param in requests #803

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 2 additions & 3 deletions assemblyline_v4_service/updater/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
import psutil
import regex as re
import requests
from assemblyline_v4_service.common.utils import DEVELOPMENT_MODE
from git import Repo

from assemblyline.common.digests import get_sha256_for_file
from assemblyline.common.identify import Identify
from assemblyline.common.isotime import iso_to_epoch
from assemblyline_v4_service.common.utils import DEVELOPMENT_MODE

BLOCK_SIZE = 64 * 1024
GIT_ALLOW_UNSAFE_PROTOCOLS = os.environ.get('GIT_ALLOW_UNSAFE_PROTOCOLS', 'false').lower() == 'true'
Expand Down Expand Up @@ -138,8 +138,7 @@ def url_download(source: Dict[str, Any], previous_update: int, logger: Logger, o
if fetch_method == 'get':
response = session.get(uri, auth=auth, headers=headers, proxies=proxies, stream=True)
elif fetch_method == 'post':
json = source.get('post_data') or None
response = session.post(uri, auth=auth, headers=headers, proxies=proxies, json=json, stream=True)
response = session.post(uri, auth=auth, headers=headers, proxies=proxies, data=source.get('data'),stream=True)
else:
raise ValueError(f"Unknown fetch method: {fetch_method}")

Expand Down
4 changes: 2 additions & 2 deletions test/test_updater/test_helper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from logging import getLogger
from unittest import mock

import pytest
import requests_mock
from assemblyline_v4_service.updater.helper import *
Expand Down Expand Up @@ -90,7 +90,7 @@ def test_url_download():
assert url_download({"name": "blah", "uri": HTML_FILE_REQUEST}, 0, log, DIRECTORY) == INDEX
assert url_download({"name": "blah", "uri": HTML_FILE_REQUEST, "fetch_method": "get"}, 0, log, DIRECTORY) == INDEX
assert url_download({"name": "blah", "uri": HTML_FILE_REQUEST, "fetch_method": "post",
"post_data": {"api-key": "123456"}}, 0, log, DIRECTORY) == INDEX
"data": {"api-key": "123456"}}, 0, log, DIRECTORY) == INDEX

os.remove(INDEX)

Expand Down