package hostops import ( "context" "errors" "testing" "github.com/carlosframework/platform/internal/release" ) // TestClassifyPromotionRecordIsExact: a build's signed promotion record, // releases///promoted/ (settings plan 2, spec ยง4.1), is // a reviewed family scoped to exactly its app, put and deleted; nothing // else under releases/// is. func TestClassifyPromotionRecordIsExact(t *testing.T) { ctx := context.Background() key := release.PromotionRecordKey("bab", "km", "v1") for _, c := range []struct { name string target MutationTarget }{ {"record put", MutationTarget{Surface: "bucket", Method: "Put", Key: key, After: []byte(`{}`)}}, {"record put over an existing one", MutationTarget{Surface: "bucket", Method: "Put", Key: key, ETag: "x", Before: []byte(`{}`), After: []byte(`{}`)}}, {"record delete", MutationTarget{Surface: "bucket", Method: "Delete", Key: key}}, } { got, err := ClassifyMutation(ctx, nil, nil, c.target) if err != nil { t.Errorf("%s: %v", c.name, err) continue } if got.Family != "promotion-record" || got.NonApp != "" || got.MailGate || len(got.Scopes) != 1 || got.Scopes[0] != (AppScope{"bab", "km"}) { t.Errorf("%s: classified %+v, want family promotion-record scoped to exactly {bab km}", c.name, got) } } for _, c := range []struct { name string target MutationTarget }{ {"an invalid account", MutationTarget{Surface: "bucket", Method: "Put", Key: "releases/BAB!/km/promoted/v1", After: []byte(`{}`)}}, {"an invalid app", MutationTarget{Surface: "bucket", Method: "Put", Key: "releases/bab/KM!/promoted/v1", After: []byte(`{}`)}}, {"an empty version", MutationTarget{Surface: "bucket", Method: "Put", Key: "releases/bab/km/promoted/", After: []byte(`{}`)}}, {"a sixth segment", MutationTarget{Surface: "bucket", Method: "Put", Key: key + "/x", After: []byte(`{}`)}}, {"no version", MutationTarget{Surface: "bucket", Method: "Put", Key: "releases/bab/km/promoted", After: []byte(`{}`)}}, {"another name under the app", MutationTarget{Surface: "bucket", Method: "Put", Key: "releases/bab/km/other/v1", After: []byte(`{}`)}}, {"the dev version", MutationTarget{Surface: "bucket", Method: "Put", Key: "releases/bab/km/promoted/dev", After: []byte(`{}`)}}, {"a delete-if-match", MutationTarget{Surface: "bucket", Method: "DeleteIfMatch", Key: key, ETag: "x"}}, } { got, err := ClassifyMutation(ctx, nil, nil, c.target) if !errors.Is(err, ErrUnclassified) && !errors.Is(err, ErrIdentity) { t.Errorf("%s: classified %+v, err %v; want ErrUnclassified or ErrIdentity", c.name, got, err) } } }