mirror of
https://github.com/outbackdingo/certificates.git
synced 2026-01-27 02:18:27 +00:00
bump go.mod to go1.20 and associated linter fixes (#1518)
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"testing"
|
||||
@@ -313,7 +314,7 @@ func TestHandler_GetOrdersByAccountID(t *testing.T) {
|
||||
"fail/nil-account": func(t *testing.T) test {
|
||||
return test{
|
||||
db: &acme.MockDB{},
|
||||
ctx: context.WithValue(context.Background(), accContextKey, nil),
|
||||
ctx: context.WithValue(context.Background(), accContextKey, http.NoBody),
|
||||
statusCode: 400,
|
||||
err: acme.NewError(acme.ErrorAccountDoesNotExistType, "account does not exist"),
|
||||
}
|
||||
@@ -363,7 +364,7 @@ func TestHandler_GetOrdersByAccountID(t *testing.T) {
|
||||
tc := run(t)
|
||||
t.Run(name, func(t *testing.T) {
|
||||
ctx := acme.NewContext(tc.ctx, tc.db, nil, acme.NewLinker("test.ca.smallstep.com", "acme"), nil)
|
||||
req := httptest.NewRequest("GET", u, nil)
|
||||
req := httptest.NewRequest("GET", u, http.NoBody)
|
||||
req = req.WithContext(ctx)
|
||||
w := httptest.NewRecorder()
|
||||
GetOrdersByAccountID(w, req)
|
||||
@@ -802,7 +803,7 @@ func TestHandler_NewAccount(t *testing.T) {
|
||||
tc := run(t)
|
||||
t.Run(name, func(t *testing.T) {
|
||||
ctx := acme.NewContext(tc.ctx, tc.db, nil, acme.NewLinker("test.ca.smallstep.com", "acme"), nil)
|
||||
req := httptest.NewRequest("GET", "/foo/bar", nil)
|
||||
req := httptest.NewRequest("GET", "/foo/bar", http.NoBody)
|
||||
req = req.WithContext(ctx)
|
||||
w := httptest.NewRecorder()
|
||||
NewAccount(w, req)
|
||||
@@ -1005,7 +1006,7 @@ func TestHandler_GetOrUpdateAccount(t *testing.T) {
|
||||
tc := run(t)
|
||||
t.Run(name, func(t *testing.T) {
|
||||
ctx := acme.NewContext(tc.ctx, tc.db, nil, acme.NewLinker("test.ca.smallstep.com", "acme"), nil)
|
||||
req := httptest.NewRequest("GET", "/foo/bar", nil)
|
||||
req := httptest.NewRequest("GET", "/foo/bar", http.NoBody)
|
||||
req = req.WithContext(ctx)
|
||||
w := httptest.NewRecorder()
|
||||
GetOrUpdateAccount(w, req)
|
||||
|
||||
@@ -60,7 +60,7 @@ func TestHandler_GetNonce(t *testing.T) {
|
||||
}
|
||||
|
||||
// Request with chi context
|
||||
req := httptest.NewRequest("GET", "http://ca.smallstep.com/nonce", nil)
|
||||
req := httptest.NewRequest("GET", "http://ca.smallstep.com/nonce", http.NoBody)
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
@@ -175,7 +175,7 @@ func TestHandler_GetDirectory(t *testing.T) {
|
||||
tc := run(t)
|
||||
t.Run(name, func(t *testing.T) {
|
||||
ctx := acme.NewLinkerContext(tc.ctx, acme.NewLinker("test.ca.smallstep.com", "acme"))
|
||||
req := httptest.NewRequest("GET", "/foo/bar", nil)
|
||||
req := httptest.NewRequest("GET", "/foo/bar", http.NoBody)
|
||||
req = req.WithContext(ctx)
|
||||
w := httptest.NewRecorder()
|
||||
GetDirectory(w, req)
|
||||
@@ -347,7 +347,7 @@ func TestHandler_GetAuthorization(t *testing.T) {
|
||||
tc := run(t)
|
||||
t.Run(name, func(t *testing.T) {
|
||||
ctx := acme.NewContext(tc.ctx, tc.db, nil, acme.NewLinker("test.ca.smallstep.com", "acme"), nil)
|
||||
req := httptest.NewRequest("GET", "/foo/bar", nil)
|
||||
req := httptest.NewRequest("GET", "/foo/bar", http.NoBody)
|
||||
req = req.WithContext(ctx)
|
||||
w := httptest.NewRecorder()
|
||||
GetAuthorization(w, req)
|
||||
@@ -489,7 +489,7 @@ func TestHandler_GetCertificate(t *testing.T) {
|
||||
tc := run(t)
|
||||
t.Run(name, func(t *testing.T) {
|
||||
ctx := acme.NewDatabaseContext(tc.ctx, tc.db)
|
||||
req := httptest.NewRequest("GET", u, nil)
|
||||
req := httptest.NewRequest("GET", u, http.NoBody)
|
||||
req = req.WithContext(ctx)
|
||||
w := httptest.NewRecorder()
|
||||
GetCertificate(w, req)
|
||||
@@ -747,7 +747,7 @@ func TestHandler_GetChallenge(t *testing.T) {
|
||||
tc := run(t)
|
||||
t.Run(name, func(t *testing.T) {
|
||||
ctx := acme.NewContext(tc.ctx, tc.db, nil, acme.NewLinker("test.ca.smallstep.com", "acme"), nil)
|
||||
req := httptest.NewRequest("GET", u, nil)
|
||||
req := httptest.NewRequest("GET", u, http.NoBody)
|
||||
req = req.WithContext(ctx)
|
||||
w := httptest.NewRecorder()
|
||||
GetChallenge(w, req)
|
||||
|
||||
@@ -75,7 +75,7 @@ func TestHandler_addNonce(t *testing.T) {
|
||||
tc := run(t)
|
||||
t.Run(name, func(t *testing.T) {
|
||||
ctx := newBaseContext(context.Background(), tc.db)
|
||||
req := httptest.NewRequest("GET", u, nil).WithContext(ctx)
|
||||
req := httptest.NewRequest("GET", u, http.NoBody).WithContext(ctx)
|
||||
w := httptest.NewRecorder()
|
||||
addNonce(testNext)(w, req)
|
||||
res := w.Result()
|
||||
@@ -127,7 +127,7 @@ func TestHandler_addDirLink(t *testing.T) {
|
||||
for name, run := range tests {
|
||||
tc := run(t)
|
||||
t.Run(name, func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/foo", nil)
|
||||
req := httptest.NewRequest("GET", "/foo", http.NoBody)
|
||||
req = req.WithContext(tc.ctx)
|
||||
w := httptest.NewRecorder()
|
||||
addDirLink(testNext)(w, req)
|
||||
@@ -230,7 +230,7 @@ func TestHandler_verifyContentType(t *testing.T) {
|
||||
if tc.url != "" {
|
||||
_u = tc.url
|
||||
}
|
||||
req := httptest.NewRequest("GET", _u, nil)
|
||||
req := httptest.NewRequest("GET", _u, http.NoBody)
|
||||
req = req.WithContext(tc.ctx)
|
||||
req.Header.Add("Content-Type", tc.contentType)
|
||||
w := httptest.NewRecorder()
|
||||
@@ -298,7 +298,7 @@ func TestHandler_isPostAsGet(t *testing.T) {
|
||||
tc := run(t)
|
||||
t.Run(name, func(t *testing.T) {
|
||||
// h := &Handler{}
|
||||
req := httptest.NewRequest("GET", u, nil)
|
||||
req := httptest.NewRequest("GET", u, http.NoBody)
|
||||
req = req.WithContext(tc.ctx)
|
||||
w := httptest.NewRecorder()
|
||||
isPostAsGet(testNext)(w, req)
|
||||
@@ -582,7 +582,7 @@ func TestHandler_verifyAndExtractJWSPayload(t *testing.T) {
|
||||
tc := run(t)
|
||||
t.Run(name, func(t *testing.T) {
|
||||
// h := &Handler{}
|
||||
req := httptest.NewRequest("GET", u, nil)
|
||||
req := httptest.NewRequest("GET", u, http.NoBody)
|
||||
req = req.WithContext(tc.ctx)
|
||||
w := httptest.NewRecorder()
|
||||
verifyAndExtractJWSPayload(tc.next)(w, req)
|
||||
@@ -829,7 +829,7 @@ func TestHandler_lookupJWK(t *testing.T) {
|
||||
tc := run(t)
|
||||
t.Run(name, func(t *testing.T) {
|
||||
ctx := newBaseContext(tc.ctx, tc.db, tc.linker)
|
||||
req := httptest.NewRequest("GET", u, nil)
|
||||
req := httptest.NewRequest("GET", u, http.NoBody)
|
||||
req = req.WithContext(ctx)
|
||||
w := httptest.NewRecorder()
|
||||
lookupJWK(tc.next)(w, req)
|
||||
@@ -1028,7 +1028,7 @@ func TestHandler_extractJWK(t *testing.T) {
|
||||
tc := run(t)
|
||||
t.Run(name, func(t *testing.T) {
|
||||
ctx := newBaseContext(tc.ctx, tc.db)
|
||||
req := httptest.NewRequest("GET", u, nil)
|
||||
req := httptest.NewRequest("GET", u, http.NoBody)
|
||||
req = req.WithContext(ctx)
|
||||
w := httptest.NewRecorder()
|
||||
extractJWK(tc.next)(w, req)
|
||||
@@ -1403,7 +1403,7 @@ func TestHandler_validateJWS(t *testing.T) {
|
||||
tc := run(t)
|
||||
t.Run(name, func(t *testing.T) {
|
||||
ctx := newBaseContext(tc.ctx, tc.db)
|
||||
req := httptest.NewRequest("GET", u, nil)
|
||||
req := httptest.NewRequest("GET", u, http.NoBody)
|
||||
req = req.WithContext(ctx)
|
||||
w := httptest.NewRecorder()
|
||||
validateJWS(tc.next)(w, req)
|
||||
@@ -1585,7 +1585,7 @@ func TestHandler_extractOrLookupJWK(t *testing.T) {
|
||||
tc := prep(t)
|
||||
t.Run(name, func(t *testing.T) {
|
||||
ctx := newBaseContext(tc.ctx, tc.db, tc.linker)
|
||||
req := httptest.NewRequest("GET", u, nil)
|
||||
req := httptest.NewRequest("GET", u, http.NoBody)
|
||||
req = req.WithContext(ctx)
|
||||
w := httptest.NewRecorder()
|
||||
extractOrLookupJWK(tc.next)(w, req)
|
||||
@@ -1670,7 +1670,7 @@ func TestHandler_checkPrerequisites(t *testing.T) {
|
||||
tc := run(t)
|
||||
t.Run(name, func(t *testing.T) {
|
||||
ctx := acme.NewPrerequisitesCheckerContext(tc.ctx, tc.prerequisitesChecker)
|
||||
req := httptest.NewRequest("GET", u, nil)
|
||||
req := httptest.NewRequest("GET", u, http.NoBody)
|
||||
req = req.WithContext(ctx)
|
||||
w := httptest.NewRecorder()
|
||||
checkPrerequisites(tc.next)(w, req)
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"reflect"
|
||||
@@ -468,7 +469,7 @@ func TestHandler_GetOrder(t *testing.T) {
|
||||
tc := run(t)
|
||||
t.Run(name, func(t *testing.T) {
|
||||
ctx := newBaseContext(tc.ctx, tc.db, acme.NewLinker("test.ca.smallstep.com", "acme"))
|
||||
req := httptest.NewRequest("GET", u, nil)
|
||||
req := httptest.NewRequest("GET", u, http.NoBody)
|
||||
req = req.WithContext(ctx)
|
||||
w := httptest.NewRecorder()
|
||||
GetOrder(w, req)
|
||||
@@ -1827,7 +1828,7 @@ func TestHandler_NewOrder(t *testing.T) {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
mockMustAuthority(t, tc.ca)
|
||||
ctx := newBaseContext(tc.ctx, tc.db, acme.NewLinker("test.ca.smallstep.com", "acme"))
|
||||
req := httptest.NewRequest("GET", u, nil)
|
||||
req := httptest.NewRequest("GET", u, http.NoBody)
|
||||
req = req.WithContext(ctx)
|
||||
w := httptest.NewRecorder()
|
||||
NewOrder(w, req)
|
||||
@@ -2124,7 +2125,7 @@ func TestHandler_FinalizeOrder(t *testing.T) {
|
||||
tc := run(t)
|
||||
t.Run(name, func(t *testing.T) {
|
||||
ctx := newBaseContext(tc.ctx, tc.db, acme.NewLinker("test.ca.smallstep.com", "acme"))
|
||||
req := httptest.NewRequest("GET", u, nil)
|
||||
req := httptest.NewRequest("GET", u, http.NoBody)
|
||||
req = req.WithContext(ctx)
|
||||
w := httptest.NewRecorder()
|
||||
FinalizeOrder(w, req)
|
||||
|
||||
@@ -1072,7 +1072,7 @@ func TestHandler_RevokeCert(t *testing.T) {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
ctx := newBaseContext(tc.ctx, tc.db, acme.NewLinker("test.ca.smallstep.com", "acme"))
|
||||
mockMustAuthority(t, tc.ca)
|
||||
req := httptest.NewRequest("POST", revokeURL, nil)
|
||||
req := httptest.NewRequest("POST", revokeURL, http.NoBody)
|
||||
req = req.WithContext(ctx)
|
||||
w := httptest.NewRecorder()
|
||||
RevokeCert(w, req)
|
||||
@@ -1094,7 +1094,7 @@ func TestHandler_RevokeCert(t *testing.T) {
|
||||
assert.Equals(t, res.Header["Content-Type"], []string{"application/problem+json"})
|
||||
} else {
|
||||
assert.True(t, bytes.Equal(bytes.TrimSpace(body), []byte{}))
|
||||
assert.Equals(t, int64(0), req.ContentLength)
|
||||
assert.Equals(t, int64(-1), req.ContentLength)
|
||||
assert.Equals(t, []string{fmt.Sprintf("<%s/acme/%s/directory>;rel=\"index\"", baseURL.String(), escProvName)}, res.Header["Link"])
|
||||
}
|
||||
})
|
||||
|
||||
@@ -803,7 +803,7 @@ func Test_CRLGeneration(t *testing.T) {
|
||||
}
|
||||
|
||||
chiCtx := chi.NewRouteContext()
|
||||
req := httptest.NewRequest("GET", "http://example.com/crl", nil)
|
||||
req := httptest.NewRequest("GET", "http://example.com/crl", http.NoBody)
|
||||
req = req.WithContext(context.WithValue(context.Background(), chi.RouteCtxKey, chiCtx))
|
||||
|
||||
for _, tt := range tests {
|
||||
@@ -856,7 +856,7 @@ func Test_caHandler_Route(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_Health(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "http://example.com/health", nil)
|
||||
req := httptest.NewRequest("GET", "http://example.com/health", http.NoBody)
|
||||
w := httptest.NewRecorder()
|
||||
Health(w, req)
|
||||
|
||||
@@ -890,7 +890,7 @@ func Test_Root(t *testing.T) {
|
||||
// Request with chi context
|
||||
chiCtx := chi.NewRouteContext()
|
||||
chiCtx.URLParams.Add("sha", "efc7d6b475a56fe587650bcdb999a4a308f815ba44db4bf0371ea68a786ccd36")
|
||||
req := httptest.NewRequest("GET", "http://example.com/root/efc7d6b475a56fe587650bcdb999a4a308f815ba44db4bf0371ea68a786ccd36", nil)
|
||||
req := httptest.NewRequest("GET", "http://example.com/root/efc7d6b475a56fe587650bcdb999a4a308f815ba44db4bf0371ea68a786ccd36", http.NoBody)
|
||||
req = req.WithContext(context.WithValue(context.Background(), chi.RouteCtxKey, chiCtx))
|
||||
|
||||
expected := []byte(`{"ca":"` + strings.ReplaceAll(rootPEM, "\n", `\n`) + `\n"}`)
|
||||
@@ -1105,7 +1105,7 @@ func Test_Renew(t *testing.T) {
|
||||
return nil
|
||||
},
|
||||
})
|
||||
req := httptest.NewRequest("POST", "http://example.com/renew", nil)
|
||||
req := httptest.NewRequest("POST", "http://example.com/renew", http.NoBody)
|
||||
req.TLS = tt.tls
|
||||
req.Header = tt.header
|
||||
w := httptest.NewRecorder()
|
||||
@@ -1313,7 +1313,7 @@ func Test_ProvisionerKey(t *testing.T) {
|
||||
// Request with chi context
|
||||
chiCtx := chi.NewRouteContext()
|
||||
chiCtx.URLParams.Add("kid", "oV1p0MJeGQ7qBlK6B-oyfVdBRjh_e7VSK_YSEEqgW00")
|
||||
req := httptest.NewRequest("GET", "http://example.com/provisioners/oV1p0MJeGQ7qBlK6B-oyfVdBRjh_e7VSK_YSEEqgW00/encrypted-key", nil)
|
||||
req := httptest.NewRequest("GET", "http://example.com/provisioners/oV1p0MJeGQ7qBlK6B-oyfVdBRjh_e7VSK_YSEEqgW00/encrypted-key", http.NoBody)
|
||||
req = req.WithContext(context.WithValue(context.Background(), chi.RouteCtxKey, chiCtx))
|
||||
|
||||
tests := []struct {
|
||||
@@ -1381,7 +1381,7 @@ func Test_Roots(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
mockMustAuthority(t, &mockAuthority{ret1: []*x509.Certificate{tt.root}, err: tt.err})
|
||||
req := httptest.NewRequest("GET", "http://example.com/roots", nil)
|
||||
req := httptest.NewRequest("GET", "http://example.com/roots", http.NoBody)
|
||||
req.TLS = tt.tls
|
||||
w := httptest.NewRecorder()
|
||||
Roots(w, req)
|
||||
@@ -1422,7 +1422,7 @@ func Test_caHandler_RootsPEM(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
mockMustAuthority(t, &mockAuthority{ret1: tt.roots, err: tt.err})
|
||||
req := httptest.NewRequest("GET", "https://example.com/roots", nil)
|
||||
req := httptest.NewRequest("GET", "https://example.com/roots", http.NoBody)
|
||||
w := httptest.NewRecorder()
|
||||
RootsPEM(w, req)
|
||||
res := w.Result()
|
||||
@@ -1467,7 +1467,7 @@ func Test_Federation(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
mockMustAuthority(t, &mockAuthority{ret1: []*x509.Certificate{tt.root}, err: tt.err})
|
||||
req := httptest.NewRequest("GET", "http://example.com/federation", nil)
|
||||
req := httptest.NewRequest("GET", "http://example.com/federation", http.NoBody)
|
||||
req.TLS = tt.tls
|
||||
w := httptest.NewRecorder()
|
||||
Federation(w, req)
|
||||
|
||||
@@ -128,7 +128,7 @@ func TestHandler_requireEABEnabled(t *testing.T) {
|
||||
for name, prep := range tests {
|
||||
tc := prep(t)
|
||||
t.Run(name, func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/foo", nil).WithContext(tc.ctx)
|
||||
req := httptest.NewRequest("GET", "/foo", http.NoBody).WithContext(tc.ctx)
|
||||
w := httptest.NewRecorder()
|
||||
requireEABEnabled(tc.next)(w, req)
|
||||
res := w.Result()
|
||||
@@ -223,7 +223,7 @@ func TestHandler_CreateExternalAccountKey(t *testing.T) {
|
||||
tc := prep(t)
|
||||
t.Run(name, func(t *testing.T) {
|
||||
|
||||
req := httptest.NewRequest("POST", "/foo", nil) // chi routing is prepared in test setup
|
||||
req := httptest.NewRequest("POST", "/foo", http.NoBody) // chi routing is prepared in test setup
|
||||
req = req.WithContext(tc.ctx)
|
||||
w := httptest.NewRecorder()
|
||||
acmeResponder := NewACMEAdminResponder()
|
||||
@@ -276,7 +276,7 @@ func TestHandler_DeleteExternalAccountKey(t *testing.T) {
|
||||
tc := prep(t)
|
||||
t.Run(name, func(t *testing.T) {
|
||||
|
||||
req := httptest.NewRequest("DELETE", "/foo", nil) // chi routing is prepared in test setup
|
||||
req := httptest.NewRequest("DELETE", "/foo", http.NoBody) // chi routing is prepared in test setup
|
||||
req = req.WithContext(tc.ctx)
|
||||
w := httptest.NewRecorder()
|
||||
acmeResponder := NewACMEAdminResponder()
|
||||
@@ -311,7 +311,7 @@ func TestHandler_GetExternalAccountKeys(t *testing.T) {
|
||||
"ok": func(t *testing.T) test {
|
||||
chiCtx := chi.NewRouteContext()
|
||||
chiCtx.URLParams.Add("provisionerName", "provName")
|
||||
req := httptest.NewRequest("GET", "/foo", nil)
|
||||
req := httptest.NewRequest("GET", "/foo", http.NoBody)
|
||||
ctx := context.WithValue(context.Background(), chi.RouteCtxKey, chiCtx)
|
||||
return test{
|
||||
ctx: ctx,
|
||||
|
||||
@@ -357,7 +357,7 @@ func TestHandler_GetAdmin(t *testing.T) {
|
||||
tc := prep(t)
|
||||
t.Run(name, func(t *testing.T) {
|
||||
mockMustAuthority(t, tc.auth)
|
||||
req := httptest.NewRequest("GET", "/foo", nil) // chi routing is prepared in test setup
|
||||
req := httptest.NewRequest("GET", "/foo", http.NoBody) // chi routing is prepared in test setup
|
||||
req = req.WithContext(tc.ctx)
|
||||
w := httptest.NewRecorder()
|
||||
GetAdmin(w, req)
|
||||
@@ -406,7 +406,7 @@ func TestHandler_GetAdmins(t *testing.T) {
|
||||
}
|
||||
var tests = map[string]func(t *testing.T) test{
|
||||
"fail/parse-cursor": func(t *testing.T) test {
|
||||
req := httptest.NewRequest("GET", "/foo?limit=A", nil)
|
||||
req := httptest.NewRequest("GET", "/foo?limit=A", http.NoBody)
|
||||
return test{
|
||||
ctx: context.Background(),
|
||||
req: req,
|
||||
@@ -420,7 +420,7 @@ func TestHandler_GetAdmins(t *testing.T) {
|
||||
}
|
||||
},
|
||||
"fail/auth.GetAdmins": func(t *testing.T) test {
|
||||
req := httptest.NewRequest("GET", "/foo", nil)
|
||||
req := httptest.NewRequest("GET", "/foo", http.NoBody)
|
||||
auth := &mockAdminAuthority{
|
||||
MockGetAdmins: func(cursor string, limit int) ([]*linkedca.Admin, string, error) {
|
||||
assert.Equals(t, "", cursor)
|
||||
@@ -442,7 +442,7 @@ func TestHandler_GetAdmins(t *testing.T) {
|
||||
}
|
||||
},
|
||||
"ok": func(t *testing.T) test {
|
||||
req := httptest.NewRequest("GET", "/foo", nil)
|
||||
req := httptest.NewRequest("GET", "/foo", http.NoBody)
|
||||
createdAt := time.Now()
|
||||
var deletedAt time.Time
|
||||
adm1 := &linkedca.Admin{
|
||||
@@ -764,7 +764,7 @@ func TestHandler_DeleteAdmin(t *testing.T) {
|
||||
tc := prep(t)
|
||||
t.Run(name, func(t *testing.T) {
|
||||
mockMustAuthority(t, tc.auth)
|
||||
req := httptest.NewRequest("DELETE", "/foo", nil) // chi routing is prepared in test setup
|
||||
req := httptest.NewRequest("DELETE", "/foo", http.NoBody) // chi routing is prepared in test setup
|
||||
req = req.WithContext(tc.ctx)
|
||||
w := httptest.NewRecorder()
|
||||
DeleteAdmin(w, req)
|
||||
|
||||
@@ -72,7 +72,7 @@ func TestHandler_requireAPIEnabled(t *testing.T) {
|
||||
tc := prep(t)
|
||||
t.Run(name, func(t *testing.T) {
|
||||
mockMustAuthority(t, tc.auth)
|
||||
req := httptest.NewRequest("GET", "/foo", nil) // chi routing is prepared in test setup
|
||||
req := httptest.NewRequest("GET", "/foo", http.NoBody) // chi routing is prepared in test setup
|
||||
req = req.WithContext(tc.ctx)
|
||||
w := httptest.NewRecorder()
|
||||
requireAPIEnabled(tc.next)(w, req)
|
||||
@@ -113,7 +113,7 @@ func TestHandler_extractAuthorizeTokenAdmin(t *testing.T) {
|
||||
}
|
||||
var tests = map[string]func(t *testing.T) test{
|
||||
"fail/missing-authorization-token": func(t *testing.T) test {
|
||||
req := httptest.NewRequest("GET", "/foo", nil)
|
||||
req := httptest.NewRequest("GET", "/foo", http.NoBody)
|
||||
req.Header["Authorization"] = []string{""}
|
||||
return test{
|
||||
ctx: context.Background(),
|
||||
@@ -128,7 +128,7 @@ func TestHandler_extractAuthorizeTokenAdmin(t *testing.T) {
|
||||
}
|
||||
},
|
||||
"fail/auth.AuthorizeAdminToken": func(t *testing.T) test {
|
||||
req := httptest.NewRequest("GET", "/foo", nil)
|
||||
req := httptest.NewRequest("GET", "/foo", http.NoBody)
|
||||
req.Header["Authorization"] = []string{"token"}
|
||||
auth := &mockAdminAuthority{
|
||||
MockAuthorizeAdminToken: func(r *http.Request, token string) (*linkedca.Admin, error) {
|
||||
@@ -153,7 +153,7 @@ func TestHandler_extractAuthorizeTokenAdmin(t *testing.T) {
|
||||
}
|
||||
},
|
||||
"ok": func(t *testing.T) test {
|
||||
req := httptest.NewRequest("GET", "/foo", nil)
|
||||
req := httptest.NewRequest("GET", "/foo", http.NoBody)
|
||||
req.Header["Authorization"] = []string{"token"}
|
||||
createdAt := time.Now()
|
||||
var deletedAt time.Time
|
||||
@@ -324,7 +324,7 @@ func TestHandler_loadProvisionerByName(t *testing.T) {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
mockMustAuthority(t, tc.auth)
|
||||
ctx := admin.NewContext(tc.ctx, tc.adminDB)
|
||||
req := httptest.NewRequest("GET", "/foo", nil) // chi routing is prepared in test setup
|
||||
req := httptest.NewRequest("GET", "/foo", http.NoBody) // chi routing is prepared in test setup
|
||||
req = req.WithContext(ctx)
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
@@ -399,7 +399,7 @@ func TestHandler_checkAction(t *testing.T) {
|
||||
tc := prep(t)
|
||||
t.Run(name, func(t *testing.T) {
|
||||
ctx := admin.NewContext(context.Background(), tc.adminDB)
|
||||
req := httptest.NewRequest("GET", "/foo", nil).WithContext(ctx)
|
||||
req := httptest.NewRequest("GET", "/foo", http.NoBody).WithContext(ctx)
|
||||
w := httptest.NewRecorder()
|
||||
checkAction(tc.next, tc.supportedInStandalone)(w, req)
|
||||
res := w.Result()
|
||||
@@ -643,7 +643,7 @@ func TestHandler_loadExternalAccountKey(t *testing.T) {
|
||||
tc := prep(t)
|
||||
t.Run(name, func(t *testing.T) {
|
||||
ctx := acme.NewDatabaseContext(tc.ctx, tc.acmeDB)
|
||||
req := httptest.NewRequest("GET", "/foo", nil)
|
||||
req := httptest.NewRequest("GET", "/foo", http.NoBody)
|
||||
req = req.WithContext(ctx)
|
||||
w := httptest.NewRecorder()
|
||||
loadExternalAccountKey(tc.next)(w, req)
|
||||
|
||||
@@ -241,7 +241,7 @@ func TestPolicyAdminResponder_GetAuthorityPolicy(t *testing.T) {
|
||||
ctx := admin.NewContext(tc.ctx, tc.adminDB)
|
||||
par := NewPolicyAdminResponder()
|
||||
|
||||
req := httptest.NewRequest("GET", "/foo", nil)
|
||||
req := httptest.NewRequest("GET", "/foo", http.NoBody)
|
||||
req = req.WithContext(ctx)
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
@@ -1164,7 +1164,7 @@ func TestPolicyAdminResponder_GetProvisionerPolicy(t *testing.T) {
|
||||
ctx = acme.NewDatabaseContext(ctx, tc.acmeDB)
|
||||
par := NewPolicyAdminResponder()
|
||||
|
||||
req := httptest.NewRequest("GET", "/foo", nil)
|
||||
req := httptest.NewRequest("GET", "/foo", http.NoBody)
|
||||
req = req.WithContext(ctx)
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
@@ -1986,7 +1986,7 @@ func TestPolicyAdminResponder_GetACMEAccountPolicy(t *testing.T) {
|
||||
ctx = acme.NewDatabaseContext(ctx, tc.acmeDB)
|
||||
par := NewPolicyAdminResponder()
|
||||
|
||||
req := httptest.NewRequest("GET", "/foo", nil)
|
||||
req := httptest.NewRequest("GET", "/foo", http.NoBody)
|
||||
req = req.WithContext(ctx)
|
||||
w := httptest.NewRecorder()
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ func TestHandler_GetProvisioner(t *testing.T) {
|
||||
}
|
||||
var tests = map[string]func(t *testing.T) test{
|
||||
"fail/auth.LoadProvisionerByID": func(t *testing.T) test {
|
||||
req := httptest.NewRequest("GET", "/foo?id=provID", nil)
|
||||
req := httptest.NewRequest("GET", "/foo?id=provID", http.NoBody)
|
||||
chiCtx := chi.NewRouteContext()
|
||||
ctx := context.WithValue(context.Background(), chi.RouteCtxKey, chiCtx)
|
||||
auth := &mockAdminAuthority{
|
||||
@@ -61,7 +61,7 @@ func TestHandler_GetProvisioner(t *testing.T) {
|
||||
}
|
||||
},
|
||||
"fail/auth.LoadProvisionerByName": func(t *testing.T) test {
|
||||
req := httptest.NewRequest("GET", "/foo", nil)
|
||||
req := httptest.NewRequest("GET", "/foo", http.NoBody)
|
||||
chiCtx := chi.NewRouteContext()
|
||||
chiCtx.URLParams.Add("name", "provName")
|
||||
ctx := context.WithValue(context.Background(), chi.RouteCtxKey, chiCtx)
|
||||
@@ -86,7 +86,7 @@ func TestHandler_GetProvisioner(t *testing.T) {
|
||||
}
|
||||
},
|
||||
"fail/db.GetProvisioner": func(t *testing.T) test {
|
||||
req := httptest.NewRequest("GET", "/foo", nil)
|
||||
req := httptest.NewRequest("GET", "/foo", http.NoBody)
|
||||
chiCtx := chi.NewRouteContext()
|
||||
chiCtx.URLParams.Add("name", "provName")
|
||||
ctx := context.WithValue(context.Background(), chi.RouteCtxKey, chiCtx)
|
||||
@@ -120,7 +120,7 @@ func TestHandler_GetProvisioner(t *testing.T) {
|
||||
}
|
||||
},
|
||||
"ok": func(t *testing.T) test {
|
||||
req := httptest.NewRequest("GET", "/foo", nil)
|
||||
req := httptest.NewRequest("GET", "/foo", http.NoBody)
|
||||
chiCtx := chi.NewRouteContext()
|
||||
chiCtx.URLParams.Add("name", "provName")
|
||||
ctx := context.WithValue(context.Background(), chi.RouteCtxKey, chiCtx)
|
||||
@@ -208,7 +208,7 @@ func TestHandler_GetProvisioners(t *testing.T) {
|
||||
}
|
||||
var tests = map[string]func(t *testing.T) test{
|
||||
"fail/parse-cursor": func(t *testing.T) test {
|
||||
req := httptest.NewRequest("GET", "/foo?limit=X", nil)
|
||||
req := httptest.NewRequest("GET", "/foo?limit=X", http.NoBody)
|
||||
return test{
|
||||
ctx: context.Background(),
|
||||
statusCode: 400,
|
||||
@@ -222,7 +222,7 @@ func TestHandler_GetProvisioners(t *testing.T) {
|
||||
}
|
||||
},
|
||||
"fail/auth.GetProvisioners": func(t *testing.T) test {
|
||||
req := httptest.NewRequest("GET", "/foo", nil)
|
||||
req := httptest.NewRequest("GET", "/foo", http.NoBody)
|
||||
auth := &mockAdminAuthority{
|
||||
MockGetProvisioners: func(cursor string, limit int) (provisioner.List, string, error) {
|
||||
assert.Equals(t, "", cursor)
|
||||
@@ -244,7 +244,7 @@ func TestHandler_GetProvisioners(t *testing.T) {
|
||||
}
|
||||
},
|
||||
"ok": func(t *testing.T) test {
|
||||
req := httptest.NewRequest("GET", "/foo", nil)
|
||||
req := httptest.NewRequest("GET", "/foo", http.NoBody)
|
||||
provisioners := provisioner.List{
|
||||
&provisioner.OIDC{
|
||||
Type: "OIDC",
|
||||
@@ -481,7 +481,7 @@ func TestHandler_DeleteProvisioner(t *testing.T) {
|
||||
}
|
||||
var tests = map[string]func(t *testing.T) test{
|
||||
"fail/auth.LoadProvisionerByID": func(t *testing.T) test {
|
||||
req := httptest.NewRequest("DELETE", "/foo?id=provID", nil)
|
||||
req := httptest.NewRequest("DELETE", "/foo?id=provID", http.NoBody)
|
||||
chiCtx := chi.NewRouteContext()
|
||||
ctx := context.WithValue(context.Background(), chi.RouteCtxKey, chiCtx)
|
||||
auth := &mockAdminAuthority{
|
||||
@@ -504,7 +504,7 @@ func TestHandler_DeleteProvisioner(t *testing.T) {
|
||||
}
|
||||
},
|
||||
"fail/auth.LoadProvisionerByName": func(t *testing.T) test {
|
||||
req := httptest.NewRequest("DELETE", "/foo", nil)
|
||||
req := httptest.NewRequest("DELETE", "/foo", http.NoBody)
|
||||
chiCtx := chi.NewRouteContext()
|
||||
chiCtx.URLParams.Add("name", "provName")
|
||||
ctx := context.WithValue(context.Background(), chi.RouteCtxKey, chiCtx)
|
||||
@@ -528,7 +528,7 @@ func TestHandler_DeleteProvisioner(t *testing.T) {
|
||||
}
|
||||
},
|
||||
"fail/auth.RemoveProvisioner": func(t *testing.T) test {
|
||||
req := httptest.NewRequest("DELETE", "/foo", nil)
|
||||
req := httptest.NewRequest("DELETE", "/foo", http.NoBody)
|
||||
chiCtx := chi.NewRouteContext()
|
||||
chiCtx.URLParams.Add("name", "provName")
|
||||
ctx := context.WithValue(context.Background(), chi.RouteCtxKey, chiCtx)
|
||||
@@ -560,7 +560,7 @@ func TestHandler_DeleteProvisioner(t *testing.T) {
|
||||
}
|
||||
},
|
||||
"ok": func(t *testing.T) test {
|
||||
req := httptest.NewRequest("DELETE", "/foo", nil)
|
||||
req := httptest.NewRequest("DELETE", "/foo", http.NoBody)
|
||||
chiCtx := chi.NewRouteContext()
|
||||
chiCtx.URLParams.Add("name", "provName")
|
||||
ctx := context.WithValue(context.Background(), chi.RouteCtxKey, chiCtx)
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -375,7 +376,7 @@ func TestWebhookAdminResponder_DeleteProvisionerWebhook(t *testing.T) {
|
||||
}
|
||||
ctx = linkedca.NewContextWithProvisioner(ctx, prov)
|
||||
ctx = admin.NewContext(ctx, &admin.MockDB{})
|
||||
req := httptest.NewRequest("DELETE", "/foo", nil).WithContext(ctx)
|
||||
req := httptest.NewRequest("DELETE", "/foo", http.NoBody).WithContext(ctx)
|
||||
|
||||
war := NewWebhookAdminResponder()
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
"html"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"os"
|
||||
"reflect"
|
||||
@@ -52,7 +51,6 @@ var (
|
||||
func init() {
|
||||
step.Set("Smallstep CA", Version, BuildTime)
|
||||
authority.GlobalVersion.Version = Version
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
// Add support for asking passwords
|
||||
pemutil.PromptPassword = func(msg string) ([]byte, error) {
|
||||
return ui.PromptPassword(msg)
|
||||
|
||||
2
go.mod
2
go.mod
@@ -1,6 +1,6 @@
|
||||
module github.com/smallstep/certificates
|
||||
|
||||
go 1.19
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
cloud.google.com/go/longrunning v0.5.1
|
||||
|
||||
@@ -58,7 +58,7 @@ func TestHealthOKHandling(t *testing.T) {
|
||||
next: tt.handler,
|
||||
}
|
||||
|
||||
r := httptest.NewRequest("GET", tt.path, nil)
|
||||
r := httptest.NewRequest("GET", tt.path, http.NoBody)
|
||||
w := httptest.NewRecorder()
|
||||
l.ServeHTTP(w, r)
|
||||
|
||||
@@ -132,7 +132,7 @@ func TestHandlingRegardlessOfOptions(t *testing.T) {
|
||||
next: tt.handler,
|
||||
}
|
||||
|
||||
r := httptest.NewRequest("GET", tt.path, nil)
|
||||
r := httptest.NewRequest("GET", tt.path, http.NoBody)
|
||||
w := httptest.NewRecorder()
|
||||
l.ServeHTTP(w, r)
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ func Test_decodeRequest(t *testing.T) {
|
||||
{
|
||||
name: "fail/unsupported-method",
|
||||
args: args{
|
||||
r: httptest.NewRequest(http.MethodPatch, "http://scep:8080/?operation=AnUnsupportOperation", nil),
|
||||
r: httptest.NewRequest(http.MethodPatch, "http://scep:8080/?operation=AnUnsupportOperation", http.NoBody),
|
||||
},
|
||||
want: request{},
|
||||
wantErr: true,
|
||||
@@ -32,7 +32,7 @@ func Test_decodeRequest(t *testing.T) {
|
||||
{
|
||||
name: "fail/get-unsupported-operation",
|
||||
args: args{
|
||||
r: httptest.NewRequest(http.MethodGet, "http://scep:8080/?operation=AnUnsupportOperation", nil),
|
||||
r: httptest.NewRequest(http.MethodGet, "http://scep:8080/?operation=AnUnsupportOperation", http.NoBody),
|
||||
},
|
||||
want: request{},
|
||||
wantErr: true,
|
||||
@@ -40,7 +40,7 @@ func Test_decodeRequest(t *testing.T) {
|
||||
{
|
||||
name: "fail/get-PKIOperation",
|
||||
args: args{
|
||||
r: httptest.NewRequest(http.MethodGet, "http://scep:8080/?operation=PKIOperation&message='somewronginput'", nil),
|
||||
r: httptest.NewRequest(http.MethodGet, "http://scep:8080/?operation=PKIOperation&message='somewronginput'", http.NoBody),
|
||||
},
|
||||
want: request{},
|
||||
wantErr: true,
|
||||
@@ -56,7 +56,7 @@ func Test_decodeRequest(t *testing.T) {
|
||||
{
|
||||
name: "ok/get-GetCACert",
|
||||
args: args{
|
||||
r: httptest.NewRequest(http.MethodGet, "http://scep:8080/?operation=GetCACert", nil),
|
||||
r: httptest.NewRequest(http.MethodGet, "http://scep:8080/?operation=GetCACert", http.NoBody),
|
||||
},
|
||||
want: request{
|
||||
Operation: "GetCACert",
|
||||
@@ -67,7 +67,7 @@ func Test_decodeRequest(t *testing.T) {
|
||||
{
|
||||
name: "ok/get-GetCACaps",
|
||||
args: args{
|
||||
r: httptest.NewRequest(http.MethodGet, "http://scep:8080/?operation=GetCACaps", nil),
|
||||
r: httptest.NewRequest(http.MethodGet, "http://scep:8080/?operation=GetCACaps", http.NoBody),
|
||||
},
|
||||
want: request{
|
||||
Operation: "GetCACaps",
|
||||
@@ -78,7 +78,7 @@ func Test_decodeRequest(t *testing.T) {
|
||||
{
|
||||
name: "ok/get-PKIOperation",
|
||||
args: args{
|
||||
r: httptest.NewRequest(http.MethodGet, "http://scep:8080/?operation=PKIOperation&message=MTIzNA==", nil),
|
||||
r: httptest.NewRequest(http.MethodGet, "http://scep:8080/?operation=PKIOperation&message=MTIzNA==", http.NoBody),
|
||||
},
|
||||
want: request{
|
||||
Operation: "PKIOperation",
|
||||
|
||||
@@ -57,7 +57,9 @@ type DB interface {
|
||||
|
||||
type dryRunDB struct{}
|
||||
|
||||
func (*dryRunDB) CreateTable([]byte) error { return nil }
|
||||
func (*dryRunDB) CreateTable([]byte) error { return nil }
|
||||
|
||||
//nolint:revive // allow unused parameters to show function signature
|
||||
func (*dryRunDB) Set(bucket, key, value []byte) error { return nil }
|
||||
|
||||
func usage(fs *flag.FlagSet) {
|
||||
|
||||
Reference in New Issue
Block a user