|
|
@@ -62,9 +62,73 @@ func newWireProvisionerWithOptions(t *testing.T, options *provisioner.Options) *
|
|
|
return prov
|
|
|
}
|
|
|
|
|
|
+func mutateStoredWireOrderDeviceID(t *testing.T, rawDB nosqlDB.DB, orderID, newValue string) {
|
|
|
+ var wireIntegrationOrderTable = []byte("acme_orders")
|
|
|
+ oldValue, err := rawDB.Get(wireIntegrationOrderTable, []byte(orderID))
|
|
|
+ require.NoError(t, err)
|
|
|
+
|
|
|
+ var stored map[string]json.RawMessage
|
|
|
+ err = json.Unmarshal(oldValue, &stored)
|
|
|
+ require.NoError(t, err)
|
|
|
+
|
|
|
+ var identifiers []acme.Identifier
|
|
|
+ err = json.Unmarshal(stored["identifiers"], &identifiers)
|
|
|
+ require.NoError(t, err)
|
|
|
+
|
|
|
+ replaced := false
|
|
|
+ for i, identifier := range identifiers {
|
|
|
+ if identifier.Type == acme.WireDevice {
|
|
|
+ identifiers[i].Value = newValue
|
|
|
+ replaced = true
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ require.True(t, replaced)
|
|
|
+
|
|
|
+ stored["identifiers"], err = json.Marshal(identifiers)
|
|
|
+ require.NoError(t, err)
|
|
|
+
|
|
|
+ newStoredValue, err := json.Marshal(stored)
|
|
|
+ require.NoError(t, err)
|
|
|
+
|
|
|
+ _, swapped, err := rawDB.CmpAndSwap(wireIntegrationOrderTable, []byte(orderID), oldValue, newStoredValue)
|
|
|
+ require.NoError(t, err)
|
|
|
+ require.True(t, swapped)
|
|
|
+}
|
|
|
+
|
|
|
// TODO(hs): replace with test CA server + acmez based test client for
|
|
|
// more realistic integration test?
|
|
|
func TestWireIntegration(t *testing.T) {
|
|
|
+ runWireIntegration(t, nil, nil)
|
|
|
+}
|
|
|
+
|
|
|
+func TestWireIntegration_DBMutation_GetOrderWireDeviceMismatch(t *testing.T) {
|
|
|
+ runWireIntegration(t, func(t *testing.T, rawDB nosqlDB.DB, order *acme.Order) {
|
|
|
+ const substitutedWireDevice = `{
|
|
|
+ "name": "Smith, Alice M (QA)",
|
|
|
+ "domain": "example.com",
|
|
|
+ "client-id": "wireapp://lJGYPz0ZRq2kvc_XpdaDlA!deadbeefdeadbeef@example.com",
|
|
|
+ "handle": "wireapp://%40alice.smith.qa@example.com"
|
|
|
+ }`
|
|
|
+ mutateStoredWireOrderDeviceID(t, rawDB, order.ID, substitutedWireDevice)
|
|
|
+ }, func(t *testing.T, res *http.Response, body []byte) {
|
|
|
+ require.Equal(t, http.StatusBadRequest, res.StatusCode)
|
|
|
+
|
|
|
+ var acmeErr acme.Error
|
|
|
+ err := json.Unmarshal(bytes.TrimSpace(body), &acmeErr)
|
|
|
+ require.NoError(t, err)
|
|
|
+ require.Equal(t, acme.NewError(acme.ErrorBadCSRType, "").Type, acmeErr.Type)
|
|
|
+ require.Equal(t, "The CSR is unacceptable", acmeErr.Detail)
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+func runWireIntegration(
|
|
|
+ t *testing.T,
|
|
|
+ beforeFinalize func(t *testing.T, rawDB nosqlDB.DB, order *acme.Order),
|
|
|
+ checkFinalizeResponse func(t *testing.T, res *http.Response, body []byte),
|
|
|
+) {
|
|
|
+ t.Helper()
|
|
|
+
|
|
|
accessTokenSignerJWK, err := jose.GenerateJWK("EC", "P-256", "ES256", "sig", "", 0)
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
@@ -488,6 +552,9 @@ func TestWireIntegration(t *testing.T) {
|
|
|
return
|
|
|
}(ctx)
|
|
|
t.Log("updated order status:", updatedOrder.Status)
|
|
|
+ if beforeFinalize != nil {
|
|
|
+ beforeFinalize(t, rawDB, order)
|
|
|
+ }
|
|
|
|
|
|
// finalize order
|
|
|
finalizedOrder := func(ctx context.Context) (finalizedOrder *acme.Order) {
|
|
|
@@ -568,11 +635,14 @@ func TestWireIntegration(t *testing.T) {
|
|
|
FinalizeOrder(w, req)
|
|
|
|
|
|
res := w.Result()
|
|
|
- require.Equal(t, http.StatusOK, res.StatusCode)
|
|
|
-
|
|
|
body, err := io.ReadAll(res.Body)
|
|
|
defer res.Body.Close()
|
|
|
require.NoError(t, err)
|
|
|
+ if checkFinalizeResponse != nil {
|
|
|
+ checkFinalizeResponse(t, res, body)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ require.Equal(t, http.StatusOK, res.StatusCode)
|
|
|
|
|
|
err = json.Unmarshal(bytes.TrimSpace(body), &finalizedOrder)
|
|
|
require.NoError(t, err)
|
|
|
@@ -584,7 +654,9 @@ func TestWireIntegration(t *testing.T) {
|
|
|
|
|
|
return
|
|
|
}(ctx)
|
|
|
- t.Log("finalized order status:", finalizedOrder.Status)
|
|
|
+ if finalizedOrder != nil {
|
|
|
+ t.Log("finalized order status:", finalizedOrder.Status)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
type mockCASigner struct {
|