-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathfake_uaa_server_test.go
More file actions
54 lines (45 loc) · 1.34 KB
/
fake_uaa_server_test.go
File metadata and controls
54 lines (45 loc) · 1.34 KB
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
package trafficcontroller_test
import (
"encoding/json"
"net/http"
)
type FakeUaaHandler struct {
}
func (h *FakeUaaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/check_token" {
w.WriteHeader(http.StatusNotFound)
return
}
if r.Header.Get("Authorization") != "Basic Ym9iOnlvdXJVbmNsZQ==" {
w.WriteHeader(http.StatusUnauthorized)
_, _ = w.Write([]byte("{\"error\":\"unauthorized\",\"error_description\":\"No client with requested id: wrongUser\"}"))
return
}
token := r.FormValue("token") //nolint:gosec
switch token {
case "iAmAnAdmin":
authData := map[string]interface{}{
"scope": []string{
"doppler.firehose",
},
}
marshaled, _ := json.Marshal(authData)
_, _ = w.Write(marshaled)
case "iAmNotAnAdmin":
authData := map[string]interface{}{
"scope": []string{
"uaa.not-admin",
},
}
marshaled, _ := json.Marshal(authData)
_, _ = w.Write(marshaled)
case "expiredToken":
w.WriteHeader(http.StatusBadRequest)
_, _ = w.Write([]byte("{\"error\":\"invalid_token\",\"error_description\":\"Token has expired\"}"))
case "invalidToken":
w.WriteHeader(http.StatusBadRequest)
_, _ = w.Write([]byte("{\"invalidToken\":\"invalid_token\",\"error_description\":\"Invalid token (could not decode): invalidToken\"}"))
default:
w.WriteHeader(http.StatusInternalServerError)
}
}