Skip to content

Commit

Permalink
Refactor e2e - part 5
Browse files Browse the repository at this point in the history
  • Loading branch information
naveensrinivasan committed Dec 10, 2022
1 parent 0a3f871 commit ec7af1f
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 66 deletions.
74 changes: 74 additions & 0 deletions cmd/rekor-server/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,77 @@ func getTreeID(t *testing.T) int64 {
func TestSearchNoEntriesRC1(t *testing.T) {
util.RunCliErr(t, "search", "--email", "noone@internetz.com")
}
func TestGetNonExistentIndex(t *testing.T) {
// this index is extremely likely to not exist
out := util.RunCliErr(t, "get", "--log-index", "100000000")
util.OutputContains(t, out, "404")
}
func TestVerifyNonExistentIndex(t *testing.T) {
// this index is extremely likely to not exist
out := util.RunCliErr(t, "verify", "--log-index", "100000000")
util.OutputContains(t, out, "entry in log cannot be located")
}

func TestGetNonExistentUUID(t *testing.T) {
// this uuid is extremely likely to not exist
out := util.RunCliErr(t, "get", "--uuid", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
util.OutputContains(t, out, "404")
}
func TestHostnameInSTH(t *testing.T) {
// get ID of container
rekorContainerID := strings.Trim(util.Run(t, "", "docker", "ps", "-q", "-f", "name=rekor-server"), "\n")
resp, err := http.Get(fmt.Sprintf("%s/api/v1/log", rekorServer()))
if err != nil {
t.Fatal(err)
}
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}

if !strings.Contains(string(body), fmt.Sprintf(" %s ", rekorContainerID)) {
t.Errorf("logInfo does not contain the hostname (%v) of the rekor-server container: %v", rekorContainerID, string(body))
}
if strings.Contains(string(body), "rekor.sigstore.dev") {
t.Errorf("logInfo contains rekor.sigstore.dev which should not be set by default")
}
}
func rekorServer() string {
if s := os.Getenv("REKOR_SERVER"); s != "" {
return s
}
return "http://localhost:3000"
}
func TestSearchSHA512(t *testing.T) {
sha512 := "c7694a1112ea1404a3c5852bdda04c2cc224b3567ef6ceb8204dbf2b382daacfc6837ee2ed9d5b82c90b880a3c7289778dbd5a8c2c08193459bcf7bd44581ed0"
var out string
out = util.RunCli(t, "upload", "--type", "intoto:0.0.2",
"--artifact", "tests/envelope.sha512",
"--pki-format", "x509",
"--public-key", "tests/test_sha512.pub")
util.OutputContains(t, out, "Created entry at")
uuid := getUUIDFromTimestampOutput(t, out)
out = util.RunCli(t, "search", "--sha", fmt.Sprintf("sha512:%s", sha512))
util.OutputContains(t, out, uuid)
}
func getUUIDFromTimestampOutput(t *testing.T, out string) string {
t.Helper()
// Output looks like "Created entry at index X, available at $URL/UUID", so grab the UUID:
urlTokens := strings.Split(strings.TrimSpace(out), "\n")
return getUUIDFromUploadOutput(t, urlTokens[len(urlTokens)-1])
}
func getUUIDFromUploadOutput(t *testing.T, out string) string {
t.Helper()
// Output looks like "Artifact timestamped at ...\m Wrote response \n Created entry at index X, available at $URL/UUID", so grab the UUID:
urlTokens := strings.Split(strings.TrimSpace(out), " ")
url := urlTokens[len(urlTokens)-1]
splitUrl := strings.Split(url, "/")
return splitUrl[len(splitUrl)-1]
}
func TestLogInfo(t *testing.T) {
// TODO: figure out some way to check the length, add something, and make sure the length increments!
out := util.RunCli(t, "loginfo")
util.OutputContains(t, out, "Verification Successful!")
}
File renamed without changes.
File renamed without changes.
67 changes: 1 addition & 66 deletions tests/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,6 @@ func getLogIndexFromUploadOutput(t *testing.T, out string) int {
return i
}

func getUUIDFromTimestampOutput(t *testing.T, out string) string {
t.Helper()
// Output looks like "Created entry at index X, available at $URL/UUID", so grab the UUID:
urlTokens := strings.Split(strings.TrimSpace(out), "\n")
return getUUIDFromUploadOutput(t, urlTokens[len(urlTokens)-1])
}

func TestEnvVariableValidation(t *testing.T) {
os.Setenv("REKOR_FORMAT", "bogus")
defer os.Unsetenv("REKOR_FORMAT")
Expand Down Expand Up @@ -118,12 +111,6 @@ func TestDuplicates(t *testing.T) {
outputContains(t, out, "Created entry at")
}

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, "Verification Successful!")
}

