-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…-upstream-release-0.2 Automatic merge from submit-queue. Automated cherry pick of #214 #215 Cherry pick of #214 #215 on release-0.2. #214: Update for v0.2.2 #215: Fix checking for expired ACME authorizations
- Loading branch information
Showing
17 changed files
with
1,415 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -1 +1,100 @@ | ||
package acme | ||
|
||
import ( | ||
"context" | ||
"io/ioutil" | ||
"net/http" | ||
"strings" | ||
"testing" | ||
|
||
"golang.org/x/crypto/acme" | ||
"gopkg.in/jarcoal/httpmock.v1" | ||
) | ||
|
||
func TestCheckAuthorization(t *testing.T) { | ||
type testT struct { | ||
name string | ||
mockStatusCode int | ||
mockResponse string | ||
ctx context.Context | ||
uri string | ||
expected bool | ||
err bool | ||
} | ||
tests := []testT{ | ||
{ | ||
name: "should return no error for 404 return code", | ||
mockStatusCode: 404, | ||
mockResponse: `{ | ||
"type": "urn:acme:error:malformed", | ||
"detail": "Expired authorization", | ||
"status": 404 | ||
}`, | ||
uri: "http://testuri", | ||
expected: false, | ||
err: false, | ||
}, | ||
{ | ||
name: "should return valid for a 200 return code", | ||
mockStatusCode: 200, | ||
mockResponse: `{ | ||
"status": "valid" | ||
}`, | ||
uri: "http://testuri", | ||
expected: true, | ||
err: false, | ||
}, | ||
{ | ||
name: "should return invalid but no error for any status that isn't 'valid'", | ||
mockStatusCode: 200, | ||
mockResponse: `{ | ||
"status": "invalid" | ||
}`, | ||
uri: "http://testuri", | ||
expected: false, | ||
err: false, | ||
}, | ||
{ | ||
name: "should return an error for an invalid response", | ||
mockStatusCode: 500, | ||
// invalid response body | ||
mockResponse: `{ | ||
"type": "urn:acme:error:malformed", | ||
"detail": "Fake error", | ||
"status": 500 | ||
}`, | ||
uri: "http://testuri", | ||
expected: false, | ||
err: true, | ||
}, | ||
} | ||
testFn := func(test testT) func(t *testing.T) { | ||
return func(t *testing.T) { | ||
mock := httpmock.NewMockTransport() | ||
mock.RegisterResponder("GET", test.uri, httpmock.ResponderFromResponse(&http.Response{ | ||
StatusCode: test.mockStatusCode, | ||
Body: ioutil.NopCloser(strings.NewReader(test.mockResponse)), | ||
})) | ||
ctx := test.ctx | ||
if ctx == nil { | ||
ctx = context.Background() | ||
} | ||
cl := &acme.Client{ | ||
HTTPClient: &http.Client{Transport: mock}, | ||
} | ||
valid, err := checkAuthorization(ctx, cl, test.uri) | ||
if err != nil && !test.err { | ||
t.Errorf("expected no error, but got: %s", err) | ||
} | ||
if err == nil && test.err { | ||
t.Errorf("expected error, but got no error") | ||
} | ||
if valid != test.expected { | ||
t.Errorf("expected checkAuthorization to return %v, but got %v", test.expected, valid) | ||
} | ||
} | ||
} | ||
for _, test := range tests { | ||
t.Run(test.name, testFn(test)) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.