Add tests for wfe.Challenge
This commit is contained in:
parent
738e442f63
commit
4311f02a90
|
@ -346,17 +346,16 @@ func (wfe *WebFrontEndImpl) Challenge(authz core.Authorization, response http.Re
|
|||
return
|
||||
}
|
||||
|
||||
challenge := updatedAuthz.Challenges[challengeIndex]
|
||||
// assumption: UpdateAuthorization does not modify order of challenges
|
||||
jsonReply, err := json.Marshal(updatedAuthz.Challenges[challengeIndex])
|
||||
jsonReply, err := json.Marshal(challenge)
|
||||
if err != nil {
|
||||
wfe.sendError(response, "Failed to marshal challenge", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
authzURL := wfe.AuthzBase + string(authz.ID)
|
||||
challengeURL := authzURL + "?challenge=" + strconv.Itoa(challengeIndex)
|
||||
|
||||
response.Header().Add("Location", challengeURL)
|
||||
response.Header().Add("Location", string(challenge.URI))
|
||||
response.Header().Set("Content-Type", "application/json")
|
||||
response.Header().Add("Link", link(authzURL, "up"))
|
||||
response.WriteHeader(http.StatusAccepted)
|
||||
|
|
|
@ -162,3 +162,36 @@ func TestIssueCertificate(t *testing.T) {
|
|||
// TODO: I think this is wrong. The CSR in the payload above was created by openssl and should be valid.
|
||||
"{\"detail\":\"Error creating new cert: Invalid signature on CSR\"}")
|
||||
}
|
||||
|
||||
func TestChallenge(t *testing.T) {
|
||||
stats, _ := statsd.NewNoopClient(nil)
|
||||
log, err := blog.Dial("", "", "tag", stats)
|
||||
test.AssertNotError(t, err, "Could not construct audit logger")
|
||||
// TODO: Use a mock RA so we can test various conditions of authorized, not authorized, etc.
|
||||
ra := ra.NewRegistrationAuthorityImpl(log)
|
||||
wfe := NewWebFrontEndImpl(log)
|
||||
wfe.RA = &ra
|
||||
responseWriter := httptest.NewRecorder()
|
||||
|
||||
challengeURI, _ := url.Parse("/acme/authz/asdf?challenge=foo")
|
||||
authz := Authorization{
|
||||
ID: "asdf",
|
||||
challenges: [...]Challenge{
|
||||
Challenge{
|
||||
Type: "bar",
|
||||
URI: AcmeURL(challengeURI),
|
||||
},
|
||||
},
|
||||
}
|
||||
wfe.Challenge(authz, responseWriter, &http.Request{
|
||||
Method: "POST",
|
||||
URL: challengeURI,
|
||||
})
|
||||
test.AssertEquals(
|
||||
t, responseWriter.Header().Get("Location"),
|
||||
"/acme/authz/asdf?challenge=foo")
|
||||
test.AssertEquals(
|
||||
t, responseWriter.Header().Get("Link"),
|
||||
"/acme/authz/asdf;rel=\"up\"")
|
||||
test.AssertEquals(t, responseWriter.Body.String(), "{type:\"bar\"}")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue