From e3a96ae7b343ab3ac3b3db45228a8671982f90ac Mon Sep 17 00:00:00 2001 From: Richard Davis Date: Tue, 8 Feb 2022 21:25:52 -0500 Subject: [PATCH] Prefix fixtures to prevent conflicts until pytest-dev/pytest#3966 is resolved. --- README.md | 153 +++--- pytest_docker_git_fixtures/fixtures.py | 680 ++++++++++++------------- setup.py | 2 +- tests/test_fixtures.py | 386 +++++++------- 4 files changed, 600 insertions(+), 621 deletions(-) diff --git a/README.md b/README.md index 0c50f8d..34db17a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## Overview -Pytest fixtures to instantiate and populated local docker GIT SCMs, using [lovely-pytest-docker](https://pypi.org/project/lovely-pytest-docker), for testing. +Pytest fixtures to instantiate and populated local GIT SCMs, using [lovely-pytest-docker](https://pypi.org/project/lovely-pytest-docker), for testing. ## Getting Started @@ -21,12 +21,12 @@ All fixtures should be automatically included via the pytest11 entry po import pytest import subprocess from pathlib import Path -from pytest_docker_git_fixtures import DockerGITInsecure, DockerGITSecure # Optional, for typing +from pytest_git_fixtures import GITInsecure, GITSecure # Optional, for typing -@pytest.mark.create_repo("test_docker_git_secure") +@pytest.mark.create_repo("test_git_secure") @pytest.mark.mirror_repo("https://github.com/crashvb/shim-bind.git") -def test_docker_git_secure(docker_git_secure: DockerGITSecure, tmp_path: Path): - uri = f"https://{docker_git_secure.endpoint}/secure/shim-bind.git" +def test_git_secure(git_secure: GITSecure, tmp_path: Path): + uri = f"https://{git_secure.endpoint}/secure/shim-bind.git" path = tmp_path.join("local-clone") subprocess.run( ["git", "clone", uri, str(path)], @@ -36,9 +36,9 @@ def test_docker_git_secure(docker_git_secure: DockerGITSecure, tmp_path: Path): ) assert path.joinpath("README.md").exists() -@pytest.mark.create_repo("test_docker_git_insecure") -def test_docker_git_insecure(docker_git_insecure: DockerGITInsecure, tmp_path: Path): - uri = f"https://{docker_git_insecure.endpoint}/insecure/test_docker_git_insecure.git" +@pytest.mark.create_repo("test_git_insecure") +def test_git_insecure(git_insecure: GITInsecure, tmp_path: Path): + uri = f"https://{git_insecure.endpoint}/insecure/test_git_insecure.git" path = tmp_path.join("local-clone") subprocess.run( ["git", "clone", uri, str(path)], @@ -58,7 +58,7 @@ The `create_repo` and `mirror_repo` marks can optionally be added to stage repos ### From [pypi.org](https://pypi.org/project/pytest-docker-git-fixtures/) ``` -$ pip install pytest_docker_git_fixtures +$ pip install pytest_git_fixtures ``` ### From source code @@ -73,25 +73,17 @@ $ python -m pip install --editable .[dev] ## Fixtures -### docker_compose_insecure +### git_auth_header -This fixture uses the `docker_compose_files` fixture to locate a user-defined docker-compose configuration file (typically tests/docker-compose.yml) that contains the pytest-docker-git-insecure service. If one cannot be located, an embedded configuration is copied to a temporary location and returned. This fixture is used to instantiate the insecure docker GIT service. +Retrieves an HTTP basic authentication header that is populated with credentials that can access the secure GIT service. The credentials are retrieved from the [git_password](#git_password) and [git_username](#git_username) fixtures. -### docker_compose_secure +### git_cacerts -This fixture uses the `docker_compose_files` fixture to locate a user-defined docker-compose configuration file (typically tests/docker-compose.yml) that contains the pytest-docker-git-secure service. If one cannot be located, an embedded configuration is copied to a temporary location and returned. This fixture is used to instantiate the secure docker GIT service; however, unlike the configuration returned by the [docker_compose_insecure](#docker_compose_insecure) fixture, this configuration will be treated as a template; the $PATH_CERTIFICATE, $PATH_HTPASSWD, and $PATH_KEY tokens will be populated with the absolute paths provided by the [docker_git_certs](#docker_git_certs) and [docker_git_htpasswd](#docker_git_htpasswd) fixtures, as appropriate. +Locates a user-defined CA trust store (tests/cacerts) to use to verify connections to the secure GIT service. If one cannot be located, a temporary trust store is created containing certificates from certifi and the [git_certs](#git_certs) fixture. This fixture is used to instantiate the secure GIT service. -### docker_git_auth_header +### git_certs -Retrieves an HTTP basic authentication header that is populated with credentials that can access the secure docker GIT service. The credentials are retrieved from the [docker_git_password](#docker_git_password) and [docker_git_username](#docker_git_username) fixtures. - -### docker_git_cacerts - -Locates a user-defined CA trust store (tests/cacerts) to use to verify connections to the secure docker GIT service. If one cannot be located, a temporary trust store is created containing certificates from certifi and the [docker_git_certs](#docker_git_certs) fixture. This fixture is used to instantiate the secure docker GIT service. - -### docker_git_certs - -Returns the paths of the self-signed certificate authority certificate, certificate, and private key that are used by the secure docker GIT service. This fixture is used to instantiate the secure docker GIT service. +Returns the paths of the self-signed certificate authority certificate, certificate, and private key that are used by the secure GIT service. This fixture is used to instantiate the secure GIT service. #### NamedTuple Fields @@ -102,25 +94,25 @@ The following fields are defined in the tuple provided by this fixture: * **certificate** - Path to the certificate. * **private_key** - Path to the private key. -Typing is provided by `pytest_docker_git_fixtures.DockerGITCerts`. +Typing is provided by `pytest_git_fixtures.GITCerts`. -### docker_git_htpasswd +### git_htpasswd -Provides the path to a htpasswd file that is used by the secure docker GIT service. If a user-defined htpasswd file (tests/htpasswd) can be located, it is used. Otherwise, a temporary htpasswd file is created using credentials from the [docker_git_password](#docker_git_password) and [docker_git_username](#docker_git_username) fixtures. This fixture is used to instantiate the secure docker GIT service. +Provides the path to a htpasswd file that is used by the secure GIT service. If a user-defined htpasswd file (tests/htpasswd) can be located, it is used. Otherwise, a temporary htpasswd file is created using credentials from the [git_password](#git_password) and [git_username](#git_username) fixtures. This fixture is used to instantiate the secure GIT service. -### docker_git_insecure +### git_insecure -Configures and instantiates a docker GIT without TLS or authentication. +Configures and instantiates a GIT without TLS or authentication. ```python import pytest import subprocess from pathlib import Path -from pytest_docker_git_fixtures import DockerGITInsecure # Optional, for typing +from pytest_git_fixtures import GITInsecure # Optional, for typing -@pytest.mark.create_repo("test_docker_git_insecure") -def test_docker_git_insecure(docker_git_insecure: DockerGITInsecure, tmp_path: Path): - uri = f"https://{docker_git_insecure.endpoint}/insecure/test_docker_git_insecure.git" +@pytest.mark.create_repo("test_git_insecure") +def test_git_insecure(git_insecure: GITInsecure, tmp_path: Path): + uri = f"https://{git_insecure.endpoint}/insecure/test_git_insecure.git" path = tmp_path.join("local-clone") subprocess.run( ["git", "clone", uri, str(path)], @@ -137,29 +129,29 @@ The following fields are defined in the tuple provided by this fixture: * **created_repos** - The list of created repositories. * **docker_compose** - Path to the fully instantiated docker-compose configuration. -* **endpoint** - Endpoint of the insecure docker GIT service. +* **endpoint** - Endpoint of the insecure GIT service. * **mirrored_repos** - The list of mirrored repositories. * **service_name** - Name of the service within the docker-compose configuration. -Typing is provided by `pytest_docker_git_fixtures.DockerGITInsecure`. +Typing is provided by `pytest_git_fixtures.GITInsecure`. -### docker_git_password +### git_password -Provides a generated password to use for authentication to the secure docker GIT service. +Provides a generated password to use for authentication to the secure GIT service. -### docker_git_secure +### git_secure -Configures and instantiates a TLS enabled docker GIT with HTTP basic authorization. +Configures and instantiates a TLS enabled GIT with HTTP basic authorization. ```python import pytest import subprocess from pathlib import Path -from pytest_docker_git_fixtures import DockerGITSecure # Optional, for typing +from pytest_git_fixtures import GITSecure # Optional, for typing @pytest.mark.mirror_repo("https://github.com/crashvb/shim-bind.git") -def test_docker_git_secure(docker_git_secure: DockerGITSecure, tmp_path: Path): - uri = f"https://{docker_git_secure.endpoint}/secure/shim-bind.git" +def test_git_secure(git_secure: GITSecure, tmp_path: Path): + uri = f"https://{git_secure.endpoint}/secure/shim-bind.git" path = tmp_path.join("local-clone") subprocess.run( ["git", "clone", uri, str(path)], @@ -174,43 +166,50 @@ def test_docker_git_secure(docker_git_secure: DockerGITSecure, tmp_path: Path): The following fields are defined in the tuple provided by this fixture: -* **auth_header** - from [docker_git_auth_header](#docker_git_auth_header). -* **cacerts** - from [docker_git_cacerts](#docker_git_cacerts). -* **certs** - from [docker_git_certs](#docker_git_certs). +* **auth_header** - from [git_auth_header](#git_auth_header). +* **cacerts** - from [git_cacerts](#git_cacerts). +* **certs** - from [git_certs](#git_certs). * **created_repos** - The list of created repositories. * **docker_compose** - Path to the fully instantiated docker-compose configuration. -* **endpoint** - Endpoint of the secure docker GIT service. -* **htpasswd** - from [docker_git_htpasswd](#docker_git_htpasswd) +* **endpoint** - Endpoint of the secure GIT service. +* **htpasswd** - from [git_htpasswd](#git_htpasswd) * **mirrored_repos** - The list of mirrored repositories. -* **password** - from [docker_git_password](#docker_git_password). +* **password** - from [git_password](#git_password). * **service_name** - Name of the service within the docker-compose configuration. -* **ssl_context** - from [docker_git_ssl_context](#docker_git_ssl_context). -* **username** - from [docker_git_username](#docker_git_username). +* **ssl_context** - from [git_ssl_context](#git_ssl_context). +* **username** - from [git_username](#git_username). + +Typing is provided by `pytest_git_fixtures.GITSecure`. + +### git_ssl_context + +Provides an SSL context containing the CA trust store from the [git_cacerts](#git_cacerts) fixture. -Typing is provided by `pytest_docker_git_fixtures.DockerGITSecure`. +### git_username -### docker_git_ssl_context +Provides a generated username to use for authentication to the secure GIT service. -Provides an SSL context containing the CA trust store from the [docker_git_cacerts](#docker_git_cacerts) fixture. +### pdgf_docker_compose_insecure -### docker_git_username +This fixture uses the `docker_compose_files` fixture to locate a user-defined docker-compose configuration file (typically tests/docker-compose.yml) that contains the pytest-docker-git-insecure service. If one cannot be located, an embedded configuration is copied to a temporary location and returned. This fixture is used to instantiate the insecure GIT service. -Provides a generated username to use for authentication to the secure docker GIT service. +### docker_compose_secure +This fixture uses the `docker_compose_files` fixture to locate a user-defined docker-compose configuration file (typically tests/docker-compose.yml) that contains the pytest-docker-git-secure service. If one cannot be located, an embedded configuration is copied to a temporary location and returned. This fixture is used to instantiate the secure GIT service; however, unlike the configuration returned by the [pdgf_docker_compose_insecure](#pdgf_docker_compose_insecure) fixture, this configuration will be treated as a template; the $PATH_CERTIFICATE, $PATH_HTPASSWD, and $PATH_KEY tokens will be populated with the absolute paths provided by the [git_certs](#git_certs) and [git_htpasswd](#git_htpasswd) fixtures, as appropriate. ## Markers ### pytest.mark.create_repo -This marker specifies the GIT repository(ies) that should be initialized within the docker GIT service(s) prior to testing. It can ... +This marker specifies the GIT repository(ies) that should be initialized within the GIT service(s) prior to testing. It can ... ... decorate individual tests: ```python import pytest -from pytest_docker_git_fixtures import DockerGITSecure # Optional, for typing +from pytest_git_fixtures import GITSecure # Optional, for typing -@pytest.mark.create_repo("test_docker_git_secure") -def test_docker_git_secure(docker_git_secure: DockerGITSecure): +@pytest.mark.create_repo("test_git_secure") +def test_git_secure(git_secure: GITSecure): ... ``` @@ -238,64 +237,64 @@ A helper function, `get_created_repos`, is included for test scenarios that wis ```python import pytest -from pytest_docker_git_fixtures import DockerGITSecure, get_created_repos +from pytest_git_fixtures import GITSecure, get_created_repos -@pytest.mark.create_repo("test_docker_git_secure") -def test_docker_git_secure(docker_git_secure: DockerGITSecure, request): +@pytest.mark.create_repo("test_git_secure") +def test_git_secure(git_secure: GITSecure, request): name = get_created_repos(request)[0] ``` ### pytest.mark.mirror_repo -Similarly to create_repo, this marker specifies the GIT repository(ies) that should be replicated to the docker GIT service(s) prior to testing. +Similarly to create_repo, this marker specifies the GIT repository(ies) that should be replicated to the GIT service(s) prior to testing. Likewise, there is a `get_mirrored_repos` helper function. ## Enumerated Fixtures -It is possible to instantiate multiple GIT instances using the corresponding enumerated fixtures. All [fixtures](#fixtures) listed above have _*_list_ (e.g. `docker_git_secure` -> `docker_git_secure_list`) versions that will return enumerated lists of corresponding data type. +It is possible to instantiate multiple GIT instances using the corresponding enumerated fixtures. All [fixtures](#fixtures) listed above have _*_list_ (e.g. `git_secure` -> `git_secure_list`) versions that will return enumerated lists of corresponding data type. For example: ```python import requests from typing import List # Optional, for typing -from pytest_docker_git_fixtures import DockerGITSecure # Optional, for typing +from pytest_git_fixtures import GITSecure # Optional, for typing -def test_docker_git_secure_list(docker_git_secure_list: List[DockerGITSecure]): - for docker_git_secure in docker_git_secure_list: +def test_git_secure_list(git_secure_list: List[GITSecure]): + for git_secure in git_secure_list: # Default listener ... response = requests.get( - f"https://{docker_git_secure.endpoint}/", - headers=docker_git_secure.auth_header, - verify=str(docker_git_secure.cacerts), + f"https://{git_secure.endpoint}/", + headers=git_secure.auth_header, + verify=str(git_secure.cacerts), ) assert response.status_code == 200 assert response.content == b"pytest-docker-git-fixtures-docker\n" ``` -It is possible to use both singular and enumerated fixtures within the same test context; however, the same values will be returned for the singular fixture as the first enumerated list value (i.e. docker_git_secure == docker_git_secure_list[0]). To avoid complications with lower layers, mainly docker-compose, and to allow for this interchangeability, caching is used internally. +It is possible to use both singular and enumerated fixtures within the same test context; however, the same values will be returned for the singular fixture as the first enumerated list value (i.e. git_secure == git_secure_list[0]). To avoid complications with lower layers, mainly docker-compose, and to allow for this interchangeability, caching is used internally. -By default, the scale factor of the enumerated instances is set to one (n=1). This value can be changed by overriding the `pdrf_scale_factor` fixture, as follows: +By default, the scale factor of the enumerated instances is set to one (n=1). This value can be changed by overriding the `pdgf_scale_factor` fixture, as follows: ```python import pytest @pytest.fixture(scope="session") -def pdrf_scale_factor() -> int: +def pdgf_scale_factor() -> int: return 4 ``` -This fixture will be used to scale both the insecure and secure docker GIT SCMs. +This fixture will be used to scale both the insecure and secure GIT SCMs. ## Limitations 1. All the fixtures provided by this package are session scoped; and will only be executed once per test execution. -2. The `create_repo`, and `mirror_repo` markers are processed as part of the `docker_git_insecure` and `docker_git_secure` fixtures. As such: +2. The `create_repo`, and `mirror_repo` markers are processed as part of the `git_insecure` and `git_secure` fixtures. As such: * _all_ markers will be aggregated during initialization of the session, and processed prior test execution. - * Initialized and mirror repositories will be applied to both the insecure and secure docker GIT SCMs, if both are instantiated. -3. At most 10 insecure and 10 secure docker GIT SCMs are supported using the embedded docker compose. -4. It is not currently possible to specify into which enumerated SCM instances repositories should be applied. As such, and for backwards compatibility, they will only be applied into the first instance of each of the insecure and secure docker GIT SCMs. + * Initialized and mirror repositories will be applied to both the insecure and secure GIT SCMs, if both are instantiated. +3. At most 10 insecure and 10 secure GIT SCMs are supported using the embedded docker compose. +4. It is not currently possible to specify into which enumerated SCM instances repositories should be applied. As such, and for backwards compatibility, they will only be applied into the first instance of each of the insecure and secure GIT SCMs. ## Development diff --git a/pytest_docker_git_fixtures/fixtures.py b/pytest_docker_git_fixtures/fixtures.py index c741b7f..bbacf39 100644 --- a/pytest_docker_git_fixtures/fixtures.py +++ b/pytest_docker_git_fixtures/fixtures.py @@ -41,7 +41,7 @@ LOGGER = logging.getLogger(__name__) -class DockerGITCerts(NamedTuple): +class GITCerts(NamedTuple): # pylint: disable=missing-class-docstring ca_certificate: Path ca_private_key: Path @@ -49,7 +49,7 @@ class DockerGITCerts(NamedTuple): private_key: Path -class DockerGITInsecure(NamedTuple): +class GITInsecure(NamedTuple): # pylint: disable=missing-class-docstring created_repos: List[str] docker_compose: Path @@ -59,11 +59,11 @@ class DockerGITInsecure(NamedTuple): # Note: NamedTuple does not support inheritance :( -class DockerGITSecure(NamedTuple): +class GITSecure(NamedTuple): # pylint: disable=missing-class-docstring auth_header: Dict[str, str] cacerts: Path - certs: DockerGITCerts + certs: GITCerts created_repos: List[str] docker_compose: Path endpoint: str @@ -75,153 +75,21 @@ class DockerGITSecure(NamedTuple): username: str -def _docker_compose_insecure( +def _git_auth_header( *, - docker_compose_files: List[str], - scale_factor: int, - tmp_path_factory: TempPathFactory, -) -> Generator[List[Path], None, None]: - """ - Provides the location of the docker-compose configuration file containing the insecure docker GIT service. - """ - cache_key = _docker_compose_insecure.__name__ - result = CACHE.get(cache_key, []) - for i in range(scale_factor): - if i < len(result): - continue - - service_name = DOCKER_GIT_SERVICE_PATTERN.format("insecure", i) - chain = itertools.chain( - get_docker_compose_user_defined(docker_compose_files, service_name), - # TODO: lovely-docker-compose uses the file for teardown ... - get_embedded_file( - tmp_path_factory, delete_after=False, name="docker-compose.yml" - ), - ) - for path in chain: - result.append(path) - break - else: - LOGGER.warning("Unable to find docker compose for: %s", service_name) - result.append("-unknown-") - CACHE[cache_key] = result - yield result - - -@pytest.fixture(scope="session") -def docker_compose_insecure( - docker_compose_files: List[str], tmp_path_factory: TempPathFactory -) -> Generator[Path, None, None]: - """ - Provides the location of the docker-compose configuration file containing the insecure docker GIT service. - """ - for lst in _docker_compose_insecure( - docker_compose_files=docker_compose_files, - scale_factor=1, - tmp_path_factory=tmp_path_factory, - ): - yield lst[0] - - -@pytest.fixture(scope="session") -def docker_compose_insecure_list( - docker_compose_files: List[str], - pdrf_scale_factor: int, - tmp_path_factory: TempPathFactory, -) -> Generator[List[Path], None, None]: - """ - Provides the location of the docker-compose configuration file containing the insecure docker GIT service. - """ - yield from _docker_compose_insecure( - docker_compose_files=docker_compose_files, - scale_factor=pdrf_scale_factor, - tmp_path_factory=tmp_path_factory, - ) - - -def _docker_compose_secure( - *, - docker_compose_files: List[str], - scale_factor: int, - tmp_path_factory: TempPathFactory, -) -> Generator[List[Path], None, None]: - """ - Provides the location of the templated docker-compose configuration file containing the secure docker GIT - service. - """ - cache_key = _docker_compose_secure.__name__ - result = CACHE.get(cache_key, []) - for i in range(scale_factor): - if i < len(result): - continue - - service_name = DOCKER_GIT_SERVICE_PATTERN.format("secure", i) - chain = itertools.chain( - get_docker_compose_user_defined(docker_compose_files, service_name), - get_embedded_file( - tmp_path_factory, delete_after=False, name="docker-compose.yml" - ), - ) - for path in chain: - result.append(path) - break - else: - LOGGER.warning("Unable to find docker compose for: %s", service_name) - result.append("-unknown-") - CACHE[cache_key] = result - yield result - - -@pytest.fixture(scope="session") -def docker_compose_secure( - docker_compose_files: List[str], tmp_path_factory: TempPathFactory -) -> Generator[Path, None, None]: - """ - Provides the location of the templated docker-compose configuration file containing the secure docker GIT - service. - """ - for lst in _docker_compose_secure( - docker_compose_files=docker_compose_files, - scale_factor=1, - tmp_path_factory=tmp_path_factory, - ): - yield lst[0] - - -@pytest.fixture(scope="session") -def docker_compose_secure_list( - docker_compose_files: List[str], - pdrf_scale_factor: int, - tmp_path_factory: TempPathFactory, -) -> Generator[List[Path], None, None]: - """ - Provides the location of the templated docker-compose configuration file containing the secure docker GIT - service. - """ - yield from _docker_compose_secure( - docker_compose_files=docker_compose_files, - scale_factor=pdrf_scale_factor, - tmp_path_factory=tmp_path_factory, - ) - - -def _docker_git_auth_header( - *, - docker_git_password_list: List[str], - docker_git_username_list: List[str], + git_password_list: List[str], + git_username_list: List[str], scale_factor: int, ) -> List[Dict[str, str]]: - """Provides an HTTP basic authentication header containing credentials for the secure docker GIT service.""" - cache_key = _docker_git_auth_header.__name__ + """Provides an HTTP basic authentication header containing credentials for the secure GIT service.""" + cache_key = _git_auth_header.__name__ result = CACHE.get(cache_key, []) for i in range(scale_factor): if i < len(result): continue auth = b64encode( - f"{docker_git_username_list[i]}:{docker_git_password_list[i]}".encode( - "utf-8" - ) + f"{git_username_list[i]}:{git_password_list[i]}".encode("utf-8") ).decode("utf-8") result.append({"Authorization": f"Basic {auth}"}) CACHE[cache_key] = result @@ -229,34 +97,32 @@ def _docker_git_auth_header( @pytest.fixture(scope="session") -def docker_git_auth_header( - docker_git_password: str, docker_git_username: str -) -> Dict[str, str]: - """Provides an HTTP basic authentication header containing credentials for the secure docker GIT service.""" - return _docker_git_auth_header( - docker_git_password_list=[docker_git_password], - docker_git_username_list=[docker_git_username], +def git_auth_header(git_password: str, git_username: str) -> Dict[str, str]: + """Provides an HTTP basic authentication header containing credentials for the secure GIT service.""" + return _git_auth_header( + git_password_list=[git_password], + git_username_list=[git_username], scale_factor=1, )[0] @pytest.fixture(scope="session") -def docker_git_auth_header_list( - docker_git_password_list: List[str], - docker_git_username_list: List[str], - pdrf_scale_factor: int, +def git_auth_header_list( + git_password_list: List[str], + git_username_list: List[str], + pdgf_scale_factor: int, ) -> List[Dict[str, str]]: - """Provides an HTTP basic authentication header containing credentials for the secure docker GIT service.""" - return _docker_git_auth_header( - docker_git_password_list=docker_git_password_list, - docker_git_username_list=docker_git_username_list, - scale_factor=pdrf_scale_factor, + """Provides an HTTP basic authentication header containing credentials for the secure GIT service.""" + return _git_auth_header( + git_password_list=git_password_list, + git_username_list=git_username_list, + scale_factor=pdgf_scale_factor, ) -def _docker_git_cacerts( +def _git_cacerts( *, - docker_git_certs_list: List[DockerGITCerts], + git_certs_list: List[GITCerts], pytestconfig: "_pytest.config.Config", scale_factor: int, tmp_path_factory: TempPathFactory, @@ -265,7 +131,7 @@ def _docker_git_cacerts( Provides the location of a temporary CA certificate trust store that contains the certificate of the secure docker GIT service. """ - cache_key = _docker_git_cacerts.__name__ + cache_key = _git_cacerts.__name__ result = CACHE.get(cache_key, []) for i in range(scale_factor): if i < len(result): @@ -275,7 +141,7 @@ def _docker_git_cacerts( get_user_defined_file(pytestconfig, "cacerts"), generate_cacerts( tmp_path_factory, - certificate=docker_git_certs_list[i].ca_certificate, + certificate=git_certs_list[i].ca_certificate, ), ) for path in chain: @@ -289,8 +155,8 @@ def _docker_git_cacerts( @pytest.fixture(scope="session") -def docker_git_cacerts( - docker_git_certs: DockerGITCerts, +def git_cacerts( + git_certs: GITCerts, pytestconfig: "_pytest.config.Config", tmp_path_factory: TempPathFactory, ) -> Generator[Path, None, None]: @@ -298,8 +164,8 @@ def docker_git_cacerts( Provides the location of a temporary CA certificate trust store that contains the certificate of the secure docker GIT service. """ - for lst in _docker_git_cacerts( - docker_git_certs_list=[docker_git_certs], + for lst in _git_cacerts( + git_certs_list=[git_certs], pytestconfig=pytestconfig, scale_factor=1, tmp_path_factory=tmp_path_factory, @@ -308,9 +174,9 @@ def docker_git_cacerts( @pytest.fixture(scope="session") -def docker_git_cacerts_list( - docker_git_certs_list: List[DockerGITCerts], - pdrf_scale_factor: int, +def git_cacerts_list( + git_certs_list: List[GITCerts], + pdgf_scale_factor: int, pytestconfig: "_pytest.config.Config", tmp_path_factory: TempPathFactory, ) -> Generator[List[Path], None, None]: @@ -318,20 +184,20 @@ def docker_git_cacerts_list( Provides the location of a temporary CA certificate trust store that contains the certificate of the secure docker GIT service. """ - yield from _docker_git_cacerts( - docker_git_certs_list=docker_git_certs_list, + yield from _git_cacerts( + git_certs_list=git_certs_list, pytestconfig=pytestconfig, - scale_factor=pdrf_scale_factor, + scale_factor=pdgf_scale_factor, tmp_path_factory=tmp_path_factory, ) -def _docker_git_certs( +def _git_certs( *, scale_factor: int, tmp_path_factory: TempPathFactory -) -> Generator[List[DockerGITCerts], None, None]: - """Provides the location of temporary certificate and private key files for the secure docker GIT service.""" +) -> Generator[List[GITCerts], None, None]: + """Provides the location of temporary certificate and private key files for the secure GIT service.""" # TODO: Augment to allow for reading certificates from /test ... - cache_key = _docker_git_certs.__name__ + cache_key = _git_certs.__name__ result = CACHE.get(cache_key, []) for i in range(scale_factor): if i < len(result): @@ -339,55 +205,55 @@ def _docker_git_certs( tmp_path = tmp_path_factory.mktemp(__name__) keypair = generate_keypair() - docker_git_cert = DockerGITCerts( + git_cert = GITCerts( ca_certificate=tmp_path.joinpath(f"{DOCKER_GIT_SERVICE}-ca-{i}.crt"), ca_private_key=tmp_path.joinpath(f"{DOCKER_GIT_SERVICE}-ca-{i}.key"), certificate=tmp_path.joinpath(f"{DOCKER_GIT_SERVICE}-{i}.crt"), private_key=tmp_path.joinpath(f"{DOCKER_GIT_SERVICE}-{i}.key"), ) - docker_git_cert.ca_certificate.write_bytes(keypair.ca_certificate) - docker_git_cert.ca_private_key.write_bytes(keypair.ca_private_key) - docker_git_cert.certificate.write_bytes(keypair.certificate) - docker_git_cert.private_key.write_bytes(keypair.private_key) - result.append(docker_git_cert) + git_cert.ca_certificate.write_bytes(keypair.ca_certificate) + git_cert.ca_private_key.write_bytes(keypair.ca_private_key) + git_cert.certificate.write_bytes(keypair.certificate) + git_cert.private_key.write_bytes(keypair.private_key) + result.append(git_cert) CACHE[cache_key] = result yield result - for docker_git_cert in result: - docker_git_cert.ca_certificate.unlink(missing_ok=True) - docker_git_cert.ca_private_key.unlink(missing_ok=True) - docker_git_cert.certificate.unlink(missing_ok=True) - docker_git_cert.private_key.unlink(missing_ok=True) + for git_cert in result: + git_cert.ca_certificate.unlink(missing_ok=True) + git_cert.ca_private_key.unlink(missing_ok=True) + git_cert.certificate.unlink(missing_ok=True) + git_cert.private_key.unlink(missing_ok=True) @pytest.fixture(scope="session") -def docker_git_certs( +def git_certs( tmp_path_factory: TempPathFactory, -) -> Generator[DockerGITCerts, None, None]: - """Provides the location of temporary certificate and private key files for the secure docker GIT service.""" - for lst in _docker_git_certs(scale_factor=1, tmp_path_factory=tmp_path_factory): +) -> Generator[GITCerts, None, None]: + """Provides the location of temporary certificate and private key files for the secure GIT service.""" + for lst in _git_certs(scale_factor=1, tmp_path_factory=tmp_path_factory): yield lst[0] @pytest.fixture(scope="session") -def docker_git_certs_list( - pdrf_scale_factor: int, tmp_path_factory: TempPathFactory -) -> Generator[List[DockerGITCerts], None, None]: - """Provides the location of temporary certificate and private key files for the secure docker GIT service.""" - yield from _docker_git_certs( - scale_factor=pdrf_scale_factor, tmp_path_factory=tmp_path_factory +def git_certs_list( + pdgf_scale_factor: int, tmp_path_factory: TempPathFactory +) -> Generator[List[GITCerts], None, None]: + """Provides the location of temporary certificate and private key files for the secure GIT service.""" + yield from _git_certs( + scale_factor=pdgf_scale_factor, tmp_path_factory=tmp_path_factory ) -def _docker_git_htpasswd( +def _git_htpasswd( *, - docker_git_password_list: List[str], - docker_git_username_list: List[str], + git_password_list: List[str], + git_username_list: List[str], pytestconfig: "_pytest.config.Config", scale_factor: int, tmp_path_factory: TempPathFactory, ) -> Generator[List[Path], None, None]: """Provides the location of the htpasswd file for the secure GIT service.""" - cache_key = _docker_git_htpasswd.__name__ + cache_key = _git_htpasswd.__name__ result = CACHE.get(cache_key, []) for i in range(scale_factor): if i < len(result): @@ -397,8 +263,8 @@ def _docker_git_htpasswd( get_user_defined_file(pytestconfig, "htpasswd"), generate_htpasswd( tmp_path_factory, - username=docker_git_username_list[i], - password=docker_git_password_list[i], + username=git_username_list[i], + password=git_password_list[i], ), ) for path in chain: @@ -412,16 +278,16 @@ def _docker_git_htpasswd( @pytest.fixture(scope="session") -def docker_git_htpasswd( - docker_git_password: str, - docker_git_username: str, +def git_htpasswd( + git_password: str, + git_username: str, pytestconfig: "_pytest.config.Config", tmp_path_factory: TempPathFactory, ) -> Generator[Path, None, None]: """Provides the location of the htpasswd file for the secure GIT service.""" - for lst in _docker_git_htpasswd( - docker_git_password_list=[docker_git_password], - docker_git_username_list=[docker_git_username], + for lst in _git_htpasswd( + git_password_list=[git_password], + git_username_list=[git_username], pytestconfig=pytestconfig, scale_factor=1, tmp_path_factory=tmp_path_factory, @@ -430,33 +296,33 @@ def docker_git_htpasswd( @pytest.fixture(scope="session") -def docker_git_htpasswd_list( - docker_git_password_list: List[str], - docker_git_username_list: List[str], - pdrf_scale_factor: int, +def git_htpasswd_list( + git_password_list: List[str], + git_username_list: List[str], + pdgf_scale_factor: int, pytestconfig: "_pytest.config.Config", tmp_path_factory: TempPathFactory, ) -> Generator[List[Path], None, None]: """Provides the location of the htpasswd file for the secure GIT service.""" - yield from _docker_git_htpasswd( - docker_git_username_list=docker_git_username_list, - docker_git_password_list=docker_git_password_list, + yield from _git_htpasswd( + git_username_list=git_username_list, + git_password_list=git_password_list, pytestconfig=pytestconfig, - scale_factor=pdrf_scale_factor, + scale_factor=pdgf_scale_factor, tmp_path_factory=tmp_path_factory, ) -def _docker_git_insecure( +def _git_insecure( *, docker_compose_insecure_list: List[Path], docker_services: Services, request, scale_factor: int, tmp_path_factory: TempPathFactory, -) -> Generator[List[DockerGITInsecure], None, None]: - """Provides the endpoint of a local, mutable, insecure, docker GIT SCM.""" - cache_key = _docker_git_insecure.__name__ +) -> Generator[List[GITInsecure], None, None]: + """Provides the endpoint of a local, mutable, insecure, GIT SCM.""" + cache_key = _git_insecure.__name__ result = CACHE.get(cache_key, []) for i in range(scale_factor): if i < len(result): @@ -496,7 +362,7 @@ def _docker_git_insecure( "utf-8", ) - LOGGER.debug("Starting insecure docker GIT service [%d] ...", i) + LOGGER.debug("Starting insecure GIT service [%d] ...", i) LOGGER.debug(" docker-compose : %s", path_docker_compose) LOGGER.debug(" service name : %s", service_name) endpoint = start_service( @@ -505,10 +371,10 @@ def _docker_git_insecure( port=80, service_name=service_name, ) - LOGGER.debug("Insecure docker GIT endpoint [%d]: %s", i, endpoint) + LOGGER.debug("Insecure GIT endpoint [%d]: %s", i, endpoint) result.append( - DockerGITInsecure( + GITInsecure( created_repos=create_repos, docker_compose=path_docker_compose, endpoint=endpoint, @@ -521,15 +387,15 @@ def _docker_git_insecure( @pytest.fixture(scope="session") -def docker_git_insecure( - docker_compose_insecure: Path, +def git_insecure( docker_services: Services, + pdgf_docker_compose_insecure: Path, request, tmp_path_factory: TempPathFactory, -) -> Generator[DockerGITInsecure, None, None]: - """Provides the endpoint of a local, mutable, insecure, docker GIT SCM.""" - for lst in _docker_git_insecure( - docker_compose_insecure_list=[docker_compose_insecure], +) -> Generator[GITInsecure, None, None]: + """Provides the endpoint of a local, mutable, insecure, GIT SCM.""" + for lst in _git_insecure( + docker_compose_insecure_list=[pdgf_docker_compose_insecure], docker_services=docker_services, request=request, scale_factor=1, @@ -539,26 +405,26 @@ def docker_git_insecure( @pytest.fixture(scope="session") -def docker_git_insecure_list( - docker_compose_insecure_list: List[Path], +def git_insecure_list( docker_services: Services, - pdrf_scale_factor: int, + pdgf_docker_compose_insecure_list: List[Path], + pdgf_scale_factor: int, request, tmp_path_factory: TempPathFactory, -) -> Generator[List[DockerGITInsecure], None, None]: - """Provides the endpoint of a local, mutable, insecure, docker GIT SCM.""" - yield from _docker_git_insecure( - docker_compose_insecure_list=docker_compose_insecure_list, +) -> Generator[List[GITInsecure], None, None]: + """Provides the endpoint of a local, mutable, insecure, GIT SCM.""" + yield from _git_insecure( + docker_compose_insecure_list=pdgf_docker_compose_insecure_list, docker_services=docker_services, request=request, - scale_factor=pdrf_scale_factor, + scale_factor=pdgf_scale_factor, tmp_path_factory=tmp_path_factory, ) -def _docker_git_password(*, scale_factor: int) -> List[str]: +def _git_password(*, scale_factor: int) -> List[str]: """Provides the password to use for authentication to the secure GIT service.""" - cache_key = _docker_git_password.__name__ + cache_key = _git_password.__name__ result = CACHE.get(cache_key, []) for i in range(scale_factor): if i < len(result): @@ -571,34 +437,34 @@ def _docker_git_password(*, scale_factor: int) -> List[str]: @pytest.fixture(scope="session") -def docker_git_password() -> str: +def git_password() -> str: """Provides the password to use for authentication to the secure GIT service.""" - return _docker_git_password(scale_factor=1)[0] + return _git_password(scale_factor=1)[0] @pytest.fixture(scope="session") -def docker_git_password_list(pdrf_scale_factor: int) -> List[str]: +def git_password_list(pdgf_scale_factor: int) -> List[str]: """Provides the password to use for authentication to the secure GIT service.""" - return _docker_git_password(scale_factor=pdrf_scale_factor) + return _git_password(scale_factor=pdgf_scale_factor) -def _docker_git_secure( +def _git_secure( *, docker_compose_secure_list: List[Path], - docker_git_auth_header_list: List[Dict[str, str]], - docker_git_cacerts_list: List[Path], - docker_git_certs_list: List[DockerGITCerts], - docker_git_htpasswd_list: List[Path], - docker_git_password_list: List[str], - docker_git_ssl_context_list: List[SSLContext], - docker_git_username_list: List[str], docker_services: Services, + git_auth_header_list: List[Dict[str, str]], + git_cacerts_list: List[Path], + git_certs_list: List[GITCerts], + git_htpasswd_list: List[Path], + git_password_list: List[str], + git_ssl_context_list: List[SSLContext], + git_username_list: List[str], request, scale_factor: int, tmp_path_factory: TempPathFactory, -) -> Generator[List[DockerGITSecure], None, None]: - """Provides the endpoint of a local, mutable, secure, docker GIT SCM.""" - cache_key = _docker_git_secure.__name__ +) -> Generator[List[GITSecure], None, None]: + """Provides the endpoint of a local, mutable, secure, GIT SCM.""" + cache_key = _git_secure.__name__ result = CACHE.get(cache_key, []) for i in range(scale_factor): if i < len(result): @@ -626,9 +492,9 @@ def _docker_git_secure( template.substitute( { "CONTAINER_NAME": service_name, - "PATH_CERTIFICATE": docker_git_certs_list[i].certificate, - "PATH_HTPASSWD": docker_git_htpasswd_list[i], - "PATH_KEY": docker_git_certs_list[i].private_key, + "PATH_CERTIFICATE": git_certs_list[i].certificate, + "PATH_HTPASSWD": git_htpasswd_list[i], + "PATH_KEY": git_certs_list[i].private_key, "PDGF_CREATE_REPOS": ",".join(create_repos), "PDGF_MIRROR_REPOS": ",".join(mirror_repos), } @@ -636,20 +502,20 @@ def _docker_git_secure( "utf-8", ) - LOGGER.debug("Starting secure docker GIT service [%d] ...", i) + LOGGER.debug("Starting secure GIT service [%d] ...", i) LOGGER.debug(" docker-compose : %s", path_docker_compose) - LOGGER.debug(" ca certificate : %s", docker_git_certs_list[i].ca_certificate) - LOGGER.debug(" certificate : %s", docker_git_certs_list[i].certificate) - LOGGER.debug(" htpasswd : %s", docker_git_htpasswd_list[i]) - LOGGER.debug(" private key : %s", docker_git_certs_list[i].private_key) - LOGGER.debug(" password : %s", docker_git_password_list[i]) + LOGGER.debug(" ca certificate : %s", git_certs_list[i].ca_certificate) + LOGGER.debug(" certificate : %s", git_certs_list[i].certificate) + LOGGER.debug(" htpasswd : %s", git_htpasswd_list[i]) + LOGGER.debug(" private key : %s", git_certs_list[i].private_key) + LOGGER.debug(" password : %s", git_password_list[i]) LOGGER.debug(" service name : %s", service_name) - LOGGER.debug(" username : %s", docker_git_username_list[i]) + LOGGER.debug(" username : %s", git_username_list[i]) check_server = partial( check_url_secure, - auth_header=docker_git_auth_header_list[i], - ssl_context=docker_git_ssl_context_list[i], + auth_header=git_auth_header_list[i], + ssl_context=git_ssl_context_list[i], ) endpoint = start_service( docker_services, @@ -658,22 +524,22 @@ def _docker_git_secure( port=443, service_name=service_name, ) - LOGGER.debug("Secure docker GIT endpoint [%d]: %s", i, endpoint) + LOGGER.debug("Secure GIT endpoint [%d]: %s", i, endpoint) result.append( - DockerGITSecure( - auth_header=docker_git_auth_header_list[i], - cacerts=docker_git_cacerts_list[i], - certs=docker_git_certs_list[i], + GITSecure( + auth_header=git_auth_header_list[i], + cacerts=git_cacerts_list[i], + certs=git_certs_list[i], created_repos=create_repos, docker_compose=path_docker_compose, endpoint=endpoint, - htpasswd=docker_git_htpasswd_list[i], + htpasswd=git_htpasswd_list[i], mirrored_repos=mirror_repos, - password=docker_git_password_list[i], + password=git_password_list[i], service_name=service_name, - ssl_context=docker_git_ssl_context_list[i], - username=docker_git_username_list[i], + ssl_context=git_ssl_context_list[i], + username=git_username_list[i], ) ) CACHE[cache_key] = result @@ -681,29 +547,29 @@ def _docker_git_secure( @pytest.fixture(scope="session") -def docker_git_secure( - docker_compose_secure: Path, - docker_git_auth_header: Dict[str, str], - docker_git_cacerts: Path, - docker_git_certs: DockerGITCerts, - docker_git_htpasswd: Path, - docker_git_password: str, - docker_git_ssl_context: SSLContext, - docker_git_username: str, +def git_secure( docker_services: Services, + git_auth_header: Dict[str, str], + git_cacerts: Path, + git_certs: GITCerts, + git_htpasswd: Path, + git_password: str, + git_ssl_context: SSLContext, + git_username: str, + pdgf_docker_compose_secure: Path, request, tmp_path_factory: TempPathFactory, -) -> Generator[DockerGITSecure, None, None]: - """Provides the endpoint of a local, mutable, secure, docker GIT SCM.""" - for lst in _docker_git_secure( - docker_compose_secure_list=[docker_compose_secure], - docker_git_auth_header_list=[docker_git_auth_header], - docker_git_cacerts_list=[docker_git_cacerts], - docker_git_certs_list=[docker_git_certs], - docker_git_htpasswd_list=[docker_git_htpasswd], - docker_git_password_list=[docker_git_password], - docker_git_ssl_context_list=[docker_git_ssl_context], - docker_git_username_list=[docker_git_username], +) -> Generator[GITSecure, None, None]: + """Provides the endpoint of a local, mutable, secure, GIT SCM.""" + for lst in _git_secure( + docker_compose_secure_list=[pdgf_docker_compose_secure], + git_auth_header_list=[git_auth_header], + git_cacerts_list=[git_cacerts], + git_certs_list=[git_certs], + git_htpasswd_list=[git_htpasswd], + git_password_list=[git_password], + git_ssl_context_list=[git_ssl_context], + git_username_list=[git_username], docker_services=docker_services, request=request, scale_factor=1, @@ -713,84 +579,82 @@ def docker_git_secure( @pytest.fixture(scope="session") -def docker_git_secure_list( - docker_compose_secure_list: List[Path], - docker_git_auth_header_list: List[Dict[str, str]], - docker_git_cacerts_list: List[Path], - docker_git_certs_list: List[DockerGITCerts], - docker_git_htpasswd_list: List[Path], - docker_git_password_list: List[str], - docker_git_ssl_context_list: List[SSLContext], - docker_git_username_list: List[str], +def git_secure_list( docker_services: Services, - pdrf_scale_factor: int, + git_auth_header_list: List[Dict[str, str]], + git_cacerts_list: List[Path], + git_certs_list: List[GITCerts], + git_htpasswd_list: List[Path], + git_password_list: List[str], + git_ssl_context_list: List[SSLContext], + git_username_list: List[str], + pdgf_docker_compose_secure_list: List[Path], + pdgf_scale_factor: int, request, tmp_path_factory: TempPathFactory, -) -> Generator[List[DockerGITSecure], None, None]: - """Provides the endpoint of a local, mutable, secure, docker GIT SCM.""" - yield from _docker_git_secure( - docker_compose_secure_list=docker_compose_secure_list, - docker_git_auth_header_list=docker_git_auth_header_list, - docker_git_cacerts_list=docker_git_cacerts_list, - docker_git_certs_list=docker_git_certs_list, - docker_git_htpasswd_list=docker_git_htpasswd_list, - docker_git_password_list=docker_git_password_list, - docker_git_ssl_context_list=docker_git_ssl_context_list, - docker_git_username_list=docker_git_username_list, +) -> Generator[List[GITSecure], None, None]: + """Provides the endpoint of a local, mutable, secure, GIT SCM.""" + yield from _git_secure( + docker_compose_secure_list=pdgf_docker_compose_secure_list, + git_auth_header_list=git_auth_header_list, + git_cacerts_list=git_cacerts_list, + git_certs_list=git_certs_list, + git_htpasswd_list=git_htpasswd_list, + git_password_list=git_password_list, + git_ssl_context_list=git_ssl_context_list, + git_username_list=git_username_list, docker_services=docker_services, - scale_factor=pdrf_scale_factor, + scale_factor=pdgf_scale_factor, request=request, tmp_path_factory=tmp_path_factory, ) -def _docker_git_ssl_context( - *, docker_git_cacerts_list: List[Path], scale_factor: int +def _git_ssl_context( + *, git_cacerts_list: List[Path], scale_factor: int ) -> List[SSLContext]: """ Provides an SSLContext referencing the temporary CA certificate trust store that contains the certificate of the - secure docker GIT service. + secure GIT service. """ - cache_key = _docker_git_ssl_context.__name__ + cache_key = _git_ssl_context.__name__ result = CACHE.get(cache_key, []) for i in range(scale_factor): if i < len(result): continue - result.append(create_default_context(cafile=str(docker_git_cacerts_list[i]))) + result.append(create_default_context(cafile=str(git_cacerts_list[i]))) CACHE[cache_key] = result return result @pytest.fixture(scope="session") -def docker_git_ssl_context(docker_git_cacerts: Path) -> SSLContext: +def git_ssl_context(git_cacerts: Path) -> SSLContext: """ Provides an SSLContext referencing the temporary CA certificate trust store that contains the certificate of the - secure docker GIT service. + secure GIT service. """ - return _docker_git_ssl_context( - docker_git_cacerts_list=[docker_git_cacerts], scale_factor=1 - )[0] + return _git_ssl_context(git_cacerts_list=[git_cacerts], scale_factor=1)[0] @pytest.fixture(scope="session") -def docker_git_ssl_context_list( - docker_git_cacerts_list: List[Path], - pdrf_scale_factor: int, +def git_ssl_context_list( + git_cacerts_list: List[Path], + pdgf_scale_factor: int, ) -> List[SSLContext]: """ Provides an SSLContext referencing the temporary CA certificate trust store that contains the certificate of the - secure docker GIT service. + secure GIT service. """ - return _docker_git_ssl_context( - docker_git_cacerts_list=docker_git_cacerts_list, - scale_factor=pdrf_scale_factor, + return _git_ssl_context( + git_cacerts_list=git_cacerts_list, + scale_factor=pdgf_scale_factor, ) -def _docker_git_username(*, scale_factor: int) -> List[str]: +def _git_username(*, scale_factor: int) -> List[str]: """Retrieve the name of the user to use for authentication to the secure GIT service.""" - cache_key = _docker_git_username.__name__ + cache_key = _git_username.__name__ result = CACHE.get(cache_key, []) for i in range(scale_factor): if i < len(result): @@ -803,21 +667,151 @@ def _docker_git_username(*, scale_factor: int) -> List[str]: @pytest.fixture(scope="session") -def docker_git_username() -> str: +def git_username() -> str: """Retrieve the name of the user to use for authentication to the secure GIT service.""" - return _docker_git_username(scale_factor=1)[0] + return _git_username(scale_factor=1)[0] @pytest.fixture(scope="session") -def docker_git_username_list( - pdrf_scale_factor: int, +def git_username_list( + pdgf_scale_factor: int, ) -> List[str]: """Retrieve the name of the user to use for authentication to the secure GIT service.""" - return _docker_git_username(scale_factor=pdrf_scale_factor) + return _git_username(scale_factor=pdgf_scale_factor) + + +def _pdgf_docker_compose_insecure( + *, + docker_compose_files: List[str], + scale_factor: int, + tmp_path_factory: TempPathFactory, +) -> Generator[List[Path], None, None]: + """ + Provides the location of the docker-compose configuration file containing the insecure GIT service. + """ + cache_key = _pdgf_docker_compose_insecure.__name__ + result = CACHE.get(cache_key, []) + for i in range(scale_factor): + if i < len(result): + continue + + service_name = DOCKER_GIT_SERVICE_PATTERN.format("insecure", i) + chain = itertools.chain( + get_docker_compose_user_defined(docker_compose_files, service_name), + # TODO: lovely-docker-compose uses the file for teardown ... + get_embedded_file( + tmp_path_factory, delete_after=False, name="docker-compose.yml" + ), + ) + for path in chain: + result.append(path) + break + else: + LOGGER.warning("Unable to find docker compose for: %s", service_name) + result.append("-unknown-") + CACHE[cache_key] = result + yield result + + +@pytest.fixture(scope="session") +def pdgf_docker_compose_insecure( + docker_compose_files: List[str], tmp_path_factory: TempPathFactory +) -> Generator[Path, None, None]: + """ + Provides the location of the docker-compose configuration file containing the insecure GIT service. + """ + for lst in _pdgf_docker_compose_insecure( + docker_compose_files=docker_compose_files, + scale_factor=1, + tmp_path_factory=tmp_path_factory, + ): + yield lst[0] + + +@pytest.fixture(scope="session") +def pdgf_docker_compose_insecure_list( + docker_compose_files: List[str], + pdgf_scale_factor: int, + tmp_path_factory: TempPathFactory, +) -> Generator[List[Path], None, None]: + """ + Provides the location of the docker-compose configuration file containing the insecure GIT service. + """ + yield from _pdgf_docker_compose_insecure( + docker_compose_files=docker_compose_files, + scale_factor=pdgf_scale_factor, + tmp_path_factory=tmp_path_factory, + ) + + +def _pdgf_docker_compose_secure( + *, + docker_compose_files: List[str], + scale_factor: int, + tmp_path_factory: TempPathFactory, +) -> Generator[List[Path], None, None]: + """ + Provides the location of the templated docker-compose configuration file containing the secure GIT + service. + """ + cache_key = _pdgf_docker_compose_secure.__name__ + result = CACHE.get(cache_key, []) + for i in range(scale_factor): + if i < len(result): + continue + + service_name = DOCKER_GIT_SERVICE_PATTERN.format("secure", i) + chain = itertools.chain( + get_docker_compose_user_defined(docker_compose_files, service_name), + get_embedded_file( + tmp_path_factory, delete_after=False, name="docker-compose.yml" + ), + ) + for path in chain: + result.append(path) + break + else: + LOGGER.warning("Unable to find docker compose for: %s", service_name) + result.append("-unknown-") + CACHE[cache_key] = result + yield result + + +@pytest.fixture(scope="session") +def pdgf_docker_compose_secure( + docker_compose_files: List[str], tmp_path_factory: TempPathFactory +) -> Generator[Path, None, None]: + """ + Provides the location of the templated docker-compose configuration file containing the secure GIT + service. + """ + for lst in _pdgf_docker_compose_secure( + docker_compose_files=docker_compose_files, + scale_factor=1, + tmp_path_factory=tmp_path_factory, + ): + yield lst[0] + + +@pytest.fixture(scope="session") +def pdgf_docker_compose_secure_list( + docker_compose_files: List[str], + pdgf_scale_factor: int, + tmp_path_factory: TempPathFactory, +) -> Generator[List[Path], None, None]: + """ + Provides the location of the templated docker-compose configuration file containing the secure GIT + service. + """ + yield from _pdgf_docker_compose_secure( + docker_compose_files=docker_compose_files, + scale_factor=pdgf_scale_factor, + tmp_path_factory=tmp_path_factory, + ) @pytest.fixture(scope="session") -def pdrf_scale_factor() -> int: +def pdgf_scale_factor() -> int: """Provides the number enumerated instances to be instantiated.""" return 1 diff --git a/setup.py b/setup.py index 319e184..c35ca86 100755 --- a/setup.py +++ b/setup.py @@ -40,7 +40,7 @@ def find_version(*segments): "pytest", ], keywords="docker fixtures git pytest scm", - license="GNU General Public License v3.0", + license="Apache Software License", long_description=open("README.md", encoding="utf-8").read(), long_description_content_type="text/markdown", name="pytest_docker_git_fixtures", diff --git a/tests/test_fixtures.py b/tests/test_fixtures.py index 73dbceb..ad1674f 100644 --- a/tests/test_fixtures.py +++ b/tests/test_fixtures.py @@ -19,9 +19,9 @@ from _pytest.tmpdir import TempPathFactory from pytest_docker_git_fixtures import ( - DockerGITCerts, - DockerGITInsecure, - DockerGITSecure, + GITCerts, + GITInsecure, + GITSecure, DOCKER_GIT_SERVICE_PATTERN, ) from pytest_docker_git_fixtures.fixtures import _get_create_repo, _get_mirror_repo @@ -32,7 +32,7 @@ # Override fixture for testing @pytest.fixture(scope="session") -def pdrf_scale_factor() -> int: +def pdgf_scale_factor() -> int: """Provides the number enumerated instances to be instantiated.""" return 4 @@ -42,187 +42,149 @@ def no_duplicates(lst: List) -> bool: return len(lst) == len(set(lst)) -def test_docker_compose_insecure(docker_compose_insecure: Path): - """Test that the embedded docker-compose for insecure scms can be copied to a temporary file.""" - service_name = DOCKER_GIT_SERVICE_PATTERN.format("insecure", 0) - assert service_name in docker_compose_insecure.read_text() - - -def test_docker_compose_insecure_list( - docker_compose_insecure_list: List[Path], pdrf_scale_factor: int -): - """Test that the embedded docker-compose for insecure scms can be copied to a temporary file.""" - for i in range(pdrf_scale_factor): - service_name = DOCKER_GIT_SERVICE_PATTERN.format("insecure", i) - assert service_name in docker_compose_insecure_list[i].read_text() - assert no_duplicates(docker_compose_insecure_list) - - -def test_docker_compose_secure(docker_compose_secure: Path): - """Test that the embedded docker-compose for secure scms can be copied to a temporary file.""" - service_name = DOCKER_GIT_SERVICE_PATTERN.format("secure", 0) - assert service_name in docker_compose_secure.read_text() - - -def test_docker_compose_secure_list( - docker_compose_secure_list: List[Path], pdrf_scale_factor: int -): - """Test that the embedded docker-compose for secure scms can be copied to a temporary file.""" - for i in range(pdrf_scale_factor): - service_name = DOCKER_GIT_SERVICE_PATTERN.format("secure", i) - assert service_name in docker_compose_secure_list[i].read_text() - assert no_duplicates(docker_compose_secure_list) - - -def test_docker_git_auth_header( - docker_git_auth_header: Dict[str, str], - docker_git_password: str, - docker_git_username: str, +def test_git_auth_header( + git_auth_header: Dict[str, str], + git_password: str, + git_username: str, ): """Test that an HTTP basic authentication header can be provided.""" - assert "Authorization" in docker_git_auth_header + assert "Authorization" in git_auth_header string = b64decode( - docker_git_auth_header["Authorization"].split()[1].encode("utf-8") + git_auth_header["Authorization"].split()[1].encode("utf-8") ).decode("utf-8") - assert docker_git_password in string - assert docker_git_username in string + assert git_password in string + assert git_username in string -def test_docker_git_auth_header_list( - docker_git_auth_header_list: List[Dict[str, str]], - docker_git_password_list: List[str], - docker_git_username_list: List[str], - pdrf_scale_factor: int, +def test_git_auth_header_list( + git_auth_header_list: List[Dict[str, str]], + git_password_list: List[str], + git_username_list: List[str], + pdgf_scale_factor: int, ): """Test that an HTTP basic authentication header can be provided.""" - for i in range(pdrf_scale_factor): - assert "Authorization" in docker_git_auth_header_list[i] + for i in range(pdgf_scale_factor): + assert "Authorization" in git_auth_header_list[i] string = b64decode( - docker_git_auth_header_list[i]["Authorization"].split()[1].encode("utf-8") + git_auth_header_list[i]["Authorization"].split()[1].encode("utf-8") ).decode("utf-8") - assert docker_git_password_list[i] in string - assert docker_git_username_list[i] in string - assert no_duplicates([str(i) for i in docker_git_auth_header_list]) - assert no_duplicates(docker_git_password_list) - assert no_duplicates(docker_git_username_list) + assert git_password_list[i] in string + assert git_username_list[i] in string + assert no_duplicates([str(i) for i in git_auth_header_list]) + assert no_duplicates(git_password_list) + assert no_duplicates(git_username_list) -def test_docker_git_cacerts(docker_git_cacerts: Path, docker_git_certs: DockerGITCerts): +def test_git_cacerts(git_cacerts: Path, git_certs: GITCerts): """Test that a temporary CA certificate trust store can be provided.""" - assert docker_git_cacerts.exists() - cacerts = docker_git_cacerts.read_text("utf-8") + assert git_cacerts.exists() + cacerts = git_cacerts.read_text("utf-8") - ca_cert = docker_git_certs.ca_certificate.read_text("utf-8") + ca_cert = git_certs.ca_certificate.read_text("utf-8") assert ca_cert in cacerts - ca_key = docker_git_certs.ca_private_key.read_text("utf-8") + ca_key = git_certs.ca_private_key.read_text("utf-8") assert ca_key not in cacerts - cert = docker_git_certs.certificate.read_text("utf-8") + cert = git_certs.certificate.read_text("utf-8") assert cert not in cacerts - key = docker_git_certs.private_key.read_text("utf-8") + key = git_certs.private_key.read_text("utf-8") assert key not in cacerts -def test_docker_git_cacerts_list( - docker_git_cacerts_list: List[Path], - docker_git_certs_list: List[DockerGITCerts], - pdrf_scale_factor: int, +def test_git_cacerts_list( + git_cacerts_list: List[Path], + git_certs_list: List[GITCerts], + pdgf_scale_factor: int, ): """Test that a temporary CA certificate trust store can be provided.""" - for i in range(pdrf_scale_factor): - assert docker_git_cacerts_list[i].exists() - cacerts = docker_git_cacerts_list[i].read_text("utf-8") + for i in range(pdgf_scale_factor): + assert git_cacerts_list[i].exists() + cacerts = git_cacerts_list[i].read_text("utf-8") - ca_cert = docker_git_certs_list[i].ca_certificate.read_text("utf-8") + ca_cert = git_certs_list[i].ca_certificate.read_text("utf-8") assert ca_cert in cacerts - ca_key = docker_git_certs_list[i].ca_private_key.read_text("utf-8") + ca_key = git_certs_list[i].ca_private_key.read_text("utf-8") assert ca_key not in cacerts - cert = docker_git_certs_list[i].certificate.read_text("utf-8") + cert = git_certs_list[i].certificate.read_text("utf-8") assert cert not in cacerts - key = docker_git_certs_list[i].private_key.read_text("utf-8") + key = git_certs_list[i].private_key.read_text("utf-8") assert key not in cacerts - assert no_duplicates(docker_git_cacerts_list) - assert no_duplicates(docker_git_certs_list) + assert no_duplicates(git_cacerts_list) + assert no_duplicates(git_certs_list) -def test_docker_git_certs(docker_git_certs: DockerGITCerts): +def test_git_certs(git_certs: GITCerts): """Test that a certificate and private key can be provided.""" - assert docker_git_certs.ca_certificate.exists() - assert "BEGIN CERTIFICATE" in docker_git_certs.ca_certificate.read_text("utf-8") - assert docker_git_certs.ca_private_key.exists() - assert "BEGIN PRIVATE KEY" in docker_git_certs.ca_private_key.read_text("utf-8") - assert docker_git_certs.certificate.exists() - assert "BEGIN CERTIFICATE" in docker_git_certs.certificate.read_text("utf-8") - assert docker_git_certs.private_key.exists() - assert "BEGIN PRIVATE KEY" in docker_git_certs.private_key.read_text("utf-8") - - -def test_docker_git_certs_list( - docker_git_certs_list: List[DockerGITCerts], pdrf_scale_factor: int -): + assert git_certs.ca_certificate.exists() + assert "BEGIN CERTIFICATE" in git_certs.ca_certificate.read_text("utf-8") + assert git_certs.ca_private_key.exists() + assert "BEGIN PRIVATE KEY" in git_certs.ca_private_key.read_text("utf-8") + assert git_certs.certificate.exists() + assert "BEGIN CERTIFICATE" in git_certs.certificate.read_text("utf-8") + assert git_certs.private_key.exists() + assert "BEGIN PRIVATE KEY" in git_certs.private_key.read_text("utf-8") + + +def test_git_certs_list(git_certs_list: List[GITCerts], pdgf_scale_factor: int): """Test that a certificate and private key can be provided.""" - for i in range(pdrf_scale_factor): - assert docker_git_certs_list[i].ca_certificate.exists() - assert "BEGIN CERTIFICATE" in docker_git_certs_list[i].ca_certificate.read_text( - "utf-8" - ) - assert docker_git_certs_list[i].ca_private_key.exists() - assert "BEGIN PRIVATE KEY" in docker_git_certs_list[i].ca_private_key.read_text( + for i in range(pdgf_scale_factor): + assert git_certs_list[i].ca_certificate.exists() + assert "BEGIN CERTIFICATE" in git_certs_list[i].ca_certificate.read_text( "utf-8" ) - assert docker_git_certs_list[i].certificate.exists() - assert "BEGIN CERTIFICATE" in docker_git_certs_list[i].certificate.read_text( + assert git_certs_list[i].ca_private_key.exists() + assert "BEGIN PRIVATE KEY" in git_certs_list[i].ca_private_key.read_text( "utf-8" ) - assert docker_git_certs_list[i].private_key.exists() - assert "BEGIN PRIVATE KEY" in docker_git_certs_list[i].private_key.read_text( - "utf-8" - ) - assert no_duplicates(docker_git_certs_list) + assert git_certs_list[i].certificate.exists() + assert "BEGIN CERTIFICATE" in git_certs_list[i].certificate.read_text("utf-8") + assert git_certs_list[i].private_key.exists() + assert "BEGIN PRIVATE KEY" in git_certs_list[i].private_key.read_text("utf-8") + assert no_duplicates(git_certs_list) -def test_docker_git_htpasswd( - docker_git_htpasswd: Path, - docker_git_password: str, - docker_git_username: str, +def test_git_htpasswd( + git_htpasswd: Path, + git_password: str, + git_username: str, ): """Test that a htpasswd can be provided.""" - assert docker_git_htpasswd.exists() - content = docker_git_htpasswd.read_text("utf-8") - assert docker_git_username in content - assert docker_git_password not in content + assert git_htpasswd.exists() + content = git_htpasswd.read_text("utf-8") + assert git_username in content + assert git_password not in content -def test_docker_git_htpasswd_list( - docker_git_htpasswd_list: List[Path], - docker_git_password_list: List[str], - docker_git_username_list: List[str], - pdrf_scale_factor: int, +def test_git_htpasswd_list( + git_htpasswd_list: List[Path], + git_password_list: List[str], + git_username_list: List[str], + pdgf_scale_factor: int, ): """Test that a htpasswd can be provided.""" - for i in range(pdrf_scale_factor): - assert docker_git_htpasswd_list[i].exists() - content = docker_git_htpasswd_list[i].read_text("utf-8") - assert docker_git_username_list[i] in content - assert docker_git_password_list[i] not in content - assert no_duplicates(docker_git_htpasswd_list) - assert no_duplicates(docker_git_password_list) - assert no_duplicates(docker_git_username_list) + for i in range(pdgf_scale_factor): + assert git_htpasswd_list[i].exists() + content = git_htpasswd_list[i].read_text("utf-8") + assert git_username_list[i] in content + assert git_password_list[i] not in content + assert no_duplicates(git_htpasswd_list) + assert no_duplicates(git_password_list) + assert no_duplicates(git_username_list) -@pytest.mark.create_repo("test_docker_git_insecure") +@pytest.mark.create_repo("test_git_insecure") @pytest.mark.mirror_repo("https://github.com/crashvb/shim-bind.git") -def test_docker_git_insecure(docker_git_insecure: DockerGITInsecure, tmp_path: Path): +def test_git_insecure(git_insecure: GITInsecure, tmp_path: Path): """Test that an insecure docker git can be instantiated.""" - assert "127.0.0.1" in docker_git_insecure.endpoint + assert "127.0.0.1" in git_insecure.endpoint - uri_insecure = f"http://{docker_git_insecure.endpoint}/insecure/shim-bind.git" - uri_secure = f"http://{docker_git_insecure.endpoint}/secure/shim-bind.git" + uri_insecure = f"http://{git_insecure.endpoint}/insecure/shim-bind.git" + uri_secure = f"http://{git_insecure.endpoint}/secure/shim-bind.git" # Should not be able to clone from secure w/o credentials ... path = tmp_path.joinpath(f"cloned-repo-{time()}") @@ -271,29 +233,25 @@ def test_docker_git_insecure(docker_git_insecure: DockerGITInsecure, tmp_path: P @pytest.mark.online -def test_docker_git_insecure_list( - docker_git_insecure_list: List[DockerGITInsecure], - pdrf_scale_factor: int, +def test_git_insecure_list( + git_insecure_list: List[GITInsecure], + pdgf_scale_factor: int, tmp_path: Path, ): """Test that an insecure docker git can be instantiated.""" - for i in range(pdrf_scale_factor): - assert "127.0.0.1" in docker_git_insecure_list[i].endpoint + for i in range(pdgf_scale_factor): + assert "127.0.0.1" in git_insecure_list[i].endpoint # Default listener ... - response = requests.get(f"http://{docker_git_insecure_list[i].endpoint}/") + response = requests.get(f"http://{git_insecure_list[i].endpoint}/") assert response.status_code == 200 assert response.content == b"pytest-docker-git-fixtures-docker\n" if i > 0: continue - uri_insecure = ( - f"http://{docker_git_insecure_list[i].endpoint}/insecure/shim-bind.git" - ) - uri_secure = ( - f"http://{docker_git_insecure_list[i].endpoint}/secure/shim-bind.git" - ) + uri_insecure = f"http://{git_insecure_list[i].endpoint}/insecure/shim-bind.git" + uri_secure = f"http://{git_insecure_list[i].endpoint}/secure/shim-bind.git" # Should not be able to clone from secure w/o credentials ... path = tmp_path.joinpath(f"cloned-repo-{time()}") @@ -339,35 +297,33 @@ def test_docker_git_insecure_list( stderr=subprocess.STDOUT, ) assert "returned non-zero exit status" in str(exception.value) - assert no_duplicates([str(i) for i in docker_git_insecure_list]) + assert no_duplicates([str(i) for i in git_insecure_list]) -def test_docker_git_password(docker_git_password: str): +def test_git_password(git_password: str): """Test that a password can be provided.""" - assert docker_git_password + assert git_password -def test_docker_git_password_list( - docker_git_password_list: List[str], pdrf_scale_factor: int -): +def test_git_password_list(git_password_list: List[str], pdgf_scale_factor: int): """Test that a password can be provided.""" - for i in range(pdrf_scale_factor): - assert docker_git_password_list[i] - assert no_duplicates(docker_git_password_list) + for i in range(pdgf_scale_factor): + assert git_password_list[i] + assert no_duplicates(git_password_list) -@pytest.mark.create_repo("test_docker_git_secure") +@pytest.mark.create_repo("test_git_secure") @pytest.mark.mirror_repo("https://github.com/crashvb/scratch-docker.git") -def test_docker_git_secure( - docker_git_secure: DockerGITSecure, +def test_git_secure( + git_secure: GITSecure, tmp_path: Path, tmp_path_factory: TempPathFactory, ): """Test that an secure docker git can be instantiated.""" - assert "127.0.0.1" in docker_git_secure.endpoint + assert "127.0.0.1" in git_secure.endpoint - uri_insecure = f"https://{docker_git_secure.endpoint}/insecure/scratch-docker.git" - uri_secure = f"https://{docker_git_secure.endpoint}/secure/scratch-docker.git" + uri_insecure = f"https://{git_secure.endpoint}/insecure/scratch-docker.git" + uri_secure = f"https://{git_secure.endpoint}/secure/scratch-docker.git" # Should be able to clone from insecure w/o credentials ... path = tmp_path.joinpath(f"cloned-repo-{time()}") @@ -375,7 +331,7 @@ def test_docker_git_secure( [ "git", "-c", - f"http.sslCAinfo={docker_git_secure.cacerts}", + f"http.sslCAinfo={git_secure.cacerts}", "clone", uri_insecure, str(path), @@ -393,7 +349,7 @@ def test_docker_git_secure( [ "git", "-c", - f"http.sslCAinfo={docker_git_secure.cacerts}", + f"http.sslCAinfo={git_secure.cacerts}", "clone", uri_secure, str(path), @@ -406,12 +362,14 @@ def test_docker_git_secure( assert "returned non-zero exit status" in str(exception.value) assert not path.exists() - uri_secure = f"https://{docker_git_secure.username}@{docker_git_secure.endpoint}/secure/scratch-docker.git" + uri_secure = ( + f"https://{git_secure.username}@{git_secure.endpoint}/secure/scratch-docker.git" + ) # Should be able to clone from secure w/ credentials ... path = tmp_path.joinpath(f"cloned-repo-{time()}") with git_askpass_script( - tmp_path_factory, password=docker_git_secure.password + tmp_path_factory, password=git_secure.password ) as askpass_script: subprocess.run( ["git", "clone", uri_secure, str(path)], @@ -419,7 +377,7 @@ def test_docker_git_secure( cwd=str(tmp_path), env={ "GIT_ASKPASS": str(askpass_script), - "GIT_SSL_CAINFO": docker_git_secure.cacerts, + "GIT_SSL_CAINFO": git_secure.cacerts, "GIT_TERMINAL_PROMPT": "0", }, stderr=subprocess.STDOUT, @@ -435,7 +393,7 @@ def test_docker_git_secure( cwd=str(path), env={ "GIT_ASKPASS": str(askpass_script), - "GIT_SSL_CAINFO": docker_git_secure.cacerts, + "GIT_SSL_CAINFO": git_secure.cacerts, "GIT_TERMINAL_PROMPT": "0", }, stderr=subprocess.STDOUT, @@ -443,21 +401,21 @@ def test_docker_git_secure( @pytest.mark.online -def test_docker_git_secure_list( - docker_git_secure_list: List[DockerGITSecure], - pdrf_scale_factor: int, +def test_git_secure_list( + git_secure_list: List[GITSecure], + pdgf_scale_factor: int, tmp_path: Path, tmp_path_factory: TempPathFactory, ): """Test that an secure docker git can be instantiated.""" - for i in range(pdrf_scale_factor): - assert "127.0.0.1" in docker_git_secure_list[i].endpoint + for i in range(pdgf_scale_factor): + assert "127.0.0.1" in git_secure_list[i].endpoint # Default listener ... response = requests.get( - f"https://{docker_git_secure_list[i].endpoint}/", - headers=docker_git_secure_list[i].auth_header, - verify=str(docker_git_secure_list[i].cacerts), + f"https://{git_secure_list[i].endpoint}/", + headers=git_secure_list[i].auth_header, + verify=str(git_secure_list[i].cacerts), ) assert response.status_code == 200 assert response.content == b"pytest-docker-git-fixtures-docker\n" @@ -466,11 +424,9 @@ def test_docker_git_secure_list( continue uri_insecure = ( - f"https://{docker_git_secure_list[i].endpoint}/insecure/scratch-docker.git" - ) - uri_secure = ( - f"https://{docker_git_secure_list[i].endpoint}/secure/scratch-docker.git" + f"https://{git_secure_list[i].endpoint}/insecure/scratch-docker.git" ) + uri_secure = f"https://{git_secure_list[i].endpoint}/secure/scratch-docker.git" # Should be able to clone from insecure w/o credentials ... path = tmp_path.joinpath(f"cloned-repo-{time()}") @@ -478,7 +434,7 @@ def test_docker_git_secure_list( [ "git", "-c", - f"http.sslCAinfo={docker_git_secure_list[i].cacerts}", + f"http.sslCAinfo={git_secure_list[i].cacerts}", "clone", uri_insecure, str(path), @@ -496,7 +452,7 @@ def test_docker_git_secure_list( [ "git", "-c", - f"http.sslCAinfo={docker_git_secure_list[i].cacerts}", + f"http.sslCAinfo={git_secure_list[i].cacerts}", "clone", uri_secure, str(path), @@ -510,14 +466,14 @@ def test_docker_git_secure_list( assert not path.exists() uri_secure = ( - f"https://{docker_git_secure_list[i].username}@" - f"{docker_git_secure_list[i].endpoint}/secure/scratch-docker.git" + f"https://{git_secure_list[i].username}@" + f"{git_secure_list[i].endpoint}/secure/scratch-docker.git" ) # Should be able to clone from secure w/ credentials ... path = tmp_path.joinpath(f"cloned-repo-{time()}") with git_askpass_script( - tmp_path_factory, password=docker_git_secure_list[i].password + tmp_path_factory, password=git_secure_list[i].password ) as askpass_script: subprocess.run( ["git", "clone", uri_secure, str(path)], @@ -525,7 +481,7 @@ def test_docker_git_secure_list( cwd=str(tmp_path), env={ "GIT_ASKPASS": str(askpass_script), - "GIT_SSL_CAINFO": docker_git_secure_list[i].cacerts, + "GIT_SSL_CAINFO": git_secure_list[i].cacerts, "GIT_TERMINAL_PROMPT": "0", }, stderr=subprocess.STDOUT, @@ -541,39 +497,69 @@ def test_docker_git_secure_list( cwd=str(path), env={ "GIT_ASKPASS": str(askpass_script), - "GIT_SSL_CAINFO": docker_git_secure_list[i].cacerts, + "GIT_SSL_CAINFO": git_secure_list[i].cacerts, "GIT_TERMINAL_PROMPT": "0", }, stderr=subprocess.STDOUT, ) -def test_docker_git_ssl_context(docker_git_ssl_context: SSLContext): +def test_git_ssl_context(git_ssl_context: SSLContext): """Test that an ssl context can be provided.""" - assert isinstance(docker_git_ssl_context, SSLContext) + assert isinstance(git_ssl_context, SSLContext) -def test_docker_git_ssl_context_list( - docker_git_ssl_context_list: List[SSLContext], pdrf_scale_factor: int +def test_git_ssl_context_list( + git_ssl_context_list: List[SSLContext], pdgf_scale_factor: int ): """Test that an ssl context can be provided.""" - for i in range(pdrf_scale_factor): - assert isinstance(docker_git_ssl_context_list[i], SSLContext) - assert no_duplicates(docker_git_ssl_context_list) + for i in range(pdgf_scale_factor): + assert isinstance(git_ssl_context_list[i], SSLContext) + assert no_duplicates(git_ssl_context_list) -def test_docker_git_username(docker_git_username: str): +def test_git_username(git_username: str): """Test that a username can be provided.""" - assert docker_git_username + assert git_username -def test_docker_git_username_list( - docker_git_username_list: List[str], pdrf_scale_factor: int -): +def test_git_username_list(git_username_list: List[str], pdgf_scale_factor: int): """Test that a username can be provided.""" - for i in range(pdrf_scale_factor): - assert docker_git_username_list[i] - assert no_duplicates(docker_git_username_list) + for i in range(pdgf_scale_factor): + assert git_username_list[i] + assert no_duplicates(git_username_list) + + +def test_pdgf_docker_compose_insecure(pdgf_docker_compose_insecure: Path): + """Test that the embedded docker-compose for insecure scms can be copied to a temporary file.""" + service_name = DOCKER_GIT_SERVICE_PATTERN.format("insecure", 0) + assert service_name in pdgf_docker_compose_insecure.read_text() + + +def test_pdgf_docker_compose_insecure_list( + pdgf_docker_compose_insecure_list: List[Path], pdgf_scale_factor: int +): + """Test that the embedded docker-compose for insecure scms can be copied to a temporary file.""" + for i in range(pdgf_scale_factor): + service_name = DOCKER_GIT_SERVICE_PATTERN.format("insecure", i) + assert service_name in pdgf_docker_compose_insecure_list[i].read_text() + assert no_duplicates(pdgf_docker_compose_insecure_list) + + +def test_pdgf_docker_compose_secure(pdgf_docker_compose_secure: Path): + """Test that the embedded docker-compose for secure scms can be copied to a temporary file.""" + service_name = DOCKER_GIT_SERVICE_PATTERN.format("secure", 0) + assert service_name in pdgf_docker_compose_secure.read_text() + + +def test_pdgf_docker_compose_secure_list( + pdgf_docker_compose_secure_list: List[Path], pdgf_scale_factor: int +): + """Test that the embedded docker-compose for secure scms can be copied to a temporary file.""" + for i in range(pdgf_scale_factor): + service_name = DOCKER_GIT_SERVICE_PATTERN.format("secure", i) + assert service_name in pdgf_docker_compose_secure_list[i].read_text() + assert no_duplicates(pdgf_docker_compose_secure_list) def test__get_create_repo(request): @@ -583,8 +569,8 @@ def test__get_create_repo(request): assert ( marks.sort() == [ - "test_docker_git_insecure", - "test_docker_git_secure", + "test_git_insecure", + "test_git_secure", ].sort() )