-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update go version to 1.22.1 and run go mod tidy #36
Merged
toddgaunt-gs
merged 6 commits into
globalsign:master
from
toddgaunt-gs:update-depdencies
Apr 9, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3668955
Update go version to 1.22.1 and run go mod tidy
toddgaunt-gs 65c740c
Remove more old go versions and pin 1.22.1 exactly
toddgaunt-gs a3f9ba5
Remove unsupported Go version
toddgaunt-gs 524f2bf
Allow multiple error messages to match test case
toddgaunt-gs 7e5757c
Allow multiple error messages to match another test case
toddgaunt-gs 17fc7b0
Fix unit test logic
toddgaunt-gs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ import ( | |
"encoding/pem" | ||
"errors" | ||
"flag" | ||
"io/ioutil" | ||
"io" | ||
"log" | ||
"net" | ||
"net/http" | ||
|
@@ -250,14 +250,18 @@ func TestCACerts(t *testing.T) { | |
var testcases = []struct { | ||
name string | ||
args []string | ||
err error | ||
err []error | ||
}{ | ||
{ | ||
name: "NoAnchor", | ||
args: []string{ | ||
"-" + serverFlag, uri, | ||
}, | ||
err: errors.New("certificate signed by unknown authority"), | ||
err: []error{ | ||
errors.New("failed to verify certificate"), | ||
errors.New("certificate is not trusted"), | ||
errors.New("certificate signed by unknown authority"), | ||
}, | ||
}, | ||
{ | ||
name: "Insecure", | ||
|
@@ -289,7 +293,7 @@ func TestCACerts(t *testing.T) { | |
"-" + apsFlag, "triggererrors", | ||
"-" + explicitAnchorFlag, cafile, | ||
}, | ||
err: errors.New("internal server error"), | ||
err: []error{errors.New("internal server error")}, | ||
}, | ||
} | ||
|
||
|
@@ -299,7 +303,7 @@ func TestCACerts(t *testing.T) { | |
t.Run(tc.name, func(t *testing.T) { | ||
buf := bytes.NewBuffer([]byte{}) | ||
err := cacerts(buf, makeCmdFlagSet(t, cacertsCmd, tc.args)) | ||
verifyErrorTextContains(t, err, tc.err) | ||
verifyErrorTextContainsOneOf(t, err, tc.err) | ||
if tc.err != nil { | ||
return | ||
} | ||
|
@@ -322,14 +326,18 @@ func TestCSRAttrs(t *testing.T) { | |
name string | ||
args []string | ||
length int | ||
err error | ||
err []error | ||
}{ | ||
{ | ||
name: "NoAnchor", | ||
args: []string{ | ||
"-" + serverFlag, uri, | ||
}, | ||
err: errors.New("certificate signed by unknown authority"), | ||
err: []error{ | ||
errors.New("failed to verify certificate"), | ||
errors.New("certificate is not trusted"), | ||
errors.New("certificate signed by unknown authority"), | ||
}, | ||
}, | ||
{ | ||
name: "Insecure", | ||
|
@@ -364,7 +372,9 @@ func TestCSRAttrs(t *testing.T) { | |
"-" + apsFlag, "triggererrors", | ||
"-" + explicitAnchorFlag, cafile, | ||
}, | ||
err: errors.New("internal server error"), | ||
err: []error{ | ||
errors.New("internal server error"), | ||
}, | ||
}, | ||
} | ||
|
||
|
@@ -374,7 +384,7 @@ func TestCSRAttrs(t *testing.T) { | |
t.Run(tc.name, func(t *testing.T) { | ||
buf := bytes.NewBuffer([]byte{}) | ||
err := csrattrs(buf, makeCmdFlagSet(t, csrattrsCmd, tc.args)) | ||
verifyErrorTextContains(t, err, tc.err) | ||
verifyErrorTextContainsOneOf(t, err, tc.err) | ||
|
||
if tc.err != nil { | ||
return | ||
|
@@ -507,7 +517,7 @@ func TestReenroll(t *testing.T) { | |
tc := tc | ||
|
||
t.Run(tc.name, func(t *testing.T) { | ||
f, err := ioutil.TempFile("", "reenroll_test_") | ||
f, err := os.CreateTemp("", "reenroll_test_") | ||
if err != nil { | ||
t.Fatalf("failed to create temporary file: %v", err) | ||
} | ||
|
@@ -809,9 +819,9 @@ func newTestServer(t *testing.T) (*httptest.Server, *x509.Certificate, string) { | |
} | ||
|
||
checkBasicAuth := func( | ||
ctx context.Context, | ||
r *http.Request, | ||
aps, username, password string, | ||
_ context.Context, | ||
_ *http.Request, | ||
_, username, password string, | ||
) error { | ||
if username != "testuser" || password != "xyzzy" { | ||
return errors.New("bad credentials") | ||
|
@@ -834,7 +844,7 @@ func newTestServer(t *testing.T) (*httptest.Server, *x509.Certificate, string) { | |
|
||
s := httptest.NewUnstartedServer(r) | ||
|
||
s.Config.ErrorLog = log.New(ioutil.Discard, "", 0) | ||
s.Config.ErrorLog = log.New(io.Discard, "", 0) | ||
|
||
var clientCAs = x509.NewCertPool() | ||
clientCAs.AddCert(caCerts[len(caCerts)-1]) | ||
|
@@ -907,7 +917,7 @@ func makeCmdFlagSet(t *testing.T, cmd string, args []string) *flag.FlagSet { | |
t.Fatalf("command not recognized: %s", cmd) | ||
} | ||
|
||
set := fcmd.FlagSet(ioutil.Discard, 80) | ||
set := fcmd.FlagSet(io.Discard, 80) | ||
if err := set.Parse(args); err != nil { | ||
t.Fatalf("failed to parse flag set: %v", err) | ||
} | ||
|
@@ -918,7 +928,7 @@ func makeCmdFlagSet(t *testing.T, cmd string, args []string) *flag.FlagSet { | |
func makeRootCertFile(t *testing.T, cert *x509.Certificate) (string, func(t *testing.T)) { | ||
t.Helper() | ||
|
||
f, err := ioutil.TempFile("", "estclient_test_") | ||
f, err := os.CreateTemp("", "estclient_test_") | ||
if err != nil { | ||
t.Fatalf("failed to create temporary file: %v", err) | ||
} | ||
|
@@ -951,6 +961,38 @@ func verifyErrorTextContains(t *testing.T, got, want error) { | |
} | ||
} | ||
|
||
// verifyErrorTextContainsOneOf tests if the error text contains one of the strings. | ||
// This is useful for testing errors that output different text on different | ||
// platforms or between versions. | ||
func verifyErrorTextContainsOneOf(t *testing.T, got error, wants []error) { | ||
t.Helper() | ||
|
||
if got == nil && len(wants) == 0 { | ||
return | ||
} | ||
|
||
if got == nil && len(wants) > 0 { | ||
t.Fatalf("got nil, want one of %v", wants) | ||
} | ||
|
||
if got != nil && len(wants) == 0 { | ||
t.Fatalf("got %v, want no error", got) | ||
} | ||
|
||
// got != nil && len(wants) > 0 | ||
|
||
contains := false | ||
for _, w := range wants { | ||
if strings.Contains(got.Error(), w.Error()) { | ||
contains = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can break here if you like. |
||
} | ||
} | ||
|
||
if !contains { | ||
t.Fatalf("got error %v, want one of %v", got, wants) | ||
} | ||
} | ||
|
||
// assertPKIXNamesEqual tests if two pkix.Name objects are equal in all | ||
// respects other than the ordering of the name attributes. | ||
func assertPKIXNamesEqual(t *testing.T, first, second pkix.Name) { | ||
|
@@ -972,11 +1014,7 @@ func assertPKIXNamesEqual(t *testing.T, first, second pkix.Name) { | |
} | ||
} | ||
|
||
if s[i].Value.(string) < s[j].Value.(string) { | ||
return true | ||
} | ||
|
||
return false | ||
return s[i].Value.(string) < s[j].Value.(string) | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove this line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was intentional, as it is documenting which case this is for.