Skip to content

Commit

Permalink
Fix incorrect API field name for ignore_rule
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhung committed Dec 3, 2024
1 parent 1cfc04e commit 5f7f157
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/xray/resource/resource_xray_ignore_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ type IgnoreFiltersAPIModel struct {
Watches []string `json:"watches,omitempty"`
DockerLayers []string `json:"docker-layers,omitempty"`
OperationalRisks []string `json:"operational_risk,omitempty"`
ReleaseBundles []IgnoreFilterNameVersionAPIModel `json:"release_bundles,omitempty"`
ReleaseBundles []IgnoreFilterNameVersionAPIModel `json:"release-bundles,omitempty"`
Builds []IgnoreFilterNameVersionProjectAPIModel `json:"builds,omitempty"`
Components []IgnoreFilterNameVersionAPIModel `json:"components,omitempty"`
Artifacts []IgnoreFilterNameVersionPathAPIModel `json:"artifacts,omitempty"`
Expand Down
95 changes: 95 additions & 0 deletions pkg/xray/resource/resource_xray_ignore_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package xray_test
import (
"fmt"
"net/http"
"os"
"regexp"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -791,6 +793,99 @@ func TestAccIgnoreRule_build_with_project_key(t *testing.T) {
})
}

// TestAccIgnoreRule_release_bundle would only be successful when executed against Artifactory instance
// that has Distribution enabled (i.e. has edge node(s) configured)
func TestAccIgnoreRule_release_bundle(t *testing.T) {
jfrogURL := os.Getenv("JFROG_URL")
if !strings.HasSuffix(jfrogURL, "jfrog.io") {
t.Skipf("env var JFROG_URL '%s' is not a cloud instance.", jfrogURL)
}

_, fqrn, name := testutil.MkNames("ignore-rule-", "xray_ignore_rule")
_, _, releaseBundleName := testutil.MkNames("test-release-bundle-v1", "distribution_release_bundle_v1")
expirationDate := time.Now().UTC().Add(time.Hour * 48)

config := util.ExecuteTemplate("TestAccIgnoreRule", `
resource "distribution_release_bundle_v1" "{{ .releaseBundleName }}" {
name = "{{ .releaseBundleName }}"
version = "1.0.0"
sign_immediately = false
description = "Test description"
release_notes = {
syntax = "plain_text"
content = "test release notes"
}
spec = {
queries = [{
aql = "items.find({ \"repo\" : \"example-repo-local\" })"
query_name: "query-1"
mappings = [{
input = "original_repository/(.*)"
output = "new_repository/$1"
}]
added_props = [{
key = "test-key"
values = ["test-value"]
}]
exclude_props_patterns = [
"test-patterns"
]
}]
}
}
resource "xray_ignore_rule" "{{ .name }}" {
notes = "fake notes"
expiration_date = "{{ .expirationDate }}"
vulnerabilities = ["any"]
cves = ["any"]
release_bundle {
name = distribution_release_bundle_v1.{{ .releaseBundleName }}.name
version = distribution_release_bundle_v1.{{ .releaseBundleName }}.version
}
}
`, map[string]interface{}{
"releaseBundleName": releaseBundleName,
"name": name,
"expirationDate": expirationDate.Local().Format("2006-01-02"),
})

resource.Test(t, resource.TestCase{
ExternalProviders: map[string]resource.ExternalProvider{
"distribution": {
Source: "jfrog/distribution",
},
},
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
CheckDestroy: acctest.VerifyDeleted(fqrn, "", testCheckIgnoreRule),
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(fqrn, "id"),
resource.TestCheckResourceAttr(fqrn, "notes", "fake notes"),
resource.TestCheckResourceAttr(fqrn, "expiration_date", expirationDate.Local().Format("2006-01-02")),
resource.TestCheckResourceAttr(fqrn, "is_expired", "false"),
resource.TestCheckResourceAttr(fqrn, "release_bundle.#", "1"),
resource.TestCheckResourceAttr(fqrn, "release_bundle.0.name", releaseBundleName),
resource.TestCheckResourceAttr(fqrn, "release_bundle.0.version", "1.0.0"),
),
},
{
ResourceName: fqrn,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

// testCheckIgnoreRule fetches the supposingly deleted ignore rule and verify it has been deleted
// Xray applies soft delete to ignore rule and adds 'deleted_by' and 'deleted_at'
// fields to the payload after a rule is deleted
Expand Down

0 comments on commit 5f7f157

Please sign in to comment.