2020-09-08 11:45:48 -05:00
|
|
|
package integration
|
|
|
|
|
|
|
|
import (
|
2024-04-18 15:31:00 -05:00
|
|
|
"bytes"
|
2020-09-08 11:45:48 -05:00
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/caddyserver/caddy/v2/caddytest"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestBrowse(t *testing.T) {
|
|
|
|
tester := caddytest.NewTester(t)
|
|
|
|
tester.InitServer(`
|
|
|
|
{
|
2022-09-24 14:00:55 -05:00
|
|
|
skip_install_trust
|
|
|
|
admin localhost:2999
|
2020-09-08 11:45:48 -05:00
|
|
|
http_port 9080
|
|
|
|
https_port 9443
|
2022-09-24 14:00:55 -05:00
|
|
|
grace_period 1ns
|
2020-09-08 11:45:48 -05:00
|
|
|
}
|
|
|
|
http://localhost:9080 {
|
|
|
|
file_server browse
|
|
|
|
}
|
|
|
|
`, "caddyfile")
|
|
|
|
|
|
|
|
req, err := http.NewRequest(http.MethodGet, "http://localhost:9080/", nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fail()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
tester.AssertResponseCode(req, 200)
|
|
|
|
}
|
2024-04-18 15:31:00 -05:00
|
|
|
|
|
|
|
func TestRespondWithJSON(t *testing.T) {
|
|
|
|
tester := caddytest.NewTester(t)
|
|
|
|
tester.InitServer(`
|
|
|
|
{
|
|
|
|
skip_install_trust
|
|
|
|
admin localhost:2999
|
|
|
|
http_port 9080
|
|
|
|
https_port 9443
|
|
|
|
grace_period 1ns
|
|
|
|
}
|
|
|
|
localhost {
|
|
|
|
respond {http.request.body}
|
|
|
|
}
|
|
|
|
`, "caddyfile")
|
|
|
|
|
|
|
|
res, _ := tester.AssertPostResponseBody("https://localhost:9443/",
|
|
|
|
nil,
|
|
|
|
bytes.NewBufferString(`{
|
|
|
|
"greeting": "Hello, world!"
|
|
|
|
}`), 200, `{
|
|
|
|
"greeting": "Hello, world!"
|
|
|
|
}`)
|
|
|
|
if res.Header.Get("Content-Type") != "application/json" {
|
|
|
|
t.Errorf("expected Content-Type to be application/json, but was %s", res.Header.Get("Content-Type"))
|
|
|
|
}
|
|
|
|
}
|