2020-03-23 08:08:02 +08:00
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/caddyserver/caddy/v2/caddytest"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDefaultSNI(t *testing.T) {
|
|
|
|
// arrange
|
2020-04-27 09:23:46 +08:00
|
|
|
tester := caddytest.NewTester(t)
|
|
|
|
tester.InitServer(`{
|
2022-09-25 03:00:55 +08:00
|
|
|
"admin": {
|
|
|
|
"listen": "localhost:2999"
|
|
|
|
},
|
|
|
|
"apps": {
|
|
|
|
"http": {
|
|
|
|
"http_port": 9080,
|
|
|
|
"https_port": 9443,
|
|
|
|
"grace_period": 1,
|
|
|
|
"servers": {
|
|
|
|
"srv0": {
|
|
|
|
"listen": [
|
|
|
|
":9443"
|
|
|
|
],
|
|
|
|
"routes": [
|
|
|
|
{
|
|
|
|
"handle": [
|
|
|
|
{
|
|
|
|
"handler": "subroute",
|
|
|
|
"routes": [
|
|
|
|
{
|
|
|
|
"handle": [
|
|
|
|
{
|
|
|
|
"body": "hello from a.caddy.localhost",
|
|
|
|
"handler": "static_response",
|
|
|
|
"status_code": 200
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"match": [
|
|
|
|
{
|
|
|
|
"path": [
|
|
|
|
"/version"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"match": [
|
|
|
|
{
|
|
|
|
"host": [
|
|
|
|
"127.0.0.1"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"terminal": true
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"tls_connection_policies": [
|
|
|
|
{
|
|
|
|
"certificate_selection": {
|
|
|
|
"any_tag": ["cert0"]
|
|
|
|
},
|
|
|
|
"match": {
|
|
|
|
"sni": [
|
|
|
|
"127.0.0.1"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"default_sni": "*.caddy.localhost"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"tls": {
|
|
|
|
"certificates": {
|
|
|
|
"load_files": [
|
|
|
|
{
|
|
|
|
"certificate": "/caddy.localhost.crt",
|
|
|
|
"key": "/caddy.localhost.key",
|
|
|
|
"tags": [
|
|
|
|
"cert0"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"pki": {
|
|
|
|
"certificate_authorities" : {
|
|
|
|
"local" : {
|
|
|
|
"install_trust": false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, "json")
|
2020-03-23 08:08:02 +08:00
|
|
|
|
|
|
|
// act and assert
|
|
|
|
// makes a request with no sni
|
2020-10-03 04:23:40 +08:00
|
|
|
tester.AssertGetResponse("https://127.0.0.1:9443/version", 200, "hello from a.caddy.localhost")
|
2020-03-23 08:08:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultSNIWithNamedHostAndExplicitIP(t *testing.T) {
|
|
|
|
// arrange
|
2020-04-27 09:23:46 +08:00
|
|
|
tester := caddytest.NewTester(t)
|
|
|
|
tester.InitServer(`
|
2022-09-25 03:00:55 +08:00
|
|
|
{
|
|
|
|
"admin": {
|
|
|
|
"listen": "localhost:2999"
|
|
|
|
},
|
|
|
|
"apps": {
|
|
|
|
"http": {
|
|
|
|
"http_port": 9080,
|
|
|
|
"https_port": 9443,
|
|
|
|
"grace_period": 1,
|
|
|
|
"servers": {
|
|
|
|
"srv0": {
|
|
|
|
"listen": [
|
|
|
|
":9443"
|
|
|
|
],
|
|
|
|
"routes": [
|
|
|
|
{
|
|
|
|
"handle": [
|
|
|
|
{
|
|
|
|
"handler": "subroute",
|
|
|
|
"routes": [
|
|
|
|
{
|
|
|
|
"handle": [
|
|
|
|
{
|
|
|
|
"body": "hello from a",
|
|
|
|
"handler": "static_response",
|
|
|
|
"status_code": 200
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"match": [
|
|
|
|
{
|
|
|
|
"path": [
|
|
|
|
"/version"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"match": [
|
|
|
|
{
|
|
|
|
"host": [
|
|
|
|
"a.caddy.localhost",
|
|
|
|
"127.0.0.1"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"terminal": true
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"tls_connection_policies": [
|
|
|
|
{
|
|
|
|
"certificate_selection": {
|
|
|
|
"any_tag": ["cert0"]
|
|
|
|
},
|
|
|
|
"default_sni": "a.caddy.localhost",
|
|
|
|
"match": {
|
|
|
|
"sni": [
|
|
|
|
"a.caddy.localhost",
|
|
|
|
"127.0.0.1",
|
|
|
|
""
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"default_sni": "a.caddy.localhost"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"tls": {
|
|
|
|
"certificates": {
|
|
|
|
"load_files": [
|
|
|
|
{
|
|
|
|
"certificate": "/a.caddy.localhost.crt",
|
|
|
|
"key": "/a.caddy.localhost.key",
|
|
|
|
"tags": [
|
|
|
|
"cert0"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"pki": {
|
|
|
|
"certificate_authorities" : {
|
|
|
|
"local" : {
|
|
|
|
"install_trust": false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, "json")
|
2020-03-23 08:08:02 +08:00
|
|
|
|
|
|
|
// act and assert
|
|
|
|
// makes a request with no sni
|
2020-04-27 09:23:46 +08:00
|
|
|
tester.AssertGetResponse("https://127.0.0.1:9443/version", 200, "hello from a")
|
2020-03-23 08:08:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultSNIWithPortMappingOnly(t *testing.T) {
|
|
|
|
// arrange
|
2020-04-27 09:23:46 +08:00
|
|
|
tester := caddytest.NewTester(t)
|
|
|
|
tester.InitServer(`
|
2022-09-25 03:00:55 +08:00
|
|
|
{
|
|
|
|
"admin": {
|
|
|
|
"listen": "localhost:2999"
|
|
|
|
},
|
|
|
|
"apps": {
|
|
|
|
"http": {
|
|
|
|
"http_port": 9080,
|
|
|
|
"https_port": 9443,
|
|
|
|
"grace_period": 1,
|
|
|
|
"servers": {
|
|
|
|
"srv0": {
|
|
|
|
"listen": [
|
|
|
|
":9443"
|
|
|
|
],
|
|
|
|
"routes": [
|
|
|
|
{
|
|
|
|
"handle": [
|
|
|
|
{
|
|
|
|
"body": "hello from a.caddy.localhost",
|
|
|
|
"handler": "static_response",
|
|
|
|
"status_code": 200
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"match": [
|
|
|
|
{
|
|
|
|
"path": [
|
|
|
|
"/version"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"tls_connection_policies": [
|
|
|
|
{
|
|
|
|
"certificate_selection": {
|
|
|
|
"any_tag": ["cert0"]
|
|
|
|
},
|
|
|
|
"default_sni": "a.caddy.localhost"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"tls": {
|
|
|
|
"certificates": {
|
|
|
|
"load_files": [
|
|
|
|
{
|
|
|
|
"certificate": "/a.caddy.localhost.crt",
|
|
|
|
"key": "/a.caddy.localhost.key",
|
|
|
|
"tags": [
|
|
|
|
"cert0"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"pki": {
|
|
|
|
"certificate_authorities" : {
|
|
|
|
"local" : {
|
|
|
|
"install_trust": false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, "json")
|
2020-03-23 08:08:02 +08:00
|
|
|
|
|
|
|
// act and assert
|
|
|
|
// makes a request with no sni
|
2020-10-03 04:23:40 +08:00
|
|
|
tester.AssertGetResponse("https://127.0.0.1:9443/version", 200, "hello from a.caddy.localhost")
|
2020-03-23 08:08:02 +08:00
|
|
|
}
|
2020-04-10 02:39:05 +08:00
|
|
|
|
|
|
|
func TestHttpOnlyOnDomainWithSNI(t *testing.T) {
|
|
|
|
caddytest.AssertAdapt(t, `
|
|
|
|
{
|
2022-09-25 03:00:55 +08:00
|
|
|
skip_install_trust
|
2020-04-10 02:39:05 +08:00
|
|
|
default_sni a.caddy.localhost
|
|
|
|
}
|
|
|
|
:80 {
|
|
|
|
respond /version 200 {
|
|
|
|
body "hello from localhost"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, "caddyfile", `{
|
|
|
|
"apps": {
|
|
|
|
"http": {
|
|
|
|
"servers": {
|
|
|
|
"srv0": {
|
|
|
|
"listen": [
|
|
|
|
":80"
|
|
|
|
],
|
|
|
|
"routes": [
|
|
|
|
{
|
|
|
|
"match": [
|
|
|
|
{
|
|
|
|
"path": [
|
|
|
|
"/version"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"handle": [
|
|
|
|
{
|
|
|
|
"body": "hello from localhost",
|
|
|
|
"handler": "static_response",
|
|
|
|
"status_code": 200
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
2022-09-25 03:00:55 +08:00
|
|
|
},
|
|
|
|
"pki": {
|
|
|
|
"certificate_authorities": {
|
|
|
|
"local": {
|
|
|
|
"install_trust": false
|
|
|
|
}
|
|
|
|
}
|
2020-04-10 02:39:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}`)
|
|
|
|
}
|