Encode challenge errors and validation records when handling protobufs (#2520)

Previously we had `Error` and `ValidationRecords` fields in the `Challenge` protobuf but they were never populated which mean't that when using gRPC these fields wouldn't be sent to the SA from the RA on a `FinalizeAuthorization` call. This change populates those fields and updates the PB marshaling tests to verify the correct behavior.

Fixes #2514.
This commit is contained in:
Roland Bracewell Shoemaker 2017-01-25 06:39:35 -08:00 committed by Daniel McCarney
parent 6c93b41f20
commit 7853532972
2 changed files with 54 additions and 5 deletions

View File

@ -90,12 +90,25 @@ func pbToProblemDetails(in *corepb.ProblemDetails) (*probs.ProblemDetails, error
func challengeToPB(challenge core.Challenge) (*corepb.Challenge, error) {
st := string(challenge.Status)
prob, err := problemDetailsToPB(challenge.Error)
if err != nil {
return nil, err
}
recordAry := make([]*corepb.ValidationRecord, len(challenge.ValidationRecord))
for i, v := range challenge.ValidationRecord {
recordAry[i], err = validationRecordToPB(v)
if err != nil {
return nil, err
}
}
return &corepb.Challenge{
Id: &challenge.ID,
Type: &challenge.Type,
Status: &st,
Token: &challenge.Token,
KeyAuthorization: &challenge.ProvidedKeyAuthorization,
Id: &challenge.ID,
Type: &challenge.Type,
Status: &st,
Token: &challenge.Token,
KeyAuthorization: &challenge.ProvidedKeyAuthorization,
Error: prob,
Validationrecords: recordAry,
}, nil
}
@ -106,12 +119,28 @@ func pbToChallenge(in *corepb.Challenge) (challenge core.Challenge, err error) {
if in.Id == nil || in.Type == nil || in.Status == nil || in.Token == nil || in.KeyAuthorization == nil {
return core.Challenge{}, ErrMissingParameters
}
var recordAry []core.ValidationRecord
if len(in.Validationrecords) > 0 {
recordAry = make([]core.ValidationRecord, len(in.Validationrecords))
for i, v := range in.Validationrecords {
recordAry[i], err = pbToValidationRecord(v)
if err != nil {
return core.Challenge{}, err
}
}
}
prob, err := pbToProblemDetails(in.Error)
if err != nil {
return core.Challenge{}, err
}
return core.Challenge{
ID: *in.Id,
Type: *in.Type,
Status: core.AcmeStatus(*in.Status),
Token: *in.Token,
ProvidedKeyAuthorization: *in.KeyAuthorization,
Error: prob,
ValidationRecord: recordAry,
}, nil
}

View File

@ -114,6 +114,26 @@ func TestChallenge(t *testing.T) {
test.AssertNotError(t, err, "pbToChallenge failed")
test.AssertDeepEquals(t, recon, chall)
ip := net.ParseIP("1.1.1.1")
chall.ValidationRecord = []core.ValidationRecord{
core.ValidationRecord{
Hostname: "host",
Port: "2020",
AddressesResolved: []net.IP{ip},
AddressUsed: ip,
URL: "url",
Authorities: []string{"auth"},
},
}
chall.Error = &probs.ProblemDetails{Type: probs.TLSProblem, Detail: "asd", HTTPStatus: 200}
pb, err = challengeToPB(chall)
test.AssertNotError(t, err, "challengeToPB failed")
test.Assert(t, pb != nil, "Returned corepb.Challenge is nil")
recon, err = pbToChallenge(pb)
test.AssertNotError(t, err, "pbToChallenge failed")
test.AssertDeepEquals(t, recon, chall)
_, err = pbToChallenge(nil)
test.AssertError(t, err, "pbToChallenge did not fail")
test.AssertEquals(t, err, ErrMissingParameters)