type getOut struct {
Attestation string
AttestationType string
Expand Down Expand Up @@ -191,19 +178,7 @@ func TestGetCLI(t *testing.T) {
if err != nil {
t.Error(err)
}
out = runCli(t, "get", "--format=json", "--uuid", entryID.ReturnEntryIDString())
}
func TestSearchSHA512(t *testing.T) {
sha512 := "c7694a1112ea1404a3c5852bdda04c2cc224b3567ef6ceb8204dbf2b382daacfc6837ee2ed9d5b82c90b880a3c7289778dbd5a8c2c08193459bcf7bd44581ed0"
var out string
out = runCli(t, "upload", "--type", "intoto:0.0.2",
"--artifact", "envelope.sha512",
"--pki-format", "x509",
"--public-key", "test_sha512.pub")
outputContains(t, out, "Created entry at")
uuid := getUUIDFromTimestampOutput(t, out)
out = runCli(t, "search", "--sha", fmt.Sprintf("sha512:%s", sha512))
outputContains(t, out, uuid)
runCli(t, "get", "--format=json", "--uuid", entryID.ReturnEntryIDString())
}

func TestWatch(t *testing.T) {
Expand Down Expand Up @@ -312,24 +287,6 @@ func TestSignedEntryTimestamp(t *testing.T) {
}
}

func TestGetNonExistentIndex(t *testing.T) {
// this index is extremely likely to not exist
out := runCliErr(t, "get", "--log-index", "100000000")
outputContains(t, out, "404")
}

func TestVerifyNonExistentIndex(t *testing.T) {
// this index is extremely likely to not exist
out := runCliErr(t, "verify", "--log-index", "100000000")
outputContains(t, out, "entry in log cannot be located")
}

func TestGetNonExistentUUID(t *testing.T) {
// this uuid is extremely likely to not exist
out := runCliErr(t, "get", "--uuid", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
outputContains(t, out, "404")
}

func TestVerifyNonExistentUUID(t *testing.T) {
// this uuid is extremely likely to not exist
out := runCliErr(t, "verify", "--uuid", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
Expand Down Expand Up @@ -468,28 +425,6 @@ func TestInclusionProofRace(t *testing.T) {
}
}

func TestHostnameInSTH(t *testing.T) {
// get ID of container
rekorContainerID := strings.Trim(run(t, "", "docker", "ps", "-q", "-f", "name=rekor-server"), "\n")
resp, err := http.Get(fmt.Sprintf("%s/api/v1/log", rekorServer()))
if err != nil {
t.Fatal(err)
}
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
t.Fatal(err)
}

if !strings.Contains(string(body), fmt.Sprintf(" %s ", rekorContainerID)) {
t.Errorf("logInfo does not contain the hostname (%v) of the rekor-server container: %v", rekorContainerID, string(body))
}
if strings.Contains(string(body), "rekor.sigstore.dev") {
t.Errorf("logInfo contains rekor.sigstore.dev which should not be set by default")
}
}

func TestSearchQueryLimit(t *testing.T) {
tests := []struct {
description string
Expand Down

0 comments on commit ec7af1f

Please sign in to comment.