Skip to content
Snippets Groups Projects
Commit 7c9a8f3d authored by Dan Lorenc's avatar Dan Lorenc
Browse files

Add some more e2e tests to make sure we exercise all the CLI commands:

- Run through the get flow, make sure the output is well structured
- Call loginfo, make sure there are no errors.
parent c6f45bb1
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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.
}
......@@ -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...)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment