Esempio n. 1
0
def test_process_non_registry_dependency_invalid_location():
    dep_identifier = "file:rxjs-6.5.5.tar.gz"
    dep_name = "rxjs"
    dep_info = {
        "version": dep_identifier,
        "requires": {
            "tslib": "^1.9.0"
        },
    }
    dep = general_js.JSDependency(dep_name, source=dep_info["version"])

    expected = f"The dependency {dep_name}@{dep_identifier} is hosted in an unsupported location"
    with pytest.raises(CachitoError, match=expected):
        general_js.process_non_registry_dependency(dep)
Esempio n. 2
0
def test_process_non_registry_dependency_http_integrity_missing():
    dep_identifier = "https://github.com/ReactiveX/rxjs/archive/6.5.5.tar.gz"
    dep_name = "rxjs"
    dep_info = {
        "version": dep_identifier,
        "requires": {
            "tslib": "^1.9.0"
        },
    }
    dep = general_js.JSDependency(dep_name, source=dep_info["version"])

    expected = (
        f"The dependency {dep_name}@{dep_identifier} is missing the integrity value. "
        'Is the "integrity" key missing in your lockfile?')
    with pytest.raises(CachitoError, match=expected):
        general_js.process_non_registry_dependency(dep)
Esempio n. 3
0
def test_convert_to_nexus_hosted(mock_process_non_registry_dep):
    dep_name = "rxjs"
    # The information from the lock file
    dep_info = {
        "version": "github:ReactiveX/rxjs#8cc6491771fcbf44984a419b7f26ff442a5d58f5",
        "from": "github:ReactiveX/rxjs#8cc6491771fcbf44984a419b7f26ff442a5d58f5",
        "requires": {"tslib": "^1.9.0"},
    }

    assert npm.convert_to_nexus_hosted(dep_name, dep_info) == {
        "integrity": mock_process_non_registry_dep.return_value.integrity,
        "resolved": mock_process_non_registry_dep.return_value.source,
        "version": mock_process_non_registry_dep.return_value.version,
        "requires": dep_info["requires"],
    }
    mock_process_non_registry_dep.assert_called_once_with(
        general_js.JSDependency(name=dep_name, source=dep_info["version"], integrity=None)
    )
Esempio n. 4
0
def test_process_non_registry_dependency_github_not_in_nexus(
        mock_unrd, mock_gncifn):
    mock_gncifn.return_value = None

    dep_identifier = "github:ReactiveX/rxjs#8cc6491771fcbf44984a419b7f26ff442a5d58f5"
    dep_name = "rxjs"
    dep_info = {
        "version": dep_identifier,
        "from":
        "github:ReactiveX/rxjs#8cc6491771fcbf44984a419b7f26ff442a5d58f5",
        "requires": {
            "tslib": "^1.9.0"
        },
    }
    dep = general_js.JSDependency(dep_name, source=dep_info["version"])

    expected = (
        f"The dependency {dep_name}@{dep_identifier} was uploaded to Nexus but is not accessible"
    )
    with pytest.raises(CachitoError, match=expected):
        general_js.process_non_registry_dependency(dep)
Esempio n. 5
0
def test_process_non_registry_dependency_http(mock_unrd, mock_gncifn, exists):
    checksum = (
        "325f07861e0ab888d90606b1074fde956fd3954dcc4c6e418dbff9d8aa8342b5507481408832bfaac8e48f344"
        "dc650c8df0f8182c0271ed9fa233aa32c329839")
    nexus_component_info = {
        "assets": [{
            "checksum": {
                "sha512": checksum
            },
            "downloadUrl":
            ("https://nexus.domain.local/repository/cachito-js-hosted/rxjs/-/"
             "rxjs-6.5.5-external-sha512-325f07861e0ab888d90606b1074fde956fd3954dcc4c6e418d"
             "bff9d8aa8342b5507481408832bfaac8e48f344.tgz"),
        }],
        "version":
        ("6.5.5-external-sha512-325f07861e0ab888d90606b1074fde956fd3954dcc4c6e418dbff9d8aa8342"
         "b5507481408832bfaac8e48f344"),
    }
    if exists:
        mock_gncifn.return_value = nexus_component_info
    else:
        mock_gncifn.side_effect = [None, nexus_component_info]

    dep_name = "rxjs"
    dep_info = {
        "version":
        "https://github.com/ReactiveX/rxjs/archive/6.5.5.tar.gz",
        "requires": {
            "tslib": "^1.9.0"
        },
        "integrity":
        ("sha512-Ml8Hhh4KuIjZBgaxB0/elW/TlU3MTG5Bjb/52KqDQrVQdIFAiDK/qsjkjzRNxlDI3w+BgsAnHtn6I"
         "zqjLDKYOQ=="),
    }

    dep = general_js.JSDependency(name=dep_name,
                                  source=dep_info["version"],
                                  integrity=dep_info["integrity"])
    new_dep = general_js.process_non_registry_dependency(dep)

    assert new_dep == general_js.JSDependency(
        name=dep.name,
        source=
        ("https://nexus.domain.local/repository/cachito-js-hosted/rxjs/-/rxjs-6.5.5-"
         "external-sha512-325f07861e0ab888d90606b1074fde956fd3954dcc4c6e418dbff9d8aa8342b55074"
         "81408832bfaac8e48f344.tgz"),
        version=
        ("6.5.5-external-sha512-325f07861e0ab888d90606b1074fde956fd3954dcc4c6e418dbff9d8"
         "aa8342b5507481408832bfaac8e48f344"),
        integrity=
        ("sha512-Ml8Hhh4KuIjZBgaxB0/elW/TlU3MTG5Bjb/52KqDQrVQdIFAiDK/qsjkjzRNxlDI3w+BgsAnHtn6I"
         "zqjLDKYOQ=="),
    )

    suffix = (
        "-external-sha512-325f07861e0ab888d90606b1074fde956fd3954dcc4c6e418dbff9d8aa8342b5"
        "507481408832bfaac8e48f344dc650c8df0f8182c0271ed9fa233aa32c329839")

    suffix_search = f"*{suffix}"
    if exists:
        mock_gncifn.assert_called_once_with("rxjs", suffix_search)
        # Verify no upload occurs when the component already exists in Nexus
        mock_unrd.assert_not_called()
    else:
        assert mock_gncifn.call_count == 2
        mock_gncifn.assert_has_calls([
            mock.call("rxjs", suffix_search),
            mock.call("rxjs", suffix_search, max_attempts=5)
        ])
        mock_unrd.assert_called_once_with(
            "https://github.com/ReactiveX/rxjs/archive/6.5.5.tar.gz",
            suffix,
            False,
            general.ChecksumInfo(
                "sha512",
                "325f07861e0ab888d90606b1074fde956fd3954dcc4c6e418dbff9d8aa8342b5507481408832bf"
                "aac8e48f344dc650c8df0f8182c0271ed9fa233aa32c329839",
            ),
        )
