| 1 | package main |
| 2 | |
| 3 | // The images spec's mutations (§6): each named risk broken on purpose, |
| 4 | // and the gate that must notice. IMG1's four, IMG3's, IMG7's copies, |
| 5 | // the owner check §6's table names, sealing before Put (IMG2), and one |
| 6 | // per walker (IMG5). |
| 7 | |
| 8 | const ( |
| 9 | imagesRead = "internal/mapa/images_read.go" |
| 10 | imagesRender = "internal/mapa/images_render.go" |
| 11 | imagesAttach = "internal/mapa/images_attach.go" |
| 12 | imagesCopies = "internal/mapa/images_copies.go" |
| 13 | imagesStore = "internal/mapa/images_store.go" |
| 14 | history = "internal/mapa/history.go" |
| 15 | walkerJPEG = "internal/mapa/imagefile/jpeg.go" |
| 16 | walkerPNG = "internal/mapa/imagefile/png.go" |
| 17 | walkerWebP = "internal/mapa/imagefile/webp.go" |
| 18 | walkerGIF = "internal/mapa/imagefile/gif.go" |
| 19 | |
| 20 | inside = "./internal/mapa/" |
| 21 | walkers = "./internal/mapa/imagefile/" |
| 22 | imgOne = "TestIMG1ImagesLeakNothing" |
| 23 | imgTwo = "TestImagesReachTheDiskSealed" |
| 24 | imgFive = "TestCleanStripsEveryCanary" |
| 25 | attaching = "TestACommitAttachesOnlyItsOwnIntroducedImages" |
| 26 | ) |
| 27 | |
| 28 | // The copies' rules, and their breaks: any page's images, not the |
| 29 | // one's. |
| 30 | const ( |
| 31 | attachedOnly = "\t\tquery = query.Where(\"page_id = ?\", pageID)" |
| 32 | attachedAnywhere = "\t\tquery = query.Where(\"page_id != ?\", -pageID)" |
| 33 | movedOnly = "\t\tquery = query.Where(\"(page_id = ? OR " + |
| 34 | "moved_from = ?)\"" |
| 35 | movedAnywhere = "\t\tquery = query.Where(\"(page_id != -? OR " + |
| 36 | "moved_from = ?)\"" |
| 37 | ) |
| 38 | |
| 39 | var imageMutations = []mutation{ |
| 40 | {gate: "IMG1", test: imgOne, |
| 41 | name: "GET /i/{id} drops its scope check", |
| 42 | edits: []edit{{file: imagesRead, |
| 43 | from: "\t\tWhere(store.readScope(database, member)).", |
| 44 | to: "\t\tWhere(\"1 = 1\")."}}}, |
| 45 | {gate: "IMG1", test: imgOne, |
| 46 | name: "drawing resolves images attached to other pages", |
| 47 | edits: []edit{{file: imagesRender, |
| 48 | from: "\tshown := entry.page != 0 && entry.page == page", |
| 49 | to: "\tshown := entry.page != 0"}}}, |
| 50 | {gate: "IMG1", test: "TestAnasOwnCommitOfAPlantedIDAttachesNothing", |
| 51 | pkg: inside, |
| 52 | name: "attach ignores \"introduced\"", |
| 53 | edits: []edit{{file: imagesAttach, |
| 54 | from: "\t\tif !held[id] {", |
| 55 | to: "\t\tif held != nil {"}}}, |
| 56 | {gate: "IMG1", test: "TestAnasRevertToBosTextAttachesNothing", |
| 57 | pkg: inside, |
| 58 | name: "Revert passes attach", |
| 59 | edits: []edit{{file: history, |
| 60 | from: "VerbReverted, attachNothing)", |
| 61 | to: "VerbReverted, attachOwn(0))"}}}, |
| 62 | {gate: "IMG1", test: "TestAnasRestoreOfBosPageAttachesNothing", |
| 63 | pkg: inside, |
| 64 | name: "Restore passes attach", |
| 65 | edits: []edit{{file: aliases, |
| 66 | from: "\t\tpage, err := tx.create(KindPage, RungTeam, actor, " + |
| 67 | "record, actor,\n\t\t\tVerbRestored, attachNothing)", |
| 68 | to: "\t\tpage, err := tx.create(KindPage, RungTeam, actor, " + |
| 69 | "record, actor,\n\t\t\tVerbRestored, attachOwn(0))"}}}, |
| 70 | {gate: "IMG7", test: attaching, pkg: inside, |
| 71 | name: "attaching without the owner check", |
| 72 | edits: []edit{{file: imagesAttach, |
| 73 | from: "\"page_id IS NULL AND owner_id = ?\", introduced, actor)", |
| 74 | to: "\"page_id IS NULL AND owner_id != ?\", introduced, -1)"}}}, |
| 75 | {gate: "IMG7", pkg: inside, |
| 76 | test: "TestMakeTeamPageCopiesOnlyImagesAttachedToItsSource", |
| 77 | name: "Make team page copies an image not attached to its source", |
| 78 | edits: []edit{{file: imagesCopies, |
| 79 | from: attachedOnly, to: attachedAnywhere}}}, |
| 80 | {gate: "IMG7", test: "TestADeletedPagesDraftKeepsOnlyItsOwnPagesImages", |
| 81 | pkg: inside, |
| 82 | name: "draftToScratch copies an image attached to another page", |
| 83 | edits: []edit{{file: imagesCopies, |
| 84 | from: movedOnly, to: movedAnywhere}}}, |
| 85 | {gate: "IMG2", test: imgTwo, name: "images are Put unsealed", |
| 86 | edits: []edit{{file: imagesStore, |
| 87 | from: "\tblob, err := store.sealer.SealPadded(seal.PurposeImage, " + |
| 88 | "plain)", |
| 89 | to: "\tblob, err := seal.Pad(plain), error(nil)"}}}, |
| 90 | {gate: "IMG3", test: gateEight, name: "an upload logs no event", |
| 91 | edits: []edit{{file: imagesStore, |
| 92 | from: "\t\treturn tx.log(actor, ObjectImage, row.ID, " + |
| 93 | "VerbUploaded, 0)", |
| 94 | to: "\t\treturn nil"}}}, |
| 95 | {gate: "IMG6", test: "TestIMG6TheUploadsMapaRefuses", |
| 96 | name: "an image may be 20 MB", |
| 97 | edits: []edit{{file: "internal/mapa/images.go", |
| 98 | from: "\tMaxImageBytes = 10 << 20", |
| 99 | to: "\tMaxImageBytes = 20 << 20"}}}, |
| 100 | {gate: "IMG6", test: "TestIMG6AWaitForASlotAnswers503", |
| 101 | name: "the blob semaphore admits everyone", |
| 102 | edits: []edit{{file: store, |
| 103 | from: "\tstore.images.slots = make(chan struct{}, BlobSlots)", |
| 104 | to: "\tstore.images.slots = make(chan struct{}, " + |
| 105 | "100*BlobSlots)"}}}, |
| 106 | {gate: "M2", test: "TestAGIFFrameStaysInsideItsScreen", pkg: walkers, |
| 107 | name: "a GIF frame may lie past its logical screen", |
| 108 | edits: []edit{{file: walkerGIF, |
| 109 | from: "\tif left+width > screen[0] || top+height > screen[1] {", |
| 110 | to: "\tif left+width > 1<<20 || top+height > 1<<20 {"}}}, |
| 111 | {gate: "IMG5", test: imgFive, pkg: walkers, |
| 112 | name: "the JPEG walker keeps comments", |
| 113 | edits: []edit{{file: walkerJPEG, |
| 114 | from: "\tcase marker == markerCOM:\n\t\treturn\n", |
| 115 | to: "\tcase marker == markerCOM:\n"}}}, |
| 116 | {gate: "IMG5", test: imgFive, pkg: walkers, |
| 117 | name: "the JPEG walker keeps what follows EOI", |
| 118 | edits: []edit{{file: walkerJPEG, |
| 119 | from: "\treturn append(out, 0xff, markerEOI), " + |
| 120 | "walk.orientation, nil", |
| 121 | to: "\treturn append(append(out, 0xff, markerEOI), " + |
| 122 | "walk.raw[len(out):]...), walk.orientation, nil"}}}, |
| 123 | {gate: "IMG5", test: imgFive, pkg: walkers, |
| 124 | name: "the PNG walker keeps text chunks", |
| 125 | edits: []edit{{file: walkerPNG, |
| 126 | from: "\t\"bKGD\": true, \"acTL\": true,", |
| 127 | to: "\t\"bKGD\": true, \"tEXt\": true, \"acTL\": true,"}}}, |
| 128 | {gate: "IMG5", test: imgFive, pkg: walkers, |
| 129 | name: "the WebP walker keeps EXIF", |
| 130 | edits: []edit{{file: walkerWebP, |
| 131 | from: "\t\"ANMF\": true, \"ICCP\": true,", |
| 132 | to: "\t\"ANMF\": true, \"ICCP\": true, \"EXIF\": true,"}}}, |
| 133 | {gate: "IMG5", test: imgFive, pkg: walkers, |
| 134 | name: "the GIF walker keeps every application extension", |
| 135 | edits: []edit{{file: walkerGIF, |
| 136 | from: "\t\treturn next, netscapeLoop(raw[at:next]), false, nil", |
| 137 | to: "\t\treturn next, nil, true, nil"}}}, |
| 138 | } |
| 139 | |