1a69fcfd04
- Updated the installation script to clarify that production wrappers do not include fixed test secrets, improving user guidance for local testing. - Modified the jiggablend-manager and jiggablend-runner scripts to remove fixed test configurations, emphasizing the use of local test credentials via `make init-test`. - Enhanced error handling in the runner script to ensure that an API key is provided, improving security and user feedback. - Added new flags and options for the runner, including sandboxing capabilities and GPU ray tracing control, enhancing flexibility for users. - Improved README documentation to reflect changes in usage and configuration, ensuring users have clear instructions for setup and execution.
145 lines
3.2 KiB
Go
145 lines
3.2 KiB
Go
package workspace
|
|
|
|
import (
|
|
"archive/tar"
|
|
"bytes"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func createTarBuffer(files map[string]string) *bytes.Buffer {
|
|
var buf bytes.Buffer
|
|
tw := tar.NewWriter(&buf)
|
|
for name, content := range files {
|
|
hdr := &tar.Header{
|
|
Name: name,
|
|
Mode: 0644,
|
|
Size: int64(len(content)),
|
|
}
|
|
tw.WriteHeader(hdr)
|
|
tw.Write([]byte(content))
|
|
}
|
|
tw.Close()
|
|
return &buf
|
|
}
|
|
|
|
func TestExtractTarStripPrefix_RejectsEscapingSymlink(t *testing.T) {
|
|
destDir := t.TempDir()
|
|
var buf bytes.Buffer
|
|
tw := tar.NewWriter(&buf)
|
|
// Top-level prefix like Blender archives
|
|
_ = tw.WriteHeader(&tar.Header{Name: "blender-x/", Typeflag: tar.TypeDir, Mode: 0755})
|
|
_ = tw.WriteHeader(&tar.Header{
|
|
Name: "blender-x/evil",
|
|
Typeflag: tar.TypeSymlink,
|
|
Linkname: "../../outside",
|
|
Mode: 0777,
|
|
})
|
|
_ = tw.Close()
|
|
|
|
if err := ExtractTarStripPrefix(&buf, destDir); err == nil {
|
|
t.Fatal("expected escaping symlink to be rejected")
|
|
}
|
|
}
|
|
|
|
func TestExtractTar(t *testing.T) {
|
|
destDir := t.TempDir()
|
|
|
|
buf := createTarBuffer(map[string]string{
|
|
"hello.txt": "world",
|
|
"sub/a.txt": "nested",
|
|
})
|
|
|
|
if err := ExtractTar(buf, destDir); err != nil {
|
|
t.Fatalf("ExtractTar: %v", err)
|
|
}
|
|
|
|
data, err := os.ReadFile(filepath.Join(destDir, "hello.txt"))
|
|
if err != nil {
|
|
t.Fatalf("read hello.txt: %v", err)
|
|
}
|
|
if string(data) != "world" {
|
|
t.Errorf("hello.txt = %q, want %q", data, "world")
|
|
}
|
|
|
|
data, err = os.ReadFile(filepath.Join(destDir, "sub", "a.txt"))
|
|
if err != nil {
|
|
t.Fatalf("read sub/a.txt: %v", err)
|
|
}
|
|
if string(data) != "nested" {
|
|
t.Errorf("sub/a.txt = %q, want %q", data, "nested")
|
|
}
|
|
}
|
|
|
|
func TestExtractTarStripPrefix(t *testing.T) {
|
|
destDir := t.TempDir()
|
|
|
|
buf := createTarBuffer(map[string]string{
|
|
"toplevel/": "",
|
|
"toplevel/foo.txt": "bar",
|
|
})
|
|
|
|
if err := ExtractTarStripPrefix(buf, destDir); err != nil {
|
|
t.Fatalf("ExtractTarStripPrefix: %v", err)
|
|
}
|
|
|
|
data, err := os.ReadFile(filepath.Join(destDir, "foo.txt"))
|
|
if err != nil {
|
|
t.Fatalf("read foo.txt: %v", err)
|
|
}
|
|
if string(data) != "bar" {
|
|
t.Errorf("foo.txt = %q, want %q", data, "bar")
|
|
}
|
|
}
|
|
|
|
func TestExtractTarStripPrefix_PathTraversal(t *testing.T) {
|
|
destDir := t.TempDir()
|
|
|
|
buf := createTarBuffer(map[string]string{
|
|
"prefix/../../../etc/passwd": "pwned",
|
|
})
|
|
|
|
err := ExtractTarStripPrefix(buf, destDir)
|
|
if err == nil {
|
|
t.Fatal("expected error for path traversal, got nil")
|
|
}
|
|
}
|
|
|
|
func TestExtractTar_PathTraversal(t *testing.T) {
|
|
destDir := t.TempDir()
|
|
|
|
buf := createTarBuffer(map[string]string{
|
|
"../../../etc/passwd": "pwned",
|
|
})
|
|
|
|
err := ExtractTar(buf, destDir)
|
|
if err == nil {
|
|
t.Fatal("expected error for path traversal, got nil")
|
|
}
|
|
}
|
|
|
|
func TestExtractTarFile(t *testing.T) {
|
|
destDir := t.TempDir()
|
|
tarPath := filepath.Join(t.TempDir(), "archive.tar")
|
|
|
|
buf := createTarBuffer(map[string]string{
|
|
"hello.txt": "world",
|
|
})
|
|
if err := os.WriteFile(tarPath, buf.Bytes(), 0644); err != nil {
|
|
t.Fatalf("write tar file: %v", err)
|
|
}
|
|
|
|
if err := ExtractTarFile(tarPath, destDir); err != nil {
|
|
t.Fatalf("ExtractTarFile: %v", err)
|
|
}
|
|
|
|
got, err := os.ReadFile(filepath.Join(destDir, "hello.txt"))
|
|
if err != nil {
|
|
t.Fatalf("read extracted file: %v", err)
|
|
}
|
|
if string(got) != "world" {
|
|
t.Fatalf("unexpected file content: %q", got)
|
|
}
|
|
}
|