MCPcopy
hub / github.com/caddyserver/caddy / TestACMEServerAllowPolicy

Function TestACMEServerAllowPolicy

caddytest/integration/acmeserver_test.go:46–134  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

44}
45
46func TestACMEServerAllowPolicy(t *testing.T) {
47 tester := caddytest.NewTester(t)
48 tester.InitServer(`
49 {
50 skip_install_trust
51 local_certs
52 admin localhost:2999
53 http_port 9080
54 https_port 9443
55 pki {
56 ca local {
57 name "Caddy Local Authority"
58 }
59 }
60 }
61 acme.localhost {
62 acme_server {
63 challenges http-01
64 allow {
65 domains localhost
66 }
67 }
68 }
69 `, "caddyfile")
70
71 ctx := context.Background()
72 logger, err := zap.NewDevelopment()
73 if err != nil {
74 t.Error(err)
75 return
76 }
77
78 client := acmez.Client{
79 Client: &acme.Client{
80 Directory: "https://acme.localhost:9443/acme/local/directory",
81 HTTPClient: tester.Client,
82 Logger: slog.New(zapslog.NewHandler(logger.Core())),
83 },
84 ChallengeSolvers: map[string]acmez.Solver{
85 acme.ChallengeTypeHTTP01: &naiveHTTPSolver{logger: logger},
86 },
87 }
88
89 accountPrivateKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
90 if err != nil {
91 t.Errorf("generating account key: %v", err)
92 }
93 account := acme.Account{
94 Contact: []string{"mailto:you@example.com"},
95 TermsOfServiceAgreed: true,
96 PrivateKey: accountPrivateKey,
97 }
98 account, err = client.NewAccount(ctx, account)
99 if err != nil {
100 t.Errorf("new account: %v", err)
101 return
102 }
103

Callers

nothing calls this directly

Calls 3

InitServerMethod · 0.95
NewTesterFunction · 0.92
ErrorMethod · 0.45

Tested by

no test coverage detected