1
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-16 21:56:40 -05:00

ci: fix integration tests (#5079)

This commit is contained in:
Mohammed Al Sahaf 2022-09-24 22:00:55 +03:00 committed by GitHub
parent 7041970059
commit b5727b9c44
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 379 additions and 248 deletions

View file

@ -237,7 +237,7 @@ func validateTestPrerequisites() error {
if isCaddyAdminRunning() != nil { if isCaddyAdminRunning() != nil {
// start inprocess caddy server // start inprocess caddy server
os.Args = []string{"caddy", "run"} os.Args = []string{"caddy", "run", "--config", "./test.init.config", "--adapter", "caddyfile"}
go func() { go func() {
caddycmd.Main() caddycmd.Main()
}() }()

View file

@ -11,6 +11,8 @@ func TestAutoHTTPtoHTTPSRedirectsImplicitPort(t *testing.T) {
tester := caddytest.NewTester(t) tester := caddytest.NewTester(t)
tester.InitServer(` tester.InitServer(`
{ {
admin localhost:2999
skip_install_trust
http_port 9080 http_port 9080
https_port 9443 https_port 9443
} }
@ -25,6 +27,8 @@ func TestAutoHTTPtoHTTPSRedirectsExplicitPortSameAsHTTPSPort(t *testing.T) {
tester := caddytest.NewTester(t) tester := caddytest.NewTester(t)
tester.InitServer(` tester.InitServer(`
{ {
skip_install_trust
admin localhost:2999
http_port 9080 http_port 9080
https_port 9443 https_port 9443
} }
@ -39,6 +43,8 @@ func TestAutoHTTPtoHTTPSRedirectsExplicitPortDifferentFromHTTPSPort(t *testing.T
tester := caddytest.NewTester(t) tester := caddytest.NewTester(t)
tester.InitServer(` tester.InitServer(`
{ {
skip_install_trust
admin localhost:2999
http_port 9080 http_port 9080
https_port 9443 https_port 9443
} }
@ -53,6 +59,9 @@ func TestAutoHTTPRedirectsWithHTTPListenerFirstInAddresses(t *testing.T) {
tester := caddytest.NewTester(t) tester := caddytest.NewTester(t)
tester.InitServer(` tester.InitServer(`
{ {
"admin": {
"listen": "localhost:2999"
},
"apps": { "apps": {
"http": { "http": {
"http_port": 9080, "http_port": 9080,
@ -74,7 +83,14 @@ func TestAutoHTTPRedirectsWithHTTPListenerFirstInAddresses(t *testing.T) {
] ]
} }
} }
} },
"pki": {
"certificate_authorities": {
"local": {
"install_trust": false
}
}
}
} }
} }
`, "json") `, "json")
@ -85,6 +101,8 @@ func TestAutoHTTPRedirectsInsertedBeforeUserDefinedCatchAll(t *testing.T) {
tester := caddytest.NewTester(t) tester := caddytest.NewTester(t)
tester.InitServer(` tester.InitServer(`
{ {
skip_install_trust
admin localhost:2999
http_port 9080 http_port 9080
https_port 9443 https_port 9443
local_certs local_certs
@ -108,6 +126,8 @@ func TestAutoHTTPRedirectsInsertedBeforeUserDefinedCatchAllWithNoExplicitHTTPSit
tester := caddytest.NewTester(t) tester := caddytest.NewTester(t)
tester.InitServer(` tester.InitServer(`
{ {
skip_install_trust
admin localhost:2999
http_port 9080 http_port 9080
https_port 9443 https_port 9443
local_certs local_certs

View file

@ -14,9 +14,10 @@ func TestRespond(t *testing.T) {
tester := caddytest.NewTester(t) tester := caddytest.NewTester(t)
tester.InitServer(` tester.InitServer(`
{ {
admin localhost:2999
http_port 9080 http_port 9080
https_port 9443 https_port 9443
grace_period 1 grace_period 1ns
} }
localhost:9080 { localhost:9080 {
@ -36,9 +37,10 @@ func TestRedirect(t *testing.T) {
tester := caddytest.NewTester(t) tester := caddytest.NewTester(t)
tester.InitServer(` tester.InitServer(`
{ {
admin localhost:2999
http_port 9080 http_port 9080
https_port 9443 https_port 9443
grace_period 1 grace_period 1ns
} }
localhost:9080 { localhost:9080 {
@ -86,9 +88,11 @@ func TestReadCookie(t *testing.T) {
tester.Client.Jar.SetCookies(localhost, []*http.Cookie{&cookie}) tester.Client.Jar.SetCookies(localhost, []*http.Cookie{&cookie})
tester.InitServer(` tester.InitServer(`
{ {
skip_install_trust
admin localhost:2999
http_port 9080 http_port 9080
https_port 9443 https_port 9443
grace_period 1 grace_period 1ns
} }
localhost:9080 { localhost:9080 {
@ -110,9 +114,11 @@ func TestReplIndex(t *testing.T) {
tester := caddytest.NewTester(t) tester := caddytest.NewTester(t)
tester.InitServer(` tester.InitServer(`
{ {
skip_install_trust
admin localhost:2999
http_port 9080 http_port 9080
https_port 9443 https_port 9443
grace_period 1 grace_period 1ns
} }
localhost:9080 { localhost:9080 {

View file

@ -11,9 +11,11 @@ func TestBrowse(t *testing.T) {
tester := caddytest.NewTester(t) tester := caddytest.NewTester(t)
tester.InitServer(` tester.InitServer(`
{ {
skip_install_trust
admin localhost:2999
http_port 9080 http_port 9080
https_port 9443 https_port 9443
grace_period 1 grace_period 1ns
} }
http://localhost:9080 { http://localhost:9080 {
file_server browse file_server browse

View file

@ -11,9 +11,11 @@ func TestMap(t *testing.T) {
// arrange // arrange
tester := caddytest.NewTester(t) tester := caddytest.NewTester(t)
tester.InitServer(`{ tester.InitServer(`{
skip_install_trust
admin localhost:2999
http_port 9080 http_port 9080
https_port 9443 https_port 9443
grace_period 1 grace_period 1ns
} }
localhost:9080 { localhost:9080 {
@ -39,6 +41,8 @@ func TestMapRespondWithDefault(t *testing.T) {
// arrange // arrange
tester := caddytest.NewTester(t) tester := caddytest.NewTester(t)
tester.InitServer(`{ tester.InitServer(`{
skip_install_trust
admin localhost:2999
http_port 9080 http_port 9080
https_port 9443 https_port 9443
} }
@ -66,7 +70,17 @@ func TestMapAsJSON(t *testing.T) {
tester := caddytest.NewTester(t) tester := caddytest.NewTester(t)
tester.InitServer(` tester.InitServer(`
{ {
"admin": {
"listen": "localhost:2999"
},
"apps": { "apps": {
"pki": {
"certificate_authorities" : {
"local" : {
"install_trust": false
}
}
},
"http": { "http": {
"http_port": 9080, "http_port": 9080,
"https_port": 9443, "https_port": 9443,

View file

@ -16,7 +16,17 @@ func TestSRVReverseProxy(t *testing.T) {
tester := caddytest.NewTester(t) tester := caddytest.NewTester(t)
tester.InitServer(` tester.InitServer(`
{ {
"admin": {
"listen": "localhost:2999"
},
"apps": { "apps": {
"pki": {
"certificate_authorities" : {
"local" : {
"install_trust": false
}
}
},
"http": { "http": {
"grace_period": 1, "grace_period": 1,
"servers": { "servers": {
@ -50,6 +60,13 @@ func TestSRVWithDial(t *testing.T) {
caddytest.AssertLoadError(t, ` caddytest.AssertLoadError(t, `
{ {
"apps": { "apps": {
"pki": {
"certificate_authorities" : {
"local" : {
"install_trust": false
}
}
},
"http": { "http": {
"grace_period": 1, "grace_period": 1,
"servers": { "servers": {
@ -115,7 +132,17 @@ func TestDialWithPlaceholderUnix(t *testing.T) {
tester := caddytest.NewTester(t) tester := caddytest.NewTester(t)
tester.InitServer(` tester.InitServer(`
{ {
"admin": {
"listen": "localhost:2999"
},
"apps": { "apps": {
"pki": {
"certificate_authorities" : {
"local" : {
"install_trust": false
}
}
},
"http": { "http": {
"grace_period": 1, "grace_period": 1,
"servers": { "servers": {
@ -157,7 +184,17 @@ func TestReverseProxyWithPlaceholderDialAddress(t *testing.T) {
tester := caddytest.NewTester(t) tester := caddytest.NewTester(t)
tester.InitServer(` tester.InitServer(`
{ {
"admin": {
"listen": "localhost:2999"
},
"apps": { "apps": {
"pki": {
"certificate_authorities" : {
"local" : {
"install_trust": false
}
}
},
"http": { "http": {
"grace_period": 1, "grace_period": 1,
"servers": { "servers": {
@ -241,7 +278,17 @@ func TestReverseProxyWithPlaceholderTCPDialAddress(t *testing.T) {
tester := caddytest.NewTester(t) tester := caddytest.NewTester(t)
tester.InitServer(` tester.InitServer(`
{ {
"admin": {
"listen": "localhost:2999"
},
"apps": { "apps": {
"pki": {
"certificate_authorities" : {
"local" : {
"install_trust": false
}
}
},
"http": { "http": {
"grace_period": 1, "grace_period": 1,
"servers": { "servers": {
@ -325,6 +372,13 @@ func TestSRVWithActiveHealthcheck(t *testing.T) {
caddytest.AssertLoadError(t, ` caddytest.AssertLoadError(t, `
{ {
"apps": { "apps": {
"pki": {
"certificate_authorities" : {
"local" : {
"install_trust": false
}
}
},
"http": { "http": {
"grace_period": 1, "grace_period": 1,
"servers": { "servers": {
@ -363,8 +417,11 @@ func TestReverseProxyHealthCheck(t *testing.T) {
tester := caddytest.NewTester(t) tester := caddytest.NewTester(t)
tester.InitServer(` tester.InitServer(`
{ {
skip_install_trust
admin localhost:2999
http_port 9080 http_port 9080
https_port 9443 https_port 9443
grace_period 1ns
} }
http://localhost:2020 { http://localhost:2020 {
respond "Hello, World!" respond "Hello, World!"
@ -424,8 +481,11 @@ func TestReverseProxyHealthCheckUnixSocket(t *testing.T) {
tester.InitServer(fmt.Sprintf(` tester.InitServer(fmt.Sprintf(`
{ {
skip_install_trust
admin localhost:2999
http_port 9080 http_port 9080
https_port 9443 https_port 9443
grace_period 1ns
} }
http://localhost:9080 { http://localhost:9080 {
reverse_proxy { reverse_proxy {
@ -479,8 +539,11 @@ func TestReverseProxyHealthCheckUnixSocketWithoutPort(t *testing.T) {
tester.InitServer(fmt.Sprintf(` tester.InitServer(fmt.Sprintf(`
{ {
skip_install_trust
admin localhost:2999
http_port 9080 http_port 9080
https_port 9443 https_port 9443
grace_period 1ns
} }
http://localhost:9080 { http://localhost:9080 {
reverse_proxy { reverse_proxy {

View file

@ -11,92 +11,95 @@ func TestDefaultSNI(t *testing.T) {
// arrange // arrange
tester := caddytest.NewTester(t) tester := caddytest.NewTester(t)
tester.InitServer(`{ tester.InitServer(`{
"apps": { "admin": {
"http": { "listen": "localhost:2999"
"http_port": 9080, },
"https_port": 9443, "apps": {
"grace_period": 1, "http": {
"servers": { "http_port": 9080,
"srv0": { "https_port": 9443,
"listen": [ "grace_period": 1,
":9443" "servers": {
], "srv0": {
"routes": [ "listen": [
{ ":9443"
"handle": [ ],
{ "routes": [
"handler": "subroute", {
"routes": [ "handle": [
{ {
"handle": [ "handler": "subroute",
{ "routes": [
"body": "hello from a.caddy.localhost", {
"handler": "static_response", "handle": [
"status_code": 200 {
} "body": "hello from a.caddy.localhost",
], "handler": "static_response",
"match": [ "status_code": 200
{ }
"path": [ ],
"/version" "match": [
] {
} "path": [
] "/version"
} ]
] }
} ]
], }
"match": [ ]
{ }
"host": [ ],
"127.0.0.1" "match": [
] {
} "host": [
], "127.0.0.1"
"terminal": true ]
} }
], ],
"tls_connection_policies": [ "terminal": true
{ }
"certificate_selection": { ],
"any_tag": ["cert0"] "tls_connection_policies": [
}, {
"match": { "certificate_selection": {
"sni": [ "any_tag": ["cert0"]
"127.0.0.1" },
] "match": {
} "sni": [
}, "127.0.0.1"
{ ]
"default_sni": "*.caddy.localhost" }
} },
] {
} "default_sni": "*.caddy.localhost"
} }
}, ]
"tls": { }
"certificates": { }
"load_files": [ },
{ "tls": {
"certificate": "/caddy.localhost.crt", "certificates": {
"key": "/caddy.localhost.key", "load_files": [
"tags": [ {
"cert0" "certificate": "/caddy.localhost.crt",
] "key": "/caddy.localhost.key",
} "tags": [
] "cert0"
} ]
}, }
"pki": { ]
"certificate_authorities" : { }
"local" : { },
"install_trust": false "pki": {
} "certificate_authorities" : {
} "local" : {
} "install_trust": false
} }
} }
`, "json") }
}
}
`, "json")
// act and assert // act and assert
// makes a request with no sni // makes a request with no sni
@ -108,97 +111,100 @@ func TestDefaultSNIWithNamedHostAndExplicitIP(t *testing.T) {
// arrange // arrange
tester := caddytest.NewTester(t) tester := caddytest.NewTester(t)
tester.InitServer(` tester.InitServer(`
{ {
"apps": { "admin": {
"http": { "listen": "localhost:2999"
"http_port": 9080, },
"https_port": 9443, "apps": {
"grace_period": 1, "http": {
"servers": { "http_port": 9080,
"srv0": { "https_port": 9443,
"listen": [ "grace_period": 1,
":9443" "servers": {
], "srv0": {
"routes": [ "listen": [
{ ":9443"
"handle": [ ],
{ "routes": [
"handler": "subroute", {
"routes": [ "handle": [
{ {
"handle": [ "handler": "subroute",
{ "routes": [
"body": "hello from a", {
"handler": "static_response", "handle": [
"status_code": 200 {
} "body": "hello from a",
], "handler": "static_response",
"match": [ "status_code": 200
{ }
"path": [ ],
"/version" "match": [
] {
} "path": [
] "/version"
} ]
] }
} ]
], }
"match": [ ]
{ }
"host": [ ],
"a.caddy.localhost", "match": [
"127.0.0.1" {
] "host": [
} "a.caddy.localhost",
], "127.0.0.1"
"terminal": true ]
} }
], ],
"tls_connection_policies": [ "terminal": true
{ }
"certificate_selection": { ],
"any_tag": ["cert0"] "tls_connection_policies": [
}, {
"default_sni": "a.caddy.localhost", "certificate_selection": {
"match": { "any_tag": ["cert0"]
"sni": [ },
"a.caddy.localhost", "default_sni": "a.caddy.localhost",
"127.0.0.1", "match": {
"" "sni": [
] "a.caddy.localhost",
} "127.0.0.1",
}, ""
{ ]
"default_sni": "a.caddy.localhost" }
} },
] {
} "default_sni": "a.caddy.localhost"
} }
}, ]
"tls": { }
"certificates": { }
"load_files": [ },
{ "tls": {
"certificate": "/a.caddy.localhost.crt", "certificates": {
"key": "/a.caddy.localhost.key", "load_files": [
"tags": [ {
"cert0" "certificate": "/a.caddy.localhost.crt",
] "key": "/a.caddy.localhost.key",
} "tags": [
] "cert0"
} ]
}, }
"pki": { ]
"certificate_authorities" : { }
"local" : { },
"install_trust": false "pki": {
} "certificate_authorities" : {
} "local" : {
} "install_trust": false
} }
} }
`, "json") }
}
}
`, "json")
// act and assert // act and assert
// makes a request with no sni // makes a request with no sni
@ -209,69 +215,72 @@ func TestDefaultSNIWithPortMappingOnly(t *testing.T) {
// arrange // arrange
tester := caddytest.NewTester(t) tester := caddytest.NewTester(t)
tester.InitServer(` tester.InitServer(`
{ {
"apps": { "admin": {
"http": { "listen": "localhost:2999"
"http_port": 9080, },
"https_port": 9443, "apps": {
"grace_period": 1, "http": {
"servers": { "http_port": 9080,
"srv0": { "https_port": 9443,
"listen": [ "grace_period": 1,
":9443" "servers": {
], "srv0": {
"routes": [ "listen": [
{ ":9443"
"handle": [ ],
{ "routes": [
"body": "hello from a.caddy.localhost", {
"handler": "static_response", "handle": [
"status_code": 200 {
} "body": "hello from a.caddy.localhost",
], "handler": "static_response",
"match": [ "status_code": 200
{ }
"path": [ ],
"/version" "match": [
] {
} "path": [
] "/version"
} ]
], }
"tls_connection_policies": [ ]
{ }
"certificate_selection": { ],
"any_tag": ["cert0"] "tls_connection_policies": [
}, {
"default_sni": "a.caddy.localhost" "certificate_selection": {
} "any_tag": ["cert0"]
] },
} "default_sni": "a.caddy.localhost"
} }
}, ]
"tls": { }
"certificates": { }
"load_files": [ },
{ "tls": {
"certificate": "/a.caddy.localhost.crt", "certificates": {
"key": "/a.caddy.localhost.key", "load_files": [
"tags": [ {
"cert0" "certificate": "/a.caddy.localhost.crt",
] "key": "/a.caddy.localhost.key",
} "tags": [
] "cert0"
} ]
}, }
"pki": { ]
"certificate_authorities" : { }
"local" : { },
"install_trust": false "pki": {
} "certificate_authorities" : {
} "local" : {
} "install_trust": false
} }
} }
`, "json") }
}
}
`, "json")
// act and assert // act and assert
// makes a request with no sni // makes a request with no sni
@ -281,6 +290,7 @@ func TestDefaultSNIWithPortMappingOnly(t *testing.T) {
func TestHttpOnlyOnDomainWithSNI(t *testing.T) { func TestHttpOnlyOnDomainWithSNI(t *testing.T) {
caddytest.AssertAdapt(t, ` caddytest.AssertAdapt(t, `
{ {
skip_install_trust
default_sni a.caddy.localhost default_sni a.caddy.localhost
} }
:80 { :80 {
@ -316,6 +326,13 @@ func TestHttpOnlyOnDomainWithSNI(t *testing.T) {
] ]
} }
} }
},
"pki": {
"certificate_authorities": {
"local": {
"install_trust": false
}
}
} }
} }
}`) }`)

View file

@ -23,6 +23,9 @@ func TestH2ToH2CStream(t *testing.T) {
tester := caddytest.NewTester(t) tester := caddytest.NewTester(t)
tester.InitServer(` tester.InitServer(`
{ {
"admin": {
"listen": "localhost:2999"
},
"apps": { "apps": {
"http": { "http": {
"http_port": 9080, "http_port": 9080,
@ -206,6 +209,9 @@ func TestH2ToH1ChunkedResponse(t *testing.T) {
tester := caddytest.NewTester(t) tester := caddytest.NewTester(t)
tester.InitServer(` tester.InitServer(`
{ {
"admin": {
"listen": "localhost:2999"
},
"logging": { "logging": {
"logs": { "logs": {
"default": { "default": {

View file

@ -0,0 +1,3 @@
{
admin localhost:2999
}