Add tests for wfe.Challenge

This commit is contained in:
Jakub Warmuz 2015-04-30 20:48:02 +00:00
parent 738e442f63
commit 4311f02a90
No known key found for this signature in database
GPG Key ID: 2A7BAD3A489B52EA
2 changed files with 36 additions and 4 deletions

View File

@ -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)

View File

@ -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\"}")
}