101 lines
3.5 KiB
Go
101 lines
3.5 KiB
Go
package instance
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
|
|
core "git.yuntuo.hk/k2safe/orbit/model"
|
|
"git.yuntuo.hk/k2safe/orbit/platform/auth"
|
|
"git.yuntuo.hk/k2safe/orbit/pulse/service"
|
|
)
|
|
|
|
type captureStore struct {
|
|
calls int
|
|
input StartInput
|
|
}
|
|
|
|
func (s *captureStore) Start(_ context.Context, _ auth.Token, _ string, in StartInput) (StartResult, error) {
|
|
s.calls++
|
|
s.input = in
|
|
return StartResult{}, nil
|
|
}
|
|
func (s *captureStore) Get(context.Context, auth.Token, core.ID) (View, error) {
|
|
s.calls++
|
|
return View{}, nil
|
|
}
|
|
func (s *captureStore) Steps(context.Context, auth.Token, core.ID) (StepsView, error) {
|
|
s.calls++
|
|
return StepsView{}, nil
|
|
}
|
|
func (s *captureStore) Step(context.Context, auth.Token, core.ID, string) (StepDetail, error) {
|
|
s.calls++
|
|
return StepDetail{}, nil
|
|
}
|
|
func TestAdmissionBoundaryPreservesExactInput(t *testing.T) {
|
|
store := &captureStore{}
|
|
api := New(store)
|
|
base := StartInput{DefinitionID: "11111111111111111111111111111111", Version: "v1", Input: json.RawMessage(`{"n":9007199254740993}`), BusinessKey: "关联 "}
|
|
for _, raw := range []string{`{"n":9007199254740993}`, `null`} {
|
|
in := base
|
|
in.Input = json.RawMessage(raw)
|
|
if _, err := api.Start(context.Background(), auth.Token{}, "identity", in); err != nil || string(store.input.Input) != raw || store.input.BusinessKey != base.BusinessKey {
|
|
t.Fatal("input changed", err)
|
|
}
|
|
}
|
|
for _, change := range []func(*StartInput){
|
|
func(in *StartInput) { in.Input = nil }, func(in *StartInput) { in.Input = json.RawMessage(`{"n":1,"n":2}`) },
|
|
func(in *StartInput) { in.Input = json.RawMessage(`"\ud800"`) }, func(in *StartInput) { in.Input = json.RawMessage(`"` + strings.Repeat("a", 256<<10) + `"`) },
|
|
func(in *StartInput) { in.Version = "../v1" }, func(in *StartInput) { in.Version = strings.Repeat("v", 65) },
|
|
func(in *StartInput) { in.BusinessKey = strings.Repeat("中", 192) }, func(in *StartInput) { in.BusinessKey = "a\x00b" },
|
|
func(in *StartInput) { in.DefinitionID = "bad" },
|
|
} {
|
|
in := base
|
|
change(&in)
|
|
before := store.calls
|
|
if _, err := api.Start(context.Background(), auth.Token{}, "identity", in); err == nil || store.calls != before {
|
|
t.Fatal("invalid input reached store")
|
|
}
|
|
}
|
|
if _, err := api.Start(context.Background(), auth.Token{}, "", base); err == nil {
|
|
t.Fatal("missing identity accepted")
|
|
}
|
|
}
|
|
|
|
func (s *captureStore) ListOperations(context.Context, auth.Token, core.ID, service.HistoryPageInput) (OperationPage, error) {
|
|
s.calls++
|
|
return OperationPage{}, nil
|
|
}
|
|
func (s *captureStore) GetOperation(context.Context, auth.Token, core.ID, core.ID) (OperationView, error) {
|
|
s.calls++
|
|
return OperationView{}, nil
|
|
}
|
|
|
|
func (s *captureStore) ListActivations(context.Context, auth.Token, core.ID, string, service.HistoryPageInput) (ActivationPage, error) {
|
|
s.calls++
|
|
return ActivationPage{}, nil
|
|
}
|
|
func (s *captureStore) GetActivation(context.Context, auth.Token, core.ID, string, core.ID) (ActivationDetail, error) {
|
|
s.calls++
|
|
return ActivationDetail{}, nil
|
|
}
|
|
func (s *captureStore) ListPollRounds(context.Context, auth.Token, core.ID, string, core.ID, service.HistoryPageInput) (PollRoundPage, error) {
|
|
s.calls++
|
|
return PollRoundPage{}, nil
|
|
}
|
|
|
|
func (s *captureStore) List(context.Context, auth.Token, ListInput) (Page, error) {
|
|
s.calls++
|
|
return Page{}, nil
|
|
}
|
|
|
|
func (s *captureStore) ListEvents(context.Context, auth.Token, core.ID, service.HistoryPageInput) (EventPage, error) {
|
|
s.calls++
|
|
return EventPage{}, nil
|
|
}
|
|
func (s *captureStore) GetEvent(context.Context, auth.Token, core.ID, core.ID) (EventDetail, error) {
|
|
s.calls++
|
|
return EventDetail{}, nil
|
|
}
|