69 lines
2.3 KiB
Go
69 lines
2.3 KiB
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"droboticflow/internal/store"
|
|
)
|
|
|
|
func TestSourceReadinessIsScopedReadOnlyAndNotAValidityCertificate(t *testing.T) {
|
|
t.Setenv("ANNOTATION_SOURCE_VALIDATION_MODE", "advisory")
|
|
t.Setenv("ANNOTATION_LEGACY_SOURCE_CUTOFF", "")
|
|
f := newCombinedDraftFixture(t)
|
|
missingTask := f.task
|
|
missingTask.ID += "-missing-proof"
|
|
if err := f.store.UpsertAnnotationTask(f.ctx, missingTask); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
missingItem := f.item
|
|
missingItem.ID += "-missing-proof"
|
|
missingItem.LegacyTaskID = missingTask.ID
|
|
missingItem.ProcessingJob = nil
|
|
if err := f.store.UpsertHumanItem(f.ctx, missingItem); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
before, _ := f.store.GetHumanItem(f.ctx, f.item.ID)
|
|
var jobs store.AnnotationProcessingStore = f.store
|
|
jobBefore, _ := jobs.GetAnnotationIndexJob(f.ctx, f.task.ID)
|
|
path := "/api/plugins/annotation-qa/source-readiness"
|
|
denied := f.request(http.MethodGet, path, f.annotator, nil)
|
|
if denied.Code != 403 {
|
|
t.Fatalf("non-admin readiness access: %d", denied.Code)
|
|
}
|
|
denied = f.request(http.MethodGet, path+"?scope=deployment", f.admin, nil)
|
|
if denied.Code != 403 {
|
|
t.Fatal("ordinary org admin got deployment-wide inventory")
|
|
}
|
|
r := f.request(http.MethodGet, path+"?organizationId=other", f.admin, nil)
|
|
if r.Code != 200 {
|
|
t.Fatalf("readiness: %d %s", r.Code, r.Body.String())
|
|
}
|
|
var report store.SourceReadiness
|
|
if err := json.Unmarshal(r.Body.Bytes(), &report); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !report.Complete || report.TargetMode != "strict" || report.Scope != "organization" || report.OrganizationID != f.task.OrganizationID || len(report.Rows) != 1 || report.Rows[0].Unverified != 1 {
|
|
t.Fatalf("incorrect impact report: %+v", report)
|
|
}
|
|
super := f.admin
|
|
super.IsSuperAdmin = true
|
|
r = f.request(http.MethodGet, path+"?scope=deployment", super, nil)
|
|
if r.Code != 200 {
|
|
t.Fatalf("superadmin inventory: %d", r.Code)
|
|
}
|
|
if err := json.Unmarshal(r.Body.Bytes(), &report); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if report.Scope != "deployment" || report.OrganizationID != "" {
|
|
t.Fatal("wrong full deployment scope")
|
|
}
|
|
after, _ := f.store.GetHumanItem(f.ctx, f.item.ID)
|
|
jobAfter, _ := jobs.GetAnnotationIndexJob(f.ctx, f.task.ID)
|
|
if !reflect.DeepEqual(before, after) || !reflect.DeepEqual(jobBefore, jobAfter) {
|
|
t.Fatal("inventory changed task or audit queue")
|
|
}
|
|
}
|