diff --git a/docker/conf/nginx.conf b/docker/conf/nginx.conf --- a/docker/conf/nginx.conf +++ b/docker/conf/nginx.conf @@ -13,13 +13,14 @@ default_type application/octet-stream; sendfile on; keepalive_timeout 65; + client_max_body_size 100M; # Built-in Docker resolver. Needed to allow on-demand resolution of proxy # upstreams. resolver 127.0.0.11 valid=30s; server { - listen 80 default_server; + listen 5080 default_server; # Add a trailing slash to top level requests (e.g. http://localhost:5080/flower) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -80,7 +80,7 @@ volumes: - "./conf/nginx.conf:/etc/nginx/nginx.conf:ro" ports: - - 5080:80 + - 5080:5080 # Scheduler diff --git a/docker/services/swh-deposit/entrypoint.sh b/docker/services/swh-deposit/entrypoint.sh --- a/docker/services/swh-deposit/entrypoint.sh +++ b/docker/services/swh-deposit/entrypoint.sh @@ -9,7 +9,12 @@ setup_pgsql if [ "$1" = 'shell' ] ; then - exec bash -i + shift + if (( $# == 0)); then + exec bash -i + else + "$@" + fi else wait_pgsql diff --git a/docker/tests/run_tests.sh b/docker/tests/run_tests.sh --- a/docker/tests/run_tests.sh +++ b/docker/tests/run_tests.sh @@ -19,7 +19,7 @@ export COMPOSE_FILE=$TEST_SCRIPTS_DIR/../docker-compose.yml # Useful global variables -SWH_WEB_API_BASEURL="http://localhost:5004/api/1" +SWH_WEB_API_BASEURL="http://localhost:5080/api/1" CURRENT_TEST_SCRIPT="" # Colored output related variables and functions (only if stdout is a terminal) diff --git a/docker/tests/test_deposit.py b/docker/tests/test_deposit.py new file mode 100644 --- /dev/null +++ b/docker/tests/test_deposit.py @@ -0,0 +1,143 @@ +# Copyright (C) 2019-2020 The Software Heritage developers +# See the AUTHORS file at the top-level directory of this distribution +# License: GNU General Public License version 3, or any later version +# See top-level LICENSE file for more information + +import json +import subprocess +import time + +import pytest +import testinfra + + +SAMPLE_METADATA = '''\ + + + Test Software + swh + test-software + + No One + + +''' + + +# scope='session' so we use the same container for all the tests; +@pytest.fixture(scope='session') +def deposit_host(request): + # start the whole cluster + subprocess.check_output(['docker-compose', 'up', '-d']) + # run a container in which test commands are executed + docker_id = subprocess.check_output( + ['docker-compose', 'run', '-d', + 'swh-deposit', 'shell', 'sleep', '1h']).decode().strip() + deposit_host = testinfra.get_host("docker://" + docker_id) + deposit_host.check_output( + 'echo \'print("Hello World!")\n\' > /tmp/hello.py') + deposit_host.check_output( + 'tar -C /tmp -czf /tmp/archive.tgz /tmp/hello.py') + deposit_host.check_output( + f'echo \'{SAMPLE_METADATA}\' > /tmp/metadata.xml') + deposit_host.check_output('wait-for-it swh-deposit:5006 -t 30') + # return a testinfra connection to the container + yield deposit_host + + # at the end of the test suite, destroy the container + subprocess.check_call(['docker', 'rm', '-f', docker_id]) + # and the wole cluster + subprocess.check_call(['docker-compose', 'down']) + + +def test_admin_collection(deposit_host): + # 'deposit_host' binds to the container + assert deposit_host.check_output( + 'swh deposit admin collection list') == 'test' + + +def test_admin_user(deposit_host): + assert deposit_host.check_output('swh deposit admin user list') == 'test' + + +def test_create_deposit_simple(deposit_host): + deposit = deposit_host.check_output( + 'swh deposit upload --format json --username test --password test ' + '--url http://nginx:5080/deposit/1 ' + '--archive /tmp/archive.tgz ' + '--name test_deposit --author somebody') + deposit = json.loads(deposit) + + assert set(deposit.keys()) == {'deposit_id', 'deposit_status', + 'deposit_status_detail', 'deposit_date'} + assert deposit['deposit_status'] == 'deposited' + deposit_id = deposit['deposit_id'] + + for i in range(60): + status = json.loads(deposit_host.check_output( + 'swh deposit status --format json --username test --password test ' + '--url http://nginx:5080/deposit/1 --deposit-id %s' % deposit_id)) + if status['deposit_status'] == 'done': + break + time.sleep(1) + else: + assert False, "Deposit loading failed" + + +def test_create_deposit_with_metadata(deposit_host): + deposit = deposit_host.check_output( + 'swh deposit upload --format json --username test --password test ' + '--url http://nginx:5080/deposit/1 ' + '--archive /tmp/archive.tgz ' + '--metadata /tmp/metadata.xml') + deposit = json.loads(deposit) + + assert set(deposit.keys()) == {'deposit_id', 'deposit_status', + 'deposit_status_detail', 'deposit_date'} + assert deposit['deposit_status'] == 'deposited' + deposit_id = deposit['deposit_id'] + + for i in range(60): + status = json.loads(deposit_host.check_output( + 'swh deposit status --format json --username test --password test ' + '--url http://nginx:5080/deposit/1 --deposit-id %s' % deposit_id)) + if status['deposit_status'] == 'done': + break + time.sleep(1) + else: + assert False, "Deposit loading failed" + + +def test_create_deposit_multipart(deposit_host): + deposit = deposit_host.check_output( + 'swh deposit upload --format json --username test --password test ' + '--url http://nginx:5080/deposit/1 ' + '--archive /tmp/archive.tgz ' + '--partial') + deposit = json.loads(deposit) + + assert set(deposit.keys()) == {'deposit_id', 'deposit_status', + 'deposit_status_detail', 'deposit_date'} + assert deposit['deposit_status'] == 'partial' + deposit_id = deposit['deposit_id'] + + deposit = deposit_host.check_output( + 'swh deposit upload --format json --username test --password test ' + '--url http://nginx:5080/deposit/1 ' + '--metadata /tmp/metadata.xml ' + '--deposit-id %s' + % deposit_id) + deposit = json.loads(deposit) + assert deposit['deposit_status'] == 'deposited' + assert deposit['deposit_id'] == deposit_id + + for i in range(60): + status = json.loads(deposit_host.check_output( + 'swh deposit status --format json --username test --password test ' + '--url http://nginx:5080/deposit/1 --deposit-id %s' % deposit_id)) + if status['deposit_status'] == 'done': + break + time.sleep(1) + else: + assert False, "Deposit loading failed; current status is %s" % status