fix: delete instance data and remove legacy shared workspace support
This commit is contained in:
@@ -126,13 +126,47 @@ func TestAdmissionDowngradeWaitsForCreate(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdmissionHistoricalCreateAndBlock(t *testing.T) {
|
||||
func TestAdmissionRejectsLegacyLayouts(t *testing.T) {
|
||||
for _, recipe := range []string{"", "1", "2", "3", "4", "5", "6", "8"} {
|
||||
t.Run(recipe, func(t *testing.T) {
|
||||
id := "sha256:" + strings.Repeat("a", 64)
|
||||
a, sid := runtimeTestAPI(t, func(w http.ResponseWriter, r *http.Request) {
|
||||
if !strings.Contains(r.URL.Path, "/images/") {
|
||||
t.Error("unexpected Docker operation", r.Method, r.URL.Path)
|
||||
}
|
||||
writeJSON(w, map[string]any{"Id": id, "Os": "linux", "Architecture": "amd64", "Config": map[string]any{"Labels": map[string]string{"dsh-mgr.role": "runtime", "dsh-mgr.version": "1.2.3", "dsh-mgr.recipe": recipe}}})
|
||||
})
|
||||
seedVerifiedImage(t, a, id, "1.2.3")
|
||||
for _, query := range []string{"UPDATE image_builds SET recipe_rev=?", "UPDATE image_admissions SET recipe_rev=?"} {
|
||||
if _, err := a.s.DB.Exec(query, recipe); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if _, err := a.s.DB.Exec("UPDATE users SET admin=1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
im, err := a.evaluateImage(context.Background(), id)
|
||||
if err != nil || im.Selectable || im.Admission != "existing_only" {
|
||||
t.Fatal(im, err)
|
||||
}
|
||||
for _, state := range []string{"compatible", "recommended"} {
|
||||
w := httptest.NewRecorder()
|
||||
a.imageAdmission(w, runtimeRequest("POST", "/api/images/admission", fmt.Sprintf(`{"image_id":%q,"state":%q,"evidence":"historical acceptance"}`, id, state), sid))
|
||||
if w.Code != 400 {
|
||||
t.Fatal(w.Code, w.Body.String())
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdmissionCurrentCreateAndBlock(t *testing.T) {
|
||||
id := "sha256:" + strings.Repeat("a", 64)
|
||||
var body map[string]any
|
||||
a, sid := runtimeTestAPI(t, func(w http.ResponseWriter, r *http.Request) {
|
||||
switch {
|
||||
case strings.Contains(r.URL.Path, "/images/"):
|
||||
writeJSON(w, map[string]any{"Id": id, "Os": "linux", "Architecture": "amd64", "Config": map[string]any{"Labels": map[string]string{"dsh-mgr.role": "runtime", "dsh-mgr.version": "1.2.3", "dsh-mgr.recipe": "4"}}})
|
||||
writeJSON(w, map[string]any{"Id": id, "Os": "linux", "Architecture": "amd64", "Config": map[string]any{"Labels": map[string]string{"dsh-mgr.role": "runtime", "dsh-mgr.version": "1.2.3", "dsh-mgr.recipe": imageRecipeRev}}})
|
||||
case strings.HasSuffix(r.URL.Path, "/containers/create"):
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
t.Error(err)
|
||||
@@ -143,33 +177,33 @@ func TestAdmissionHistoricalCreateAndBlock(t *testing.T) {
|
||||
}
|
||||
})
|
||||
seedVerifiedImage(t, a, id, "1.2.3")
|
||||
if _, err := a.s.DB.Exec("UPDATE image_builds SET recipe_rev='4'; DELETE FROM image_admissions; UPDATE users SET admin=1"); err != nil {
|
||||
if _, err := a.s.DB.Exec("DELETE FROM image_admissions; UPDATE users SET admin=1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
im, err := a.evaluateImage(context.Background(), id)
|
||||
if err != nil || im.Status != "existing_only" || im.Selectable {
|
||||
t.Fatal(im, err)
|
||||
}
|
||||
records := []buildRecord{{ID: "unused", ImageID: id, Version: "1.2.3", RecipeRev: "4", Platform: imagePlatform, Status: "success"}}
|
||||
records := []buildRecord{{ID: "unused", ImageID: id, Version: "1.2.3", RecipeRev: imageRecipeRev, Platform: imagePlatform, Status: "success"}}
|
||||
if err := a.reconcileBuilds(context.Background(), records); err != nil || records[0].Status != "success" {
|
||||
t.Fatal(records, err)
|
||||
}
|
||||
admit := func(state string) *httptest.ResponseRecorder {
|
||||
w := httptest.NewRecorder()
|
||||
a.imageAdmission(w, runtimeRequest("POST", "/api/images/admission", fmt.Sprintf(`{"image_id":%q,"state":%q,"evidence":"legacy layout explicitly accepted"}`, id, state), sid))
|
||||
a.imageAdmission(w, runtimeRequest("POST", "/api/images/admission", fmt.Sprintf(`{"image_id":%q,"state":%q,"evidence":"current layout explicitly accepted"}`, id, state), sid))
|
||||
return w
|
||||
}
|
||||
if w := admit("compatible"); w.Code != 200 {
|
||||
t.Fatal(w.Code, w.Body.String())
|
||||
}
|
||||
w := httptest.NewRecorder()
|
||||
a.instances(w, runtimeRequest("POST", "/api/instances", fmt.Sprintf(`{"name":"legacy","image_id":%q}`, id), sid))
|
||||
a.instances(w, runtimeRequest("POST", "/api/instances", fmt.Sprintf(`{"name":"current","image_id":%q}`, id), sid))
|
||||
if w.Code != 200 {
|
||||
t.Fatal(w.Code, w.Body.String())
|
||||
}
|
||||
host := body["HostConfig"].(map[string]any)
|
||||
mounts := host["Mounts"].([]any)
|
||||
if len(mounts) != 2 || mounts[0].(map[string]any)["Target"] != "/data/dsh-home" || mounts[1].(map[string]any)["Target"] != "/workspace" || !strings.Contains(fmt.Sprint(body["Env"]), "DSH_HOME=/data/dsh-home") {
|
||||
if len(mounts) != 1 || mounts[0].(map[string]any)["Target"] != "/workspace" || !strings.Contains(fmt.Sprint(body["Env"]), "DSH_HOME=/workspace") {
|
||||
t.Fatal(body)
|
||||
}
|
||||
var instance store.Instance
|
||||
|
||||
Reference in New Issue
Block a user