ci: expand CI checks and make consumer sync opt-in
- Add Go, npm, Python, and Java validation to CI - Run Go tests against PostgreSQL - Record performance fixes in the report
This commit is contained in:
1 parent
199a5efaef
commit
22887fef03
100 files changed
+9740
-429
No files matched your search
@@ -457,6 +457,30 @@ func thumbnailFile(id string) (string, error) {
|
||||
return id + ".jpg", nil
|
||||
}
|
||||
|
||||
// validName reports an error unless name can be used as one path segment: it must not be empty,
|
||||
// ".", ".." or contain a path separator. Every push and delete helper checks its name with this.
|
||||
func validName(name string) error {
|
||||
if name == "" || name == "." || name == ".." || strings.ContainsAny(name, `/\`) {
|
||||
return fmt.Errorf("invalid name %q", name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// validRelativeName is validName for outputs, inputs and copies, which may sit in nested
|
||||
// directories (for example CraftStudio's "<user>/<workflow>/<file>"). It refuses an empty or
|
||||
// absolute name, a backslash, and any empty, "." or ".." segment.
|
||||
func validRelativeName(name string) error {
|
||||
if name == "" || strings.HasPrefix(name, "/") || strings.ContainsRune(name, '\\') {
|
||||
return fmt.Errorf("invalid name %q", name)
|
||||
}
|
||||
for _, segment := range strings.Split(name, "/") {
|
||||
if segment == "" || segment == "." || segment == ".." {
|
||||
return fmt.Errorf("invalid name %q", name)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// thumbnailPaths lists every CarrierNode path a thumbnail may live at, in lookup order: the
|
||||
// project's thumbnails mount first, then CarrierNode's legacy thumbnail root. Thumbnails
|
||||
// stored before the mount existed sit in the legacy root, and reads keep finding them there
|
||||
@@ -670,6 +694,9 @@ func pushedSize(response *http.Response) int64 {
|
||||
|
||||
// PushThumbnail uploads a locally-generated thumbnail to CarrierNode.
|
||||
func (c *Client) PushThumbnail(ctx context.Context, id, localPath string) (int64, error) {
|
||||
if err := validName(id); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
response, err := c.push(ctx, http.MethodPost, "/api/thumbnails/"+url.PathEscape(id), localPath)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -680,6 +707,9 @@ func (c *Client) PushThumbnail(ctx context.Context, id, localPath string) (int64
|
||||
// DeleteThumbnail removes a thumbnail from CarrierNode. A 404 is treated as
|
||||
// already-deleted, not an error. Always targets the primary instance.
|
||||
func (c *Client) DeleteThumbnail(ctx context.Context, id string) error {
|
||||
if err := validName(id); err != nil {
|
||||
return err
|
||||
}
|
||||
request, err := c.newRequest(ctx, c.primaryBaseURL(ctx), http.MethodDelete, "/api/thumbnails/"+url.PathEscape(id), nil)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -698,6 +728,9 @@ func (c *Client) DeleteThumbnail(ctx context.Context, id string) error {
|
||||
// PushOutput uploads a locally-produced output file (e.g. a converted or
|
||||
// generated media file) to CarrierNode's OutputRoot.
|
||||
func (c *Client) PushOutput(ctx context.Context, name, localPath string) (int64, error) {
|
||||
if err := validRelativeName(name); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
response, err := c.push(ctx, http.MethodPost, "/api/outputs/"+url.PathEscape(name), localPath)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -707,6 +740,9 @@ func (c *Client) PushOutput(ctx context.Context, name, localPath string) (int64,
|
||||
|
||||
// PushInput uploads a local file to CarrierNode's InputRoot.
|
||||
func (c *Client) PushInput(ctx context.Context, name, localPath string) (int64, error) {
|
||||
if err := validRelativeName(name); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
response, err := c.push(ctx, http.MethodPost, "/api/inputs/"+url.PathEscape(name), localPath)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -716,6 +752,9 @@ func (c *Client) PushInput(ctx context.Context, name, localPath string) (int64,
|
||||
|
||||
// PushCopy uploads a local file to CarrierNode's CopyRoot.
|
||||
func (c *Client) PushCopy(ctx context.Context, name, localPath string) (int64, error) {
|
||||
if err := validRelativeName(name); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
response, err := c.push(ctx, http.MethodPost, "/api/copies/"+url.PathEscape(name), localPath)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
||||
@@ -181,3 +181,58 @@ func TestThumbnailIDsCannotEscapeTheThumbnailsDirectory(t *testing.T) {
|
||||
t.Fatalf("invalid thumbnail ids reached CarrierNode: %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestPushAndDeleteNamesCannotEscapeTheirDirectory checks that the push and delete helpers refuse
|
||||
// names that are "." or ".." or contain a separator before any request reaches CarrierNode.
|
||||
func TestPushAndDeleteNamesCannotEscapeTheirDirectory(t *testing.T) {
|
||||
client, node := newThumbnailTestClient(t, nil)
|
||||
ctx := context.Background()
|
||||
local := filepath.Join(t.TempDir(), "payload.bin")
|
||||
if err := os.WriteFile(local, []byte("x"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for _, name := range []string{"", ".", "..", "../escape", `..\escape`, "nested/name"} {
|
||||
if _, err := client.PushThumbnail(ctx, name, local); err == nil {
|
||||
t.Errorf("PushThumbnail accepted name %q", name)
|
||||
}
|
||||
if err := client.DeleteThumbnail(ctx, name); err == nil {
|
||||
t.Errorf("DeleteThumbnail accepted name %q", name)
|
||||
}
|
||||
}
|
||||
// Outputs, inputs and copies may nest, but no segment may climb out of its directory.
|
||||
for _, name := range []string{"", ".", "..", "../escape", `..\escape`, "/abs", "a//b", "a/../b", "a/./b", "a/"} {
|
||||
if _, err := client.PushOutput(ctx, name, local); err == nil {
|
||||
t.Errorf("PushOutput accepted name %q", name)
|
||||
}
|
||||
if _, err := client.PushInput(ctx, name, local); err == nil {
|
||||
t.Errorf("PushInput accepted name %q", name)
|
||||
}
|
||||
if _, err := client.PushCopy(ctx, name, local); err == nil {
|
||||
t.Errorf("PushCopy accepted name %q", name)
|
||||
}
|
||||
}
|
||||
if got := node.seen(); len(got) != 0 {
|
||||
t.Fatalf("invalid names reached CarrierNode: %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestNestedOutputNamesAreAccepted checks that CraftStudio-style nested output names pass the
|
||||
// relative-name check, so generator outputs keep their CarrierNode path.
|
||||
func TestNestedOutputNamesAreAccepted(t *testing.T) {
|
||||
for _, name := range []string{"CraftStudio/alice/flux/out.png", "a/b.txt"} {
|
||||
if err := validRelativeName(name); err != nil {
|
||||
t.Errorf("validRelativeName(%q) = %v, want nil", name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestValidNamesAreNotRefused checks that ordinary names, including ones with spaces or query
|
||||
// characters, pass the name check; the path escaping in MountPath and the push helpers handles them.
|
||||
func TestValidNamesAreNotRefused(t *testing.T) {
|
||||
for _, name := range []string{"clip.mp4", "my clip?.mp4", "a#b", "v1.2.final"} {
|
||||
if err := validName(name); err != nil {
|
||||
t.Errorf("validName(%q) = %v, want nil", name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user