feat: import Sea vHost single-server testing release
This commit is contained in:
commit
248badd33e
441 files changed
+63221
No files matched your search
@@ -0,0 +1,85 @@
|
||||
//go:build linux
|
||||
|
||||
package isolation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestOfflinePythonSourceCacheRequiresOfficialDigest(t *testing.T) {
|
||||
if os.Geteuid() != 0 {
|
||||
t.Skip("root-owned offline source test")
|
||||
}
|
||||
root := t.TempDir()
|
||||
a := Agent{PythonMetadataCacheRoot: root}
|
||||
const name = "Python-3.12.15.tar.xz"
|
||||
source := []byte("verified offline source")
|
||||
digest := sha256.Sum256(source)
|
||||
bundle := []byte(fmt.Sprintf(`{"messageSignature":{"messageDigest":{"algorithm":"SHA2_256","digest":%q}}}`, base64.StdEncoding.EncodeToString(digest[:])))
|
||||
a.cachePythonMetadata(name+".sigstore", bundle)
|
||||
if err := os.WriteFile(filepath.Join(root, name), source, 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
archive, err := a.downloadVerifiedPythonSource(context.Background(), t.TempDir(), "3.12.15")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
actual, err := os.ReadFile(archive)
|
||||
if err != nil || string(actual) != string(source) {
|
||||
t.Fatal("verified offline source was not staged")
|
||||
}
|
||||
if err = os.WriteFile(filepath.Join(root, name), []byte("tampered"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = a.downloadVerifiedPythonSource(context.Background(), t.TempDir(), "3.12.15"); err == nil {
|
||||
t.Fatal("tampered offline source trusted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPythonMetadataCacheOnlyAcceptsRootProtectedFiles(t *testing.T) {
|
||||
if os.Geteuid() != 0 {
|
||||
t.Skip("root-owned offline metadata test")
|
||||
}
|
||||
root := t.TempDir()
|
||||
a := Agent{PythonMetadataCacheRoot: root}
|
||||
const name = "Python-3.12.15.tar.xz.sigstore"
|
||||
data := []byte(`{"messageSignature":{"messageDigest":{"algorithm":"SHA2_256","digest":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="}}}`)
|
||||
a.cachePythonMetadata(name, data)
|
||||
if _, err := a.readPythonMetadataCache(name); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.Chmod(filepath.Join(root, name), 0666); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := a.readPythonMetadataCache(name); err == nil {
|
||||
t.Fatal("world-writable cache trusted")
|
||||
}
|
||||
if err := os.Chmod(filepath.Join(root, name), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.Chown(filepath.Join(root, name), 65534, 65534); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := a.readPythonMetadataCache(name); err == nil {
|
||||
t.Fatal("non-root cache trusted")
|
||||
}
|
||||
if err := os.Remove(filepath.Join(root, name)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
target := filepath.Join(t.TempDir(), "public")
|
||||
if err := os.WriteFile(target, data, 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.Symlink(target, filepath.Join(root, name)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := a.readPythonMetadataCache(name); err == nil {
|
||||
t.Fatal("symlink cache trusted")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user