Пример #1
0
def test_apt_unmarshal_invalid_extra_keys():
    test_dict = {
        "architectures": ["amd64", "i386"],
        "components": ["main", "multiverse"],
        "formats": ["deb", "deb-src"],
        "key-id": "A" * 40,
        "key-server": "keyserver.ubuntu.com",
        "name": "test-name",
        "suites": ["xenial", "xenial-updates"],
        "type": "apt",
        "url": "http://archive.ubuntu.com/ubuntu",
        "foo": "bar",
        "foo2": "bar",
    }

    with pytest.raises(errors.PackageRepositoryValidationError) as exc_info:
        PackageRepositoryApt.unmarshal(test_dict)

    assert (
        exc_info.value.brief
        == "Found unsupported package repository properties 'foo', 'foo2'."
    )
    assert exc_info.value.details is None
    assert (
        exc_info.value.resolution
        == "Verify repository configuration and ensure it is correct."
    )
Пример #2
0
def test_apt_unmarshal_invalid_data():
    test_dict = "not-a-dict"

    with pytest.raises(errors.PackageRepositoryValidationError) as exc_info:
        PackageRepositoryApt.unmarshal(test_dict)

    assert exc_info.value.brief == "Invalid package repository object 'not-a-dict'."
    assert (
        exc_info.value.details
        == "Package repository must be a valid dictionary object."
    )
    assert (
        exc_info.value.resolution
        == "Verify repository configuration and ensure that the correct syntax is used."
    )
Пример #3
0
 def get_required_package_repositories(cls) -> List[PackageRepository]:
     codename = os_release.OsRelease().version_codename()
     return [
         PackageRepositoryApt(
             formats=["deb"],
             components=["main"],
             key_id="C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654",
             url="http://packages.ros.org/ros2/ubuntu",
             suites=[codename],
         )
     ]
Пример #4
0
def test_apt_name():
    repo = PackageRepositoryApt(
        architectures=["amd64", "i386"],
        components=["main", "multiverse"],
        formats=["deb", "deb-src"],
        key_id="A" * 40,
        key_server="keyserver.ubuntu.com",
        suites=["xenial", "xenial-updates"],
        url="http://archive.ubuntu.com/ubuntu",
    )

    assert repo.name == "http_archive_ubuntu_com_ubuntu"
Пример #5
0
def test_apt_invalid_url():
    with pytest.raises(errors.PackageRepositoryValidationError) as exc_info:
        PackageRepositoryApt(
            key_id="A" * 40,
            url="",
        )

    assert exc_info.value.brief == "Invalid URL ''."
    assert exc_info.value.details == "URLs must be non-empty strings."
    assert (
        exc_info.value.resolution
        == "Verify the repository configuration and ensure that 'url' is correctly specified."
    )
Пример #6
0
def test_apt_unmarshal_invalid_type():
    test_dict = {
        "architectures": ["amd64", "i386"],
        "components": ["main", "multiverse"],
        "formats": ["deb", "deb-src"],
        "key-id": "A" * 40,
        "key-server": "keyserver.ubuntu.com",
        "name": "test-name",
        "suites": ["xenial", "xenial-updates"],
        "type": "aptx",
        "url": "http://archive.ubuntu.com/ubuntu",
    }

    with pytest.raises(errors.PackageRepositoryValidationError) as exc_info:
        PackageRepositoryApt.unmarshal(test_dict)

    assert exc_info.value.brief == "Unsupported type 'aptx'."
    assert exc_info.value.details == "The only currently supported type is 'apt'."
    assert (
        exc_info.value.resolution
        == "Verify repository configuration and ensure that 'type' is correctly specified."
    )
Пример #7
0
def test_apt_marshal():
    repo = PackageRepositoryApt(
        architectures=["amd64", "i386"],
        components=["main", "multiverse"],
        formats=["deb", "deb-src"],
        key_id="A" * 40,
        key_server="xkeyserver.ubuntu.com",
        name="test-name",
        suites=["xenial", "xenial-updates"],
        url="http://archive.ubuntu.com/ubuntu",
    )

    assert repo.marshal() == {
        "architectures": ["amd64", "i386"],
        "components": ["main", "multiverse"],
        "formats": ["deb", "deb-src"],
        "key-id": "A" * 40,
        "key-server": "xkeyserver.ubuntu.com",
        "name": "test-name",
        "suites": ["xenial", "xenial-updates"],
        "type": "apt",
        "url": "http://archive.ubuntu.com/ubuntu",
    }
Пример #8
0
def test_apt_invalid_suites_as_path():
    with pytest.raises(errors.PackageRepositoryValidationError) as exc_info:
        PackageRepositoryApt(
            key_id="A" * 40,
            suites=["my-suite/"],
            url="http://archive.ubuntu.com/ubuntu",
        )

    assert exc_info.value.brief == "Invalid suite 'my-suite/'."
    assert exc_info.value.details == "Suites must not end with a '/'."
    assert (
        exc_info.value.resolution
        == "Verify the repository configuration and remove the trailing '/ from suites or use the 'path' property to define a path."
    )
