The problem: osbuild-composer used to have a rather uncomplete logic for selecting client certificates and keys while fetching data from repositories that use the "subscription model". In this scenario, every repo requires the user to use a client-side TLS certificate. The problem is that every repo can use its own CA and require a different pair of a certificate and a key. This case wasn't handled at all in composer. Furthermore, osbuild-composer can use remote workers which complicates things even more. Assumptions: The problem outlined above is hard to solve in the general case, but Red Hat Subscription Manager places certain limitations on how subscriptions might be used. For example, a subscription must be tight to a host system, so there is no way to use such a repository in osbuild-composer without it being available on the host system as well. Also, if a user wishes to use a certain repository in osbuild-composer it must be available on both hosts: the composer and the worker. It will come with different pair of a client certificate and a key but otherwise, its configuration remains the same. The solution: Expect all the subscriptions to be registered in the /etc/yum.repos.d/redhat.repo file. Read the mapping of URLs to certificates and keys from there and use it. Don't change the manifest format and let osbuild guess the appropriate subscription to use.
95 lines
3.3 KiB
Go
95 lines
3.3 KiB
Go
// This package contains tests related to dnf-json and rpmmd package.
|
|
|
|
// +build integration
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"os"
|
|
"path"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
|
"github.com/osbuild/osbuild-composer/internal/distro"
|
|
"github.com/osbuild/osbuild-composer/internal/distro/fedora33"
|
|
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
|
"github.com/osbuild/osbuild-composer/internal/test"
|
|
)
|
|
|
|
func TestFetchChecksum(t *testing.T) {
|
|
dir, err := test.SetUpTemporaryRepository()
|
|
defer func(dir string) {
|
|
err := test.TearDownTemporaryRepository(dir)
|
|
assert.Nil(t, err, "Failed to clean up temporary repository.")
|
|
}(dir)
|
|
assert.Nilf(t, err, "Failed to set up temporary repository: %v", err)
|
|
|
|
repoCfg := rpmmd.RepoConfig{
|
|
Name: "repo",
|
|
BaseURL: fmt.Sprintf("file://%s", dir),
|
|
IgnoreSSL: true,
|
|
}
|
|
|
|
// use a fullpath to dnf-json, this allows this test to have an arbitrary
|
|
// working directory
|
|
rpmMetadata := rpmmd.NewRPMMD(path.Join(dir, "rpmmd"), "/usr/libexec/osbuild-composer/dnf-json")
|
|
_, c, err := rpmMetadata.FetchMetadata([]rpmmd.RepoConfig{repoCfg}, "platform:f31", "x86_64", "31")
|
|
assert.Nilf(t, err, "Failed to fetch checksum: %v", err)
|
|
assert.NotEqual(t, "", c["repo"], "The checksum is empty")
|
|
}
|
|
|
|
// This test loads all the repositories available in /repositories directory
|
|
// and tries to run depsolve for each architecture. With N architectures available
|
|
// this should run cross-arch dependency solving N-1 times.
|
|
func TestCrossArchDepsolve(t *testing.T) {
|
|
// Load repositories from the definition we provide in the RPM package
|
|
repoDir := "/usr/share/osbuild-composer"
|
|
|
|
// NOTE: we can add RHEL, but don't make it hard requirement because it will fail outside of VPN
|
|
for _, distroStruct := range []distro.Distro{fedora33.New()} {
|
|
t.Run(distroStruct.Name(), func(t *testing.T) {
|
|
|
|
// Run tests in parallel to speed up run times.
|
|
t.Parallel()
|
|
|
|
// Set up temporary directory for rpm/dnf cache
|
|
dir, err := ioutil.TempDir("/tmp", "rpmmd-test-")
|
|
require.Nilf(t, err, "Failed to create tmp dir for depsolve test: %v", err)
|
|
defer os.RemoveAll(dir)
|
|
|
|
// use a fullpath to dnf-json, this allows this test to have an arbitrary
|
|
// working directory
|
|
rpm := rpmmd.NewRPMMD(dir, "/usr/libexec/osbuild-composer/dnf-json")
|
|
|
|
repos, err := rpmmd.LoadRepositories([]string{repoDir}, distroStruct.Name())
|
|
require.NoErrorf(t, err, "Failed to LoadRepositories %v", distroStruct.Name())
|
|
|
|
for _, archStr := range distroStruct.ListArches() {
|
|
t.Run(archStr, func(t *testing.T) {
|
|
arch, err := distroStruct.GetArch(archStr)
|
|
require.NoError(t, err)
|
|
|
|
for _, imgTypeStr := range arch.ListImageTypes() {
|
|
t.Run(imgTypeStr, func(t *testing.T) {
|
|
imgType, err := arch.GetImageType(imgTypeStr)
|
|
require.NoError(t, err)
|
|
|
|
packages := imgType.PackageSets(blueprint.Blueprint{})
|
|
|
|
_, _, err = rpm.Depsolve(packages["build-packages"], repos[archStr], distroStruct.ModulePlatformID(), archStr, distroStruct.Releasever())
|
|
assert.NoError(t, err)
|
|
|
|
_, _, err = rpm.Depsolve(packages["packages"], repos[archStr], distroStruct.ModulePlatformID(), archStr, distroStruct.Releasever())
|
|
assert.NoError(t, err)
|
|
})
|
|
}
|
|
})
|
|
}
|
|
})
|
|
}
|
|
}
|