ci-platforms / darwin arm64 smoke (push) Skipped
ci / build (amd64, linux, ubuntu-24.04) (push) Failing after 12m19s
ci-platforms / darwin amd64 smoke (push) Skipped
ci-platforms / windows amd64 smoke (push) Skipped
github-native / gitea-pending (push) Skipped
github-native / darwin amd64 native (push) Skipped
github-native / linux amd64 native (push) Skipped
github-native / windows amd64 native (push) Skipped
github-native / darwin arm64 native (push) Skipped
github-native / gitea-result (push) Skipped
ci / checks (push) Failing after 23m57s
ci / release (push) Skipped
GitHub / windows amd64 native GitHub-hosted native CI: failure
GitHub / darwin arm64 native GitHub-hosted native CI: failure
GitHub / darwin amd64 native GitHub-hosted native CI: failure
GitHub / linux amd64 native GitHub-hosted native CI: success
31 lines
867 B
Go
31 lines
867 B
Go
package pipeline
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestReadExternalFileIsBoundedAndRegular(t *testing.T) {
|
|
root := t.TempDir()
|
|
file := filepath.Join(root, "source")
|
|
if err := os.WriteFile(file, []byte("1234"), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if data, err := ReadExternalFile(file, 4); err != nil || string(data) != "1234" {
|
|
t.Fatalf("bounded file: %q, %v", data, err)
|
|
}
|
|
for _, name := range []string{file, root} {
|
|
if _, err := ReadExternalFile(name, 3); !errors.Is(err, ErrExternalFileLimit) {
|
|
t.Errorf("%s: oversized or non-regular file was accepted: %v", name, err)
|
|
}
|
|
}
|
|
if _, err := ReadExternalFile(file, 0); err == nil {
|
|
t.Fatal("invalid size limit was accepted")
|
|
}
|
|
if _, err := ReadExternalFile(filepath.Join(root, "missing"), 4); !errors.Is(err, os.ErrNotExist) {
|
|
t.Fatalf("missing file: %v", err)
|
|
}
|
|
}
|