diff --git a/go.mod b/go.mod index ba090f340f688bfd135aac2c90a0278a15a603ba..7558e8ac17295ada079f20fe68fe762fa9a3d435 100644 --- a/go.mod +++ b/go.mod @@ -19,6 +19,7 @@ require ( github.com/go-swagger/go-swagger v0.25.1-0.20201206132650-7c73d972c8b9 // indirect github.com/golang/protobuf v1.4.3 github.com/google/certificate-transparency-go v1.1.0 // indirect + github.com/google/go-cmp v0.5.2 github.com/google/martian v2.1.0+incompatible github.com/google/trillian v1.3.10 github.com/gorilla/handlers v1.5.1 // indirect diff --git a/go.sum b/go.sum index 2cf73633c65a52937db2a1ed1d9ac0c6820f0b4c..01383c5f0637d4aaff1229cb289b484f537f839a 100644 --- a/go.sum +++ b/go.sum @@ -387,6 +387,7 @@ github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no= diff --git a/tests/e2e_test.go b/tests/e2e_test.go index 1fa8ce98d86890869e2f903a3a9d0ee14e43c6c3..eebeaf604fa01be62ce68f5ad2ecbb2ccac412a2 100644 --- a/tests/e2e_test.go +++ b/tests/e2e_test.go @@ -3,6 +3,7 @@ package e2e import ( + "encoding/json" "io/ioutil" "path/filepath" "strings" @@ -24,22 +25,16 @@ func TestDuplicates(t *testing.T) { // Now upload to rekor! out := runCli(t, "upload", "--artifact", artifactPath, "--signature", sigPath, "--public-key", pubPath) - if !strings.Contains(out, "Created entry at") { - t.Errorf("Expected [Created entry at], got %s", out) - } + outputContains(t, out, "Created entry at") // Now upload the same one again, we should get a dupe entry. out = runCli(t, "upload", "--artifact", artifactPath, "--signature", sigPath, "--public-key", pubPath) - if !strings.Contains(out, "Entry already exists") { - t.Errorf("Expected [Entry already exists], got %s", out) - } + outputContains(t, out, "Entry already exists") // Now do a new one, we should get a new entry createdSignedArtifact(t, artifactPath, sigPath) out = runCli(t, "upload", "--artifact", artifactPath, "--signature", sigPath, "--public-key", pubPath) - if !strings.Contains(out, "Created entry at") { - t.Errorf("Expected [Created entry at], got %s", out) - } + outputContains(t, out, "Created entry at") } func TestUploadVerify(t *testing.T) { @@ -61,17 +56,53 @@ func TestUploadVerify(t *testing.T) { // It should upload successfully. out := runCli(t, "upload", "--artifact", artifactPath, "--signature", sigPath, "--public-key", pubPath) - if !strings.Contains(out, "Created entry at") { - t.Errorf("Expected [Created entry at], got %s", out) - } + outputContains(t, out, "Created entry at") // We have to wait some time for the log to get signed and included. time.Sleep(3 * time.Second) // Now we should be able to verify it. out = runCli(t, "verify", "--artifact", artifactPath, "--signature", sigPath, "--public-key", pubPath) - if !strings.Contains(out, "Inclusion Proof:") { - t.Errorf("Expected [Inclusion Proof] in response, got %s", out) - } + outputContains(t, out, "Inclusion Proof:") +} + +func TestLogInfo(t *testing.T) { + // TODO: figure out some way to check the length, add something, and make sure the length increments! + out := runCli(t, "loginfo") + outputContains(t, out, "Verified signature of log root!") +} + +func TestGet(t *testing.T) { + // Create something and add it to the log + artifactPath := filepath.Join(t.TempDir(), "artifact") + sigPath := filepath.Join(t.TempDir(), "signature.asc") + + createdSignedArtifact(t, artifactPath, sigPath) + // Write the public key to a file + pubPath := filepath.Join(t.TempDir(), "pubKey.asc") + if err := ioutil.WriteFile(pubPath, []byte(publicKey), 0644); err != nil { + t.Fatal(err) + } + out := runCli(t, "upload", "--artifact", artifactPath, "--signature", sigPath, "--public-key", pubPath) + outputContains(t, out, "Created entry at") + + // Wait a second for the entry to be added. + time.Sleep(1 * time.Second) + + // Output looks like "Created entry at $URL/UUID", so grab the UUID: + url := strings.Split(strings.TrimSpace(out), " ")[3] + splitUrl := strings.Split(url, "/") + uuid := splitUrl[len(splitUrl)-1] + + out = runCli(t, "get", "--uuid", uuid) + // The output here should be in JSON with this structure: + g := struct { + Body string + LogIndex int + }{} + if err := json.Unmarshal([]byte(out), &g); err != nil { + t.Error(err) + } + // TODO: check the actual data in here. } diff --git a/tests/util.go b/tests/util.go index 41bb1d8216a707f2d8caf0b72c8aa0a83aa4f804..3d1ff59366a51afd60e91322a0a1c1b6e9f22979 100644 --- a/tests/util.go +++ b/tests/util.go @@ -17,6 +17,13 @@ const ( nodeDataDir = "node" ) +func outputContains(t *testing.T, output, sub string) { + t.Helper() + if !strings.Contains(output, sub) { + t.Errorf("Expected [%s] in response, got %s", sub, output) + } +} + func runCli(t *testing.T, arg ...string) string { t.Helper() cmd := exec.Command(cli, arg...)