Skip to content

Commit

Permalink
When interacting with fs do not use OS specific separators.
Browse files Browse the repository at this point in the history
Signed-off-by: Ville Aikas <vaikas@chainguard.dev>
  • Loading branch information
vaikas committed May 31, 2022
1 parent 89bc9f9 commit 2805823
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
3 changes: 1 addition & 2 deletions pkg/cosign/tuf/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ func (t *TUF) getRootStatus() (*RootStatus, error) {
}

func getRoot(meta map[string]json.RawMessage, fallback fs.FS) (json.RawMessage, error) {
trustedRoot, ok := meta["root.json"]
if ok {
if trustedRoot, ok := meta["root.json"]; ok {
return trustedRoot, nil
}
// On first initialize, there will be no root in the TUF DB, so read from embedded.
Expand Down
13 changes: 7 additions & 6 deletions pkg/cosign/tuf/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"net/http"
"net/http/httptest"
"os"
"path"
"path/filepath"
"reflect"
"sort"
Expand Down Expand Up @@ -334,16 +335,16 @@ func TestGetTargetsByMeta(t *testing.T) {
func makeMapFS(repo string) (fs fstest.MapFS) {
fs = make(fstest.MapFS)
_ = filepath.Walk(repo,
func(path string, info os.FileInfo, err error) error {
func(fpath string, info os.FileInfo, err error) error {
if err != nil {
return err
}
rel, _ := filepath.Rel(repo, path)
rel, _ := filepath.Rel(repo, fpath)
if info.IsDir() {
fs[filepath.FromSlash(filepath.Join("repository", rel))] = &fstest.MapFile{Mode: os.ModeDir}
fs[path.Join("repository", rel)] = &fstest.MapFile{Mode: os.ModeDir}
} else {
b, _ := os.ReadFile(path)
fs[filepath.FromSlash(filepath.Join("repository", rel))] = &fstest.MapFile{Data: b}
b, _ := os.ReadFile(fpath)
fs[path.Join("repository", rel)] = &fstest.MapFile{Data: b}
}
return nil
})
Expand Down Expand Up @@ -386,7 +387,7 @@ func TestUpdatedTargetNamesEmbedded(t *testing.T) {
if !ok {
t.Fatal("fs.ReadFileFS unimplemented for embedded repo")
}
if _, err := rd.ReadFile(filepath.FromSlash(filepath.Join("repository", "targets", newTarget))); err == nil {
if _, err := rd.ReadFile(path.Join("repository", "targets", newTarget)); err == nil {
t.Fatal("embedded repository should not contain new target")
}

Expand Down

0 comments on commit 2805823

Please sign in to comment.