cloudapi: require gpgkey if check_gpg is set

If a user requires that packages from a certain repository are checked using
a GPG key, they should specify it. Now, this is enforced to catch this issue
earlier than in osbuild.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
This commit is contained in:
Ondřej Budai 2022-03-25 09:21:09 +01:00 committed by Ondřej Budai
parent af44202b1c
commit 7a194bfcb5
3 changed files with 45 additions and 12 deletions

View file

@ -230,17 +230,44 @@ func TestRepoConfigConversion(t *testing.T) {
assert.Equal(rc, &tc.repoConfig, "mismatch in test case %d", idx)
}
// test error
noURL := Repository{
Baseurl: nil,
CheckGpg: nil,
Gpgkey: nil,
IgnoreSsl: nil,
Metalink: nil,
Mirrorlist: nil,
Rhsm: true,
PackageSets: nil,
errorTestCases := []struct {
repo Repository
err string
}{
// invalid repo
{
repo: Repository{
Baseurl: nil,
CheckGpg: nil,
Gpgkey: nil,
IgnoreSsl: nil,
Metalink: nil,
Mirrorlist: nil,
Rhsm: true,
PackageSets: nil,
},
err: HTTPError(ErrorInvalidRepository).Error(),
},
// check gpg required but no gpgkey given
{
repo: Repository{
Baseurl: nil,
CheckGpg: common.BoolToPtr(true),
Gpgkey: nil,
IgnoreSsl: common.BoolToPtr(true),
Metalink: common.StringToPtr("http://example.org/metalink"),
Mirrorlist: nil,
Rhsm: true,
PackageSets: nil,
},
err: HTTPError(ErrorNoGPGKey).Error(),
},
}
for _, tc := range errorTestCases {
rc, err := genRepoConfig(tc.repo)
assert.Nil(rc)
assert.EqualError(err, tc.err)
}
_, err := genRepoConfig(noURL)
assert.EqualError(err, HTTPError(ErrorInvalidRepository).Error())
}