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 authored and asraa committed May 31, 2022
1 parent 530c29e commit b8a5075
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
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
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 b8a5075

Please sign in to comment.