diff --git a/swh/loader/cvs/cvsclient.py b/swh/loader/cvs/cvsclient.py --- a/swh/loader/cvs/cvsclient.py +++ b/swh/loader/cvs/cvsclient.py @@ -1,4 +1,4 @@ -# Copyright (C) 2015-2021 The Software Heritage developers +# Copyright (C) 2015-2022 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information @@ -95,8 +95,9 @@ "a pserver connection: %s" % EXAMPLE_PSERVER_URL ) try: - user = auth.split(":")[0] - password = auth.split(":")[1] + auth_splitted = auth.split(":") + user = auth_splitted[0] + password = auth_splitted[1] if len(auth_splitted) > 1 else "" except IndexError: raise NotFound( "Username and password are required for " diff --git a/swh/loader/cvs/tests/test_loader.py b/swh/loader/cvs/tests/test_loader.py --- a/swh/loader/cvs/tests/test_loader.py +++ b/swh/loader/cvs/tests/test_loader.py @@ -1,4 +1,4 @@ -# Copyright (C) 2016-2021 The Software Heritage developers +# Copyright (C) 2016-2022 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information @@ -9,7 +9,9 @@ from typing import Any, Dict import pytest +from urllib3.util import parse_url +from swh.loader.cvs.cvsclient import CVSClient from swh.loader.cvs.loader import BadPathException, CvsLoader from swh.loader.tests import ( assert_last_visit_matches, @@ -1236,3 +1238,22 @@ loader.cvs_module_name = module_name loader.cvsroot_path = tmp_path loader.fetch_cvs_repo_with_rsync(host, path) + + +@pytest.mark.parametrize( + "pserver_url", + [ + "pserver://anonymous:anonymous@cvs.example.org/cvsroot/project/module", + "pserver://anonymous@cvs.example.org/cvsroot/project/module", + ], +) +def test_cvs_client_connect_pserver(mocker, pserver_url): + from swh.loader.cvs.cvsclient import socket + + conn = mocker.MagicMock() + conn.recv.side_effect = [b"I LOVE YOU\n", b"Valid-requests \n", b"ok\n"] + mocker.patch.object(socket, "create_connection").return_value = conn + parsed_url = parse_url(pserver_url) + + # check cvs client can be instantiated without errors + CVSClient(parsed_url)