Skip to content
Snippets Groups Projects
Unverified Commit 2164914b authored by dlorenc's avatar dlorenc Committed by GitHub
Browse files

Patch out the TUF IsExpired method in tests. (#550)


This was set to fail on December 18th, which happens to be yesterday!

Signed-off-by: default avatarDan Lorenc <lorenc.d@gmail.com>
parent e55259dd
No related branches found
No related tags found
No related merge requests found
...@@ -20,8 +20,22 @@ import ( ...@@ -20,8 +20,22 @@ import (
"io" "io"
"os" "os"
"testing" "testing"
"time"
"github.com/theupdateframework/go-tuf/verify"
) )
func patchIsExpired() func() {
// Patch out the IsExpired to make the tests stable :)
old := verify.IsExpired
verify.IsExpired = func(t time.Time) bool {
return false
}
return func() {
verify.IsExpired = old
}
}
func TestReadPublicKey(t *testing.T) { func TestReadPublicKey(t *testing.T) {
// Tests reading a valid public key (root.json) // Tests reading a valid public key (root.json)
type test struct { type test struct {
...@@ -37,6 +51,9 @@ func TestReadPublicKey(t *testing.T) { ...@@ -37,6 +51,9 @@ func TestReadPublicKey(t *testing.T) {
{caseDesc: "Valid TUF root.json", inputFile: "testdata/1.root.json", errorFound: false, specVersion: "1.0"}, {caseDesc: "Valid TUF root.json", inputFile: "testdata/1.root.json", errorFound: false, specVersion: "1.0"},
} }
// Patch out the expired function to make tests stable :)
defer patchIsExpired()()
for _, tc := range tests { for _, tc := range tests {
file, err := os.Open(tc.inputFile) file, err := os.Open(tc.inputFile)
if err != nil { if err != nil {
...@@ -101,6 +118,9 @@ func TestCanonicalValue(t *testing.T) { ...@@ -101,6 +118,9 @@ func TestCanonicalValue(t *testing.T) {
t.Errorf("CanonicalValue did not error out for uninitialized key") t.Errorf("CanonicalValue did not error out for uninitialized key")
} }
// Patch out the expired function to make tests stable :)
defer patchIsExpired()()
tests := []test{ tests := []test{
{caseDesc: "root", input: "testdata/1.root.json", output: "testdata/reformat.1.root.json", match: true}, {caseDesc: "root", input: "testdata/1.root.json", output: "testdata/reformat.1.root.json", match: true},
} }
...@@ -115,7 +135,7 @@ func TestCanonicalValue(t *testing.T) { ...@@ -115,7 +135,7 @@ func TestCanonicalValue(t *testing.T) {
inputKey, err := NewPublicKey(inputFile) inputKey, err := NewPublicKey(inputFile)
if err != nil { if err != nil {
t.Errorf("%v: Error reading input for TestCanonicalValuePublicKey: %v", tc.caseDesc, err) t.Errorf("%v: Error reading input for TestCanonicalValue: %v", tc.caseDesc, err)
} }
cvInput, err := inputKey.CanonicalValue() cvInput, err := inputKey.CanonicalValue()
...@@ -130,7 +150,7 @@ func TestCanonicalValue(t *testing.T) { ...@@ -130,7 +150,7 @@ func TestCanonicalValue(t *testing.T) {
outputKey, err := NewPublicKey(outputFile) outputKey, err := NewPublicKey(outputFile)
if err != nil { if err != nil {
t.Errorf("%v: Error reading input for TestCanonicalValuePublicKey: %v", tc.caseDesc, err) t.Errorf("%v: Error reading input for TestCanonicalValue: %v", tc.caseDesc, err)
} }
cvOutput, err := outputKey.CanonicalValue() cvOutput, err := outputKey.CanonicalValue()
...@@ -159,6 +179,8 @@ func TestVerifySignature(t *testing.T) { ...@@ -159,6 +179,8 @@ func TestVerifySignature(t *testing.T) {
{caseDesc: "Valid root.json, unsigned root.json", keyFile: "testdata/1.root.json", sigFile: "testdata/unsigned_root.json", verified: false}, {caseDesc: "Valid root.json, unsigned root.json", keyFile: "testdata/1.root.json", sigFile: "testdata/unsigned_root.json", verified: false},
} }
defer patchIsExpired()()
for _, tc := range tests { for _, tc := range tests {
keyFile, err := os.Open(tc.keyFile) keyFile, err := os.Open(tc.keyFile)
if err != nil { if err != nil {
......
...@@ -26,6 +26,7 @@ import ( ...@@ -26,6 +26,7 @@ import (
"net/http/httptest" "net/http/httptest"
"reflect" "reflect"
"testing" "testing"
"time"
"github.com/go-openapi/runtime" "github.com/go-openapi/runtime"
"github.com/go-openapi/strfmt" "github.com/go-openapi/strfmt"
...@@ -33,10 +34,22 @@ import ( ...@@ -33,10 +34,22 @@ import (
"github.com/sigstore/rekor/pkg/generated/models" "github.com/sigstore/rekor/pkg/generated/models"
"github.com/sigstore/rekor/pkg/types" "github.com/sigstore/rekor/pkg/types"
"github.com/theupdateframework/go-tuf/data" "github.com/theupdateframework/go-tuf/data"
"github.com/theupdateframework/go-tuf/verify"
"go.uber.org/goleak" "go.uber.org/goleak"
) )
func patchIsExpired() func() {
// Patch out the IsExpired to make the tests stable :)
old := verify.IsExpired
verify.IsExpired = func(t time.Time) bool {
return false
}
return func() {
verify.IsExpired = old
}
}
func TestMain(m *testing.M) { func TestMain(m *testing.M) {
goleak.VerifyTestMain(m) goleak.VerifyTestMain(m)
} }
...@@ -49,6 +62,8 @@ func TestNewEntryReturnType(t *testing.T) { ...@@ -49,6 +62,8 @@ func TestNewEntryReturnType(t *testing.T) {
} }
func TestCrossFieldValidation(t *testing.T) { func TestCrossFieldValidation(t *testing.T) {
defer patchIsExpired()()
type TestCase struct { type TestCase struct {
caseDesc string caseDesc string
entry V001Entry entry V001Entry
......
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