package hostops import ( "context" "errors" "testing" ) // TestClassifyAccountLimitsRecordIsExact: the console's per-account limits // record (plans-caps-packs spec ยง7) is a reviewed non-app family. It is only // ever put; nothing deletes it, and nothing else under accounts// rides // on its classification. func TestClassifyAccountLimitsRecordIsExact(t *testing.T) { ctx := context.Background() key := "accounts/bab/limits.json" for _, c := range []struct { name string target MutationTarget }{ {"first put", MutationTarget{Surface: "bucket", Method: "Put", Key: key, After: []byte(`{}`)}}, {"replacing put", MutationTarget{Surface: "bucket", Method: "Put", Key: key, ETag: "x", Before: []byte(`{}`), After: []byte(`{}`)}}, } { got, err := ClassifyMutation(ctx, nil, nil, c.target) if err != nil { t.Errorf("%s: %v", c.name, err) continue } if got.Family != "account-limits" || got.NonApp == "" || len(got.Scopes) != 0 || got.MailGate { t.Errorf("%s: classified %+v, want non-app family account-limits with no scopes", c.name, got) } } for _, c := range []struct { name string target MutationTarget }{ {"a delete", MutationTarget{Surface: "bucket", Method: "Delete", Key: key}}, {"an invalid account", MutationTarget{Surface: "bucket", Method: "Put", Key: "accounts/BAB!/limits.json", After: []byte(`{}`)}}, {"a deeper key", MutationTarget{Surface: "bucket", Method: "Put", Key: "accounts/bab/x/limits.json", After: []byte(`{}`)}}, {"a lookalike name", MutationTarget{Surface: "bucket", Method: "Put", Key: "accounts/bab/limits.json.bak", After: []byte(`{}`)}}, } { if got, err := ClassifyMutation(ctx, nil, nil, c.target); !errors.Is(err, ErrUnclassified) { t.Errorf("%s: classified %+v, err %v; want ErrUnclassified", c.name, got, err) } } } // TestClassifyPlansMarkerIsExact: the console's deployment marker (plans 2) // is a reviewed non-app family, put only. func TestClassifyPlansMarkerIsExact(t *testing.T) { ctx := context.Background() key := "control/plans.json" got, err := ClassifyMutation(ctx, nil, nil, MutationTarget{Surface: "bucket", Method: "Put", Key: key, After: []byte(`{}`)}) if err != nil || got.NonApp == "" || len(got.Scopes) != 0 { t.Fatalf("put: %+v, %v; want a non-app family", got, err) } for _, c := range []MutationTarget{ {Surface: "bucket", Method: "Delete", Key: key}, {Surface: "bucket", Method: "Put", Key: "control/plans.json.bak", After: []byte(`{}`)}, {Surface: "bucket", Method: "Put", Key: "control/plans", After: []byte(`{}`)}, } { if got, err := ClassifyMutation(ctx, nil, nil, c); !errors.Is(err, ErrUnclassified) { t.Errorf("%s %s: classified %+v, err %v; want ErrUnclassified", c.Method, c.Key, got, err) } } }