summaryrefslogtreecommitdiff
path: root/caddytest/integration
diff options
context:
space:
mode:
authorMark Sargent <99003+sarge@users.noreply.github.com>2020-04-27 13:23:46 +1200
committerGitHub <noreply@github.com>2020-04-27 13:23:46 +1200
commit570d84f7d3642b85f96906ceab6402678177949e (patch)
treee16c2693b8ec69bb95163fc389f4939ecc9150dc /caddytest/integration
parenta6761153cbbf4547b9c0a76656d74f1401067205 (diff)
refactored caddytest helpers (#3285)
* refactored caddytest helpers * added cookie jar support. Added support for more http verbs
Diffstat (limited to 'caddytest/integration')
-rw-r--r--caddytest/integration/caddyfile_test.go45
-rw-r--r--caddytest/integration/sni_test.go15
-rw-r--r--caddytest/integration/testdata/cookie.html1
3 files changed, 50 insertions, 11 deletions
diff --git a/caddytest/integration/caddyfile_test.go b/caddytest/integration/caddyfile_test.go
index dd3dcba..4e9bdd9 100644
--- a/caddytest/integration/caddyfile_test.go
+++ b/caddytest/integration/caddyfile_test.go
@@ -1,6 +1,8 @@
package integration
import (
+ "net/http"
+ "net/url"
"testing"
"github.com/caddyserver/caddy/v2/caddytest"
@@ -9,7 +11,8 @@ import (
func TestRespond(t *testing.T) {
// arrange
- caddytest.InitServer(t, `
+ tester := caddytest.NewTester(t)
+ tester.InitServer(`
{
http_port 9080
https_port 9443
@@ -23,13 +26,14 @@ func TestRespond(t *testing.T) {
`, "caddyfile")
// act and assert
- caddytest.AssertGetResponse(t, "http://localhost:9080/version", 200, "hello from localhost")
+ tester.AssertGetResponse("http://localhost:9080/version", 200, "hello from localhost")
}
func TestRedirect(t *testing.T) {
// arrange
- caddytest.InitServer(t, `
+ tester := caddytest.NewTester(t)
+ tester.InitServer(`
{
http_port 9080
https_port 9443
@@ -46,10 +50,10 @@ func TestRedirect(t *testing.T) {
`, "caddyfile")
// act and assert
- caddytest.AssertRedirect(t, "http://localhost:9080/", "http://localhost:9080/hello", 301)
+ tester.AssertRedirect("http://localhost:9080/", "http://localhost:9080/hello", 301)
// follow redirect
- caddytest.AssertGetResponse(t, "http://localhost:9080/", 200, "hello from localhost")
+ tester.AssertGetResponse("http://localhost:9080/", 200, "hello from localhost")
}
func TestDuplicateHosts(t *testing.T) {
@@ -66,3 +70,34 @@ func TestDuplicateHosts(t *testing.T) {
"caddyfile",
"duplicate site address not allowed")
}
+
+func TestReadCookie(t *testing.T) {
+
+ localhost, _ := url.Parse("http://localhost")
+ cookie := http.Cookie{
+ Name: "clientname",
+ Value: "caddytest",
+ }
+
+ // arrange
+ tester := caddytest.NewTester(t)
+ tester.Client.Jar.SetCookies(localhost, []*http.Cookie{&cookie})
+ tester.InitServer(`
+ {
+ http_port 9080
+ https_port 9443
+ }
+
+ localhost:9080 {
+ templates {
+ root testdata
+ }
+ file_server {
+ root testdata
+ }
+ }
+ `, "caddyfile")
+
+ // act and assert
+ tester.AssertGetResponse("http://localhost:9080/cookie.html", 200, "<h2>Cookie.ClientName caddytest</h2>")
+}
diff --git a/caddytest/integration/sni_test.go b/caddytest/integration/sni_test.go
index f26131e..46f7c83 100644
--- a/caddytest/integration/sni_test.go
+++ b/caddytest/integration/sni_test.go
@@ -9,7 +9,8 @@ import (
func TestDefaultSNI(t *testing.T) {
// arrange
- caddytest.InitServer(t, `{
+ tester := caddytest.NewTester(t)
+ tester.InitServer(`{
"apps": {
"http": {
"http_port": 9080,
@@ -98,13 +99,14 @@ func TestDefaultSNI(t *testing.T) {
// act and assert
// makes a request with no sni
- caddytest.AssertGetResponse(t, "https://127.0.0.1:9443/version", 200, "hello from a")
+ tester.AssertGetResponse("https://127.0.0.1:9443/version", 200, "hello from a")
}
func TestDefaultSNIWithNamedHostAndExplicitIP(t *testing.T) {
// arrange
- caddytest.InitServer(t, `
+ tester := caddytest.NewTester(t)
+ tester.InitServer(`
{
"apps": {
"http": {
@@ -198,13 +200,14 @@ func TestDefaultSNIWithNamedHostAndExplicitIP(t *testing.T) {
// act and assert
// makes a request with no sni
- caddytest.AssertGetResponse(t, "https://127.0.0.1:9443/version", 200, "hello from a")
+ tester.AssertGetResponse("https://127.0.0.1:9443/version", 200, "hello from a")
}
func TestDefaultSNIWithPortMappingOnly(t *testing.T) {
// arrange
- caddytest.InitServer(t, `
+ tester := caddytest.NewTester(t)
+ tester.InitServer(`
{
"apps": {
"http": {
@@ -270,7 +273,7 @@ func TestDefaultSNIWithPortMappingOnly(t *testing.T) {
// act and assert
// makes a request with no sni
- caddytest.AssertGetResponse(t, "https://127.0.0.1:9443/version", 200, "hello from a")
+ tester.AssertGetResponse("https://127.0.0.1:9443/version", 200, "hello from a")
}
func TestHttpOnlyOnDomainWithSNI(t *testing.T) {
diff --git a/caddytest/integration/testdata/cookie.html b/caddytest/integration/testdata/cookie.html
new file mode 100644
index 0000000..fa53a39
--- /dev/null
+++ b/caddytest/integration/testdata/cookie.html
@@ -0,0 +1 @@
+<h2>Cookie.ClientName {{.Cookie "clientname"}}</h2> \ No newline at end of file