diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index e676a62e95..5b19a5e86c 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -196,4 +196,5 @@ jobs: - name: Execute tests run: | + pip install tcms-api make test-docker-image diff --git a/Makefile b/Makefile index 0feea049f8..e48bea07c6 100644 --- a/Makefile +++ b/Makefile @@ -93,7 +93,7 @@ docker-image: .PHONY: test-docker-image test-docker-image: docker-image - sudo ./tests/runner.sh + sudo --preserve-env env PATH=$$PATH ./tests/runner.sh .PHONY: docs docs: diff --git a/tests/test_http.sh b/tests/test_http.sh index e86b38bdf5..fe556aafa1 100755 --- a/tests/test_http.sh +++ b/tests/test_http.sh @@ -48,6 +48,17 @@ rlJournalStart rlAssertGrep "You are not using a secure connection." /tmp/testdata.txt rlPhaseEnd + rlPhaseStartTest "Should allow file upload with UTF-8 filenames" + cat > ~/.tcms.conf << _EOF_ +[tcms] +url = https://$IP_ADDRESS:8443/xml-rpc/ +username = testadmin +password = password +_EOF_ + + rlRun -t -c "./tests/test_utf8_uploads.py -v" + rlPhaseEnd + rlPhaseStartTest "Should send ETag header" rlRun -t -c "curl -k -D- https://$IP_ADDRESS:8443/static/images/kiwi_h20.png 2>/dev/null | grep 'ETag'" rlPhaseEnd diff --git a/tests/test_utf8_uploads.py b/tests/test_utf8_uploads.py new file mode 100755 index 0000000000..b1b7bd0d85 --- /dev/null +++ b/tests/test_utf8_uploads.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python + +# +# Copyright (c) 2022 Kiwi TCMS project. All rights reserved. +# Author: Alexander Todorov +# + +import ssl +import unittest +from unittest.mock import patch + +import requests +from tcms_api import TCMS + +try: + _create_unverified_https_context = ssl._create_unverified_context +except AttributeError: + # Legacy Python that doesn't verify HTTPS certificates by default + pass +else: + # Handle target environment that doesn't support HTTPS verification + ssl._create_default_https_context = _create_unverified_https_context + + +class DoNotVerifySSLSession(requests.sessions.Session): + def get(self, url, **kwargs): + kwargs.setdefault("verify", False) + return super().get(url, **kwargs) + + +class Utf8UploadTestCase(unittest.TestCase): + @classmethod + def setUpClass(cls): + with patch("requests.sessions.Session") as session: + session.return_value = DoNotVerifySSLSession() + cls.rpc = TCMS().exec + + def upload_and_assert(self, filename): + result = self.rpc.User.add_attachment(filename, "a2l3aXRjbXM=") + self.assertIn("url", result) + self.assertIn("filename", result) + + def test_with_filename_in_french(self): + self.upload_and_assert("Screenshot_20211117-164527_Paramètres.png") + + def test_with_filename_in_bulgarian(self): + self.upload_and_assert("Screenshot_2021-12-07 Плащане.png") + + +if __name__ == "__main__": + unittest.main()