浏览代码

Show clean URL on HTTP-01 errors

Mariano Cano 2 年之前
父节点
当前提交
2b30ae5087
共有 2 个文件被更改,包括 11 次插入 和 10 次删除
  1. 3 2
      acme/challenge.go
  2. 8 8
      acme/challenge_test.go

+ 3 - 2
acme/challenge.go

@@ -110,7 +110,8 @@ func (ch *Challenge) Validate(ctx context.Context, db DB, jwk *jose.JSONWebKey,
 }
 }
 
 
 func http01Validate(ctx context.Context, ch *Challenge, db DB, jwk *jose.JSONWebKey) error {
 func http01Validate(ctx context.Context, ch *Challenge, db DB, jwk *jose.JSONWebKey) error {
-	u := &url.URL{Scheme: "http", Host: http01ChallengeHost(ch.Value), Path: fmt.Sprintf("/.well-known/acme-challenge/%s", ch.Token)}
+	u := &url.URL{Scheme: "http", Host: ch.Value, Path: fmt.Sprintf("/.well-known/acme-challenge/%s", ch.Token)}
+	challengeURL := &url.URL{Scheme: "http", Host: http01ChallengeHost(ch.Value), Path: fmt.Sprintf("/.well-known/acme-challenge/%s", ch.Token)}
 
 
 	// Append insecure port if set.
 	// Append insecure port if set.
 	// Only used for testing purposes.
 	// Only used for testing purposes.
@@ -119,7 +120,7 @@ func http01Validate(ctx context.Context, ch *Challenge, db DB, jwk *jose.JSONWeb
 	}
 	}
 
 
 	vc := MustClientFromContext(ctx)
 	vc := MustClientFromContext(ctx)
-	resp, err := vc.Get(u.String())
+	resp, err := vc.Get(challengeURL.String())
 	if err != nil {
 	if err != nil {
 		return storeError(ctx, db, ch, false, WrapError(ErrorConnectionType, err,
 		return storeError(ctx, db, ch, false, WrapError(ErrorConnectionType, err,
 			"error doing http GET for url %s", u))
 			"error doing http GET for url %s", u))

+ 8 - 8
acme/challenge_test.go

@@ -457,7 +457,7 @@ func TestChallenge_Validate(t *testing.T) {
 						assert.Equal(t, "zap.internal", updch.Value)
 						assert.Equal(t, "zap.internal", updch.Value)
 						assert.Equal(t, StatusPending, updch.Status)
 						assert.Equal(t, StatusPending, updch.Status)
 
 
-						err := NewError(ErrorConnectionType, "error doing http GET for url http://zap.internal./.well-known/acme-challenge/%s: force", ch.Token)
+						err := NewError(ErrorConnectionType, "error doing http GET for url http://zap.internal/.well-known/acme-challenge/%s: force", ch.Token)
 						assert.EqualError(t, updch.Error.Err, err.Err.Error())
 						assert.EqualError(t, updch.Error.Err, err.Err.Error())
 						assert.Equal(t, err.Type, updch.Error.Type)
 						assert.Equal(t, err.Type, updch.Error.Type)
 						assert.Equal(t, err.Detail, updch.Error.Detail)
 						assert.Equal(t, err.Detail, updch.Error.Detail)
@@ -494,7 +494,7 @@ func TestChallenge_Validate(t *testing.T) {
 						assert.Equal(t, "zap.internal", updch.Value)
 						assert.Equal(t, "zap.internal", updch.Value)
 						assert.Equal(t, StatusPending, updch.Status)
 						assert.Equal(t, StatusPending, updch.Status)
 
 
-						err := NewError(ErrorConnectionType, "error doing http GET for url http://zap.internal./.well-known/acme-challenge/%s: force", ch.Token)
+						err := NewError(ErrorConnectionType, "error doing http GET for url http://zap.internal/.well-known/acme-challenge/%s: force", ch.Token)
 						assert.EqualError(t, updch.Error.Err, err.Err.Error())
 						assert.EqualError(t, updch.Error.Err, err.Err.Error())
 						assert.Equal(t, err.Type, updch.Error.Type)
 						assert.Equal(t, err.Type, updch.Error.Type)
 						assert.Equal(t, err.Detail, updch.Error.Detail)
 						assert.Equal(t, err.Detail, updch.Error.Detail)
@@ -536,7 +536,7 @@ func TestChallenge_Validate(t *testing.T) {
 						assert.Equal(t, "zap.internal", updch.Value)
 						assert.Equal(t, "zap.internal", updch.Value)
 						assert.Equal(t, StatusPending, updch.Status)
 						assert.Equal(t, StatusPending, updch.Status)
 
 
-						err := NewError(ErrorConnectionType, "error doing http GET for url http://zap.internal.:8080/.well-known/acme-challenge/%s: force", ch.Token)
+						err := NewError(ErrorConnectionType, "error doing http GET for url http://zap.internal:8080/.well-known/acme-challenge/%s: force", ch.Token)
 						assert.EqualError(t, updch.Error.Err, err.Err.Error())
 						assert.EqualError(t, updch.Error.Err, err.Err.Error())
 						assert.Equal(t, err.Type, updch.Error.Type)
 						assert.Equal(t, err.Type, updch.Error.Type)
 						assert.Equal(t, err.Detail, updch.Error.Detail)
 						assert.Equal(t, err.Detail, updch.Error.Detail)
@@ -926,7 +926,7 @@ func TestHTTP01Validate(t *testing.T) {
 						assert.Equal(t, "zap.internal", updch.Value)
 						assert.Equal(t, "zap.internal", updch.Value)
 						assert.Equal(t, StatusPending, updch.Status)
 						assert.Equal(t, StatusPending, updch.Status)
 
 
-						err := NewError(ErrorConnectionType, "error doing http GET for url http://zap.internal./.well-known/acme-challenge/%s: force", ch.Token)
+						err := NewError(ErrorConnectionType, "error doing http GET for url http://zap.internal/.well-known/acme-challenge/%s: force", ch.Token)
 						assert.EqualError(t, updch.Error.Err, err.Err.Error())
 						assert.EqualError(t, updch.Error.Err, err.Err.Error())
 						assert.Equal(t, err.Type, updch.Error.Type)
 						assert.Equal(t, err.Type, updch.Error.Type)
 						assert.Equal(t, err.Detail, updch.Error.Detail)
 						assert.Equal(t, err.Detail, updch.Error.Detail)
@@ -961,7 +961,7 @@ func TestHTTP01Validate(t *testing.T) {
 						assert.Equal(t, "zap.internal", updch.Value)
 						assert.Equal(t, "zap.internal", updch.Value)
 						assert.Equal(t, StatusPending, updch.Status)
 						assert.Equal(t, StatusPending, updch.Status)
 
 
-						err := NewError(ErrorConnectionType, "error doing http GET for url http://zap.internal./.well-known/acme-challenge/%s: force", ch.Token)
+						err := NewError(ErrorConnectionType, "error doing http GET for url http://zap.internal/.well-known/acme-challenge/%s: force", ch.Token)
 						assert.EqualError(t, updch.Error.Err, err.Err.Error())
 						assert.EqualError(t, updch.Error.Err, err.Err.Error())
 						assert.Equal(t, err.Type, updch.Error.Type)
 						assert.Equal(t, err.Type, updch.Error.Type)
 						assert.Equal(t, err.Detail, updch.Error.Detail)
 						assert.Equal(t, err.Detail, updch.Error.Detail)
@@ -998,7 +998,7 @@ func TestHTTP01Validate(t *testing.T) {
 						assert.Equal(t, "zap.internal", updch.Value)
 						assert.Equal(t, "zap.internal", updch.Value)
 						assert.Equal(t, StatusPending, updch.Status)
 						assert.Equal(t, StatusPending, updch.Status)
 
 
-						err := NewError(ErrorConnectionType, "error doing http GET for url http://zap.internal./.well-known/acme-challenge/%s with status code 400", ch.Token)
+						err := NewError(ErrorConnectionType, "error doing http GET for url http://zap.internal/.well-known/acme-challenge/%s with status code 400", ch.Token)
 						assert.EqualError(t, updch.Error.Err, err.Err.Error())
 						assert.EqualError(t, updch.Error.Err, err.Err.Error())
 						assert.Equal(t, err.Type, updch.Error.Type)
 						assert.Equal(t, err.Type, updch.Error.Type)
 						assert.Equal(t, err.Detail, updch.Error.Detail)
 						assert.Equal(t, err.Detail, updch.Error.Detail)
@@ -1036,7 +1036,7 @@ func TestHTTP01Validate(t *testing.T) {
 						assert.Equal(t, "zap.internal", updch.Value)
 						assert.Equal(t, "zap.internal", updch.Value)
 						assert.Equal(t, StatusPending, updch.Status)
 						assert.Equal(t, StatusPending, updch.Status)
 
 
-						err := NewError(ErrorConnectionType, "error doing http GET for url http://zap.internal./.well-known/acme-challenge/%s with status code 400", ch.Token)
+						err := NewError(ErrorConnectionType, "error doing http GET for url http://zap.internal/.well-known/acme-challenge/%s with status code 400", ch.Token)
 						assert.EqualError(t, updch.Error.Err, err.Err.Error())
 						assert.EqualError(t, updch.Error.Err, err.Err.Error())
 						assert.Equal(t, err.Type, updch.Error.Type)
 						assert.Equal(t, err.Type, updch.Error.Type)
 						assert.Equal(t, err.Detail, updch.Error.Detail)
 						assert.Equal(t, err.Detail, updch.Error.Detail)
@@ -1065,7 +1065,7 @@ func TestHTTP01Validate(t *testing.T) {
 						}, nil
 						}, nil
 					},
 					},
 				},
 				},
-				err: NewErrorISE("error reading response body for url http://zap.internal./.well-known/acme-challenge/%s: force", ch.Token),
+				err: NewErrorISE("error reading response body for url http://zap.internal/.well-known/acme-challenge/%s: force", ch.Token),
 			}
 			}
 		},
 		},
 		"fail/key-auth-gen-error": func(t *testing.T) test {
 		"fail/key-auth-gen-error": func(t *testing.T) test {