Пример #9
0
def test_apt_invalid_missing_suites():
    with pytest.raises(errors.PackageRepositoryValidationError) as exc_info:
        PackageRepositoryApt(
            key_id="A" * 40,
            components=["main"],
            url="http://archive.ubuntu.com/ubuntu",
        )

    assert exc_info.value.brief == "No suites specified."
    assert exc_info.value.details == "Suites are required when using components."
    assert (
        exc_info.value.resolution
        == "Verify the repository configuration and ensure that 'suites' is correctly specified."
    )
Пример #10
0
def test_apt_invalid_path():
    with pytest.raises(errors.PackageRepositoryValidationError) as exc_info:
        PackageRepositoryApt(
            key_id="A" * 40,
            path="",
            url="http://archive.ubuntu.com/ubuntu",
        )

    assert exc_info.value.brief == "Invalid path ''."
    assert exc_info.value.details == "Paths must be non-empty strings."
    assert (
        exc_info.value.resolution
        == "Verify the repository configuration and ensure that 'path' is a non-empty string such as '/'."
    )
Пример #11
0
def test_install_package_repository_key_already_installed(
    mock_is_key_installed, is_installed, apt_gpg,
):
    mock_is_key_installed.return_value = is_installed
    package_repo = PackageRepositoryApt(
        components=["main", "multiverse"],
        key_id="8" * 40,
        key_server="xkeyserver.com",
        suites=["xenial"],
        url="http://archive.ubuntu.com/ubuntu",
    )

    updated = apt_gpg.install_package_repository_key(package_repo=package_repo)

    assert updated is not is_installed
Пример #12
0
def test_apt_invalid_path_with_components():
    with pytest.raises(errors.PackageRepositoryValidationError) as exc_info:
        PackageRepositoryApt(
            key_id="A" * 40,
            path="/",
            components=["main"],
            url="http://archive.ubuntu.com/ubuntu",
        )

    assert (
        exc_info.value.brief == "Components ['main'] cannot be combined with path '/'."
    )
    assert exc_info.value.details == "Path and components are incomptiable options."
    assert (
        exc_info.value.resolution
        == "Verify the repository configuration and remove 'path' or 'components'."
    )
Пример #13
0
def test_apt_invalid_path_with_suites():
    with pytest.raises(errors.PackageRepositoryValidationError) as exc_info:
        PackageRepositoryApt(
            key_id="A" * 40,
            path="/",
            suites=["xenial", "xenial-updates"],
            url="http://archive.ubuntu.com/ubuntu",
        )

    assert (
        exc_info.value.brief
        == "Suites ['xenial', 'xenial-updates'] cannot be combined with path '/'."
    )
    assert exc_info.value.details == "Path and suites are incomptiable options."
    assert (
        exc_info.value.resolution
        == "Verify the repository configuration and remove 'path' or 'suites'."
    )
Пример #14
0
def test_install_package_repository_key_from_asset(
    mock_install_key, mock_is_key_installed, apt_gpg, key_assets,
):
    key_id = "123456789012345678901234567890123456AABB"
    expected_key_path = key_assets / "3456AABB.asc"
    expected_key_path.write_text("key-data")

    package_repo = PackageRepositoryApt(
        components=["main", "multiverse"],
        key_id=key_id,
        suites=["xenial"],
        url="http://archive.ubuntu.com/ubuntu",
    )

    updated = apt_gpg.install_package_repository_key(package_repo=package_repo)

    assert updated is True
    assert mock_install_key.mock_calls == [call(key="key-data")]
Пример #15
0
def test_install_package_repository_key_apt_from_keyserver(
    mock_install_key_from_keyserver, mock_is_key_installed, apt_gpg,
):
    key_id = "8" * 40

    package_repo = PackageRepositoryApt(
        components=["main", "multiverse"],
        key_id=key_id,
        key_server="key.server",
        suites=["xenial"],
        url="http://archive.ubuntu.com/ubuntu",
    )

    updated = apt_gpg.install_package_repository_key(package_repo=package_repo)

    assert updated is True
    assert mock_install_key_from_keyserver.mock_calls == [
        call(key_id=key_id, key_server="key.server")
    ]
Пример #16
0
        apt_sources_manager._sudo_write_file(dst_path="/foo/bar",
                                             content=b"some-content")

    assert (str(error.value).startswith(
        "Failed to install repository config with: ['sudo', 'install'") is
            True)


@pytest.mark.parametrize(
    "package_repo,name,content",
    [
        (
            PackageRepositoryApt(
                architectures=["amd64", "arm64"],
                components=["test-component"],
                formats=["deb", "deb-src"],
                key_id="A" * 40,
                suites=["test-suite1", "test-suite2"],
                url="http://test.url/ubuntu",
            ),
            "snapcraft-http_test_url_ubuntu.sources",
            dedent("""\
                Types: deb deb-src
                URIs: http://test.url/ubuntu
                Suites: test-suite1 test-suite2
                Components: test-component
                Architectures: amd64 arm64
                """).encode(),
        ),
        (
            PackageRepositoryApt(
                architectures=["amd64", "arm64"],
Пример #17
0
def test_apt_valid_architectures(arch):
    package_repo = PackageRepositoryApt(
        key_id="A" * 40, url="http://test", architectures=[arch]
    )

    assert package_repo.architectures == [arch]