54 lines
1.6 KiB
Go
54 lines
1.6 KiB
Go
package wristband
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// DocsBackend returns the in-memory MCP backend of this package's tests,
|
|
// holding one public client and one pending authorization request, and
|
|
// that request's id, for the docs examples in example_test.go.
|
|
func DocsBackend(t *testing.T) (Backend, string) {
|
|
t.Helper()
|
|
b := newMemoryBackend()
|
|
ctx := context.Background()
|
|
const requestID = "docs-request"
|
|
err := b.WithinTx(ctx, func(tx Tx) error {
|
|
client := &ClientRecord{
|
|
ClientID: "docs-client",
|
|
ClientName: "Docs Client",
|
|
RedirectURIs: []string{"https://client.example.org/callback"},
|
|
TokenEndpointAuthMethod: "none",
|
|
}
|
|
if err := tx.CreateWithCap(ctx, client, 200); err != nil {
|
|
return err
|
|
}
|
|
state, id := "docs-state", requestID
|
|
return tx.CreatePending(ctx, &AuthCodeRecord{
|
|
ClientID: client.ClientID,
|
|
RedirectURI: "https://client.example.org/callback",
|
|
Scopes: []string{"read", "write"},
|
|
CodeChallenge: strings.Repeat("a", 43),
|
|
CodeChallengeMethod: "S256",
|
|
State: &state,
|
|
RequestID: &id,
|
|
ExpiresAt: time.Now().Add(10 * time.Minute),
|
|
})
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return b, requestID
|
|
}
|
|
|
|
// DocsOIDC returns the in-memory OpenID Connect storage, a key ring with
|
|
// one RS256 key and a host fake, for the docs examples in example_test.go.
|
|
func DocsOIDC(t *testing.T) (OIDCBackend, KeyStore, OIDCHost) {
|
|
t.Helper()
|
|
keys := newMemoryKeyStore()
|
|
keys.rotate(t, AlgRS256, time.Now())
|
|
return newMemoryOIDCBackend(), keys, &fakeOIDCHost{}
|
|
}
|