aboutsummaryrefslogtreecommitdiffhomepage
path: root/caddytest/caddytest_test.go
blob: d788a810b5e2102aef2cd83eca59b3dc4a606f01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package caddytest

import (
	"fmt"
	"net/http"
	"strings"
	"testing"
)

func TestReplaceCertificatePaths(t *testing.T) {
	rawConfig := `a.caddy.localhost:9443{
		tls /caddy.localhost.crt /caddy.localhost.key {
		}

		redir / https://b.caddy.localhost:9443/version 301

		respond /version 200 {
		  body "hello from a.caddy.localhost"
		}
	  }`

	r := prependCaddyFilePath(rawConfig)

	if !strings.Contains(r, getIntegrationDir()+"/caddy.localhost.crt") {
		t.Error("expected the /caddy.localhost.crt to be expanded to include the full path")
	}

	if !strings.Contains(r, getIntegrationDir()+"/caddy.localhost.key") {
		t.Error("expected the /caddy.localhost.crt to be expanded to include the full path")
	}

	if !strings.Contains(r, "https://b.caddy.localhost:9443/version") {
		t.Error("expected redirect uri to be unchanged")
	}
}

func TestLoadUnorderedJSON(t *testing.T) {
	harness := StartHarness(t)
	harness.LoadConfig(`
	{
		"logging": {
			"logs": {
				"default": {
					"level": "DEBUG",
					"writer": {
						"output": "stdout"
					}
				},
				"sStdOutLogs": {
					"level": "DEBUG",
					"writer": {
						"output": "stdout"
					},
					"include": [
						"http.*",
						"admin.*"
					]
				},
				"sFileLogs": {
					"level": "DEBUG",
					"writer": {
						"output": "stdout"
					},
					"include": [
						"http.*",
						"admin.*"
					]
				}
			}
		},
		"admin": {
			"listen": "{$TESTING_CADDY_ADMIN_BIND}"
		},
		"apps": {
			"pki": {
				"certificate_authorities" : {
				  "local" : {
					"install_trust": false
				  }
				}
			},
			"http": {
				"http_port": {$TESTING_CADDY_PORT_ONE},
				"https_port": {$TESTING_CADDY_PORT_TWO},
				"servers": {
					"s_server": {
						"listen": [
							":{$TESTING_CADDY_PORT_ONE}",
							":{$TESTING_CADDY_PORT_TWO}"
						],
						"routes": [
							{
								"handle": [
									{
										"handler": "static_response",
										"body": "Hello"
									}
								]
							},
							{
								"match": [
									{
										"host": [
											"localhost",
											"127.0.0.1"
										]
									}
								]
							}
						],
						"logs": {
							"default_logger_name": "sStdOutLogs",
							"logger_names": {
								"localhost": "sStdOutLogs",
								"127.0.0.1": "sFileLogs"
							}
						}
					}
				}
			}
		}
	}
  `, "json")
	req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://localhost:%d/", harness.Tester().PortOne()), nil)
	if err != nil {
		t.Fail()
		return
	}
	harness.AssertResponseCode(req, 200)
}