فهرست منبع

Apply suggestions from code review

Co-authored-by: Herman Slatman <hslatman@users.noreply.github.com>
Marten Seemann 2 سال پیش
والد
کامیت
72285d82bc
3فایلهای تغییر یافته به همراه4 افزوده شده و 7 حذف شده
  1. 1 1
      api/api.go
  2. 1 2
      api/api_test.go
  3. 2 4
      test/integration/requestid_test.go

+ 1 - 1
api/api.go

@@ -372,7 +372,7 @@ func Root(w http.ResponseWriter, r *http.Request) {
 	// Load root certificate with the
 	// Load root certificate with the
 	cert, err := mustAuthority(r.Context()).Root(sum)
 	cert, err := mustAuthority(r.Context()).Root(sum)
 	if err != nil {
 	if err != nil {
-		render.Error(w, r, errs.NotFoundErr(err, errs.WithMessage("root with fingerprint %s was not found", sum)))
+		render.Error(w, r, errs.NotFoundErr(err, errs.WithMessage("root certificate with fingerprint %q was not found", sum)))
 		return
 		return
 	}
 	}
 
 

+ 1 - 2
api/api_test.go

@@ -844,7 +844,7 @@ func Test_Root(t *testing.T) {
 		statusCode  int
 		statusCode  int
 	}{
 	}{
 		{"ok", parseCertificate(rootPEM), nil, "", 200},
 		{"ok", parseCertificate(rootPEM), nil, "", 200},
-		{"fail", nil, fmt.Errorf("not found"), fmt.Sprintf("root with fingerprint %s was not found", sha), 404},
+		{"fail", nil, fmt.Errorf("not found"), fmt.Sprintf("root certificate with fingerprint %q was not found", sha), 404},
 	}
 	}
 
 
 	// Request with chi context
 	// Request with chi context
@@ -868,7 +868,6 @@ func Test_Root(t *testing.T) {
 
 
 			body, err := io.ReadAll(res.Body)
 			body, err := io.ReadAll(res.Body)
 			res.Body.Close()
 			res.Body.Close()
-			fmt.Println("body:", string(body))
 			if err != nil {
 			if err != nil {
 				t.Errorf("caHandler.Root unexpected error = %v", err)
 				t.Errorf("caHandler.Root unexpected error = %v", err)
 			}
 			}

+ 2 - 4
test/integration/requestid_test.go

@@ -146,11 +146,9 @@ func Test_reflectRequestID(t *testing.T) {
 	var firstErr *errs.Error
 	var firstErr *errs.Error
 	if assert.ErrorAs(t, err, &firstErr) {
 	if assert.ErrorAs(t, err, &firstErr) {
 		assert.Equal(t, 404, firstErr.StatusCode())
 		assert.Equal(t, 404, firstErr.StatusCode())
-		assert.Equal(t, "root with fingerprint invalid was not found", firstErr.Err.Error())
+		assert.Equal(t, `root certificate with fingerprint "invalid" was not found`, firstErr.Err.Error())
 		assert.NotEmpty(t, firstErr.RequestID)
 		assert.NotEmpty(t, firstErr.RequestID)
 
 
-		// TODO: include the below error in the JSON? It's currently only output to the CA logs. Also see https://github.com/smallstep/certificates/pull/759
-		// assert.Equal(t, "/root/invalid was not found: certificate with fingerprint invalid was not found", apiErr.Msg)
 	}
 	}
 	assert.Nil(t, rootResponse)
 	assert.Nil(t, rootResponse)
 
 
@@ -159,7 +157,7 @@ func Test_reflectRequestID(t *testing.T) {
 	var secondErr *errs.Error
 	var secondErr *errs.Error
 	if assert.ErrorAs(t, err, &secondErr) {
 	if assert.ErrorAs(t, err, &secondErr) {
 		assert.Equal(t, 404, secondErr.StatusCode())
 		assert.Equal(t, 404, secondErr.StatusCode())
-		assert.Equal(t, "root with fingerprint invalid was not found", secondErr.Err.Error())
+		assert.Equal(t, `root certificate with fingerprint "invalid" was not found`, secondErr.Err.Error())
 		assert.Equal(t, "reqID", secondErr.RequestID)
 		assert.Equal(t, "reqID", secondErr.RequestID)
 	}
 	}
 	assert.Nil(t, rootResponse)
 	assert.Nil(t, rootResponse)