@@ -142,10 +142,11 @@ func TestUploadVerifyRekord(t *testing.T) {
142142 }
143143
144144 // Verify should fail initially
145- runCliErr (t , "verify" , "--artifact" , artifactPath , "--signature" , sigPath , "--public-key" , pubPath )
145+ out := runCliErr (t , "verify" , "--artifact" , artifactPath , "--signature" , sigPath , "--public-key" , pubPath )
146+ outputContains (t , out , "404" )
146147
147148 // It should upload successfully.
148- out : = runCli (t , "upload" , "--artifact" , artifactPath , "--signature" , sigPath , "--public-key" , pubPath )
149+ out = runCli (t , "upload" , "--artifact" , artifactPath , "--signature" , sigPath , "--public-key" , pubPath )
149150 outputContains (t , out , "Created entry at" )
150151
151152 // Now we should be able to verify it.
@@ -996,12 +997,45 @@ func TestGetNonExistantIndex(t *testing.T) {
996997 outputContains (t , out , "404" )
997998}
998999
1000+ func TestVerifyNonExistantIndex (t * testing.T ) {
1001+ // this index is extremely likely to not exist
1002+ out := runCliErr (t , "verify" , "--log-index" , "100000000" )
1003+ outputContains (t , out , "404" )
1004+ }
1005+
9991006func TestGetNonExistantUUID (t * testing.T ) {
10001007 // this uuid is extremely likely to not exist
10011008 out := runCliErr (t , "get" , "--uuid" , "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" )
10021009 outputContains (t , out , "404" )
10031010}
10041011
1012+ func TestVerifyNonExistantUUID (t * testing.T ) {
1013+ // this uuid is extremely likely to not exist
1014+ out := runCliErr (t , "verify" , "--uuid" , "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" )
1015+ outputContains (t , out , "404" )
1016+
1017+ // Check response code
1018+ tid := getTreeID (t )
1019+ h := sha256 .Sum256 ([]byte ("123" ))
1020+ entryID , err := sharding .CreateEntryIDFromParts (fmt .Sprintf ("%x" , tid ),
1021+ hex .EncodeToString (h [:]))
1022+ if err != nil {
1023+ t .Fatal (err )
1024+ }
1025+ body := fmt .Sprintf ("{\" entryUUIDs\" :[\" %s\" ]}" , entryID .ReturnEntryIDString ())
1026+ resp , err := http .Post ("http://localhost:3000/api/v1/log/entries/retrieve" ,
1027+ "application/json" ,
1028+ bytes .NewReader ([]byte (body )))
1029+ if err != nil {
1030+ t .Fatal (err )
1031+ }
1032+ c , _ := ioutil .ReadAll (resp .Body )
1033+ t .Log (string (c ))
1034+ if resp .StatusCode != 404 {
1035+ t .Fatal ("expected 404 status" )
1036+ }
1037+ }
1038+
10051039func TestEntryUpload (t * testing.T ) {
10061040 artifactPath := filepath .Join (t .TempDir (), "artifact" )
10071041 sigPath := filepath .Join (t .TempDir (), "signature.asc" )
@@ -1193,6 +1227,54 @@ func TestSearchQueryLimit(t *testing.T) {
11931227 }
11941228}
11951229
1230+ func TestSearchQueryMalformedEntry (t * testing.T ) {
1231+ wd , err := os .Getwd ()
1232+ if err != nil {
1233+ t .Fatal (err )
1234+ }
1235+ b , err := ioutil .ReadFile (filepath .Join (wd , "rekor.json" ))
1236+ if err != nil {
1237+ t .Fatal (err )
1238+ }
1239+ body := fmt .Sprintf ("{\" entries\" :[\" %s\" ]}" , b )
1240+ resp , err := http .Post ("http://localhost:3000/api/v1/log/entries/retrieve" ,
1241+ "application/json" ,
1242+ bytes .NewBuffer ([]byte (body )))
1243+ if err != nil {
1244+ t .Fatal (err )
1245+ }
1246+ c , _ := ioutil .ReadAll (resp .Body )
1247+ t .Log (string (c ))
1248+ if resp .StatusCode != 400 {
1249+ t .Fatal ("expected status 400" )
1250+ }
1251+ }
1252+
1253+ func TestSearchQueryNonExistentEntry (t * testing.T ) {
1254+ // Nonexistent but well-formed entry results in 404 not found.
1255+ wd , err := os .Getwd ()
1256+ if err != nil {
1257+ t .Fatal (err )
1258+ }
1259+ b , err := ioutil .ReadFile (filepath .Join (wd , "canonical_rekor.json" ))
1260+ if err != nil {
1261+ t .Fatal (err )
1262+ }
1263+ body := fmt .Sprintf ("{\" entries\" :[%s]}" , b )
1264+ t .Log (string (body ))
1265+ resp , err := http .Post ("http://localhost:3000/api/v1/log/entries/retrieve" ,
1266+ "application/json" ,
1267+ bytes .NewBuffer ([]byte (body )))
1268+ if err != nil {
1269+ t .Fatal (err )
1270+ }
1271+ c , _ := ioutil .ReadAll (resp .Body )
1272+ t .Log (string (c ))
1273+ if resp .StatusCode != 404 {
1274+ t .Fatal ("expected 404 status" )
1275+ }
1276+ }
1277+
11961278func getBody (t * testing.T , limit int ) []byte {
11971279 t .Helper ()
11981280 s := fmt .Sprintf ("{\" logIndexes\" : [%d" , limit )
@@ -1260,7 +1342,8 @@ func TestSearchValidateTreeID(t *testing.T) {
12601342 if err != nil {
12611343 t .Fatal (err )
12621344 }
1263- if resp .StatusCode != 400 {
1264- t .Fatalf ("expected 400 status code but got %d" , resp .StatusCode )
1345+ // Not Found because currently we don't detect that an unused random tree ID is invalid.
1346+ if resp .StatusCode != 404 {
1347+ t .Fatalf ("expected 404 status code but got %d" , resp .StatusCode )
12651348 }
12661349}
0 commit comments