Skip to content
Open
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
8 changes: 1 addition & 7 deletions Cubelet/plugins/cube/internals/createid/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,7 @@ func (l *local) Create(ctx context.Context, opts *workflow.CreateContext) error
opts.SandboxID = utils.GenerateID()

if opts.IsCreateSnapshot() {

templateID, ok := opts.GetSnapshotTemplateID()
if !ok {
return ret.Err(errorcode.ErrorCode_InvalidParamFormat, "cube.master.appsnapshot.template.id should provide")
}

opts.SandboxID = templateID + "_" + "0"
opts.SandboxID = utils.GenerateID() + "_snapshot"
}
return nil
}
Expand Down
49 changes: 48 additions & 1 deletion network-agent/internal/service/state_store_test.go
Comment thread
rogeroger-yu marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,54 @@

package service

import "testing"
import (
"path/filepath"
"testing"
)

func TestStateStorePath(t *testing.T) {
store, err := newStateStore(t.TempDir())
if err != nil {
t.Fatalf("newStateStore error=%v", err)
}

tests := []struct {
name string
sandboxID string
wantErr bool
}{
{name: "valid simple id", sandboxID: "sb-1", wantErr: false},
{name: "valid uuid", sandboxID: "a1b2c3d4e5f6", wantErr: false},
{name: "valid snapshot id", sandboxID: "a1b2c3d4e5f6_snapshot", wantErr: false},
{name: "empty string", sandboxID: "", wantErr: true},
{name: "contains dot", sandboxID: "sb.1", wantErr: true},
{name: "forward slash", sandboxID: "a/b", wantErr: true},
{name: "backslash", sandboxID: "a\\b", wantErr: true},
{name: "dot prefix", sandboxID: ".hidden", wantErr: true},
{name: "double dot traversal", sandboxID: "..", wantErr: true},
{name: "oci image name", sandboxID: "registry.example.com/path/image:tag", wantErr: true},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p, err := store.path(tt.sandboxID)
if tt.wantErr {
if err == nil {
t.Errorf("path(%q) = %q, want error", tt.sandboxID, p)
}
return
}
if err != nil {
t.Errorf("path(%q) unexpected error: %v", tt.sandboxID, err)
return
}
want := filepath.Join(store.dir, tt.sandboxID+".json")
if p != want {
t.Errorf("path(%q) = %q, want %q", tt.sandboxID, p, want)
}
})
}
}

func TestStateStoreSaveLoadDelete(t *testing.T) {
store, err := newStateStore(t.TempDir())
Expand Down