RA: fix error returned through WFE2 for too big NewOrders. (#4572)

We need the RA's `NewOrder` RPC to return a `berrors.Malformed` instance
when there are too many identifiers. A bare error will be turned into
a server internal problem by the WFE2's `web.ProblemDetailsForError`
call while a `berrors.Malformed` will produce the expected malformed
problem.

This commit fixes the err, updates the unit test, and adds an end-to-end
integration test so we don't mess this up again.
This commit is contained in:
Daniel McCarney 2019-11-21 13:54:49 -05:00 committed by GitHub
parent 4e9ab5f04e
commit a86ed0f753
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 2 deletions

View File

@ -1796,7 +1796,8 @@ func (ra *RegistrationAuthorityImpl) NewOrder(ctx context.Context, req *rapb.New
}
if len(order.Names) > ra.maxNames {
return nil, fmt.Errorf("Order cannot contain more than %d DNS names", ra.maxNames)
return nil, berrors.MalformedError(
"Order cannot contain more than %d DNS names", ra.maxNames)
}
// Validate that our policy allows issuing for each of the names in the order

View File

@ -3781,6 +3781,7 @@ func TestNewOrderMaxNames(t *testing.T) {
})
test.AssertError(t, err, "NewOrder didn't fail with too many names in request")
test.AssertEquals(t, err.Error(), "Order cannot contain more than 2 DNS names")
test.AssertEquals(t, berrors.Is(err, berrors.Malformed), true)
}
var CAkeyPEM = `

View File

@ -108,7 +108,7 @@ func authAndIssue(c *client, csrKey *ecdsa.PrivateKey, domains []string) (*issua
}
order, err := c.Client.NewOrder(c.Account, ids)
if err != nil {
return nil, fmt.Errorf("making order: %s", err)
return nil, err
}
for _, authUrl := range order.Authorizations {

View File

@ -0,0 +1,35 @@
// +build integration
package integration
import (
"fmt"
"os"
"testing"
"github.com/eggsampler/acme/v3"
"github.com/letsencrypt/boulder/test"
)
// TestTooBigOrderError tests that submitting an order with more than 100 names
// produces the expected problem result.
func TestTooBigOrderError(t *testing.T) {
t.Parallel()
os.Setenv("DIRECTORY", "http://boulder:4001/directory")
var domains []string
for i := 0; i < 101; i++ {
domains = append(domains, fmt.Sprintf("%d.example.com", i))
}
_, err := authAndIssue(nil, nil, domains)
test.AssertError(t, err, "authAndIssue failed")
if prob, ok := err.(acme.Problem); !ok {
t.Fatalf("expected problem result, got %#v\n", err)
} else {
test.AssertEquals(t, prob.Type, "urn:ietf:params:acme:error:malformed")
test.AssertEquals(t, prob.Detail, "Error creating new order :: Order cannot contain more than 100 DNS names")
}
}