Explorar o código

Merge branch 'master' into add-omit-zero-times

Herman Slatman hai 6 meses
pai
achega
b13ddadd43
Modificáronse 5 ficheiros con 1692 adicións e 16 borrados
  1. 1 1
      Makefile
  2. 75 3
      acme/api/wire_integration_test.go
  3. 1604 0
      acme/challenge_wire_test.go
  4. 4 4
      go.mod
  5. 8 8
      go.sum

+ 1 - 1
Makefile

@@ -18,7 +18,7 @@ ci: testcgo build
 #########################################
 
 bootstra%:
-	$Q curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin latest
+	$Q curl -sSfL https://golangci-lint.run/install.sh | sh -s -- -b $$(go env GOPATH)/bin latest
 	$Q go install golang.org/x/vuln/cmd/govulncheck@latest
 	$Q go install gotest.tools/gotestsum@latest
 	$Q go install github.com/goreleaser/goreleaser/v2@latest

+ 75 - 3
acme/api/wire_integration_test.go

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

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 1604 - 0
acme/challenge_wire_test.go


+ 4 - 4
go.mod

@@ -12,7 +12,7 @@ require (
 	github.com/dgraph-io/badger v1.6.2
 	github.com/dgraph-io/badger/v2 v2.2007.4
 	github.com/fxamacker/cbor/v2 v2.9.2
-	github.com/go-chi/chi/v5 v5.2.5
+	github.com/go-chi/chi/v5 v5.3.0
 	github.com/go-jose/go-jose/v3 v3.0.5
 	github.com/google/go-cmp v0.7.0
 	github.com/google/go-tpm v0.9.8
@@ -39,8 +39,8 @@ require (
 	github.com/urfave/cli v1.22.17
 	go.step.sm/crypto v0.81.0
 	go.uber.org/mock v0.6.0
-	golang.org/x/crypto v0.51.0
-	golang.org/x/net v0.54.0
+	golang.org/x/crypto v0.52.0
+	golang.org/x/net v0.55.0
 	golang.org/x/sync v0.20.0
 	google.golang.org/api v0.280.0
 	google.golang.org/grpc v1.81.1
@@ -164,7 +164,7 @@ require (
 	go.yaml.in/yaml/v2 v2.4.3 // indirect
 	golang.org/x/mod v0.35.0 // indirect
 	golang.org/x/oauth2 v0.36.0 // indirect
-	golang.org/x/sys v0.44.0 // indirect
+	golang.org/x/sys v0.45.0 // indirect
 	golang.org/x/term v0.43.0 // indirect
 	golang.org/x/text v0.37.0 // indirect
 	golang.org/x/time v0.15.0 // indirect

+ 8 - 8
go.sum

@@ -149,8 +149,8 @@ github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7z
 github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
 github.com/fxamacker/cbor/v2 v2.9.2 h1:X4Ksno9+x3cz0TZv69ec1hxP/+tymuR8PXQJyDwfh78=
 github.com/fxamacker/cbor/v2 v2.9.2/go.mod h1:vM4b+DJCtHn+zz7h3FFp/hDAI9WNWCsZj23V5ytsSxQ=
-github.com/go-chi/chi/v5 v5.2.5 h1:Eg4myHZBjyvJmAFjFvWgrqDTXFyOzjj7YIm3L3mu6Ug=
-github.com/go-chi/chi/v5 v5.2.5/go.mod h1:X7Gx4mteadT3eDOMTsXzmI4/rwUpOwBHLpAfupzFJP0=
+github.com/go-chi/chi/v5 v5.3.0 h1:halUjDxhshgXHMrao5bB8eNBXo/rnzwr8m5m36glehM=
+github.com/go-chi/chi/v5 v5.3.0/go.mod h1:R+tYY2hNuVUUjxoPtqUdgBqevM9s9njzkTLutVsOCto=
 github.com/go-jose/go-jose/v3 v3.0.5 h1:BLLJWbC4nMZOfuPVxoZIxeYsn6Nl2r1fITaJ78UQlVQ=
 github.com/go-jose/go-jose/v3 v3.0.5/go.mod h1:5b+7YgP7ZICgJDBdfjZaIt+H/9L9T/YQrVfLAMboGkQ=
 github.com/go-jose/go-jose/v4 v4.1.4 h1:moDMcTHmvE6Groj34emNPLs/qtYXRVcd6S7NHbHz3kA=
@@ -431,8 +431,8 @@ golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliY
 golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
 golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
 golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
-golang.org/x/crypto v0.51.0 h1:IBPXwPfKxY7cWQZ38ZCIRPI50YLeevDLlLnyC5wRGTI=
-golang.org/x/crypto v0.51.0/go.mod h1:8AdwkbraGNABw2kOX6YFPs3WM22XqI4EXEd8g+x7Oc8=
+golang.org/x/crypto v0.52.0 h1:RMs7fP2rXdep0CftQlK8Uf+kibLm7qkCcradZWYz988=
+golang.org/x/crypto v0.52.0/go.mod h1:1QgfPxDqh0T2M/elOJtp9RvuR95kVjir0e6/BvEmGbc=
 golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
 golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
 golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
@@ -449,8 +449,8 @@ golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
 golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
 golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
 golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
-golang.org/x/net v0.54.0 h1:2zJIZAxAHV/OHCDTCOHAYehQzLfSXuf/5SoL/Dv6w/w=
-golang.org/x/net v0.54.0/go.mod h1:Sj4oj8jK6XmHpBZU/zWHw3BV3abl4Kvi+Ut7cQcY+cQ=
+golang.org/x/net v0.55.0 h1:bcvxaJn3e1U6InsFWt1JUq1aSjnRxLzT2rtD2KfkDF8=
+golang.org/x/net v0.55.0/go.mod h1:L5U2KuzuOe1lY7Z+aWVIKK6qEeJXnXV9yzGA+WCHJww=
 golang.org/x/oauth2 v0.36.0 h1:peZ/1z27fi9hUOFCAZaHyrpWG5lwe0RJEEEeH0ThlIs=
 golang.org/x/oauth2 v0.36.0/go.mod h1:YDBUJMTkDnJS+A4BP4eZBjCqtokkg1hODuPjwiGPO7Q=
 golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -485,8 +485,8 @@ golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
 golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
 golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
-golang.org/x/sys v0.44.0 h1:ildZl3J4uzeKP07r2F++Op7E9B29JRUy+a27EibtBTQ=
-golang.org/x/sys v0.44.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
+golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY=
+golang.org/x/sys v0.45.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
 golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
 golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
 golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=

Algúns arquivos non se mostraron porque demasiados arquivos cambiaron neste cambio