Skip to content

Commit 99cab73

Browse files
committed
Remove unused import /provisioners/jwk-set-by-issuer
1 parent 0ccf775 commit 99cab73

File tree

3 files changed

+0
-169
lines changed

3 files changed

+0
-169
lines changed

api/api.go

-28
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"github.com/pkg/errors"
1515
"github.com/smallstep/ca-component/authority"
1616
"github.com/smallstep/cli/crypto/tlsutil"
17-
"github.com/smallstep/cli/jose"
1817
)
1918

2019
// Authority is the interface implemented by a CA authority.
@@ -157,12 +156,6 @@ type ProvisionersResponse struct {
157156
NextCursor string `json:"nextCursor"`
158157
}
159158

160-
// JWKSetByIssuerResponse is the response object that returns the map of
161-
// provisioners.
162-
type JWKSetByIssuerResponse struct {
163-
Map map[string]*jose.JSONWebKeySet `json:"map"`
164-
}
165-
166159
// ProvisionerKeyResponse is the response object that returns the encryptoed key
167160
// of a provisioner.
168161
type ProvisionerKeyResponse struct {
@@ -212,7 +205,6 @@ func (h *caHandler) Route(r Router) {
212205
r.MethodFunc("POST", "/renew", h.Renew)
213206
r.MethodFunc("GET", "/provisioners", h.Provisioners)
214207
r.MethodFunc("GET", "/provisioners/{kid}/encrypted-key", h.ProvisionerKey)
215-
r.MethodFunc("GET", "/provisioners/jwk-set-by-issuer", h.JWKSetByIssuer)
216208
// For compatibility with old code:
217209
r.MethodFunc("POST", "/re-sign", h.Renew)
218210
}
@@ -328,26 +320,6 @@ func (h *caHandler) ProvisionerKey(w http.ResponseWriter, r *http.Request) {
328320
JSON(w, &ProvisionerKeyResponse{key})
329321
}
330322

331-
func (h *caHandler) JWKSetByIssuer(w http.ResponseWriter, r *http.Request) {
332-
m := map[string]*jose.JSONWebKeySet{}
333-
ps, _, err := h.Authority.GetProvisioners("", 0)
334-
if err != nil {
335-
WriteError(w, InternalServerError(err))
336-
return
337-
}
338-
for _, p := range ps {
339-
ks, found := m[p.Issuer]
340-
if found {
341-
ks.Keys = append(ks.Keys, *p.Key)
342-
} else {
343-
ks = new(jose.JSONWebKeySet)
344-
ks.Keys = []jose.JSONWebKey{*p.Key}
345-
m[p.Issuer] = ks
346-
}
347-
}
348-
JSON(w, &JWKSetByIssuerResponse{m})
349-
}
350-
351323
func parseCursor(r *http.Request) (cursor string, limit int, err error) {
352324
q := r.URL.Query()
353325
cursor = q.Get("cursor")

api/api_test.go

-77
Original file line numberDiff line numberDiff line change
@@ -655,83 +655,6 @@ func Test_caHandler_Renew(t *testing.T) {
655655
}
656656
}
657657

658-
func Test_caHandler_JWKSetByIssuer(t *testing.T) {
659-
t.SkipNow()
660-
type fields struct {
661-
Authority Authority
662-
}
663-
type args struct {
664-
w http.ResponseWriter
665-
r *http.Request
666-
}
667-
668-
req, err := http.NewRequest("GET", "http://example.com/provisioners/jwk-set-by-issuer", nil)
669-
if err != nil {
670-
t.Fatal(err)
671-
}
672-
673-
var key jose.JSONWebKey
674-
if err := json.Unmarshal([]byte(pubKey), &key); err != nil {
675-
t.Fatal(err)
676-
}
677-
678-
p := []*authority.Provisioner{
679-
{
680-
Issuer: "p1",
681-
Key: &key,
682-
},
683-
{
684-
Issuer: "p2",
685-
Key: &key,
686-
},
687-
}
688-
689-
tests := []struct {
690-
name string
691-
fields fields
692-
args args
693-
statusCode int
694-
}{
695-
{"ok", fields{&mockAuthority{ret1: p}}, args{httptest.NewRecorder(), req}, 200},
696-
{"fail", fields{&mockAuthority{ret1: p, err: fmt.Errorf("the error")}}, args{httptest.NewRecorder(), req}, 500},
697-
}
698-
699-
expectedKey, err := json.Marshal(key)
700-
if err != nil {
701-
t.Fatal(err)
702-
}
703-
expected := []byte(`{"map":{"p1":{"keys":[` + string(expectedKey) + `]},"p2":{"keys":[` + string(expectedKey) + `]}}}`)
704-
expectedError := []byte(`{"status":500,"message":"Internal Server Error"}`)
705-
for _, tt := range tests {
706-
t.Run(tt.name, func(t *testing.T) {
707-
h := &caHandler{
708-
Authority: tt.fields.Authority,
709-
}
710-
h.JWKSetByIssuer(tt.args.w, tt.args.r)
711-
712-
rec := tt.args.w.(*httptest.ResponseRecorder)
713-
res := rec.Result()
714-
if res.StatusCode != tt.statusCode {
715-
t.Errorf("caHandler.JWKSetByIssuer StatusCode = %d, wants %d", res.StatusCode, tt.statusCode)
716-
}
717-
body, err := ioutil.ReadAll(res.Body)
718-
res.Body.Close()
719-
if err != nil {
720-
t.Errorf("caHandler.JWKSetByIssuer unexpected error = %v", err)
721-
}
722-
if tt.statusCode < http.StatusBadRequest {
723-
if !bytes.Equal(bytes.TrimSpace(body), expected) {
724-
t.Errorf("caHandler.JWKSetByIssuer Body = %s, wants %s", body, expected)
725-
}
726-
} else {
727-
if !bytes.Equal(bytes.TrimSpace(body), expectedError) {
728-
t.Errorf("caHandler.JWKSetByIssuer Body = %s, wants %s", body, expectedError)
729-
}
730-
}
731-
})
732-
}
733-
}
734-
735658
func Test_caHandler_Provisioners(t *testing.T) {
736659
type fields struct {
737660
Authority Authority

ca/ca_test.go

-64
Original file line numberDiff line numberDiff line change
@@ -321,70 +321,6 @@ func TestCAProvisioners(t *testing.T) {
321321
}
322322
}
323323

324-
func TestCAJWKSetByIssuer(t *testing.T) {
325-
config, err := authority.LoadConfiguration("testdata/ca.json")
326-
assert.FatalError(t, err)
327-
ca, err := New(config)
328-
assert.FatalError(t, err)
329-
330-
type ekt struct {
331-
ca *CA
332-
status int
333-
errMsg string
334-
}
335-
tests := map[string]func(t *testing.T) *ekt{
336-
"ok": func(t *testing.T) *ekt {
337-
return &ekt{
338-
ca: ca,
339-
status: http.StatusOK,
340-
}
341-
},
342-
}
343-
344-
for name, genTestCase := range tests {
345-
t.Run(name, func(t *testing.T) {
346-
tc := genTestCase(t)
347-
348-
rq, err := http.NewRequest("GET", fmt.Sprintf("/provisioners/jwk-set-by-issuer"), strings.NewReader(""))
349-
assert.FatalError(t, err)
350-
rr := httptest.NewRecorder()
351-
352-
tc.ca.srv.Handler.ServeHTTP(rr, rq)
353-
354-
if assert.Equals(t, rr.Code, tc.status) {
355-
body := &ClosingBuffer{rr.Body}
356-
if rr.Code < http.StatusBadRequest {
357-
var (
358-
resp api.JWKSetByIssuerResponse
359-
psList = config.AuthorityConfig.Provisioners
360-
)
361-
362-
assert.FatalError(t, readJSON(body, &resp))
363-
psMap := resp.Map
364-
365-
maxks, found := psMap["max"]
366-
assert.Fatal(t, found)
367-
assert.Equals(t, maxks.Keys, []jose.JSONWebKey{*psList[0].Key, *psList[1].Key})
368-
369-
marianoks, found := psMap["mariano"]
370-
assert.Fatal(t, found)
371-
assert.Equals(t, marianoks.Keys, []jose.JSONWebKey{*psList[3].Key, *psList[4].Key})
372-
373-
stepcliks, found := psMap["step-cli"]
374-
assert.Fatal(t, found)
375-
assert.Equals(t, stepcliks.Keys, []jose.JSONWebKey{*psList[2].Key})
376-
} else {
377-
err := readError(body)
378-
if len(tc.errMsg) == 0 {
379-
assert.FatalError(t, errors.New("must validate response error"))
380-
}
381-
assert.HasPrefix(t, err.Error(), tc.errMsg)
382-
}
383-
}
384-
})
385-
}
386-
}
387-
388324
func TestCAProvisionerEncryptedKey(t *testing.T) {
389325
config, err := authority.LoadConfiguration("testdata/ca.json")
390326
assert.FatalError(t, err)

0 commit comments

Comments
 (0)