2022-12-08 17:10:36 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
"crypto/ed25519"
|
|
|
|
"crypto/rand"
|
|
|
|
"crypto/x509"
|
|
|
|
"crypto/x509/pkix"
|
2024-01-08 23:33:01 +00:00
|
|
|
"encoding/asn1"
|
2022-12-08 17:10:36 +00:00
|
|
|
"encoding/base64"
|
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
|
|
|
"io"
|
|
|
|
"math/big"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"net/url"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2024-01-08 23:33:01 +00:00
|
|
|
"github.com/go-chi/chi/v5"
|
2022-12-08 17:10:36 +00:00
|
|
|
"github.com/smallstep/certificates/acme"
|
|
|
|
"github.com/smallstep/certificates/acme/db/nosql"
|
|
|
|
"github.com/smallstep/certificates/authority"
|
|
|
|
"github.com/smallstep/certificates/authority/provisioner"
|
2024-01-11 12:18:43 +00:00
|
|
|
"github.com/smallstep/certificates/authority/provisioner/wire"
|
2022-12-08 17:10:36 +00:00
|
|
|
nosqlDB "github.com/smallstep/nosql"
|
2024-01-09 17:24:37 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2022-12-08 17:10:36 +00:00
|
|
|
"go.step.sm/crypto/jose"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
baseURL = "test.ca.smallstep.com"
|
|
|
|
linkerPrefix = "acme"
|
|
|
|
)
|
|
|
|
|
2024-01-10 19:23:01 +00:00
|
|
|
func newWireProvisionerWithOptions(t *testing.T, options *provisioner.Options) *provisioner.ACME {
|
|
|
|
p := newProvWithOptions(options)
|
|
|
|
a, ok := p.(*provisioner.ACME)
|
|
|
|
if !ok {
|
|
|
|
t.Fatal("not a valid ACME provisioner")
|
|
|
|
}
|
|
|
|
a.Challenges = []provisioner.ACMEChallenge{
|
|
|
|
provisioner.WIREOIDC_01,
|
|
|
|
provisioner.WIREDPOP_01,
|
|
|
|
}
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestWireIntegration(t *testing.T) {
|
2024-01-11 16:04:08 +00:00
|
|
|
fakeKey := `-----BEGIN PUBLIC KEY-----
|
|
|
|
MCowBQYDK2VwAyEA5c+4NKZSNQcR1T8qN6SjwgdPZQ0Ge12Ylx/YeGAJ35k=
|
|
|
|
-----END PUBLIC KEY-----`
|
2024-01-10 19:23:01 +00:00
|
|
|
prov := newWireProvisionerWithOptions(t, &provisioner.Options{
|
2024-01-11 12:18:43 +00:00
|
|
|
Wire: &wire.Options{
|
|
|
|
OIDC: &wire.OIDCOptions{
|
2024-01-11 14:08:44 +00:00
|
|
|
Provider: &wire.Provider{
|
2024-01-11 15:14:53 +00:00
|
|
|
IssuerURL: "https://issuer.example.com",
|
2024-01-11 12:18:43 +00:00
|
|
|
AuthURL: "",
|
|
|
|
TokenURL: "",
|
|
|
|
JWKSURL: "",
|
|
|
|
UserInfoURL: "",
|
|
|
|
Algorithms: []string{},
|
|
|
|
},
|
2024-01-11 14:08:44 +00:00
|
|
|
Config: &wire.Config{
|
2024-01-11 12:18:43 +00:00
|
|
|
ClientID: "integration test",
|
2024-01-12 08:48:49 +00:00
|
|
|
SignatureAlgorithms: []string{},
|
2024-01-11 12:18:43 +00:00
|
|
|
SkipClientIDCheck: true,
|
|
|
|
SkipExpiryCheck: true,
|
|
|
|
SkipIssuerCheck: true,
|
|
|
|
InsecureSkipSignatureCheck: true,
|
|
|
|
Now: time.Now,
|
|
|
|
},
|
2022-12-08 17:10:36 +00:00
|
|
|
},
|
2024-01-11 16:04:08 +00:00
|
|
|
DPOP: &wire.DPOPOptions{
|
|
|
|
SigningKey: []byte(fakeKey),
|
|
|
|
},
|
2022-12-08 17:10:36 +00:00
|
|
|
},
|
2024-01-08 23:33:01 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
// mock provisioner and linker
|
2024-01-09 20:31:10 +00:00
|
|
|
ctx := context.Background()
|
2024-01-08 23:33:01 +00:00
|
|
|
ctx = acme.NewProvisionerContext(ctx, prov)
|
2022-12-08 17:10:36 +00:00
|
|
|
ctx = acme.NewLinkerContext(ctx, acme.NewLinker(baseURL, linkerPrefix))
|
|
|
|
|
|
|
|
// create temporary BoltDB file
|
|
|
|
file, err := os.CreateTemp(os.TempDir(), "integration-db-")
|
2024-01-09 20:52:00 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-12-08 17:10:36 +00:00
|
|
|
t.Log("database file name:", file.Name())
|
|
|
|
dbFn := file.Name()
|
|
|
|
err = file.Close()
|
2024-01-09 20:52:00 +00:00
|
|
|
require.NoError(t, err)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
// open BoltDB
|
|
|
|
rawDB, err := nosqlDB.New(nosqlDB.BBoltDriver, dbFn)
|
2024-01-09 20:52:00 +00:00
|
|
|
require.NoError(t, err)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
// create tables
|
|
|
|
db, err := nosql.New(rawDB)
|
2024-01-09 20:52:00 +00:00
|
|
|
require.NoError(t, err)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
// make DB available to handlers
|
|
|
|
ctx = acme.NewDatabaseContext(ctx, db)
|
|
|
|
|
|
|
|
// simulate signed payloads by making the signing key available in ctx
|
|
|
|
jwk, err := jose.GenerateJWK("OKP", "", "EdDSA", "sig", "", 0)
|
2024-01-09 20:52:00 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-12-08 17:10:36 +00:00
|
|
|
ed25519PrivKey, ok := jwk.Key.(ed25519.PrivateKey)
|
2024-01-09 20:52:00 +00:00
|
|
|
require.True(t, ok)
|
|
|
|
|
2022-12-08 17:10:36 +00:00
|
|
|
ed25519PubKey, ok := ed25519PrivKey.Public().(ed25519.PublicKey)
|
2024-01-09 20:52:00 +00:00
|
|
|
require.True(t, ok)
|
|
|
|
|
2022-12-08 17:10:36 +00:00
|
|
|
jwk.Key = ed25519PubKey
|
|
|
|
ctx = context.WithValue(ctx, jwkContextKey, jwk)
|
|
|
|
|
|
|
|
// get directory
|
|
|
|
dir := func(ctx context.Context) (dir Directory) {
|
2024-01-09 20:31:10 +00:00
|
|
|
req := httptest.NewRequest(http.MethodGet, "/foo/bar", http.NoBody)
|
2022-12-08 17:10:36 +00:00
|
|
|
req = req.WithContext(ctx)
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
|
|
|
|
GetDirectory(w, req)
|
|
|
|
res := w.Result()
|
2024-01-09 20:52:00 +00:00
|
|
|
require.Equal(t, http.StatusOK, res.StatusCode)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
body, err := io.ReadAll(res.Body)
|
2024-01-09 20:52:00 +00:00
|
|
|
require.NoError(t, err)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
err = json.Unmarshal(bytes.TrimSpace(body), &dir)
|
2024-01-09 20:52:00 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-12-08 17:10:36 +00:00
|
|
|
return
|
|
|
|
}(ctx)
|
|
|
|
t.Log("directory:", dir)
|
|
|
|
|
|
|
|
// get nonce
|
|
|
|
nonce := func(ctx context.Context) (nonce string) {
|
2024-01-09 20:31:10 +00:00
|
|
|
req := httptest.NewRequest(http.MethodGet, dir.NewNonce, http.NoBody).WithContext(ctx)
|
2022-12-08 17:10:36 +00:00
|
|
|
w := httptest.NewRecorder()
|
|
|
|
addNonce(GetNonce)(w, req)
|
|
|
|
res := w.Result()
|
2024-01-09 20:52:00 +00:00
|
|
|
require.Equal(t, http.StatusNoContent, res.StatusCode)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
nonce = res.Header["Replay-Nonce"][0]
|
|
|
|
return
|
|
|
|
}(ctx)
|
|
|
|
t.Log("nonce:", nonce)
|
|
|
|
|
|
|
|
// create new account
|
|
|
|
acc := func(ctx context.Context) (acc *acme.Account) {
|
|
|
|
// create payload
|
|
|
|
nar := &NewAccountRequest{
|
|
|
|
Contact: []string{"foo", "bar"},
|
|
|
|
}
|
|
|
|
rawNar, err := json.Marshal(nar)
|
2024-01-09 20:52:00 +00:00
|
|
|
require.NoError(t, err)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
// create account
|
2024-01-09 20:52:00 +00:00
|
|
|
ctx = context.WithValue(ctx, payloadContextKey, &payloadInfo{value: rawNar})
|
2024-01-09 20:31:10 +00:00
|
|
|
req := httptest.NewRequest(http.MethodGet, dir.NewAccount, http.NoBody).WithContext(ctx)
|
2022-12-08 17:10:36 +00:00
|
|
|
w := httptest.NewRecorder()
|
|
|
|
NewAccount(w, req)
|
|
|
|
|
|
|
|
res := w.Result()
|
2024-01-09 20:52:00 +00:00
|
|
|
require.Equal(t, http.StatusCreated, res.StatusCode)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
body, err := io.ReadAll(res.Body)
|
2024-01-09 20:52:00 +00:00
|
|
|
defer res.Body.Close()
|
|
|
|
require.NoError(t, err)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
err = json.Unmarshal(bytes.TrimSpace(body), &acc)
|
2024-01-09 20:52:00 +00:00
|
|
|
require.NoError(t, err)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
locationParts := strings.Split(res.Header["Location"][0], "/")
|
|
|
|
acc, err = db.GetAccount(ctx, locationParts[len(locationParts)-1])
|
2024-01-09 20:52:00 +00:00
|
|
|
require.NoError(t, err)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}(ctx)
|
|
|
|
ctx = context.WithValue(ctx, accContextKey, acc)
|
|
|
|
t.Log("account ID:", acc.ID)
|
|
|
|
|
|
|
|
// new order
|
|
|
|
order := func(ctx context.Context) (order *acme.Order) {
|
|
|
|
mockMustAuthority(t, &mockCA{})
|
|
|
|
nor := &NewOrderRequest{
|
|
|
|
Identifiers: []acme.Identifier{
|
|
|
|
{
|
|
|
|
Type: "wireapp-id",
|
2024-01-05 08:56:34 +00:00
|
|
|
Value: `{"name": "Smith, Alice M (QA)", "domain": "example.com", "client-id": "wireapp://lJGYPz0ZRq2kvc_XpdaDlA!ed416ce8ecdd9fad@example.com", "handle": "wireapp://%40alice.smith.qa@example.com"}`,
|
2022-12-08 17:10:36 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
b, err := json.Marshal(nor)
|
2024-01-09 20:52:00 +00:00
|
|
|
require.NoError(t, err)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
ctx = context.WithValue(ctx, payloadContextKey, &payloadInfo{value: b})
|
2024-01-09 20:31:10 +00:00
|
|
|
req := httptest.NewRequest("POST", "https://random.local/", http.NoBody)
|
2022-12-08 17:10:36 +00:00
|
|
|
req = req.WithContext(ctx)
|
|
|
|
w := httptest.NewRecorder()
|
|
|
|
NewOrder(w, req)
|
|
|
|
|
|
|
|
res := w.Result()
|
2024-01-09 20:52:00 +00:00
|
|
|
require.Equal(t, http.StatusCreated, res.StatusCode)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
body, err := io.ReadAll(res.Body)
|
2024-01-09 20:52:00 +00:00
|
|
|
defer res.Body.Close()
|
|
|
|
require.NoError(t, err)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
err = json.Unmarshal(bytes.TrimSpace(body), &order)
|
2024-01-09 20:52:00 +00:00
|
|
|
require.NoError(t, err)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
order, err = db.GetOrder(ctx, order.ID)
|
2024-01-09 20:52:00 +00:00
|
|
|
require.NoError(t, err)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}(ctx)
|
|
|
|
t.Log("authzs IDs:", order.AuthorizationIDs)
|
|
|
|
|
|
|
|
// get authorization
|
|
|
|
getAuthz := func(ctx context.Context, authzID string) (az *acme.Authorization) {
|
|
|
|
chiCtx := chi.NewRouteContext()
|
|
|
|
chiCtx.URLParams.Add("authzID", authzID)
|
|
|
|
ctx = context.WithValue(ctx, chi.RouteCtxKey, chiCtx)
|
|
|
|
|
2024-01-09 20:31:10 +00:00
|
|
|
req := httptest.NewRequest(http.MethodGet, "https://random.local/", http.NoBody).WithContext(ctx)
|
2022-12-08 17:10:36 +00:00
|
|
|
w := httptest.NewRecorder()
|
|
|
|
GetAuthorization(w, req)
|
|
|
|
|
|
|
|
res := w.Result()
|
2024-01-09 20:52:00 +00:00
|
|
|
require.Equal(t, http.StatusOK, res.StatusCode)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
body, err := io.ReadAll(res.Body)
|
2024-01-09 20:52:00 +00:00
|
|
|
defer res.Body.Close()
|
|
|
|
require.NoError(t, err)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
err = json.Unmarshal(bytes.TrimSpace(body), &az)
|
2024-01-09 20:52:00 +00:00
|
|
|
require.NoError(t, err)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
az, err = db.GetAuthorization(ctx, authzID)
|
2024-01-09 20:52:00 +00:00
|
|
|
require.NoError(t, err)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var azs []*acme.Authorization
|
|
|
|
for _, azID := range order.AuthorizationIDs {
|
|
|
|
az := getAuthz(ctx, azID)
|
|
|
|
azs = append(azs, az)
|
|
|
|
for _, challenge := range az.Challenges {
|
|
|
|
chiCtx := chi.NewRouteContext()
|
|
|
|
chiCtx.URLParams.Add("chID", challenge.ID)
|
|
|
|
ctx = context.WithValue(ctx, chi.RouteCtxKey, chiCtx)
|
|
|
|
ctx = context.WithValue(ctx, payloadContextKey, &payloadInfo{value: nil})
|
|
|
|
|
2024-01-09 20:31:10 +00:00
|
|
|
req := httptest.NewRequest(http.MethodGet, "https://random.local/", http.NoBody).WithContext(ctx)
|
2022-12-08 17:10:36 +00:00
|
|
|
w := httptest.NewRecorder()
|
|
|
|
GetChallenge(w, req)
|
|
|
|
|
|
|
|
res := w.Result()
|
2024-01-09 20:52:00 +00:00
|
|
|
require.Equal(t, http.StatusOK, res.StatusCode)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
body, err := io.ReadAll(res.Body)
|
2024-01-09 20:52:00 +00:00
|
|
|
defer res.Body.Close() //nolint:gocritic // close the body
|
|
|
|
require.NoError(t, err)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
err = json.Unmarshal(bytes.TrimSpace(body), &challenge)
|
2024-01-09 20:52:00 +00:00
|
|
|
require.NoError(t, err)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
t.Log("challenge:", challenge.ID, challenge.Status)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// get/validate challenge simulation
|
|
|
|
updateAz := func(ctx context.Context, az *acme.Authorization) (updatedAz *acme.Authorization) {
|
|
|
|
now := clock.Now().Format(time.RFC3339)
|
|
|
|
for _, challenge := range az.Challenges {
|
|
|
|
challenge.Status = acme.StatusValid
|
|
|
|
challenge.ValidatedAt = now
|
|
|
|
err := db.UpdateChallenge(ctx, challenge)
|
|
|
|
if err != nil {
|
|
|
|
t.Error("updating challenge", challenge.ID, ":", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
updatedAz, err = db.GetAuthorization(ctx, az.ID)
|
2024-01-09 20:52:00 +00:00
|
|
|
require.NoError(t, err)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, az := range azs {
|
|
|
|
updatedAz := updateAz(ctx, az)
|
|
|
|
for _, challenge := range updatedAz.Challenges {
|
|
|
|
t.Log("updated challenge:", challenge.ID, challenge.Status)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// get order
|
|
|
|
updatedOrder := func(ctx context.Context) (updatedOrder *acme.Order) {
|
|
|
|
chiCtx := chi.NewRouteContext()
|
|
|
|
chiCtx.URLParams.Add("ordID", order.ID)
|
|
|
|
ctx = context.WithValue(ctx, chi.RouteCtxKey, chiCtx)
|
|
|
|
|
2024-01-09 20:31:10 +00:00
|
|
|
req := httptest.NewRequest(http.MethodGet, "https://random.local/", http.NoBody).WithContext(ctx)
|
2022-12-08 17:10:36 +00:00
|
|
|
w := httptest.NewRecorder()
|
|
|
|
GetOrder(w, req)
|
|
|
|
|
|
|
|
res := w.Result()
|
2024-01-09 20:52:00 +00:00
|
|
|
require.Equal(t, http.StatusOK, res.StatusCode)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
body, err := io.ReadAll(res.Body)
|
2024-01-09 20:52:00 +00:00
|
|
|
defer res.Body.Close()
|
|
|
|
require.NoError(t, err)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
err = json.Unmarshal(bytes.TrimSpace(body), &updatedOrder)
|
2024-01-09 20:52:00 +00:00
|
|
|
require.NoError(t, err)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
2024-01-09 20:52:00 +00:00
|
|
|
require.Equal(t, acme.StatusReady, updatedOrder.Status)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}(ctx)
|
|
|
|
t.Log("updated order status:", updatedOrder.Status)
|
|
|
|
|
2024-01-09 20:31:10 +00:00
|
|
|
// finalize order
|
2022-12-08 17:10:36 +00:00
|
|
|
finalizedOrder := func(ctx context.Context) (finalizedOrder *acme.Order) {
|
|
|
|
mockMustAuthority(t, &mockCASigner{
|
|
|
|
signer: func(*x509.CertificateRequest, provisioner.SignOptions, ...provisioner.SignOption) ([]*x509.Certificate, error) {
|
|
|
|
return []*x509.Certificate{
|
|
|
|
{SerialNumber: big.NewInt(2)},
|
|
|
|
}, nil
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2024-01-05 08:56:34 +00:00
|
|
|
qUserID, err := url.Parse("wireapp://lJGYPz0ZRq2kvc_XpdaDlA!ed416ce8ecdd9fad@example.com")
|
2024-01-09 20:52:00 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-01-02 13:38:41 +00:00
|
|
|
qUserName, err := url.Parse("wireapp://%40alice.smith.qa@example.com")
|
2024-01-09 20:52:00 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-12-08 17:10:36 +00:00
|
|
|
_, priv, err := ed25519.GenerateKey(rand.Reader)
|
2024-01-09 20:52:00 +00:00
|
|
|
require.NoError(t, err)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
csrTemplate := &x509.CertificateRequest{
|
|
|
|
Subject: pkix.Name{
|
|
|
|
Organization: []string{"example.com"},
|
2024-01-08 23:33:01 +00:00
|
|
|
ExtraNames: []pkix.AttributeTypeAndValue{
|
|
|
|
{
|
|
|
|
Type: asn1.ObjectIdentifier{2, 16, 840, 1, 113730, 3, 1, 241},
|
|
|
|
Value: "Smith, Alice M (QA)",
|
|
|
|
},
|
|
|
|
},
|
2022-12-08 17:10:36 +00:00
|
|
|
},
|
|
|
|
URIs: []*url.URL{
|
|
|
|
qUserName,
|
|
|
|
qUserID,
|
|
|
|
},
|
|
|
|
SignatureAlgorithm: x509.PureEd25519,
|
|
|
|
}
|
2024-01-08 23:33:01 +00:00
|
|
|
|
2022-12-08 17:10:36 +00:00
|
|
|
csr, err := x509.CreateCertificateRequest(rand.Reader, csrTemplate, priv)
|
2024-01-09 20:52:00 +00:00
|
|
|
require.NoError(t, err)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
fr := FinalizeRequest{CSR: base64.RawURLEncoding.EncodeToString(csr)}
|
|
|
|
frRaw, err := json.Marshal(fr)
|
2024-01-09 20:52:00 +00:00
|
|
|
require.NoError(t, err)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
2024-01-09 17:24:37 +00:00
|
|
|
// TODO(hs): move these to a more appropriate place and/or provide more realistic value
|
2024-01-12 10:46:25 +00:00
|
|
|
err = db.CreateDpopToken(ctx, order.ID, &acme.WireDpopToken{Challenge: "challenge", Handle: "handle", Team: "wire"})
|
2024-01-09 17:24:37 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
err = db.CreateOidcToken(ctx, order.ID, map[string]any{"fake-oidc": "oidc-value"})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-12-08 17:10:36 +00:00
|
|
|
ctx = context.WithValue(ctx, payloadContextKey, &payloadInfo{value: frRaw})
|
|
|
|
|
|
|
|
chiCtx := chi.NewRouteContext()
|
|
|
|
chiCtx.URLParams.Add("ordID", order.ID)
|
|
|
|
ctx = context.WithValue(ctx, chi.RouteCtxKey, chiCtx)
|
|
|
|
|
2024-01-09 20:31:10 +00:00
|
|
|
req := httptest.NewRequest(http.MethodGet, "https://random.local/", http.NoBody).WithContext(ctx)
|
2022-12-08 17:10:36 +00:00
|
|
|
w := httptest.NewRecorder()
|
|
|
|
FinalizeOrder(w, req)
|
|
|
|
|
|
|
|
res := w.Result()
|
2024-01-09 20:52:00 +00:00
|
|
|
require.Equal(t, http.StatusOK, res.StatusCode)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
body, err := io.ReadAll(res.Body)
|
2024-01-09 20:52:00 +00:00
|
|
|
defer res.Body.Close()
|
|
|
|
require.NoError(t, err)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
err = json.Unmarshal(bytes.TrimSpace(body), &finalizedOrder)
|
2024-01-09 20:52:00 +00:00
|
|
|
require.NoError(t, err)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
2024-01-09 20:52:00 +00:00
|
|
|
require.Equal(t, acme.StatusValid, finalizedOrder.Status)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
finalizedOrder, err = db.GetOrder(ctx, order.ID)
|
2024-01-09 20:52:00 +00:00
|
|
|
require.NoError(t, err)
|
2022-12-08 17:10:36 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}(ctx)
|
|
|
|
t.Log("finalized order status:", finalizedOrder.Status)
|
|
|
|
}
|
|
|
|
|
|
|
|
type mockCASigner struct {
|
|
|
|
signer func(*x509.CertificateRequest, provisioner.SignOptions, ...provisioner.SignOption) ([]*x509.Certificate, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockCASigner) Sign(cr *x509.CertificateRequest, opts provisioner.SignOptions, signOpts ...provisioner.SignOption) ([]*x509.Certificate, error) {
|
|
|
|
if m.signer == nil {
|
|
|
|
return nil, errors.New("unimplemented")
|
|
|
|
}
|
|
|
|
return m.signer(cr, opts, signOpts...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockCASigner) AreSANsAllowed(ctx context.Context, sans []string) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockCASigner) IsRevoked(sn string) (bool, error) {
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockCASigner) Revoke(ctx context.Context, opts *authority.RevokeOptions) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *mockCASigner) LoadProvisionerByName(string) (provisioner.Interface, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|