worker: Add identity filter and client oauth support

This commit is contained in:
sanne 2021-06-07 09:33:21 +02:00 committed by Sanne Raymaekers
parent 968e7b210f
commit 0ea31c39d5
11 changed files with 277 additions and 65 deletions

View file

@ -50,9 +50,14 @@ func externalRequest(method, path, body string) *http.Response {
return resp
}
func internalRequest(api http.Handler, method, path, body string) *http.Response {
func internalRequest(api http.Handler, method, path, body string, header map[string]string) *http.Response {
req := httptest.NewRequest(method, path, bytes.NewReader([]byte(body)))
req.Header.Set("Content-Type", "application/json")
for k, h := range header {
req.Header.Set(k, h)
}
resp := httptest.NewRecorder()
api.ServeHTTP(resp, req)
@ -66,10 +71,14 @@ func SendHTTP(api http.Handler, external bool, method, path, body string) *http.
}
return externalRequest(method, path, body)
} else {
return internalRequest(api, method, path, body)
return internalRequest(api, method, path, body, map[string]string{})
}
}
func SendHTTPWithHeader(api http.Handler, method, path, body string, header map[string]string) *http.Response {
return internalRequest(api, method, path, body, header)
}
// this function serves to drop fields that shouldn't be tested from the unmarshalled json objects
func dropFields(obj interface{}, fields ...string) {
switch v := obj.(type) {