Esempio n. 6
0
def test_process_non_registry_dependency_github(mock_unrd, mock_gncifn,
                                                exists):
    checksum = (
        "325f07861e0ab888d90606b1074fde956fd3954dcc4c6e418dbff9d8aa8342b5507481408832bfaac8e48f344"
        "dc650c8df0f8182c0271ed9fa233aa32c329839")
    # The information returned from Nexus of the uploaded component
    nexus_component_info = {
        "assets": [{
            "checksum": {
                "sha512": checksum
            },
            "downloadUrl":
            ("https://nexus.domain.local/repository/cachito-js-hosted/rxjs/-/"
             "rxjs-6.5.5-external-gitcommit-dfa239d41b97504312fa95e13f4d593d95b49c4b.tgz"
             ),
        }],
        "version":
        "6.5.5-external-gitcommit-8cc6491771fcbf44984a419b7f26ff442a5d58f5",
    }
    if exists:
        mock_gncifn.return_value = nexus_component_info
    else:
        mock_gncifn.side_effect = [None, nexus_component_info]

    dep_name = "rxjs"
    # The information from the lock file
    dep_info = {
        "version":
        "github:ReactiveX/rxjs#8cc6491771fcbf44984a419b7f26ff442a5d58f5",
        "from":
        "github:ReactiveX/rxjs#8cc6491771fcbf44984a419b7f26ff442a5d58f5",
        "requires": {
            "tslib": "^1.9.0"
        },
    }

    dep = general_js.JSDependency(name=dep_name, source=dep_info["version"])
    new_dep = general_js.process_non_registry_dependency(dep)

    # Verify the information to update the lock file with is correct
    assert new_dep == general_js.JSDependency(
        name=dep.name,
        source=
        ("https://nexus.domain.local/repository/cachito-js-hosted/rxjs/-/rxjs-6.5.5-"
         "external-gitcommit-dfa239d41b97504312fa95e13f4d593d95b49c4b.tgz"),
        version=
        "6.5.5-external-gitcommit-8cc6491771fcbf44984a419b7f26ff442a5d58f5",
        integrity=
        ("sha512-Ml8Hhh4KuIjZBgaxB0/elW/TlU3MTG5Bjb/52KqDQrVQdIFAiDK/qsjkjzRNxlDI3w+BgsAnHtn6I"
         "zqjLDKYOQ=="),
    )
    if exists:
        mock_gncifn.assert_called_once_with(
            "rxjs",
            "*-external-gitcommit-8cc6491771fcbf44984a419b7f26ff442a5d58f5")
        # Verify no upload occurs when the component already exists in Nexus
        mock_unrd.assert_not_called()
    else:
        assert mock_gncifn.call_count == 2
        mock_gncifn.assert_has_calls([
            mock.call(
                "rxjs",
                "*-external-gitcommit-8cc6491771fcbf44984a419b7f26ff442a5d58f5"
            ),
            mock.call(
                "rxjs",
                "*-external-gitcommit-8cc6491771fcbf44984a419b7f26ff442a5d58f5",
                max_attempts=5,
            ),
        ])
        mock_unrd.assert_called_once_with(
            "github:ReactiveX/rxjs#8cc6491771fcbf44984a419b7f26ff442a5d58f5",
            "-external-gitcommit-8cc6491771fcbf44984a419b7f26ff442a5d58f5",
            True,
            None,
        )