Skip to content

Commit

Permalink
YDA-6040: add portal info API tests
Browse files Browse the repository at this point in the history
On API test failures, print more information for troubleshooting
purposes:
- CI: On failures, print web server error logs and portal access log
  for troubleshooting on portal level.
- API tests: if tests are unable to get a CSRF token, print the user
  that the error occurred with and the response from the web server
  for troubleshooting purposes.

(version for Yoda 1.9)
  • Loading branch information
stsnel committed Dec 5, 2024
1 parent 6982c18 commit 7aba7b5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/api-and-integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ jobs:
run: |
docker exec provider.yoda sh -c 'set -x ; cat /var/lib/irods/log/rodsLog*'
- name: Output web server logs
if: failure()
run: |
docker exec portal.yoda sh -c 'set -x ; for log in error_log portal_access.log ; do echo "${log}:" ; cat "/var/log/httpd/$log" ; echo; done'
# Uncomment section below when needed for debugging.
#
# - name: Setup tmate session for debugging
Expand Down
15 changes: 13 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import json
import re
import sys

import pytest
import requests
Expand Down Expand Up @@ -201,7 +202,12 @@ def login(user, password):
# Retrieve the login CSRF token.
content = client.get(url, verify=False).content.decode()
p = re.compile("tokenValue: '([a-zA-Z0-9._-]*)'")
csrf = p.findall(content)[0]
found_csrf_tokens = p.findall(content)
if len(found_csrf_tokens) == 0:
print(f"Error: could not find login CSRF token in response from server for login of user {user}. Response was:")
print(content)
sys.exit(1)
csrf = found_csrf_tokens[0]

# Login as user.
if verbose_test:
Expand All @@ -214,7 +220,12 @@ def login(user, password):
# Retrieve the authenticated CSRF token.
content = response.content.decode()
p = re.compile("tokenValue: '([a-zA-Z0-9._-]*)'")
csrf = p.findall(content)[0]
found_csrf_tokens = p.findall(content)
if len(found_csrf_tokens) == 0:
print(f"Error: could not find authenticated CSRF token in response from server for login of user {user}. Response was:")
print(content)
sys.exit(1)
csrf = found_csrf_tokens[0]

# Return CSRF and session cookies.
if verbose_test:
Expand Down

0 comments on commit 7aba7b5

Please sign in to comment.