Skip to content

Commit ff9478f

Browse files
authored
e2e: don't mix e2e and regular utilities (#2672)
E2E utilities should be only defined in test files and should not be mixed with the common function in pkg/util. Go modules/vendoring makes no filtering based on build tags and so all the dependencies needed for E2E become dependencies to any package that internally imports pkg/util. Signed-off-by: Tonis Tiigi <[email protected]>
1 parent 018dd64 commit ff9478f

File tree

23 files changed

+260
-256
lines changed

23 files changed

+260
-256
lines changed

cmd/rekor-cli/get_e2e_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ package main
2020
import (
2121
"testing"
2222

23-
"github.com/sigstore/rekor/pkg/util"
23+
e2eutil "github.com/sigstore/rekor/pkg/util/e2eutil"
2424
)
2525

2626
func TestGetNonExistentIndex(t *testing.T) {
2727
// this index is extremely likely to not exist
28-
out := util.RunCliErr(t, "get", "--log-index", "100000000")
29-
util.OutputContains(t, out, "404")
28+
out := e2eutil.RunCliErr(t, "get", "--log-index", "100000000")
29+
e2eutil.OutputContains(t, out, "404")
3030
}
3131
func TestGetNonExistentUUID(t *testing.T) {
3232
// this uuid is extremely likely to not exist
33-
out := util.RunCliErr(t, "get", "--uuid", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
34-
util.OutputContains(t, out, "404")
33+
out := e2eutil.RunCliErr(t, "get", "--uuid", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
34+
e2eutil.OutputContains(t, out, "404")
3535
}

cmd/rekor-cli/loginfo_e2e_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"sync"
2222
"testing"
2323

24-
"github.com/sigstore/rekor/pkg/util"
24+
e2eutil "github.com/sigstore/rekor/pkg/util/e2eutil"
2525
)
2626

2727
var (
@@ -30,9 +30,9 @@ var (
3030

3131
func TestLogInfo(t *testing.T) {
3232
once.Do(func() {
33-
util.SetupTestData(t)
33+
e2eutil.SetupTestData(t)
3434
})
3535
// TODO: figure out some way to check the length, add something, and make sure the length increments!
36-
out := util.RunCli(t, "loginfo")
37-
util.OutputContains(t, out, "Verification Successful!")
36+
out := e2eutil.RunCli(t, "loginfo")
37+
e2eutil.OutputContains(t, out, "Verification Successful!")
3838
}

cmd/rekor-cli/logproof_e2e_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ package main
2020
import (
2121
"testing"
2222

23-
"github.com/sigstore/rekor/pkg/util"
23+
e2eutil "github.com/sigstore/rekor/pkg/util/e2eutil"
2424
)
2525

2626
// TestLogProofLastSizeBiggerThanCurrentLog tests that asking for a consistency proof for a size greater than the current log
2727
func TestLogProofLastSizeBiggerThanCurrentLog(t *testing.T) {
28-
out := util.RunCliErr(t, "logproof", "--last-size", "14212414124124124")
29-
util.OutputContains(t, out, "400")
28+
out := e2eutil.RunCliErr(t, "logproof", "--last-size", "14212414124124124")
29+
e2eutil.OutputContains(t, out, "400")
3030
}

cmd/rekor-cli/verify_e2e_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ package main
2020
import (
2121
"testing"
2222

23-
"github.com/sigstore/rekor/pkg/util"
23+
e2eutil "github.com/sigstore/rekor/pkg/util/e2eutil"
2424
)
2525

2626
func TestVerifyNonExistentIndex(t *testing.T) {
2727
// this index is extremely likely to not exist
28-
out := util.RunCliErr(t, "verify", "--log-index", "100000000")
29-
util.OutputContains(t, out, "entry in log cannot be located")
28+
out := e2eutil.RunCliErr(t, "verify", "--log-index", "100000000")
29+
e2eutil.OutputContains(t, out, "entry in log cannot be located")
3030
}

cmd/rekor-server/e2e_test.go

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -38,34 +38,33 @@ import (
3838
"testing"
3939

4040
"github.com/sigstore/rekor/pkg/sharding"
41-
42-
"github.com/sigstore/rekor/pkg/util"
41+
e2eutil "github.com/sigstore/rekor/pkg/util/e2eutil"
4342
)
4443

4544
func TestDuplicates(t *testing.T) {
4645
artifactPath := filepath.Join(t.TempDir(), "artifact")
4746
sigPath := filepath.Join(t.TempDir(), "signature.asc")
4847

49-
util.CreatedPGPSignedArtifact(t, artifactPath, sigPath)
48+
e2eutil.CreatedPGPSignedArtifact(t, artifactPath, sigPath)
5049

5150
// Write the public key to a file
5251
pubPath := filepath.Join(t.TempDir(), "pubKey.asc")
53-
if err := ioutil.WriteFile(pubPath, []byte(util.PubKey), 0644); err != nil {
52+
if err := ioutil.WriteFile(pubPath, []byte(e2eutil.PubKey), 0644); err != nil {
5453
t.Fatal(err)
5554
}
5655

5756
// Now upload to rekor!
58-
out := util.RunCli(t, "upload", "--artifact", artifactPath, "--signature", sigPath, "--public-key", pubPath)
59-
util.OutputContains(t, out, "Created entry at")
57+
out := e2eutil.RunCli(t, "upload", "--artifact", artifactPath, "--signature", sigPath, "--public-key", pubPath)
58+
e2eutil.OutputContains(t, out, "Created entry at")
6059

6160
// Now upload the same one again, we should get a dupe entry.
62-
out = util.RunCli(t, "upload", "--artifact", artifactPath, "--signature", sigPath, "--public-key", pubPath)
63-
util.OutputContains(t, out, "Entry already exists")
61+
out = e2eutil.RunCli(t, "upload", "--artifact", artifactPath, "--signature", sigPath, "--public-key", pubPath)
62+
e2eutil.OutputContains(t, out, "Entry already exists")
6463

6564
// Now do a new one, we should get a new entry
66-
util.CreatedPGPSignedArtifact(t, artifactPath, sigPath)
67-
out = util.RunCli(t, "upload", "--artifact", artifactPath, "--signature", sigPath, "--public-key", pubPath)
68-
util.OutputContains(t, out, "Created entry at")
65+
e2eutil.CreatedPGPSignedArtifact(t, artifactPath, sigPath)
66+
out = e2eutil.RunCli(t, "upload", "--artifact", artifactPath, "--signature", sigPath, "--public-key", pubPath)
67+
e2eutil.OutputContains(t, out, "Created entry at")
6968
}
7069

7170
// Smoke test to ensure we're publishing and recording metrics when an API is
@@ -143,7 +142,7 @@ func TestEnvVariableValidation(t *testing.T) {
143142
os.Setenv("REKOR_FORMAT", "bogus")
144143
defer os.Unsetenv("REKOR_FORMAT")
145144

146-
util.RunCliErr(t, "loginfo")
145+
e2eutil.RunCliErr(t, "loginfo")
147146
}
148147
func TestGetCLI(t *testing.T) {
149148
// Create something and add it to the log
@@ -153,31 +152,31 @@ func TestGetCLI(t *testing.T) {
153152
os.Remove(artifactPath)
154153
os.Remove(sigPath)
155154
})
156-
util.CreatedPGPSignedArtifact(t, artifactPath, sigPath)
155+
e2eutil.CreatedPGPSignedArtifact(t, artifactPath, sigPath)
157156

158157
// Write the public key to a file
159158
pubPath := filepath.Join(t.TempDir(), "pubKey.asc")
160-
if err := ioutil.WriteFile(pubPath, []byte(util.PubKey), 0644); err != nil {
159+
if err := ioutil.WriteFile(pubPath, []byte(e2eutil.PubKey), 0644); err != nil {
161160
t.Error(err)
162161
}
163162
t.Cleanup(func() {
164163
os.Remove(pubPath)
165164
})
166-
out := util.RunCli(t, "upload", "--artifact", artifactPath, "--signature", sigPath, "--public-key", pubPath)
167-
util.OutputContains(t, out, "Created entry at")
165+
out := e2eutil.RunCli(t, "upload", "--artifact", artifactPath, "--signature", sigPath, "--public-key", pubPath)
166+
e2eutil.OutputContains(t, out, "Created entry at")
168167

169-
uuid, err := sharding.GetUUIDFromIDString(util.GetUUIDFromUploadOutput(t, out))
168+
uuid, err := sharding.GetUUIDFromIDString(e2eutil.GetUUIDFromUploadOutput(t, out))
170169
if err != nil {
171170
t.Error(err)
172171
}
173172

174173
// since we at least have 1 valid entry, check the log at index 0
175-
util.RunCli(t, "get", "--log-index", "0")
174+
e2eutil.RunCli(t, "get", "--log-index", "0")
176175

177-
out = util.RunCli(t, "get", "--format=json", "--uuid", uuid)
176+
out = e2eutil.RunCli(t, "get", "--format=json", "--uuid", uuid)
178177

179178
// The output here should be in JSON with this structure:
180-
g := util.GetOut{}
179+
g := e2eutil.GetOut{}
181180
if err := json.Unmarshal([]byte(out), &g); err != nil {
182181
t.Error(err)
183182
}
@@ -186,35 +185,35 @@ func TestGetCLI(t *testing.T) {
186185
t.Errorf("Expected IntegratedTime to be set. Got %s", out)
187186
}
188187
// Get it with the logindex as well
189-
util.RunCli(t, "get", "--format=json", "--log-index", strconv.Itoa(g.LogIndex))
188+
e2eutil.RunCli(t, "get", "--format=json", "--log-index", strconv.Itoa(g.LogIndex))
190189

191190
// check index via the file and public key to ensure that the index has updated correctly
192-
out = util.RunCli(t, "search", "--artifact", artifactPath)
193-
util.OutputContains(t, out, uuid)
191+
out = e2eutil.RunCli(t, "search", "--artifact", artifactPath)
192+
e2eutil.OutputContains(t, out, uuid)
194193

195-
out = util.RunCli(t, "search", "--public-key", pubPath)
196-
util.OutputContains(t, out, uuid)
194+
out = e2eutil.RunCli(t, "search", "--public-key", pubPath)
195+
e2eutil.OutputContains(t, out, uuid)
197196

198197
artifactBytes, err := ioutil.ReadFile(artifactPath)
199198
if err != nil {
200199
t.Error(err)
201200
}
202201
sha := sha256.Sum256(artifactBytes)
203202

204-
out = util.RunCli(t, "search", "--sha", fmt.Sprintf("sha256:%s", hex.EncodeToString(sha[:])))
205-
util.OutputContains(t, out, uuid)
203+
out = e2eutil.RunCli(t, "search", "--sha", fmt.Sprintf("sha256:%s", hex.EncodeToString(sha[:])))
204+
e2eutil.OutputContains(t, out, uuid)
206205

207206
// Exercise GET with the new EntryID (TreeID + UUID)
208207
tid := getTreeID(t)
209208
entryID, err := sharding.CreateEntryIDFromParts(fmt.Sprintf("%x", tid), uuid)
210209
if err != nil {
211210
t.Error(err)
212211
}
213-
out = util.RunCli(t, "get", "--format=json", "--uuid", entryID.ReturnEntryIDString())
212+
out = e2eutil.RunCli(t, "get", "--format=json", "--uuid", entryID.ReturnEntryIDString())
214213
}
215214
func getTreeID(t *testing.T) int64 {
216215
t.Helper()
217-
out := util.RunCli(t, "loginfo")
216+
out := e2eutil.RunCli(t, "loginfo")
218217
tidStr := strings.TrimSpace(strings.Split(out, "TreeID: ")[1])
219218
tid, err := strconv.ParseInt(tidStr, 10, 64)
220219
if err != nil {
@@ -224,11 +223,11 @@ func getTreeID(t *testing.T) int64 {
224223
return tid
225224
}
226225
func TestSearchNoEntriesRC1(t *testing.T) {
227-
util.RunCliErr(t, "search", "--email", "[email protected]")
226+
e2eutil.RunCliErr(t, "search", "--email", "[email protected]")
228227
}
229228
func TestHostnameInSTH(t *testing.T) {
230229
// get ID of container
231-
c := exec.Command("docker","ps","-q","-f","name=rekor-server")
230+
c := exec.Command("docker", "ps", "-q", "-f", "name=rekor-server")
232231
b, err := c.CombinedOutput()
233232
if err != nil {
234233
t.Fatal(err)
@@ -261,19 +260,19 @@ func rekorServer() string {
261260
func TestSearchSHA512(t *testing.T) {
262261
sha512 := "c7694a1112ea1404a3c5852bdda04c2cc224b3567ef6ceb8204dbf2b382daacfc6837ee2ed9d5b82c90b880a3c7289778dbd5a8c2c08193459bcf7bd44581ed0"
263262
var out string
264-
out = util.RunCli(t, "upload", "--type", "intoto:0.0.2",
263+
out = e2eutil.RunCli(t, "upload", "--type", "intoto:0.0.2",
265264
"--artifact", "tests/envelope.sha512",
266265
"--pki-format", "x509",
267266
"--public-key", "tests/test_sha512.pub")
268-
util.OutputContains(t, out, "Created entry at")
269-
uuid := util.GetUUIDFromTimestampOutput(t, out)
270-
out = util.RunCli(t, "search", "--sha", fmt.Sprintf("sha512:%s", sha512))
271-
util.OutputContains(t, out, uuid)
267+
e2eutil.OutputContains(t, out, "Created entry at")
268+
uuid := e2eutil.GetUUIDFromTimestampOutput(t, out)
269+
out = e2eutil.RunCli(t, "search", "--sha", fmt.Sprintf("sha512:%s", sha512))
270+
e2eutil.OutputContains(t, out, uuid)
272271
}
273272
func TestVerifyNonExistentUUID(t *testing.T) {
274273
// this uuid is extremely likely to not exist
275-
out := util.RunCliErr(t, "verify", "--uuid", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
276-
util.OutputContains(t, out, "entry in log cannot be located")
274+
out := e2eutil.RunCliErr(t, "verify", "--uuid", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
275+
e2eutil.OutputContains(t, out, "entry in log cannot be located")
277276

278277
// Check response code
279278
tid := getTreeID(t)

pkg/pki/minisign/minisign_e2e_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"strings"
2424
"testing"
2525

26-
"github.com/sigstore/rekor/pkg/util"
26+
e2eutil "github.com/sigstore/rekor/pkg/util/e2eutil"
2727
)
2828

2929
func TestMinisign(t *testing.T) {
@@ -32,40 +32,40 @@ func TestMinisign(t *testing.T) {
3232
pubPath := filepath.Join(t.TempDir(), "minisign.pub")
3333

3434
// Set an empty password, we have to hit enter twice to confirm
35-
util.Run(t, "\n\n", "minisign", "-G", "-s", keyPath, "-p", pubPath)
35+
e2eutil.Run(t, "\n\n", "minisign", "-G", "-s", keyPath, "-p", pubPath)
3636

3737
// Create a random artifact and sign it.
3838
artifactPath := filepath.Join(t.TempDir(), "artifact")
3939
sigPath := filepath.Join(t.TempDir(), "signature.asc")
40-
util.CreateArtifact(t, artifactPath)
40+
e2eutil.CreateArtifact(t, artifactPath)
4141

4242
// Send in one empty password over stdin
43-
out := util.Run(t, "\n", "minisign", "-S", "-s", keyPath, "-m", artifactPath, "-x", sigPath)
43+
out := e2eutil.Run(t, "\n", "minisign", "-S", "-s", keyPath, "-m", artifactPath, "-x", sigPath)
4444
t.Log(out)
4545

4646
// Now upload to the log!
47-
out = util.RunCli(t, "upload", "--artifact", artifactPath, "--signature", sigPath,
47+
out = e2eutil.RunCli(t, "upload", "--artifact", artifactPath, "--signature", sigPath,
4848
"--public-key", pubPath, "--pki-format", "minisign")
49-
util.OutputContains(t, out, "Created entry at")
49+
e2eutil.OutputContains(t, out, "Created entry at")
5050

51-
uuidA := util.GetUUIDFromUploadOutput(t, out)
51+
uuidA := e2eutil.GetUUIDFromUploadOutput(t, out)
5252

53-
out = util.RunCli(t, "verify", "--artifact", artifactPath, "--signature", sigPath,
53+
out = e2eutil.RunCli(t, "verify", "--artifact", artifactPath, "--signature", sigPath,
5454
"--public-key", pubPath, "--pki-format", "minisign")
55-
util.OutputContains(t, out, "Inclusion Proof")
55+
e2eutil.OutputContains(t, out, "Inclusion Proof")
5656

57-
out = util.RunCli(t, "search", "--public-key", pubPath, "--pki-format", "minisign")
58-
util.OutputContains(t, out, uuidA)
57+
out = e2eutil.RunCli(t, "search", "--public-key", pubPath, "--pki-format", "minisign")
58+
e2eutil.OutputContains(t, out, uuidA)
5959

6060
// crease a second artifact and sign it
6161
artifactPath_B := filepath.Join(t.TempDir(), "artifact2")
62-
util.CreateArtifact(t, artifactPath_B)
63-
out = util.Run(t, "\n", "minisign", "-S", "-s", keyPath, "-m", artifactPath_B, "-x", sigPath)
62+
e2eutil.CreateArtifact(t, artifactPath_B)
63+
out = e2eutil.Run(t, "\n", "minisign", "-S", "-s", keyPath, "-m", artifactPath_B, "-x", sigPath)
6464
// Now upload to the log!
65-
out = util.RunCli(t, "upload", "--artifact", artifactPath_B, "--signature", sigPath,
65+
out = e2eutil.RunCli(t, "upload", "--artifact", artifactPath_B, "--signature", sigPath,
6666
"--public-key", pubPath, "--pki-format", "minisign")
67-
util.OutputContains(t, out, "Created entry at")
68-
uuidB := util.GetUUIDFromUploadOutput(t, out)
67+
e2eutil.OutputContains(t, out, "Created entry at")
68+
uuidB := e2eutil.GetUUIDFromUploadOutput(t, out)
6969

7070
tests := []struct {
7171
name string
@@ -105,7 +105,7 @@ func TestMinisign(t *testing.T) {
105105
}
106106
for _, test := range tests {
107107
t.Run(test.name, func(t *testing.T) {
108-
out = util.RunCli(t, "search", "--public-key", pubPath, "--pki-format", "minisign",
108+
out = e2eutil.RunCli(t, "search", "--public-key", pubPath, "--pki-format", "minisign",
109109
"--operator", test.operator, "--artifact", test.artifact)
110110

111111
expected := map[string]int{uuidA: test.expectedUuidACount, uuidB: test.expectedUuidBCount}

pkg/pki/ssh/e2e_test.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
package ssh
1919

2020
import (
21-
"github.com/sigstore/rekor/pkg/util"
2221
"io/ioutil"
2322
"path/filepath"
2423
"strings"
2524
"testing"
25+
26+
e2eutil "github.com/sigstore/rekor/pkg/util/e2eutil"
2627
)
2728

2829
func TestSSH(t *testing.T) {
@@ -41,24 +42,24 @@ func TestSSH(t *testing.T) {
4142
// Create a random artifact and sign it.
4243
artifactPath := filepath.Join(td, "artifact")
4344
sigPath := filepath.Join(td, "signature.sig")
44-
artifact := util.CreateArtifact(t, artifactPath)
45+
artifact := e2eutil.CreateArtifact(t, artifactPath)
4546

4647
sig := SSHSign(t, strings.NewReader(artifact))
4748
if err := ioutil.WriteFile(sigPath, []byte(sig), 0600); err != nil {
4849
t.Fatal(err)
4950
}
5051

5152
// Now upload to the log!
52-
out := util.RunCli(t, "upload", "--artifact", artifactPath, "--signature", sigPath,
53+
out := e2eutil.RunCli(t, "upload", "--artifact", artifactPath, "--signature", sigPath,
5354
"--public-key", pubPath, "--pki-format", "ssh")
54-
util.OutputContains(t, out, "Created entry at")
55+
e2eutil.OutputContains(t, out, "Created entry at")
5556

56-
uuid := util.GetUUIDFromUploadOutput(t, out)
57+
uuid := e2eutil.GetUUIDFromUploadOutput(t, out)
5758

58-
out = util.RunCli(t, "verify", "--artifact", artifactPath, "--signature", sigPath,
59+
out = e2eutil.RunCli(t, "verify", "--artifact", artifactPath, "--signature", sigPath,
5960
"--public-key", pubPath, "--pki-format", "ssh")
60-
util.OutputContains(t, out, "Inclusion Proof")
61+
e2eutil.OutputContains(t, out, "Inclusion Proof")
6162

62-
out = util.RunCli(t, "search", "--public-key", pubPath, "--pki-format", "ssh")
63-
util.OutputContains(t, out, uuid)
63+
out = e2eutil.RunCli(t, "search", "--public-key", pubPath, "--pki-format", "ssh")
64+
e2eutil.OutputContains(t, out, uuid)
6465
}

0 commit comments

Comments
 (0)