-
Notifications
You must be signed in to change notification settings - Fork 929
/
fake_server.go
95 lines (86 loc) · 2.37 KB
/
fake_server.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
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
package helpers
import (
"fmt"
"net/http"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
. "github.com/onsi/gomega/ghttp"
)
func StartAndTargetServerWithoutV3API() *Server {
server := NewTLSServer()
server.AppendHandlers(
CombineHandlers(
VerifyRequest(http.MethodGet, "/v2/info"),
RespondWith(http.StatusOK, `{"api_version":"2.34.0"}`),
),
CombineHandlers(
VerifyRequest(http.MethodGet, "/"),
RespondWith(http.StatusNotFound, "{}"),
),
)
Eventually(CF("api", server.URL(), "--skip-ssl-validation")).Should(Exit(0))
return server
}
func StartAndTargetServerWithV3Version(v3Version string) *Server {
server := NewTLSServer()
rootResponse := fmt.Sprintf(`{
"links": {
"self": {
"href": "%[1]s"
},
"cloud_controller_v2": {
"href": "%[1]s/v2",
"meta": {
"version": "2.94.0"
}
},
"cloud_controller_v3": {
"href": "%[1]s/v3",
"meta": {
"version": "%[2]s"
}
},
"network_policy_v0": {
"href": "%[1]s/networking/v0/external"
},
"network_policy_v1": {
"href": "%[1]s/networking/v1/external"
},
"uaa": {
"href": "%[1]s"
},
"logging": {
"href": "wss://unused:443"
},
"app_ssh": {
"href": "unused:2222",
"meta": {
"host_key_fingerprint": "unused",
"oauth_client": "ssh-proxy"
}
}
}
}`, server.URL(), v3Version)
v2InfoResponse := fmt.Sprintf(`{
"api_version":"2.34.0",
"authorization_endpoint": "%[1]s"
}`, server.URL())
server.RouteToHandler(http.MethodGet, "/v2/info", func(res http.ResponseWriter, req *http.Request) {
res.WriteHeader(http.StatusOK)
res.Write([]byte(v2InfoResponse))
})
server.RouteToHandler(http.MethodGet, "/v3", func(res http.ResponseWriter, req *http.Request) {
res.WriteHeader(http.StatusOK)
res.Write([]byte(`{"links":{}}`))
})
server.RouteToHandler(http.MethodGet, "/login", func(res http.ResponseWriter, req *http.Request) {
res.WriteHeader(http.StatusOK)
res.Write([]byte(`{"links":{}}`))
})
server.RouteToHandler(http.MethodGet, "/", func(res http.ResponseWriter, req *http.Request) {
res.WriteHeader(http.StatusOK)
res.Write([]byte(rootResponse))
})
Eventually(CF("api", server.URL(), "--skip-ssl-validation")).Should(Exit(0))
return server
}