-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switches yaml parsing library to sigs.k8s.io/yaml which respects json field tags. This fixes yaml parsing for policies, since previously it was not respecting the tags. Also adds a test!
- Loading branch information
Showing
5 changed files
with
64 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
pkg/webhook/testdata/api/v3/repos/foo/bar/contents/policy.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "verify-prod.sts.yaml", | ||
"path": ".github/chainguard/verify-prod.sts.yaml", | ||
"sha": "9f4890d268e2ad02d4171e131018597a7651f61e", | ||
"size": 284, | ||
"url": "https://api.github.com/repos/octo-sts/app/contents/.github/chainguard/verify-prod.sts.yaml?ref=main", | ||
"html_url": "https://github.com/octo-sts/app/blob/main/.github/chainguard/verify-prod.sts.yaml", | ||
"git_url": "https://api.github.com/repos/octo-sts/app/git/blobs/9f4890d268e2ad02d4171e131018597a7651f61e", | ||
"download_url": "https://raw.githubusercontent.com/octo-sts/app/main/.github/chainguard/verify-prod.sts.yaml", | ||
"type": "file", | ||
"content": "IyBDb3B5cmlnaHQgMjAyNCBDaGFpbmd1YXJkLCBJbmMuCiMgU1BEWC1MaWNl\nbnNlLUlkZW50aWZpZXI6IEFwYWNoZS0yLjAKCmlzc3VlcjogaHR0cHM6Ly90\nb2tlbi5hY3Rpb25zLmdpdGh1YnVzZXJjb250ZW50LmNvbQpzdWJqZWN0OiBy\nZXBvOm9jdG8tc3RzL2FwcDpwdWxsX3JlcXVlc3QKY2xhaW1fcGF0dGVybjoK\nICB3b3JrZmxvd19yZWY6IG9jdG8tc3RzL2FwcC8uZ2l0aHViL3dvcmtmbG93\ncy92ZXJpZnktcHJvZC55YW1sQC4qCgpwZXJtaXNzaW9uczoKICBwdWxsX3Jl\ncXVlc3RzOiB3cml0ZQo=\n", | ||
"encoding": "base64", | ||
"_links": { | ||
"self": "https://api.github.com/repos/octo-sts/app/contents/.github/chainguard/verify-prod.sts.yaml?ref=main", | ||
"git": "https://api.github.com/repos/octo-sts/app/git/blobs/9f4890d268e2ad02d4171e131018597a7651f61e", | ||
"html": "https://github.com/octo-sts/app/blob/main/.github/chainguard/verify-prod.sts.yaml" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2024 Chainguard, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package webhook | ||
|
||
import ( | ||
"io" | ||
"net/http" | ||
"net/http/httptest" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/chainguard-dev/clog/slogtest" | ||
"github.com/google/go-github/v61/github" | ||
) | ||
|
||
func TestValidatePolicy(t *testing.T) { | ||
// Use prefetched data. | ||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
path := filepath.Join("testdata", r.URL.Path) | ||
f, err := os.Open(path) | ||
if err != nil { | ||
t.Logf("%s not found", path) | ||
http.Error(w, err.Error(), http.StatusNotFound) | ||
return | ||
} | ||
defer f.Close() | ||
if _, err := io.Copy(w, f); err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
})) | ||
|
||
gh, err := github.NewClient(srv.Client()).WithEnterpriseURLs(srv.URL, srv.URL) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
ctx := slogtest.TestContextWithLogger(t) | ||
if err := validatePolicies(ctx, gh, "foo", "bar", "deadbeef", []string{"policy.json"}); err != nil { | ||
t.Fatal(err) | ||
} | ||
} |