-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adapt tests, add mock DNS module for config testing
- Loading branch information
1 parent
ff4dfa1
commit ad266d8
Showing
3 changed files
with
324 additions
and
0 deletions.
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
caddytest/integration/caddyfile_adapt/auto_https_prefer_wildcard.caddyfiletest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
{ | ||
auto_https prefer_wildcard | ||
} | ||
|
||
*.example.com { | ||
tls { | ||
dns mock | ||
} | ||
respond "fallback" | ||
} | ||
|
||
foo.example.com { | ||
respond "foo" | ||
} | ||
---------- | ||
{ | ||
"apps": { | ||
"http": { | ||
"servers": { | ||
"srv0": { | ||
"listen": [ | ||
":443" | ||
], | ||
"routes": [ | ||
{ | ||
"match": [ | ||
{ | ||
"host": [ | ||
"foo.example.com" | ||
] | ||
} | ||
], | ||
"handle": [ | ||
{ | ||
"handler": "subroute", | ||
"routes": [ | ||
{ | ||
"handle": [ | ||
{ | ||
"body": "foo", | ||
"handler": "static_response" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
], | ||
"terminal": true | ||
}, | ||
{ | ||
"match": [ | ||
{ | ||
"host": [ | ||
"*.example.com" | ||
] | ||
} | ||
], | ||
"handle": [ | ||
{ | ||
"handler": "subroute", | ||
"routes": [ | ||
{ | ||
"handle": [ | ||
{ | ||
"body": "fallback", | ||
"handler": "static_response" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
], | ||
"terminal": true | ||
} | ||
], | ||
"automatic_https": { | ||
"prefer_wildcard": true | ||
} | ||
} | ||
} | ||
}, | ||
"tls": { | ||
"automation": { | ||
"policies": [ | ||
{ | ||
"subjects": [ | ||
"*.example.com" | ||
], | ||
"issuers": [ | ||
{ | ||
"challenges": { | ||
"dns": { | ||
"provider": { | ||
"name": "mock" | ||
} | ||
} | ||
}, | ||
"module": "acme" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} |
157 changes: 157 additions & 0 deletions
157
caddytest/integration/caddyfile_adapt/wildcard_pattern.caddyfiletest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
*.example.com { | ||
tls [email protected] { | ||
dns mock | ||
} | ||
|
||
@foo host foo.example.com | ||
handle @foo { | ||
respond "Foo!" | ||
} | ||
|
||
@bar host bar.example.com | ||
handle @bar { | ||
respond "Bar!" | ||
} | ||
|
||
# Fallback for otherwise unhandled domains | ||
handle { | ||
abort | ||
} | ||
} | ||
---------- | ||
{ | ||
"apps": { | ||
"http": { | ||
"servers": { | ||
"srv0": { | ||
"listen": [ | ||
":443" | ||
], | ||
"routes": [ | ||
{ | ||
"match": [ | ||
{ | ||
"host": [ | ||
"*.example.com" | ||
] | ||
} | ||
], | ||
"handle": [ | ||
{ | ||
"handler": "subroute", | ||
"routes": [ | ||
{ | ||
"group": "group3", | ||
"handle": [ | ||
{ | ||
"handler": "subroute", | ||
"routes": [ | ||
{ | ||
"handle": [ | ||
{ | ||
"body": "Foo!", | ||
"handler": "static_response" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
], | ||
"match": [ | ||
{ | ||
"host": [ | ||
"foo.example.com" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"group": "group3", | ||
"handle": [ | ||
{ | ||
"handler": "subroute", | ||
"routes": [ | ||
{ | ||
"handle": [ | ||
{ | ||
"body": "Bar!", | ||
"handler": "static_response" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
], | ||
"match": [ | ||
{ | ||
"host": [ | ||
"bar.example.com" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"group": "group3", | ||
"handle": [ | ||
{ | ||
"handler": "subroute", | ||
"routes": [ | ||
{ | ||
"handle": [ | ||
{ | ||
"abort": true, | ||
"handler": "static_response" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} | ||
], | ||
"terminal": true | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"tls": { | ||
"automation": { | ||
"policies": [ | ||
{ | ||
"subjects": [ | ||
"*.example.com" | ||
], | ||
"issuers": [ | ||
{ | ||
"challenges": { | ||
"dns": { | ||
"provider": { | ||
"name": "mock" | ||
} | ||
} | ||
}, | ||
"email": "[email protected]", | ||
"module": "acme" | ||
}, | ||
{ | ||
"ca": "https://acme.zerossl.com/v2/DV90", | ||
"challenges": { | ||
"dns": { | ||
"provider": { | ||
"name": "mock" | ||
} | ||
} | ||
}, | ||
"email": "[email protected]", | ||
"module": "acme" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package integration | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/caddyserver/caddy/v2" | ||
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile" | ||
"github.com/caddyserver/certmagic" | ||
"github.com/libdns/libdns" | ||
) | ||
|
||
func init() { | ||
caddy.RegisterModule(MockDNSProvider{}) | ||
} | ||
|
||
// MockDNSProvider is a mock DNS provider, for testing config with DNS modules. | ||
type MockDNSProvider struct{} | ||
|
||
// CaddyModule returns the Caddy module information. | ||
func (MockDNSProvider) CaddyModule() caddy.ModuleInfo { | ||
return caddy.ModuleInfo{ | ||
ID: "dns.providers.mock", | ||
New: func() caddy.Module { return new(MockDNSProvider) }, | ||
} | ||
} | ||
|
||
// Provision sets up the module. | ||
func (MockDNSProvider) Provision(ctx caddy.Context) error { | ||
return nil | ||
} | ||
|
||
// UnmarshalCaddyfile sets up the module from Caddyfile tokens. | ||
func (MockDNSProvider) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { | ||
return nil | ||
} | ||
|
||
// AppendsRecords appends DNS records to the zone. | ||
func (MockDNSProvider) AppendRecords(ctx context.Context, zone string, recs []libdns.Record) ([]libdns.Record, error) { | ||
return nil, nil | ||
} | ||
|
||
// DeleteRecords deletes DNS records from the zone. | ||
func (MockDNSProvider) DeleteRecords(ctx context.Context, zone string, recs []libdns.Record) ([]libdns.Record, error) { | ||
return nil, nil | ||
} | ||
|
||
// GetRecords gets DNS records from the zone. | ||
func (MockDNSProvider) GetRecords(ctx context.Context, zone string) ([]libdns.Record, error) { | ||
return nil, nil | ||
} | ||
|
||
// SetRecords sets DNS records in the zone. | ||
func (MockDNSProvider) SetRecords(ctx context.Context, zone string, recs []libdns.Record) ([]libdns.Record, error) { | ||
return nil, nil | ||
} | ||
|
||
// Interface guard | ||
var _ caddyfile.Unmarshaler = (*MockDNSProvider)(nil) | ||
var _ certmagic.DNSProvider = (*MockDNSProvider)(nil) | ||
var _ caddy.Provisioner = (*MockDNSProvider)(nil) | ||
var _ caddy.Module = (*MockDNSProvider)(nil) |