package delivery import ( "strings" "testing" ) // A candidate's module carries the git objects of its named paths at the preview (novox/hq ADR 0499 clause 2), so the // builder's fetch request for a candidate names them; an older candidate decodes without them, and a path that is not // clean and relative, or names no object, is refused. func TestACandidatesModuleCarriesItsNamedPaths(t *testing.T) { c := sampleCandidate() paths := map[string]string{"src": strings.Repeat("a", 40), "package.json": strings.Repeat("b", 40)} c.Pulls[0].Fps = map[string]CandidateModule{"mesh-mail": {FP2: SourcePrefix2 + strings.Repeat("1", 64), Manifest: strings.Repeat("2", 64), Paths: paths}} c.FPSet = FingerprintSet(c.Pulls) data, err := EncodeCandidate(c) if err != nil { t.Fatal(err) } back, err := DecodeCandidate(data) if err != nil || back.Pulls[0].Fps["mesh-mail"].Paths["src"] != paths["src"] { t.Fatalf("decoded %+v, %v", back.Pulls[0].Fps, err) } old := sampleCandidate() old.Pulls[0].Fps = map[string]CandidateModule{"mesh-mail": {FP2: SourcePrefix2 + strings.Repeat("1", 64)}} old.FPSet = FingerprintSet(old.Pulls) if data, err := EncodeCandidate(old); err != nil { t.Fatal(err) } else if b, err := DecodeCandidate(data); err != nil || b.Pulls[0].Fps["mesh-mail"].Paths != nil { t.Fatalf("an older candidate: %+v, %v", b, err) } for _, bad := range []map[string]string{{"../x": "a"}, {"/src": "a"}, {"": "a"}, {"src": ""}} { c.Pulls[0].Fps = map[string]CandidateModule{"mesh-mail": {FP2: SourcePrefix2 + strings.Repeat("1", 64), Paths: bad}} c.FPSet = FingerprintSet(c.Pulls) if _, err := EncodeCandidate(c); err == nil { t.Errorf("%v was accepted", bad) } } }