Skip to content

Commit

Permalink
Merge pull request #2063 from robnester-rh/EC-908
Browse files Browse the repository at this point in the history
EC-908 Move GetPinnedURL func to go-gather.
  • Loading branch information
robnester-rh authored Oct 10, 2024
2 parents 18a5326 + 5d6a771 commit dcbef98
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 390 deletions.
4 changes: 2 additions & 2 deletions cmd/inspect/inspect_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestFetchSourcesFromPolicy(t *testing.T) {
assert.NoError(t, err)

assert.Equal(t, "[one,two,three]", inspectPolicyCmd.Flag("source").Value.String())
assert.Equal(t, "# Source: one\n\n# Source: three\n\n# Source: two\n\n", buffy.String())
assert.Equal(t, "# Source: file::one\n\n# Source: file::three\n\n# Source: file::two\n\n", buffy.String())
}

func TestFetchSources(t *testing.T) {
Expand Down Expand Up @@ -131,7 +131,7 @@ func TestFetchSources(t *testing.T) {
assert.NoError(t, err)

assert.Equal(t, "[one,two,three]", inspectPolicyCmd.Flag("source").Value.String())
assert.Equal(t, "# Source: one\n\n# Source: three\n\n# Source: two\n\n", buffy.String())
assert.Equal(t, "# Source: file::one\n\n# Source: file::three\n\n# Source: file::two\n\n", buffy.String())
}

func TestSourcesAndPolicyCantBeBothProvided(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions cmd/validate/__snapshots__/image_test.snap
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
]
},
"policy": [
"oci://quay.io/hacbs-contract/ec-release-policy:latest@sha256:da54bca5477bf4e3449bc37de1822888fa0fbb8d89c640218cb31b987374d357"
"oci::quay.io/hacbs-contract/ec-release-policy:latest@sha256:da54bca5477bf4e3449bc37de1822888fa0fbb8d89c640218cb31b987374d357"
]
}
]
Expand Down Expand Up @@ -66,7 +66,7 @@
]
},
"policy": [
"oci://quay.io/hacbs-contract/ec-release-policy:latest@sha256:da54bca5477bf4e3449bc37de1822888fa0fbb8d89c640218cb31b987374d357"
"oci::quay.io/hacbs-contract/ec-release-policy:latest@sha256:da54bca5477bf4e3449bc37de1822888fa0fbb8d89c640218cb31b987374d357"
]
}
]
Expand Down
2 changes: 1 addition & 1 deletion cmd/validate/image_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestEvaluatorLifecycle(t *testing.T) {

newConftestEvaluator = func(_ context.Context, s []source.PolicySource, _ evaluator.ConfigProvider, _ v1alpha1.Source) (evaluator.Evaluator, error) {
// We are splitting this url to get to the index of the evaluator.
idx, err := strconv.Atoi(strings.Split(strings.Split(s[0].PolicyUrl(), "@")[0], "://")[1])
idx, err := strconv.Atoi(strings.Split(strings.Split(s[0].PolicyUrl(), "@")[0], "::")[1])
require.NoError(t, err)

return evaluators[idx], nil
Expand Down
12 changes: 6 additions & 6 deletions cmd/validate/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,10 +699,10 @@ spec:
assert.NoError(t, err)
assert.JSONEq(t, `{
"data": [
"oci://registry/policy-data:latest@sha256:da54bca5477bf4e3449bc37de1822888fa0fbb8d89c640218cb31b987374d357"
"oci::registry/policy-data:latest@sha256:da54bca5477bf4e3449bc37de1822888fa0fbb8d89c640218cb31b987374d357"
],
"policy": [
"oci://registry/policy:latest@sha256:da54bca5477bf4e3449bc37de1822888fa0fbb8d89c640218cb31b987374d357"
"oci::registry/policy:latest@sha256:da54bca5477bf4e3449bc37de1822888fa0fbb8d89c640218cb31b987374d357"
],
"ruleData": {
"custom_rule_data":{"prefix_data":["registry1"]},
Expand Down Expand Up @@ -773,17 +773,17 @@ func Test_ValidateImageErrorLog(t *testing.T) {
ctx = oci.WithClient(ctx, &client)

mdl := MockDownloader{}
mdl.On("Download", mock.Anything, "oci::registry/policy:latest", false).Return(&ociMetadata.OCIMetadata{Digest: "sha256:da54bca5477bf4e3449bc37de1822888fa0fbb8d89c640218cb31b987374d357"}, nil)
mdl.On("Download", mock.Anything, "oci::registry/policy-data:latest", false).Return(&ociMetadata.OCIMetadata{Digest: "sha256:da54bca5477bf4e3449bc37de1822888fa0fbb8d89c640218cb31b987374d357"}, nil)
mdl.On("Download", mock.Anything, "oci://registry/policy:latest", false).Return(&ociMetadata.OCIMetadata{Digest: "sha256:da54bca5477bf4e3449bc37de1822888fa0fbb8d89c640218cb31b987374d357"}, nil)
mdl.On("Download", mock.Anything, "oci://registry/policy-data:latest", false).Return(&ociMetadata.OCIMetadata{Digest: "sha256:da54bca5477bf4e3449bc37de1822888fa0fbb8d89c640218cb31b987374d357"}, nil)
ctx = context.WithValue(ctx, source.DownloaderFuncKey, &mdl)

cmd.SetContext(ctx)

testPolicyJSON := `sources:
- policy:
- "oci::registry/policy:latest"
- "oci://registry/policy:latest"
data:
- "oci::registry/policy-data:latest"
- "oci://registry/policy-data:latest"
config:
include:
- '@minimal'
Expand Down
8 changes: 4 additions & 4 deletions features/__snapshots__/inspect_policy.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Error: Merge error. The 'rule_data' key was found more than once!

[json output:stdout - 1]
{
"git::https://${GITHOST}/git/policy.git?ref=${LATEST_COMMIT}": [
"git::${GITHOST}/git/policy.git?ref=${LATEST_COMMIT}": [
{
"annotations": {
"custom": {
Expand Down Expand Up @@ -57,7 +57,7 @@ Error: Merge error. The 'rule_data' key was found more than once!
---

[default output:stdout - 1]
# Source: git::https://${GITHOST}/git/policy.git?ref=${LATEST_COMMIT}
# Source: git::${GITHOST}/git/policy.git?ref=${LATEST_COMMIT}

policy.release.kitty.purr (deny)
https://enterprisecontract.dev/docs/ec-policies/release_policy.html#kitty__purr
Expand Down Expand Up @@ -94,14 +94,14 @@ kitty.purr
---

[sources from ECP:stdout - 1]
# Source: git::https://${GITHOST}/git/policy1.git?ref=8288b21ca5e7d8863efffb47c2bc3eac1274d1ff
# Source: git::${GITHOST}/git/policy1.git?ref=8288b21ca5e7d8863efffb47c2bc3eac1274d1ff

policy.release.kitty.purr (deny)
https://enterprisecontract.dev/docs/ec-policies/release_policy.html#kitty__purr
Kittens
Fluffy
--
# Source: git::https://${GITHOST}/git/policy2.git?ref=${LATEST_COMMIT}
# Source: git::${GITHOST}/git/policy2.git?ref=${LATEST_COMMIT}

main.rejector (deny)
Reject rule
Expand Down
Loading

0 comments on commit dcbef98

Please sign in to comment.