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

tests: add bearer cookie usage for http gw #660

Merged
merged 1 commit into from
Oct 2, 2023
Merged
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
11 changes: 10 additions & 1 deletion pytest_tests/testsuites/services/http_gate/test_http_bearer.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def test_unable_put_without_bearer_token(
error_pattern="access to object operation denied",
)

@pytest.mark.parametrize("bearer_type", ('header', 'cookie'))
@pytest.mark.parametrize(
"object_size",
[pytest.lazy_fixture("simple_object_size"), pytest.lazy_fixture("complex_object_size")],
Expand All @@ -103,6 +104,7 @@ def test_unable_put_without_bearer_token(
def test_put_with_bearer_when_eacl_restrict(
self,
object_size: int,
bearer_type: str,
user_container: str,
eacl_deny_for_others,
bearer_token_no_limit_for_others: str,
Expand All @@ -113,12 +115,19 @@ def test_put_with_bearer_when_eacl_restrict(
with allure.step(
f"Put object with bearer token for {EACLRole.OTHERS}, then get and verify hashes"
):
headers = [f" -H 'Authorization: Bearer {bearer}'"]
headers = None
cookies = None
if bearer_type == 'header':
headers = [f" -H 'Authorization: Bearer {bearer}'"]
if bearer_type == 'cookie':
cookies = {'Bearer': bearer}

oid = upload_via_http_gate_curl(
cid=user_container,
filepath=file_path,
endpoint=self.cluster.default_http_gate_endpoint,
headers=headers,
cookies=cookies
)
get_object_and_verify_hashes(
oid=oid,
Expand Down
10 changes: 8 additions & 2 deletions robot/resources/lib/python_keywords/http_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ def upload_via_http_gate_curl(
endpoint: str,
headers: list = None,
error_pattern: Optional[str] = None,
cookies: dict = None,
) -> str:
"""
This function upload given object through HTTP gate using curl utility.
Expand All @@ -219,18 +220,23 @@ def upload_via_http_gate_curl(
# parse attributes
attributes = " ".join(headers)

cookies_attr = ""
if cookies:
for k, v in cookies.items():
cookies_attr += f" -b '{k}={v}'"

large_object = is_object_large(filepath)
if large_object:
# pre-clean
_cmd_run("rm pipe -f")
files = f"file=@pipe;filename={os.path.basename(filepath)}"
cmd = f"mkfifo pipe;cat {filepath} > pipe & curl --no-buffer -F '{files}' {attributes} {request}"
cmd = f"mkfifo pipe;cat {filepath} > pipe & curl --no-buffer -F '{files}' {attributes}{cookies_attr} {request}"
output = _cmd_run(cmd, LONG_TIMEOUT)
# clean up pipe
_cmd_run("rm pipe")
else:
files = f"file=@{filepath};filename={os.path.basename(filepath)}"
cmd = f"curl -F '{files}' {attributes} {request}"
cmd = f"curl -F '{files}' {attributes}{cookies_attr} {request}"
output = _cmd_run(cmd)

if error_pattern:
Expand Down
Loading