Signed-off-by: John Howard <jhoward@microsoft.com>
| 1 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,233 +0,0 @@ |
| 1 |
-package authorization |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "encoding/json" |
|
| 5 |
- "io/ioutil" |
|
| 6 |
- "log" |
|
| 7 |
- "net" |
|
| 8 |
- "net/http" |
|
| 9 |
- "net/http/httptest" |
|
| 10 |
- "os" |
|
| 11 |
- "path" |
|
| 12 |
- "reflect" |
|
| 13 |
- "testing" |
|
| 14 |
- |
|
| 15 |
- "github.com/docker/docker/pkg/plugins" |
|
| 16 |
- "github.com/docker/go-connections/tlsconfig" |
|
| 17 |
- "github.com/gorilla/mux" |
|
| 18 |
-) |
|
| 19 |
- |
|
| 20 |
-const pluginAddress = "authzplugin.sock" |
|
| 21 |
- |
|
| 22 |
-func TestAuthZRequestPluginError(t *testing.T) {
|
|
| 23 |
- server := authZPluginTestServer{t: t}
|
|
| 24 |
- go server.start() |
|
| 25 |
- defer server.stop() |
|
| 26 |
- |
|
| 27 |
- authZPlugin := createTestPlugin(t) |
|
| 28 |
- |
|
| 29 |
- request := Request{
|
|
| 30 |
- User: "user", |
|
| 31 |
- RequestBody: []byte("sample body"),
|
|
| 32 |
- RequestURI: "www.authz.com", |
|
| 33 |
- RequestMethod: "GET", |
|
| 34 |
- RequestHeaders: map[string]string{"header": "value"},
|
|
| 35 |
- } |
|
| 36 |
- server.replayResponse = Response{
|
|
| 37 |
- Err: "an error", |
|
| 38 |
- } |
|
| 39 |
- |
|
| 40 |
- actualResponse, err := authZPlugin.AuthZRequest(&request) |
|
| 41 |
- if err != nil {
|
|
| 42 |
- t.Fatalf("Failed to authorize request %v", err)
|
|
| 43 |
- } |
|
| 44 |
- |
|
| 45 |
- if !reflect.DeepEqual(server.replayResponse, *actualResponse) {
|
|
| 46 |
- t.Fatalf("Response must be equal")
|
|
| 47 |
- } |
|
| 48 |
- if !reflect.DeepEqual(request, server.recordedRequest) {
|
|
| 49 |
- t.Fatalf("Requests must be equal")
|
|
| 50 |
- } |
|
| 51 |
-} |
|
| 52 |
- |
|
| 53 |
-func TestAuthZRequestPlugin(t *testing.T) {
|
|
| 54 |
- server := authZPluginTestServer{t: t}
|
|
| 55 |
- go server.start() |
|
| 56 |
- defer server.stop() |
|
| 57 |
- |
|
| 58 |
- authZPlugin := createTestPlugin(t) |
|
| 59 |
- |
|
| 60 |
- request := Request{
|
|
| 61 |
- User: "user", |
|
| 62 |
- RequestBody: []byte("sample body"),
|
|
| 63 |
- RequestURI: "www.authz.com", |
|
| 64 |
- RequestMethod: "GET", |
|
| 65 |
- RequestHeaders: map[string]string{"header": "value"},
|
|
| 66 |
- } |
|
| 67 |
- server.replayResponse = Response{
|
|
| 68 |
- Allow: true, |
|
| 69 |
- Msg: "Sample message", |
|
| 70 |
- } |
|
| 71 |
- |
|
| 72 |
- actualResponse, err := authZPlugin.AuthZRequest(&request) |
|
| 73 |
- if err != nil {
|
|
| 74 |
- t.Fatalf("Failed to authorize request %v", err)
|
|
| 75 |
- } |
|
| 76 |
- |
|
| 77 |
- if !reflect.DeepEqual(server.replayResponse, *actualResponse) {
|
|
| 78 |
- t.Fatalf("Response must be equal")
|
|
| 79 |
- } |
|
| 80 |
- if !reflect.DeepEqual(request, server.recordedRequest) {
|
|
| 81 |
- t.Fatalf("Requests must be equal")
|
|
| 82 |
- } |
|
| 83 |
-} |
|
| 84 |
- |
|
| 85 |
-func TestAuthZResponsePlugin(t *testing.T) {
|
|
| 86 |
- server := authZPluginTestServer{t: t}
|
|
| 87 |
- go server.start() |
|
| 88 |
- defer server.stop() |
|
| 89 |
- |
|
| 90 |
- authZPlugin := createTestPlugin(t) |
|
| 91 |
- |
|
| 92 |
- request := Request{
|
|
| 93 |
- User: "user", |
|
| 94 |
- RequestBody: []byte("sample body"),
|
|
| 95 |
- } |
|
| 96 |
- server.replayResponse = Response{
|
|
| 97 |
- Allow: true, |
|
| 98 |
- Msg: "Sample message", |
|
| 99 |
- } |
|
| 100 |
- |
|
| 101 |
- actualResponse, err := authZPlugin.AuthZResponse(&request) |
|
| 102 |
- if err != nil {
|
|
| 103 |
- t.Fatalf("Failed to authorize request %v", err)
|
|
| 104 |
- } |
|
| 105 |
- |
|
| 106 |
- if !reflect.DeepEqual(server.replayResponse, *actualResponse) {
|
|
| 107 |
- t.Fatalf("Response must be equal")
|
|
| 108 |
- } |
|
| 109 |
- if !reflect.DeepEqual(request, server.recordedRequest) {
|
|
| 110 |
- t.Fatalf("Requests must be equal")
|
|
| 111 |
- } |
|
| 112 |
-} |
|
| 113 |
- |
|
| 114 |
-func TestResponseModifier(t *testing.T) {
|
|
| 115 |
- r := httptest.NewRecorder() |
|
| 116 |
- m := NewResponseModifier(r) |
|
| 117 |
- m.Header().Set("h1", "v1")
|
|
| 118 |
- m.Write([]byte("body"))
|
|
| 119 |
- m.WriteHeader(500) |
|
| 120 |
- |
|
| 121 |
- m.FlushAll() |
|
| 122 |
- if r.Header().Get("h1") != "v1" {
|
|
| 123 |
- t.Fatalf("Header value must exists %s", r.Header().Get("h1"))
|
|
| 124 |
- } |
|
| 125 |
- if !reflect.DeepEqual(r.Body.Bytes(), []byte("body")) {
|
|
| 126 |
- t.Fatalf("Body value must exists %s", r.Body.Bytes())
|
|
| 127 |
- } |
|
| 128 |
- if r.Code != 500 {
|
|
| 129 |
- t.Fatalf("Status code must be correct %d", r.Code)
|
|
| 130 |
- } |
|
| 131 |
-} |
|
| 132 |
- |
|
| 133 |
-func TestResponseModifierOverride(t *testing.T) {
|
|
| 134 |
- r := httptest.NewRecorder() |
|
| 135 |
- m := NewResponseModifier(r) |
|
| 136 |
- m.Header().Set("h1", "v1")
|
|
| 137 |
- m.Write([]byte("body"))
|
|
| 138 |
- m.WriteHeader(500) |
|
| 139 |
- |
|
| 140 |
- overrideHeader := make(http.Header) |
|
| 141 |
- overrideHeader.Add("h1", "v2")
|
|
| 142 |
- overrideHeaderBytes, err := json.Marshal(overrideHeader) |
|
| 143 |
- if err != nil {
|
|
| 144 |
- t.Fatalf("override header failed %v", err)
|
|
| 145 |
- } |
|
| 146 |
- |
|
| 147 |
- m.OverrideHeader(overrideHeaderBytes) |
|
| 148 |
- m.OverrideBody([]byte("override body"))
|
|
| 149 |
- m.OverrideStatusCode(404) |
|
| 150 |
- m.FlushAll() |
|
| 151 |
- if r.Header().Get("h1") != "v2" {
|
|
| 152 |
- t.Fatalf("Header value must exists %s", r.Header().Get("h1"))
|
|
| 153 |
- } |
|
| 154 |
- if !reflect.DeepEqual(r.Body.Bytes(), []byte("override body")) {
|
|
| 155 |
- t.Fatalf("Body value must exists %s", r.Body.Bytes())
|
|
| 156 |
- } |
|
| 157 |
- if r.Code != 404 {
|
|
| 158 |
- t.Fatalf("Status code must be correct %d", r.Code)
|
|
| 159 |
- } |
|
| 160 |
-} |
|
| 161 |
- |
|
| 162 |
-// createTestPlugin creates a new sample authorization plugin |
|
| 163 |
-func createTestPlugin(t *testing.T) *authorizationPlugin {
|
|
| 164 |
- plugin := &plugins.Plugin{Name: "authz"}
|
|
| 165 |
- pwd, err := os.Getwd() |
|
| 166 |
- if err != nil {
|
|
| 167 |
- log.Fatal(err) |
|
| 168 |
- } |
|
| 169 |
- |
|
| 170 |
- plugin.Client, err = plugins.NewClient("unix:///"+path.Join(pwd, pluginAddress), tlsconfig.Options{InsecureSkipVerify: true})
|
|
| 171 |
- if err != nil {
|
|
| 172 |
- t.Fatalf("Failed to create client %v", err)
|
|
| 173 |
- } |
|
| 174 |
- |
|
| 175 |
- return &authorizationPlugin{name: "plugin", plugin: plugin}
|
|
| 176 |
-} |
|
| 177 |
- |
|
| 178 |
-// AuthZPluginTestServer is a simple server that implements the authZ plugin interface |
|
| 179 |
-type authZPluginTestServer struct {
|
|
| 180 |
- listener net.Listener |
|
| 181 |
- t *testing.T |
|
| 182 |
- // request stores the request sent from the daemon to the plugin |
|
| 183 |
- recordedRequest Request |
|
| 184 |
- // response stores the response sent from the plugin to the daemon |
|
| 185 |
- replayResponse Response |
|
| 186 |
-} |
|
| 187 |
- |
|
| 188 |
-// start starts the test server that implements the plugin |
|
| 189 |
-func (t *authZPluginTestServer) start() {
|
|
| 190 |
- r := mux.NewRouter() |
|
| 191 |
- os.Remove(pluginAddress) |
|
| 192 |
- l, err := net.ListenUnix("unix", &net.UnixAddr{Name: pluginAddress, Net: "unix"})
|
|
| 193 |
- if err != nil {
|
|
| 194 |
- t.t.Fatalf("Failed to listen %v", err)
|
|
| 195 |
- } |
|
| 196 |
- t.listener = l |
|
| 197 |
- |
|
| 198 |
- r.HandleFunc("/Plugin.Activate", t.activate)
|
|
| 199 |
- r.HandleFunc("/"+AuthZApiRequest, t.auth)
|
|
| 200 |
- r.HandleFunc("/"+AuthZApiResponse, t.auth)
|
|
| 201 |
- t.listener, err = net.Listen("tcp", pluginAddress)
|
|
| 202 |
- server := http.Server{Handler: r, Addr: pluginAddress}
|
|
| 203 |
- server.Serve(l) |
|
| 204 |
-} |
|
| 205 |
- |
|
| 206 |
-// stop stops the test server that implements the plugin |
|
| 207 |
-func (t *authZPluginTestServer) stop() {
|
|
| 208 |
- os.Remove(pluginAddress) |
|
| 209 |
- if t.listener != nil {
|
|
| 210 |
- t.listener.Close() |
|
| 211 |
- } |
|
| 212 |
-} |
|
| 213 |
- |
|
| 214 |
-// auth is a used to record/replay the authentication api messages |
|
| 215 |
-func (t *authZPluginTestServer) auth(w http.ResponseWriter, r *http.Request) {
|
|
| 216 |
- t.recordedRequest = Request{}
|
|
| 217 |
- defer r.Body.Close() |
|
| 218 |
- body, err := ioutil.ReadAll(r.Body) |
|
| 219 |
- json.Unmarshal(body, &t.recordedRequest) |
|
| 220 |
- b, err := json.Marshal(t.replayResponse) |
|
| 221 |
- if err != nil {
|
|
| 222 |
- log.Fatal(err) |
|
| 223 |
- } |
|
| 224 |
- w.Write(b) |
|
| 225 |
-} |
|
| 226 |
- |
|
| 227 |
-func (t *authZPluginTestServer) activate(w http.ResponseWriter, r *http.Request) {
|
|
| 228 |
- b, err := json.Marshal(plugins.Manifest{Implements: []string{AuthZApiImplements}})
|
|
| 229 |
- if err != nil {
|
|
| 230 |
- log.Fatal(err) |
|
| 231 |
- } |
|
| 232 |
- w.Write(b) |
|
| 233 |
-} |
| 234 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,238 @@ |
| 0 |
+// +build !windows |
|
| 1 |
+ |
|
| 2 |
+// TODO Windows: This uses a Unix socket for testing. This might be possible |
|
| 3 |
+// to port to Windows using a named pipe instead. |
|
| 4 |
+ |
|
| 5 |
+package authorization |
|
| 6 |
+ |
|
| 7 |
+import ( |
|
| 8 |
+ "encoding/json" |
|
| 9 |
+ "io/ioutil" |
|
| 10 |
+ "log" |
|
| 11 |
+ "net" |
|
| 12 |
+ "net/http" |
|
| 13 |
+ "net/http/httptest" |
|
| 14 |
+ "os" |
|
| 15 |
+ "path" |
|
| 16 |
+ "reflect" |
|
| 17 |
+ "testing" |
|
| 18 |
+ |
|
| 19 |
+ "github.com/docker/docker/pkg/plugins" |
|
| 20 |
+ "github.com/docker/go-connections/tlsconfig" |
|
| 21 |
+ "github.com/gorilla/mux" |
|
| 22 |
+) |
|
| 23 |
+ |
|
| 24 |
+const pluginAddress = "authzplugin.sock" |
|
| 25 |
+ |
|
| 26 |
+func TestAuthZRequestPluginError(t *testing.T) {
|
|
| 27 |
+ server := authZPluginTestServer{t: t}
|
|
| 28 |
+ go server.start() |
|
| 29 |
+ defer server.stop() |
|
| 30 |
+ |
|
| 31 |
+ authZPlugin := createTestPlugin(t) |
|
| 32 |
+ |
|
| 33 |
+ request := Request{
|
|
| 34 |
+ User: "user", |
|
| 35 |
+ RequestBody: []byte("sample body"),
|
|
| 36 |
+ RequestURI: "www.authz.com", |
|
| 37 |
+ RequestMethod: "GET", |
|
| 38 |
+ RequestHeaders: map[string]string{"header": "value"},
|
|
| 39 |
+ } |
|
| 40 |
+ server.replayResponse = Response{
|
|
| 41 |
+ Err: "an error", |
|
| 42 |
+ } |
|
| 43 |
+ |
|
| 44 |
+ actualResponse, err := authZPlugin.AuthZRequest(&request) |
|
| 45 |
+ if err != nil {
|
|
| 46 |
+ t.Fatalf("Failed to authorize request %v", err)
|
|
| 47 |
+ } |
|
| 48 |
+ |
|
| 49 |
+ if !reflect.DeepEqual(server.replayResponse, *actualResponse) {
|
|
| 50 |
+ t.Fatalf("Response must be equal")
|
|
| 51 |
+ } |
|
| 52 |
+ if !reflect.DeepEqual(request, server.recordedRequest) {
|
|
| 53 |
+ t.Fatalf("Requests must be equal")
|
|
| 54 |
+ } |
|
| 55 |
+} |
|
| 56 |
+ |
|
| 57 |
+func TestAuthZRequestPlugin(t *testing.T) {
|
|
| 58 |
+ server := authZPluginTestServer{t: t}
|
|
| 59 |
+ go server.start() |
|
| 60 |
+ defer server.stop() |
|
| 61 |
+ |
|
| 62 |
+ authZPlugin := createTestPlugin(t) |
|
| 63 |
+ |
|
| 64 |
+ request := Request{
|
|
| 65 |
+ User: "user", |
|
| 66 |
+ RequestBody: []byte("sample body"),
|
|
| 67 |
+ RequestURI: "www.authz.com", |
|
| 68 |
+ RequestMethod: "GET", |
|
| 69 |
+ RequestHeaders: map[string]string{"header": "value"},
|
|
| 70 |
+ } |
|
| 71 |
+ server.replayResponse = Response{
|
|
| 72 |
+ Allow: true, |
|
| 73 |
+ Msg: "Sample message", |
|
| 74 |
+ } |
|
| 75 |
+ |
|
| 76 |
+ actualResponse, err := authZPlugin.AuthZRequest(&request) |
|
| 77 |
+ if err != nil {
|
|
| 78 |
+ t.Fatalf("Failed to authorize request %v", err)
|
|
| 79 |
+ } |
|
| 80 |
+ |
|
| 81 |
+ if !reflect.DeepEqual(server.replayResponse, *actualResponse) {
|
|
| 82 |
+ t.Fatalf("Response must be equal")
|
|
| 83 |
+ } |
|
| 84 |
+ if !reflect.DeepEqual(request, server.recordedRequest) {
|
|
| 85 |
+ t.Fatalf("Requests must be equal")
|
|
| 86 |
+ } |
|
| 87 |
+} |
|
| 88 |
+ |
|
| 89 |
+func TestAuthZResponsePlugin(t *testing.T) {
|
|
| 90 |
+ server := authZPluginTestServer{t: t}
|
|
| 91 |
+ go server.start() |
|
| 92 |
+ defer server.stop() |
|
| 93 |
+ |
|
| 94 |
+ authZPlugin := createTestPlugin(t) |
|
| 95 |
+ |
|
| 96 |
+ request := Request{
|
|
| 97 |
+ User: "user", |
|
| 98 |
+ RequestBody: []byte("sample body"),
|
|
| 99 |
+ } |
|
| 100 |
+ server.replayResponse = Response{
|
|
| 101 |
+ Allow: true, |
|
| 102 |
+ Msg: "Sample message", |
|
| 103 |
+ } |
|
| 104 |
+ |
|
| 105 |
+ actualResponse, err := authZPlugin.AuthZResponse(&request) |
|
| 106 |
+ if err != nil {
|
|
| 107 |
+ t.Fatalf("Failed to authorize request %v", err)
|
|
| 108 |
+ } |
|
| 109 |
+ |
|
| 110 |
+ if !reflect.DeepEqual(server.replayResponse, *actualResponse) {
|
|
| 111 |
+ t.Fatalf("Response must be equal")
|
|
| 112 |
+ } |
|
| 113 |
+ if !reflect.DeepEqual(request, server.recordedRequest) {
|
|
| 114 |
+ t.Fatalf("Requests must be equal")
|
|
| 115 |
+ } |
|
| 116 |
+} |
|
| 117 |
+ |
|
| 118 |
+func TestResponseModifier(t *testing.T) {
|
|
| 119 |
+ r := httptest.NewRecorder() |
|
| 120 |
+ m := NewResponseModifier(r) |
|
| 121 |
+ m.Header().Set("h1", "v1")
|
|
| 122 |
+ m.Write([]byte("body"))
|
|
| 123 |
+ m.WriteHeader(500) |
|
| 124 |
+ |
|
| 125 |
+ m.FlushAll() |
|
| 126 |
+ if r.Header().Get("h1") != "v1" {
|
|
| 127 |
+ t.Fatalf("Header value must exists %s", r.Header().Get("h1"))
|
|
| 128 |
+ } |
|
| 129 |
+ if !reflect.DeepEqual(r.Body.Bytes(), []byte("body")) {
|
|
| 130 |
+ t.Fatalf("Body value must exists %s", r.Body.Bytes())
|
|
| 131 |
+ } |
|
| 132 |
+ if r.Code != 500 {
|
|
| 133 |
+ t.Fatalf("Status code must be correct %d", r.Code)
|
|
| 134 |
+ } |
|
| 135 |
+} |
|
| 136 |
+ |
|
| 137 |
+func TestResponseModifierOverride(t *testing.T) {
|
|
| 138 |
+ r := httptest.NewRecorder() |
|
| 139 |
+ m := NewResponseModifier(r) |
|
| 140 |
+ m.Header().Set("h1", "v1")
|
|
| 141 |
+ m.Write([]byte("body"))
|
|
| 142 |
+ m.WriteHeader(500) |
|
| 143 |
+ |
|
| 144 |
+ overrideHeader := make(http.Header) |
|
| 145 |
+ overrideHeader.Add("h1", "v2")
|
|
| 146 |
+ overrideHeaderBytes, err := json.Marshal(overrideHeader) |
|
| 147 |
+ if err != nil {
|
|
| 148 |
+ t.Fatalf("override header failed %v", err)
|
|
| 149 |
+ } |
|
| 150 |
+ |
|
| 151 |
+ m.OverrideHeader(overrideHeaderBytes) |
|
| 152 |
+ m.OverrideBody([]byte("override body"))
|
|
| 153 |
+ m.OverrideStatusCode(404) |
|
| 154 |
+ m.FlushAll() |
|
| 155 |
+ if r.Header().Get("h1") != "v2" {
|
|
| 156 |
+ t.Fatalf("Header value must exists %s", r.Header().Get("h1"))
|
|
| 157 |
+ } |
|
| 158 |
+ if !reflect.DeepEqual(r.Body.Bytes(), []byte("override body")) {
|
|
| 159 |
+ t.Fatalf("Body value must exists %s", r.Body.Bytes())
|
|
| 160 |
+ } |
|
| 161 |
+ if r.Code != 404 {
|
|
| 162 |
+ t.Fatalf("Status code must be correct %d", r.Code)
|
|
| 163 |
+ } |
|
| 164 |
+} |
|
| 165 |
+ |
|
| 166 |
+// createTestPlugin creates a new sample authorization plugin |
|
| 167 |
+func createTestPlugin(t *testing.T) *authorizationPlugin {
|
|
| 168 |
+ plugin := &plugins.Plugin{Name: "authz"}
|
|
| 169 |
+ pwd, err := os.Getwd() |
|
| 170 |
+ if err != nil {
|
|
| 171 |
+ log.Fatal(err) |
|
| 172 |
+ } |
|
| 173 |
+ |
|
| 174 |
+ plugin.Client, err = plugins.NewClient("unix:///"+path.Join(pwd, pluginAddress), tlsconfig.Options{InsecureSkipVerify: true})
|
|
| 175 |
+ if err != nil {
|
|
| 176 |
+ t.Fatalf("Failed to create client %v", err)
|
|
| 177 |
+ } |
|
| 178 |
+ |
|
| 179 |
+ return &authorizationPlugin{name: "plugin", plugin: plugin}
|
|
| 180 |
+} |
|
| 181 |
+ |
|
| 182 |
+// AuthZPluginTestServer is a simple server that implements the authZ plugin interface |
|
| 183 |
+type authZPluginTestServer struct {
|
|
| 184 |
+ listener net.Listener |
|
| 185 |
+ t *testing.T |
|
| 186 |
+ // request stores the request sent from the daemon to the plugin |
|
| 187 |
+ recordedRequest Request |
|
| 188 |
+ // response stores the response sent from the plugin to the daemon |
|
| 189 |
+ replayResponse Response |
|
| 190 |
+} |
|
| 191 |
+ |
|
| 192 |
+// start starts the test server that implements the plugin |
|
| 193 |
+func (t *authZPluginTestServer) start() {
|
|
| 194 |
+ r := mux.NewRouter() |
|
| 195 |
+ os.Remove(pluginAddress) |
|
| 196 |
+ l, err := net.ListenUnix("unix", &net.UnixAddr{Name: pluginAddress, Net: "unix"})
|
|
| 197 |
+ if err != nil {
|
|
| 198 |
+ t.t.Fatalf("Failed to listen %v", err)
|
|
| 199 |
+ } |
|
| 200 |
+ t.listener = l |
|
| 201 |
+ |
|
| 202 |
+ r.HandleFunc("/Plugin.Activate", t.activate)
|
|
| 203 |
+ r.HandleFunc("/"+AuthZApiRequest, t.auth)
|
|
| 204 |
+ r.HandleFunc("/"+AuthZApiResponse, t.auth)
|
|
| 205 |
+ t.listener, err = net.Listen("tcp", pluginAddress)
|
|
| 206 |
+ server := http.Server{Handler: r, Addr: pluginAddress}
|
|
| 207 |
+ server.Serve(l) |
|
| 208 |
+} |
|
| 209 |
+ |
|
| 210 |
+// stop stops the test server that implements the plugin |
|
| 211 |
+func (t *authZPluginTestServer) stop() {
|
|
| 212 |
+ os.Remove(pluginAddress) |
|
| 213 |
+ if t.listener != nil {
|
|
| 214 |
+ t.listener.Close() |
|
| 215 |
+ } |
|
| 216 |
+} |
|
| 217 |
+ |
|
| 218 |
+// auth is a used to record/replay the authentication api messages |
|
| 219 |
+func (t *authZPluginTestServer) auth(w http.ResponseWriter, r *http.Request) {
|
|
| 220 |
+ t.recordedRequest = Request{}
|
|
| 221 |
+ defer r.Body.Close() |
|
| 222 |
+ body, err := ioutil.ReadAll(r.Body) |
|
| 223 |
+ json.Unmarshal(body, &t.recordedRequest) |
|
| 224 |
+ b, err := json.Marshal(t.replayResponse) |
|
| 225 |
+ if err != nil {
|
|
| 226 |
+ log.Fatal(err) |
|
| 227 |
+ } |
|
| 228 |
+ w.Write(b) |
|
| 229 |
+} |
|
| 230 |
+ |
|
| 231 |
+func (t *authZPluginTestServer) activate(w http.ResponseWriter, r *http.Request) {
|
|
| 232 |
+ b, err := json.Marshal(plugins.Manifest{Implements: []string{AuthZApiImplements}})
|
|
| 233 |
+ if err != nil {
|
|
| 234 |
+ log.Fatal(err) |
|
| 235 |
+ } |
|
| 236 |
+ w.Write(b) |
|
| 237 |
+} |