Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rekor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SafSec
rekor
Commits
c56fe249
Commit
c56fe249
authored
4 years ago
by
Dan Lorenc
Browse files
Options
Downloads
Patches
Plain Diff
Add an e2e test that uses verify.
parent
b814424b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/e2e_test.go
+34
-58
34 additions, 58 deletions
tests/e2e_test.go
tests/util.go
+70
-0
70 additions, 0 deletions
tests/util.go
with
104 additions
and
58 deletions
tests/e2e_test.go
+
34
−
58
View file @
c56fe249
...
...
@@ -3,71 +3,13 @@
package
e2e
import
(
"encoding/base64"
"io/ioutil"
"math/rand"
"os/exec"
"path/filepath"
"strings"
"testing"
"time"
)
const
(
cli
=
"../rekor-cli"
nodeDataDir
=
"node"
)
func
runCli
(
t
*
testing
.
T
,
arg
...
string
)
string
{
cmd
:=
exec
.
Command
(
cli
,
arg
...
)
b
,
err
:=
cmd
.
CombinedOutput
()
if
err
!=
nil
{
t
.
Log
(
string
(
b
))
t
.
Fatal
(
err
)
}
return
string
(
b
)
}
func
runCliErr
(
t
*
testing
.
T
,
arg
...
string
)
{
cmd
:=
exec
.
Command
(
cli
,
arg
...
)
b
,
err
:=
cmd
.
CombinedOutput
()
if
err
==
nil
{
t
.
Log
(
string
(
b
))
t
.
Fatalf
(
"expected error, got %s"
,
string
(
b
))
}
}
func
readFile
(
t
*
testing
.
T
,
p
string
)
string
{
b
,
err
:=
ioutil
.
ReadFile
(
p
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
return
strings
.
TrimSpace
(
string
(
b
))
}
// createdSignedArtifact gets the test dir setup correctly with some random artifacts and keys.
func
createdSignedArtifact
(
t
*
testing
.
T
,
artifactPath
,
sigPath
string
)
{
t
.
Helper
()
// First let's generate some random data so we don't have to worry about dupes.
rand
.
Seed
(
time
.
Now
()
.
UnixNano
())
data
:=
[
100
]
byte
{}
if
_
,
err
:=
rand
.
Read
(
data
[
:
]);
err
!=
nil
{
t
.
Fatal
(
err
)
}
artifact
:=
base64
.
StdEncoding
.
EncodeToString
(
data
[
:
])
// Write this to a file
if
err
:=
ioutil
.
WriteFile
(
artifactPath
,
[]
byte
(
artifact
),
0644
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Sign it with our key and write that to a file
signature
:=
Sign
(
t
,
strings
.
NewReader
(
artifact
))
if
err
:=
ioutil
.
WriteFile
(
sigPath
,
[]
byte
(
signature
),
0644
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
func
TestDuplicates
(
t
*
testing
.
T
)
{
artifactPath
:=
filepath
.
Join
(
t
.
TempDir
(),
"artifact"
)
sigPath
:=
filepath
.
Join
(
t
.
TempDir
(),
"signature.asc"
)
...
...
@@ -99,3 +41,37 @@ func TestDuplicates(t *testing.T) {
t
.
Errorf
(
"Expected [Created entry at], got %s"
,
out
)
}
}
func
TestUploadVerify
(
t
*
testing
.
T
)
{
// Create a random artifact and sign it.
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
)
}
// Verify should fail initially
runCliErr
(
t
,
"verify"
,
"--artifact"
,
artifactPath
,
"--signature"
,
sigPath
,
"--public-key"
,
pubPath
)
// 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
)
}
// 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
)
}
}
This diff is collapsed.
Click to expand it.
tests/util.go
0 → 100644
+
70
−
0
View file @
c56fe249
// +build e2e
package
e2e
import
(
"encoding/base64"
"io/ioutil"
"math/rand"
"os/exec"
"strings"
"testing"
"time"
)
const
(
cli
=
"../rekor-cli"
nodeDataDir
=
"node"
)
func
runCli
(
t
*
testing
.
T
,
arg
...
string
)
string
{
t
.
Helper
()
cmd
:=
exec
.
Command
(
cli
,
arg
...
)
b
,
err
:=
cmd
.
CombinedOutput
()
if
err
!=
nil
{
t
.
Log
(
string
(
b
))
t
.
Fatal
(
err
)
}
return
string
(
b
)
}
func
runCliErr
(
t
*
testing
.
T
,
arg
...
string
)
{
t
.
Helper
()
cmd
:=
exec
.
Command
(
cli
,
arg
...
)
b
,
err
:=
cmd
.
CombinedOutput
()
if
err
==
nil
{
t
.
Log
(
string
(
b
))
t
.
Fatalf
(
"expected error, got %s"
,
string
(
b
))
}
}
func
readFile
(
t
*
testing
.
T
,
p
string
)
string
{
b
,
err
:=
ioutil
.
ReadFile
(
p
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
return
strings
.
TrimSpace
(
string
(
b
))
}
// createdSignedArtifact gets the test dir setup correctly with some random artifacts and keys.
func
createdSignedArtifact
(
t
*
testing
.
T
,
artifactPath
,
sigPath
string
)
{
t
.
Helper
()
// First let's generate some random data so we don't have to worry about dupes.
rand
.
Seed
(
time
.
Now
()
.
UnixNano
())
data
:=
[
100
]
byte
{}
if
_
,
err
:=
rand
.
Read
(
data
[
:
]);
err
!=
nil
{
t
.
Fatal
(
err
)
}
artifact
:=
base64
.
StdEncoding
.
EncodeToString
(
data
[
:
])
// Write this to a file
if
err
:=
ioutil
.
WriteFile
(
artifactPath
,
[]
byte
(
artifact
),
0644
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
// Sign it with our key and write that to a file
signature
:=
Sign
(
t
,
strings
.
NewReader
(
artifact
))
if
err
:=
ioutil
.
WriteFile
(
sigPath
,
[]
byte
(
signature
),
0644
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment