From 7856a56e9e3176cc8dc39cb412a094b2ad07fa5d Mon Sep 17 00:00:00 2001 From: ruaridhg Date: Fri, 19 Jan 2024 15:35:49 +0000 Subject: [PATCH] FTP_TLS in production and FTP for testing --- pixl_core/src/core/upload.py | 8 +++--- pixl_core/tests/conftest.py | 7 ++++- pixl_core/tests/docker-compose.yml | 7 +++-- pixl_core/tests/ftp-server/Dockerfile | 11 ++++---- .../tests/ftp-server/mounts/ssl/localhost.crt | 19 ------------- .../tests/ftp-server/mounts/ssl/localhost.key | 28 ------------------- 6 files changed, 20 insertions(+), 60 deletions(-) delete mode 100644 pixl_core/tests/ftp-server/mounts/ssl/localhost.crt delete mode 100644 pixl_core/tests/ftp-server/mounts/ssl/localhost.key diff --git a/pixl_core/src/core/upload.py b/pixl_core/src/core/upload.py index aae55c4fd..c3bf51dd1 100644 --- a/pixl_core/src/core/upload.py +++ b/pixl_core/src/core/upload.py @@ -14,7 +14,7 @@ logger = logging.getLogger(__name__) - +FTP_type = FTP_TLS # Make a DSHUploader class that takes a project slug and study pseudonymised id? @@ -54,7 +54,7 @@ def upload_content(content: BinaryIO, *, remote_dir: str, remote_file: str) -> s return f"{remote_dir}/{remote_file}" -def _connect_to_ftp() -> FTP_TLS: +def _connect_to_ftp() -> FTP_type: # Set your FTP server details ftp_host = os.environ["FTP_HOST"] ftp_port = os.environ["FTP_PORT"] # FTPS usually uses port 21 @@ -62,13 +62,13 @@ def _connect_to_ftp() -> FTP_TLS: ftp_password = os.environ["FTP_USER_PASS"] # Connect to the server and login - ftp = FTP_TLS() # noqa: S321, we're required to use FTP_TLS + ftp = FTP_type() # , we're required to use FTP_TLS ftp.connect(ftp_host, int(ftp_port)) ftp.login(ftp_user, ftp_password) return ftp -def _create_and_set_as_cwd(ftp: FTP_TLS, project_dir: str) -> None: +def _create_and_set_as_cwd(ftp: FTP_type, project_dir: str) -> None: try: ftp.cwd(project_dir) logger.info("'%s' exists on remote ftp, so moving into it", project_dir) diff --git a/pixl_core/tests/conftest.py b/pixl_core/tests/conftest.py index 632d29cf1..a51394d58 100644 --- a/pixl_core/tests/conftest.py +++ b/pixl_core/tests/conftest.py @@ -15,6 +15,7 @@ import os import subprocess +from ftplib import FTP from pathlib import Path import pytest @@ -34,6 +35,11 @@ TEST_DIR = Path(__file__).parent +@pytest.fixture(autouse=True) +def _use_FTP(monkeypatch): + monkeypatch.setattr("core.upload.FTP_type", FTP) + + @pytest.fixture(scope="package") def _run_containers() -> None: """WIP, should be able to get this up and running from pytest""" @@ -43,7 +49,6 @@ def _run_containers() -> None: check=True, cwd=TEST_DIR, shell=True, # noqa: S602 - timeout=60 ) yield subprocess.run(b"docker compose down --volumes", check=True, cwd=TEST_DIR, shell=True) # noqa: S602 diff --git a/pixl_core/tests/docker-compose.yml b/pixl_core/tests/docker-compose.yml index f5fb8f2e2..c8015975e 100644 --- a/pixl_core/tests/docker-compose.yml +++ b/pixl_core/tests/docker-compose.yml @@ -32,7 +32,8 @@ services: retries: 5 ftp-server: container_name: test-ftp-server - image: delfer/alpine-ftp-server + build: + context: ftp-server ports: - "20021:21" - "21000-21010:21000-21010" @@ -44,8 +45,8 @@ services: environment: ADDRESS: "localhost" USERS: pixl|pixl|/home/pixl - TLS_KEY: /etc/ssl/private/localhost.key - TLS_CERT: /etc/ssl/private/localhost.crt + # TLS_KEY: /etc/ssl/private/localhost.key + # TLS_CERT: /etc/ssl/private/localhost.crt healthcheck: test: netstat -lnt | grep ":21" || exit 1 interval: 30s diff --git a/pixl_core/tests/ftp-server/Dockerfile b/pixl_core/tests/ftp-server/Dockerfile index 1f786165f..42e99eb8e 100644 --- a/pixl_core/tests/ftp-server/Dockerfile +++ b/pixl_core/tests/ftp-server/Dockerfile @@ -1,6 +1,7 @@ +FROM delfer/alpine-ftp-server - -SHELL ["/bin/bash", "-c"] -RUN echo $'# Enable FTPS.\n\ -ssl_enable=YES\n\ -require_ssl_reuse=NO' \ No newline at end of file +SHELL ["/bin/sh", "-c"] +# RUN echo $'# Enable FTPS.\n\ +# ssl_enable=YES\n\ +# ssl_tlsv1_1=YES\n\ +# require_ssl_reuse=NO' >> /etc/vsftpd/vsftpd.conf \ No newline at end of file diff --git a/pixl_core/tests/ftp-server/mounts/ssl/localhost.crt b/pixl_core/tests/ftp-server/mounts/ssl/localhost.crt deleted file mode 100644 index e4ae63bd2..000000000 --- a/pixl_core/tests/ftp-server/mounts/ssl/localhost.crt +++ /dev/null @@ -1,19 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIDDzCCAfegAwIBAgIUAp2Lf0PMph7l0wbBBawd8gT+esEwDQYJKoZIhvcNAQEL -BQAwFDESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTI0MDExNTE4MTY0NFoXDTI0MDIx -NDE4MTY0NFowFDESMBAGA1UEAwwJbG9jYWxob3N0MIIBIjANBgkqhkiG9w0BAQEF -AAOCAQ8AMIIBCgKCAQEAw2CKWkHi4iiPVXhxiHXkwFsYPRidLgSPc872NXGvnSA4 -XyjBs1mo2DV8GZdafAYcpB1vbmSXaIp8l6K/kXu4Xg+PX0H1e815/hh0F4BuGfIh -RunYMSJDnAQrW14pfJb+xmJeCaMPG6F83eOm+p672Emoy+ny2cAlXApV/yuFsUd+ -hq2aGhX2QkN3LD/Q3qOcRqt1I2+kzWgQs3NffEm+Rm22RnIlc3utiAZ84AnKDabe -seMeqXq7UGh8qIpL17aaWmOHouUzncpmf7Qd3nZejDiebbYoULFQt7y4qbaFJHbx -kZT1zxJdgh/nBVakYwTeMmyIWDUx/MRvIiG1sC0ujwIDAQABo1kwVzAUBgNVHREE -DTALgglsb2NhbGhvc3QwCwYDVR0PBAQDAgeAMBMGA1UdJQQMMAoGCCsGAQUFBwMB -MB0GA1UdDgQWBBRL0Yu9JdkI1LPobvtjaXDf+wjPkjANBgkqhkiG9w0BAQsFAAOC -AQEArFruYj8CADxeHD1nRyCm7KIL1Z8jQFpw+GbV34eM583Q5lokJW7bfamqvdDj -46Mb77U/q6OA8si+HVQ5AOUoIM6qQkWitM8PQT5Unf8juHOaAnKJS+jebQccm9B0 -ZvRsXE900Z6dyxPUjKO+RUxloeyoSjqU6Sss9VzLudr2zXC1Hz76D38ZtoUYgXlA -amqkJ6TS5f5YXvMmY3ofeApxmVYniCJWxzhlvxyED6egKKeyaFVLfR/4UfaWSm1S -8UADyVLjGjhEvXBOEiwNQUz8/p6HePuE1bXP3vRM/nveWPzRXDceIisniJ2Jfrqn -NKY9u2LIiGYON4dL9Lfh8xzdMg== ------END CERTIFICATE----- diff --git a/pixl_core/tests/ftp-server/mounts/ssl/localhost.key b/pixl_core/tests/ftp-server/mounts/ssl/localhost.key deleted file mode 100644 index 4351caa7a..000000000 --- a/pixl_core/tests/ftp-server/mounts/ssl/localhost.key +++ /dev/null @@ -1,28 +0,0 @@ ------BEGIN PRIVATE KEY----- -MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDDYIpaQeLiKI9V -eHGIdeTAWxg9GJ0uBI9zzvY1ca+dIDhfKMGzWajYNXwZl1p8BhykHW9uZJdoinyX -or+Re7heD49fQfV7zXn+GHQXgG4Z8iFG6dgxIkOcBCtbXil8lv7GYl4Jow8boXzd -46b6nrvYSajL6fLZwCVcClX/K4WxR36GrZoaFfZCQ3csP9Deo5xGq3Ujb6TNaBCz -c198Sb5GbbZGciVze62IBnzgCcoNpt6x4x6pertQaHyoikvXtppaY4ei5TOdymZ/ -tB3edl6MOJ5ttihQsVC3vLiptoUkdvGRlPXPEl2CH+cFVqRjBN4ybIhYNTH8xG8i -IbWwLS6PAgMBAAECggEADeRK4hEGOftqpEf3QUh/VoKuTgXL2Jj1aZAWfIVUAxw7 -4ImW1ZLzSPBAndc1AAA1QCFhqhvtPL8quGNs3ezJ6/ziPlfZGw+TSX22n3HVIkjP -lJRi+AIOLu/dn1ZUz9QyqFYX2/U5SUcpsuM8HQd1UXMnVTG8v+kuyYUTSUdFxG2H -gkKNn3D60EdKrOjtYQGMk18frwFs0e2tBu4GSkLqKE/07O6JYM6BxO6U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