summaryrefslogtreecommitdiff
path: root/pkg/trust/trust.go
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2022-08-24 22:56:54 +0200
committerMiloslav Trmač <mitr@redhat.com>2022-08-25 01:51:58 +0200
commit4df1e2524b9a8b3ff2d3768ac7fe54e98a966886 (patch)
tree4a6ecf081805b37e4cbda78f492268da0527e822 /pkg/trust/trust.go
parent4b2bd1036b4952a35a526202c8965cd3b32162ad (diff)
downloadpodman-4df1e2524b9a8b3ff2d3768ac7fe54e98a966886.tar.gz
podman-4df1e2524b9a8b3ff2d3768ac7fe54e98a966886.tar.bz2
podman-4df1e2524b9a8b3ff2d3768ac7fe54e98a966886.zip
Add a unit test for trust.PolicyDescription
Add at least a basic unit test for the various entry types. So that we don't have to actually deal with GPG keys and /usr/bin/gpg*, parametrize the code with a gpgIDReader , and pass a fake one in the unit test. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Diffstat (limited to 'pkg/trust/trust.go')
-rw-r--r--pkg/trust/trust.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/pkg/trust/trust.go b/pkg/trust/trust.go
index e93b4cd9d..9dd6878f9 100644
--- a/pkg/trust/trust.go
+++ b/pkg/trust/trust.go
@@ -19,18 +19,23 @@ type Policy struct {
// PolicyDescription returns an user-focused description of the policy in policyPath and registries.d data from registriesDirPath.
func PolicyDescription(policyPath, registriesDirPath string) ([]*Policy, error) {
+ return policyDescriptionWithGPGIDReader(policyPath, registriesDirPath, getGPGIdFromKeyPath)
+}
+
+// policyDescriptionWithGPGIDReader is PolicyDescription with a gpgIDReader parameter. It exists only to make testing easier.
+func policyDescriptionWithGPGIDReader(policyPath, registriesDirPath string, idReader gpgIDReader) ([]*Policy, error) {
policyContentStruct, err := getPolicy(policyPath)
if err != nil {
return nil, fmt.Errorf("could not read trust policies: %w", err)
}
- res, err := getPolicyShowOutput(policyContentStruct, registriesDirPath)
+ res, err := getPolicyShowOutput(policyContentStruct, registriesDirPath, idReader)
if err != nil {
return nil, fmt.Errorf("could not show trust policies: %w", err)
}
return res, nil
}
-func getPolicyShowOutput(policyContentStruct policyContent, systemRegistriesDirPath string) ([]*Policy, error) {
+func getPolicyShowOutput(policyContentStruct policyContent, systemRegistriesDirPath string, idReader gpgIDReader) ([]*Policy, error) {
var output []*Policy
registryConfigs, err := loadAndMergeConfig(systemRegistriesDirPath)
@@ -76,10 +81,10 @@ func getPolicyShowOutput(policyContentStruct policyContent, systemRegistriesDirP
uids := []string{}
for _, repoele := range repoval {
if len(repoele.KeyPath) > 0 {
- uids = append(uids, getGPGIdFromKeyPath(repoele.KeyPath)...)
+ uids = append(uids, idReader(repoele.KeyPath)...)
}
if len(repoele.KeyData) > 0 {
- uids = append(uids, getGPGIdFromKeyData(repoele.KeyData)...)
+ uids = append(uids, getGPGIdFromKeyData(idReader, repoele.KeyData)...)
}
}
tempTrustShowOutput.GPGId = strings.Join(uids, ", ")