Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ CLAUDE.md
# https://github.com/knative/func/issues/3196
/pkg/builders/testdata/go-fn-with-private-deps/.s2i

# TODO: Run this test from a temp directory instead:
# https://github.com/knative/func/issues/3197
pkg/oci/testdata/test-links/absoluteLink
pkg/oci/testdata/test-links/absoluteLinkWindows

# TODO: update the test which creates this to run in a temp directory:
# https://github.com/knative/func/issues/3158
/pkg/creds/auth.json
45 changes: 42 additions & 3 deletions pkg/oci/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,40 @@ import (

var TestPlatforms = []fn.Platform{{OS: "linux", Architecture: runtime.GOARCH}}

func copyDir(src, dst string) error {
return filepath.Walk(src, func(path string, info fs.FileInfo, err error) error {
if err != nil {
return err
}

rel, err := filepath.Rel(src, path)
if err != nil {
return err
}

target := filepath.Join(dst, rel)

if info.Mode()&os.ModeSymlink != 0 {
linkTarget, err := os.Readlink(path)
if err != nil {
return err
}
return os.Symlink(linkTarget, target)
}

if info.IsDir() {
return os.MkdirAll(target, info.Mode())
}

data, err := os.ReadFile(path)
if err != nil {
return err
}

return os.WriteFile(target, data, info.Mode())
})
}

// TestBuilder_BuildGo ensures that, when given a Go Function, an OCI-compliant
// directory structure is created on .Build in the expected path.
func TestBuilder_BuildGo(t *testing.T) {
Expand Down Expand Up @@ -504,13 +538,18 @@ func (l *TestLanguageBuilder) Configure(job buildJob, p v1.Platform, c v1.Config
return l.ConfigureFn(job, p, c)
}

// Test_validatedLinkTaarget ensures that the function disallows
// Test_validatedLinkTarget ensures that the function disallows
// links which are absolute or refer to targets outside the given root, in
// addition to the basic job of returning the value of reading the link.
func Test_validatedLinkTarget(t *testing.T) {
root := filepath.Join("testdata", "test-links")
tmp := t.TempDir()
root := filepath.Join(tmp, "test-links")
err := copyDir("testdata/test-links", root)

err := os.Symlink("/var/example/absolute/link", filepath.Join(root, "absoluteLink"))
if err != nil {
t.Fatalf("failed to copy test data: %v", err)
}
err = os.Symlink("/var/example/absolute/link", filepath.Join(root, "absoluteLink"))
if err != nil && !errors.Is(err, os.ErrExist) {
t.Fatal(err)
}
Expand Down
Loading