-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdefault_https_server_integration_test.go
53 lines (45 loc) · 1.46 KB
/
default_https_server_integration_test.go
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
// Copyright 2016 struktur AG. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package phoenix
import (
"crypto/tls"
"io/ioutil"
"net/http"
"testing"
)
var okHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("ok"))
})
func simpleTLSRunFunc(runtime Runtime) error {
runtime.DefaultHTTPSHandler(okHandler)
return runtime.Start()
}
func Test_Server_DefaultTLSServer_IsConnectableAfterStartup(t *testing.T) {
// NOTE(lcooper): simply making requests to localhost is far easier
// than generating a cert with an IP SAN. If this changes, feel free
// to use 127.0.0.1 instead.
baseURL := "localhost:62001"
server := NewServer("integration-test", "unreleased").
OverrideOption("https", "listen", baseURL).
OverrideOption("https", "certificate", "testdata/server.crt").
OverrideOption("https", "key", "testdata/key.pem")
withTestServer(t, server, simpleTLSRunFunc, func() {
client := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
}
resp, err := client.Get("https://" + baseURL + "/")
if err != nil {
t.Errorf("unexpected error making HTTP request: %v", err)
}
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
t.Errorf("unexpected error reading response body: %v", err)
}
if string(data) != "ok" {
t.Errorf("Expected data to be 'ok', but was '%s'", data)
}
})
}